simple-circuit-engine 0.0.11 → 0.0.13

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 (161) hide show
  1. package/AGENTS.md +11 -7
  2. package/CLAUDE.md +6 -6
  3. package/README.md +5 -2
  4. package/dist/core/index.d.ts +0 -1
  5. package/dist/core/index.js +85 -2115
  6. package/dist/core/setup.d.ts +25 -0
  7. package/dist/core/simulation/CircuitRunner.d.ts +176 -0
  8. package/dist/core/simulation/DirtyTracker.d.ts +87 -0
  9. package/dist/core/simulation/EventQueue.d.ts +68 -0
  10. package/dist/core/simulation/StateManager.d.ts +100 -0
  11. package/dist/core/simulation/behaviors/BehaviorRegistry.d.ts +70 -0
  12. package/dist/core/simulation/behaviors/ComponentBehavior.d.ts +53 -0
  13. package/dist/core/simulation/behaviors/arithmetic/AdderBehavior.d.ts +28 -0
  14. package/dist/core/simulation/behaviors/arithmetic/ArithmeticBehaviorMixin.d.ts +63 -0
  15. package/dist/core/simulation/behaviors/arithmetic/EightBitAdderBehavior.d.ts +51 -0
  16. package/dist/core/simulation/behaviors/arithmetic/EightBitOnesComplementBehavior.d.ts +29 -0
  17. package/dist/core/simulation/behaviors/arithmetic/HalfAdderBehavior.d.ts +22 -0
  18. package/dist/core/simulation/behaviors/arithmetic/index.d.ts +7 -0
  19. package/dist/core/simulation/behaviors/basic/BatteryBehavior.d.ts +14 -0
  20. package/dist/core/simulation/behaviors/basic/ClockBehavior.d.ts +24 -0
  21. package/dist/core/simulation/behaviors/basic/DoubleThrowSwitchBehavior.d.ts +33 -0
  22. package/dist/core/simulation/behaviors/basic/LightbulbBehavior.d.ts +23 -0
  23. package/dist/core/simulation/behaviors/basic/RectangleLEDBehavior.d.ts +24 -0
  24. package/dist/core/simulation/behaviors/basic/RelayBehavior.d.ts +33 -0
  25. package/dist/core/simulation/behaviors/basic/SmallLEDBehavior.d.ts +24 -0
  26. package/dist/core/simulation/behaviors/basic/SwitchBehavior.d.ts +33 -0
  27. package/dist/core/simulation/behaviors/basic/index.d.ts +20 -0
  28. package/dist/core/simulation/behaviors/gates/InverterBehavior.d.ts +29 -0
  29. package/dist/core/simulation/behaviors/gates/Nand4GateBehavior.d.ts +18 -0
  30. package/dist/core/simulation/behaviors/gates/Nand8GateBehavior.d.ts +18 -0
  31. package/dist/core/simulation/behaviors/gates/NandGateBehavior.d.ts +28 -0
  32. package/dist/core/simulation/behaviors/gates/Nor4GateBehavior.d.ts +18 -0
  33. package/dist/core/simulation/behaviors/gates/Nor8GateBehavior.d.ts +18 -0
  34. package/dist/core/simulation/behaviors/gates/NorGateBehavior.d.ts +22 -0
  35. package/dist/core/simulation/behaviors/gates/Xor4GateBehavior.d.ts +18 -0
  36. package/dist/core/simulation/behaviors/gates/Xor8GateBehavior.d.ts +18 -0
  37. package/dist/core/simulation/behaviors/gates/XorGateBehavior.d.ts +22 -0
  38. package/dist/core/simulation/behaviors/gates/index.d.ts +34 -0
  39. package/dist/core/simulation/behaviors/index.d.ts +28 -0
  40. package/dist/core/simulation/behaviors/types.d.ts +101 -0
  41. package/dist/core/simulation/index.d.ts +18 -0
  42. package/dist/core/simulation/states/ComponentState.d.ts +57 -0
  43. package/dist/core/simulation/states/SimulationState.d.ts +46 -0
  44. package/dist/core/simulation/states/arithmetic/AdderState.d.ts +16 -0
  45. package/dist/core/simulation/states/arithmetic/ArithmeticState.d.ts +53 -0
  46. package/dist/core/simulation/states/arithmetic/EightBitAdderState.d.ts +25 -0
  47. package/dist/core/simulation/states/arithmetic/EightBitOnesComplementState.d.ts +18 -0
  48. package/dist/core/simulation/states/arithmetic/HalfAdderState.d.ts +16 -0
  49. package/dist/core/simulation/states/arithmetic/index.d.ts +7 -0
  50. package/dist/core/simulation/states/basic/BatteryState.d.ts +16 -0
  51. package/dist/core/simulation/states/basic/ClockState.d.ts +16 -0
  52. package/dist/core/simulation/states/basic/DoubleThrowSwitchState.d.ts +21 -0
  53. package/dist/core/simulation/states/basic/LightbulbState.d.ts +21 -0
  54. package/dist/core/simulation/states/basic/RectangleLEDState.d.ts +9 -0
  55. package/dist/core/simulation/states/basic/RelayState.d.ts +25 -0
  56. package/dist/core/simulation/states/basic/SmallLEDState.d.ts +21 -0
  57. package/dist/core/simulation/states/basic/SwitchState.d.ts +25 -0
  58. package/dist/core/simulation/states/gates/InverterState.d.ts +17 -0
  59. package/dist/core/simulation/states/gates/Nand4GateState.d.ts +10 -0
  60. package/dist/core/simulation/states/gates/Nand8GateState.d.ts +10 -0
  61. package/dist/core/simulation/states/gates/NandGateState.d.ts +16 -0
  62. package/dist/core/simulation/states/gates/Nor4GateState.d.ts +10 -0
  63. package/dist/core/simulation/states/gates/Nor8GateState.d.ts +10 -0
  64. package/dist/core/simulation/states/gates/NorGateState.d.ts +10 -0
  65. package/dist/core/simulation/states/gates/Xor4GateState.d.ts +10 -0
  66. package/dist/core/simulation/states/gates/Xor8GateState.d.ts +10 -0
  67. package/dist/core/simulation/states/gates/XorGateState.d.ts +10 -0
  68. package/dist/core/simulation/states/gates/index.d.ts +25 -0
  69. package/dist/core/simulation/states/index.d.ts +31 -0
  70. package/dist/core/simulation/states/types.d.ts +32 -0
  71. package/dist/core/simulation/types.d.ts +155 -0
  72. package/dist/core/topology/Circuit.d.ts +420 -0
  73. package/dist/core/topology/CircuitMetadata.d.ts +24 -0
  74. package/dist/core/topology/CircuitOptions.d.ts +14 -0
  75. package/dist/core/topology/Component.d.ts +153 -0
  76. package/dist/core/topology/ENode.d.ts +200 -0
  77. package/dist/core/topology/Wire.d.ts +130 -0
  78. package/dist/core/topology/delays.d.ts +52 -0
  79. package/dist/core/topology/index.d.ts +14 -0
  80. package/dist/core/topology/types.d.ts +189 -0
  81. package/dist/core/utils/CameraOptions.d.ts +83 -0
  82. package/dist/core/utils/MemoizeDecorator.d.ts +9 -0
  83. package/dist/core/utils/Position.d.ts +166 -0
  84. package/dist/core/utils/Position3D.d.ts +77 -0
  85. package/dist/core/utils/Rotation.d.ts +82 -0
  86. package/dist/core/utils/index.d.ts +24 -0
  87. package/dist/core/utils/types.d.ts +35 -0
  88. package/dist/core-b6Q8w2sn.js +3560 -0
  89. package/dist/core-b6Q8w2sn.js.map +1 -0
  90. package/dist/i18n/index.d.ts +882 -0
  91. package/dist/i18n/locales/en.json.d.ts +268 -0
  92. package/dist/i18n/locales/fr.json.d.ts +268 -0
  93. package/dist/index.d.ts +14 -6306
  94. package/dist/index.js +136 -112
  95. package/dist/scene/CircuitEngine.d.ts +283 -0
  96. package/dist/scene/index.d.ts +1 -2
  97. package/dist/scene/index.js +50 -41
  98. package/dist/scene/setup.d.ts +26 -0
  99. package/dist/scene/shared/AbstractCircuitController.d.ts +217 -0
  100. package/dist/scene/shared/BranchingPointVisualFactory.d.ts +70 -0
  101. package/dist/scene/shared/EventEmitter.d.ts +92 -0
  102. package/dist/scene/shared/HoverManager.d.ts +151 -0
  103. package/dist/scene/shared/SelectionManager.d.ts +159 -0
  104. package/dist/scene/shared/WireVisualManager.d.ts +242 -0
  105. package/dist/scene/shared/components/ComponentVisualFactory.d.ts +438 -0
  106. package/dist/scene/shared/components/DefaultVisualFactory.d.ts +51 -0
  107. package/dist/scene/shared/components/FactoryRegistry.d.ts +84 -0
  108. package/dist/scene/shared/components/GroupedFactoryRegistry.d.ts +153 -0
  109. package/dist/scene/shared/components/arithmetic/AdderVisualFactory.d.ts +54 -0
  110. package/dist/scene/shared/components/arithmetic/EightBitAdderVisualFactory.d.ts +45 -0
  111. package/dist/scene/shared/components/arithmetic/EightBitOnesComplementVisualFactory.d.ts +63 -0
  112. package/dist/scene/shared/components/arithmetic/HalfAdderVisualFactory.d.ts +55 -0
  113. package/dist/scene/shared/components/arithmetic/index.d.ts +4 -0
  114. package/dist/scene/shared/components/basic/BatteryVisualFactory.d.ts +13 -0
  115. package/dist/scene/shared/components/basic/ClockVisualFactory.d.ts +79 -0
  116. package/dist/scene/shared/components/basic/DoubleThrowSwitchVisualFactory.d.ts +87 -0
  117. package/dist/scene/shared/components/basic/LabelVisualFactory.d.ts +148 -0
  118. package/dist/scene/shared/components/basic/LightbulbVisualFactory.d.ts +72 -0
  119. package/dist/scene/shared/components/basic/RectangleLEDVisualFactory.d.ts +86 -0
  120. package/dist/scene/shared/components/basic/RelayVisualFactory.d.ts +92 -0
  121. package/dist/scene/shared/components/basic/SmallLEDVisualFactory.d.ts +86 -0
  122. package/dist/scene/shared/components/basic/SwitchVisualFactory.d.ts +85 -0
  123. package/dist/scene/shared/components/gates/InverterVisualFactory.d.ts +104 -0
  124. package/dist/scene/shared/components/gates/Nand4GateVisualFactory.d.ts +27 -0
  125. package/dist/scene/shared/components/gates/Nand8GateVisualFactory.d.ts +27 -0
  126. package/dist/scene/shared/components/gates/NandGateVisualFactory.d.ts +101 -0
  127. package/dist/scene/shared/components/gates/Nor4GateVisualFactory.d.ts +27 -0
  128. package/dist/scene/shared/components/gates/Nor8GateVisualFactory.d.ts +27 -0
  129. package/dist/scene/shared/components/gates/NorGateVisualFactory.d.ts +101 -0
  130. package/dist/scene/shared/components/gates/Xor4GateVisualFactory.d.ts +29 -0
  131. package/dist/scene/shared/components/gates/Xor8GateVisualFactory.d.ts +29 -0
  132. package/dist/scene/shared/components/gates/XorGateVisualFactory.d.ts +103 -0
  133. package/dist/scene/shared/components/index.d.ts +33 -0
  134. package/dist/scene/shared/components/types.d.ts +43 -0
  135. package/dist/scene/shared/types.d.ts +474 -0
  136. package/dist/scene/shared/utils/CameraUtils.d.ts +23 -0
  137. package/dist/scene/shared/utils/ColorUtils.d.ts +26 -0
  138. package/dist/scene/shared/utils/ControlsUtils.d.ts +8 -0
  139. package/dist/scene/shared/utils/GeometryUtils.d.ts +337 -0
  140. package/dist/scene/shared/utils/LayerConstants.d.ts +40 -0
  141. package/dist/scene/shared/utils/LightingUtils.d.ts +31 -0
  142. package/dist/scene/shared/utils/MaterialUtils.d.ts +73 -0
  143. package/dist/scene/shared/utils/Options.d.ts +16 -0
  144. package/dist/scene/simulation/CircuitRunnerController.d.ts +227 -0
  145. package/dist/scene/static/CircuitController.d.ts +228 -0
  146. package/dist/scene/static/CircuitWriter.d.ts +146 -0
  147. package/dist/scene/static/PinTooltipWidget.d.ts +31 -0
  148. package/dist/scene/static/tools/BuildTool.d.ts +290 -0
  149. package/dist/scene/static/tools/ComponentPickerWidget.d.ts +89 -0
  150. package/dist/scene/static/tools/ConfigPanelWidget.d.ts +107 -0
  151. package/dist/scene/static/tools/MultiSelectTool.d.ts +265 -0
  152. package/dist/scene-D4QcWeiq.js +8745 -0
  153. package/dist/scene-D4QcWeiq.js.map +1 -0
  154. package/package.json +29 -25
  155. package/dist/CircuitRunner-BQQlhwjD.js +0 -1981
  156. package/dist/CircuitRunner-BQQlhwjD.js.map +0 -1
  157. package/dist/core/index.js.map +0 -1
  158. package/dist/index.js.map +0 -1
  159. package/dist/scene/index.js.map +0 -1
  160. package/dist/setup-CIq_kgaw.js +0 -10230
  161. package/dist/setup-CIq_kgaw.js.map +0 -1
@@ -0,0 +1,51 @@
1
+ import { Component } from '../../../topology/Component';
2
+ import { ComponentState } from '../../states/ComponentState';
3
+ import { INodeElectricalState } from '../../states/types';
4
+ import { IComponentBehavior, IBehaviorResult } from '../types';
5
+ import { IScheduledEvent } from '../../types';
6
+ import { UUID } from '../../../utils/types';
7
+ import { ArithmeticBehaviorMixin } from './ArithmeticBehaviorMixin';
8
+ /**
9
+ * Behavior for the 8-bit ripple carry adder (8 full adders in series).
10
+ *
11
+ * Unlike the single full adder whose output settles in one transition, the
12
+ * 8-bit adder models **carry propagation**: when inputs change, only stage 0
13
+ * recomputes immediately (with its own propagation delay); the carry then
14
+ * ripples through stages 1–7, one `transitionSpan` per stage.
15
+ *
16
+ * ### State encoding
17
+ *
18
+ * 16 interleaved bits `C7S7 C6S6 … C1S1 C0S0` stored as a 4-digit hex
19
+ * string. Sum at bit `2*i`, carry at bit `2*i+1`.
20
+ * See {@link EightBitAdderState}.
21
+ *
22
+ * ### Ripple algorithm
23
+ *
24
+ * - **`onPinsChange`**: computes ALL 8 stages with new inputs but **old
25
+ * carries** from the current effective state, producing an intermediate
26
+ * state. Schedules one event for carry propagation starting at stage 1.
27
+ * Uses `shouldCancelPending: true` to restart the ripple cleanly when
28
+ * inputs change mid-propagation.
29
+ *
30
+ * - **`onEventFiring`**: lands on the intermediate, then checks whether the
31
+ * next stage's carry-in changed. If so, recomputes that stage, builds the
32
+ * next intermediate, and schedules the following stage. If not, the carry
33
+ * has stopped and the state is stable. Uses `shouldCancelPending: false`.
34
+ *
35
+ * - **Initialization shortcut**: at `targetTick === 0` the full stable state
36
+ * is computed directly via {@link computeTargetStableState} to avoid the
37
+ * init-loop limitation where chained events are dropped.
38
+ *
39
+ * @public
40
+ */
41
+ export declare class EightBitAdderBehavior extends ArithmeticBehaviorMixin implements IComponentBehavior {
42
+ constructor();
43
+ createInitialState(component: Component): ComponentState;
44
+ onPinsChange(component: Component, state: ComponentState, nodeStates: ReadonlyMap<UUID, INodeElectricalState>, targetTick: number): IBehaviorResult;
45
+ onEventFiring(component: Component, state: ComponentState, event: IScheduledEvent): IBehaviorResult;
46
+ /**
47
+ * Compute the fully-settled stable state by propagating the carry chain
48
+ * through all 8 stages. Used at initialization and for test verification.
49
+ */
50
+ protected computeTargetStableState(pinStates: Map<string, INodeElectricalState>): string;
51
+ }
@@ -0,0 +1,29 @@
1
+ import { Component } from '../../../topology/Component';
2
+ import { ComponentState } from '../../states/ComponentState';
3
+ import { INodeElectricalState } from '../../states/types';
4
+ import { IComponentBehavior } from '../types';
5
+ import { ENodeSourceType } from '../../../topology/types';
6
+ import { ArithmeticBehaviorMixin } from './ArithmeticBehaviorMixin';
7
+ /**
8
+ * Behavior for the 8-bit one's complement (8 parallel XOR gates with shared
9
+ * `invert` input).
10
+ *
11
+ * When `invert` is high every output is the bitwise NOT of its input; when low
12
+ * outputs pass through unchanged. All 8 gates fire in parallel — a single
13
+ * `transitionSpan` covers the whole transition (no ripple).
14
+ *
15
+ * State encoding: 9 bits as a 3-hex-char string. Bits 0–7 are outputs,
16
+ * bit 8 is the invert flag. See {@link EightBitOnesComplementState}.
17
+ *
18
+ * The mixin's default `onPinsChange` / `onEventFiring` / `scheduleTransition`
19
+ * handle everything — only `computeTargetStableState` and
20
+ * `allowConductivity` need implementation.
21
+ *
22
+ * @public
23
+ */
24
+ export declare class EightBitOnesComplementBehavior extends ArithmeticBehaviorMixin implements IComponentBehavior {
25
+ constructor();
26
+ createInitialState(component: Component): ComponentState;
27
+ allowConductivity(component: Component, state: ComponentState, _conductivityType: ENodeSourceType, pinId: string, otherPinId: string): boolean;
28
+ protected computeTargetStableState(pinStates: Map<string, INodeElectricalState>): string;
29
+ }
@@ -0,0 +1,22 @@
1
+ import { Component } from '../../../topology/Component';
2
+ import { ComponentState } from '../../states/ComponentState';
3
+ import { INodeElectricalState } from '../../states/types';
4
+ import { IComponentBehavior } from '../types';
5
+ import { ArithmeticBehaviorMixin } from './ArithmeticBehaviorMixin';
6
+ /**
7
+ * Behavior for the Half Adder component (XOR + AND in one block).
8
+ *
9
+ * - `sum = A XOR B`
10
+ * - `carry = A AND B`
11
+ *
12
+ * State encoding follows `${sumBit}${carryBit}` — see {@link HalfAdderState}.
13
+ * Because `sum` and `carry` can never both be high, only three stable states
14
+ * are reachable: `'00' | '10' | '01'`.
15
+ *
16
+ * @public
17
+ */
18
+ export declare class HalfAdderBehavior extends ArithmeticBehaviorMixin implements IComponentBehavior {
19
+ constructor();
20
+ createInitialState(component: Component): ComponentState;
21
+ protected computeTargetStableState(pinStates: Map<string, INodeElectricalState>): string;
22
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Arithmetic components behaviors
3
+ * @module core/simulation/behaviors
4
+ */
5
+ export { ArithmeticBehaviorMixin } from './ArithmeticBehaviorMixin';
6
+ export { HalfAdderBehavior } from './HalfAdderBehavior';
7
+ export { AdderBehavior } from './AdderBehavior';
@@ -0,0 +1,14 @@
1
+ import { Component } from '../../../topology/Component';
2
+ import { ComponentBehaviorMixin } from '../ComponentBehavior';
3
+ import { ComponentState } from '../../states/ComponentState';
4
+ import { IComponentBehavior } from '../types';
5
+ export declare class BatteryBehavior extends ComponentBehaviorMixin implements IComponentBehavior {
6
+ constructor();
7
+ /**
8
+ * Create initial state for a battery.
9
+ *
10
+ * @param component - The Battery component
11
+ * @returns Battery Initial state (always active and delivering voltage)
12
+ */
13
+ createInitialState(component: Component): ComponentState;
14
+ }
@@ -0,0 +1,24 @@
1
+ import { Component } from '../../../topology/Component';
2
+ import { ComponentBehaviorMixin } from '../ComponentBehavior';
3
+ import { ComponentState } from '../../states/ComponentState';
4
+ import { IComponentBehavior, IBehaviorResult } from '../types';
5
+ import { ENodeSourceType } from '../../../topology/types';
6
+ import { IScheduledEvent } from '../../types';
7
+ export declare class ClockBehavior extends ComponentBehaviorMixin implements IComponentBehavior {
8
+ constructor();
9
+ /**
10
+ * Create initial state for a Clock.
11
+ *
12
+ * @param component - The Clock component
13
+ * @returns Clock Initial state (needle rotation)
14
+ */
15
+ createInitialState(component: Component): ComponentState;
16
+ allowConductivity(component: Component, state: ComponentState, _conductivityType: ENodeSourceType, pinId: string, otherPinId: string): boolean;
17
+ /**
18
+ * Clock onStart allows to bootstrap cycling
19
+ * @param component
20
+ * @param state
21
+ */
22
+ onStart(component: Component, state: ComponentState): IBehaviorResult | null;
23
+ onEventFiring(component: Component, state: ComponentState, event: IScheduledEvent): IBehaviorResult;
24
+ }
@@ -0,0 +1,33 @@
1
+ import { Component } from '../../../topology/Component';
2
+ import { ComponentState, INodeElectricalState } from '../../states';
3
+ import { IScheduledEvent, IUserCommand } from '../../types';
4
+ import { ComponentBehaviorMixin } from '../ComponentBehavior';
5
+ import { IBehaviorResult, IComponentBehavior } from '../types';
6
+ import { ENodeSourceType } from '../../../topology/types';
7
+ import { UUID } from '../../../utils';
8
+ /**
9
+ * Behavior implementation for switches components.
10
+ *
11
+ * @public
12
+ */
13
+ export declare class DoubleThrowSwitchBehavior extends ComponentBehaviorMixin implements IComponentBehavior {
14
+ constructor();
15
+ /**
16
+ * Create initial state for a double throw switch (SPDT).
17
+ *
18
+ * @param component - The double Switch component
19
+ * @returns double Switch Initial state (input1 by default)
20
+ */
21
+ createInitialState(component: Component): ComponentState;
22
+ allowConductivity(component: Component, state: ComponentState, _conductivityType: ENodeSourceType, pinId: string, otherPinId: string): boolean;
23
+ /**
24
+ * used for contactor color change
25
+ * @param component
26
+ * @param state
27
+ * @param nodeStates
28
+ * @param _targetTick
29
+ */
30
+ onPinsChange(component: Component, state: ComponentState, nodeStates: ReadonlyMap<UUID, INodeElectricalState>, _targetTick: number): IBehaviorResult;
31
+ onUserCommand(component: Component, state: ComponentState, command: IUserCommand): IBehaviorResult;
32
+ onEventFiring(_component: Component, state: ComponentState, event: IScheduledEvent): IBehaviorResult;
33
+ }
@@ -0,0 +1,23 @@
1
+ import { Component } from '../../../topology/Component';
2
+ import { ComponentState } from '../../states/ComponentState';
3
+ import { BipolarLightEmitterBehaviorMixin } from './index';
4
+ import { IBehaviorResult, IComponentBehavior } from '../types';
5
+ import { INodeElectricalState } from '../../states';
6
+ import { UUID } from '../../../utils/types';
7
+ export declare class LightbulbBehavior extends BipolarLightEmitterBehaviorMixin implements IComponentBehavior {
8
+ constructor();
9
+ /**
10
+ * Create initial state for a lightbulb.
11
+ *
12
+ * @param component - The lightbulb component
13
+ * @returns lightbulbInitial state (always active and delivering voltage)
14
+ */
15
+ createInitialState(component: Component): ComponentState;
16
+ /**
17
+ * @param component
18
+ * @param state
19
+ * @param nodeStates
20
+ * @param targetTick
21
+ */
22
+ onPinsChange(component: Component, state: ComponentState, nodeStates: ReadonlyMap<UUID, INodeElectricalState>, targetTick: number): IBehaviorResult;
23
+ }
@@ -0,0 +1,24 @@
1
+ import { Component } from '../../../topology/Component';
2
+ import { ComponentState } from '../../states/ComponentState';
3
+ import { INodeElectricalState } from '../../states';
4
+ import { BipolarLightEmitterBehaviorMixin } from './index';
5
+ import { IBehaviorResult, IComponentBehavior } from '../types';
6
+ import { UUID } from '../../../utils/types';
7
+ export declare class RectangleLEDBehavior extends BipolarLightEmitterBehaviorMixin implements IComponentBehavior {
8
+ constructor();
9
+ /**
10
+ * Create initial state for a RectangleLED.
11
+ *
12
+ * @param component - The smallLED component
13
+ * @returns LED Initial state (always active and delivering voltage)
14
+ */
15
+ createInitialState(component: Component): ComponentState;
16
+ /**
17
+ * only symmetrical behavior of LEDS is handled for now
18
+ * @param component
19
+ * @param state
20
+ * @param nodeStates
21
+ * @param targetTick
22
+ */
23
+ onPinsChange(component: Component, state: ComponentState, nodeStates: ReadonlyMap<UUID, INodeElectricalState>, targetTick: number): IBehaviorResult;
24
+ }
@@ -0,0 +1,33 @@
1
+ import { Component } from '../../../topology/Component';
2
+ import { ComponentState } from '../../states/ComponentState';
3
+ import { IScheduledEvent } from '../../types';
4
+ import { ComponentBehaviorMixin } from '../ComponentBehavior';
5
+ import { IBehaviorResult, IComponentBehavior } from '../types';
6
+ import { INodeElectricalState } from '../../states';
7
+ import { UUID } from '../../../utils/types';
8
+ import { ENodeSourceType } from '../../../topology/types';
9
+ /**
10
+ * Behavior implementation for relays components.
11
+ *
12
+ * @public
13
+ */
14
+ export declare class RelayBehavior extends ComponentBehaviorMixin implements IComponentBehavior {
15
+ constructor();
16
+ /**
17
+ * Create initial state for a relay.
18
+ *
19
+ * @param component - The Relay component
20
+ * @returns Relay Initial state (open by default)
21
+ */
22
+ createInitialState(component: Component): ComponentState;
23
+ allowConductivity(component: Component, state: ComponentState, _conductivityType: ENodeSourceType, pinId: string, otherPinId: string): boolean;
24
+ /**
25
+ * Relay cmd pins need to have voltage and current so that relay contactor stays closed
26
+ * @param component
27
+ * @param state
28
+ * @param nodeStates
29
+ * @param targetTick
30
+ */
31
+ onPinsChange(component: Component, state: ComponentState, nodeStates: ReadonlyMap<UUID, INodeElectricalState>, targetTick: number): IBehaviorResult;
32
+ onEventFiring(_component: Component, state: ComponentState, event: IScheduledEvent): IBehaviorResult;
33
+ }
@@ -0,0 +1,24 @@
1
+ import { Component } from '../../../topology/Component';
2
+ import { ComponentState } from '../../states/ComponentState';
3
+ import { BipolarLightEmitterBehaviorMixin } from './index';
4
+ import { IBehaviorResult, IComponentBehavior } from '../types';
5
+ import { INodeElectricalState } from '../../states';
6
+ import { UUID } from '../../../utils/types';
7
+ export declare class SmallLEDBehavior extends BipolarLightEmitterBehaviorMixin implements IComponentBehavior {
8
+ constructor();
9
+ /**
10
+ * Create initial state for a smallLED.
11
+ *
12
+ * @param component - The smallLED component
13
+ * @returns LED Initial state (always active and delivering voltage)
14
+ */
15
+ createInitialState(component: Component): ComponentState;
16
+ /**
17
+ * only symmetrical behavior of LEDS is handled for now
18
+ * @param component
19
+ * @param state
20
+ * @param nodeStates
21
+ * @param targetTick
22
+ */
23
+ onPinsChange(component: Component, state: ComponentState, nodeStates: ReadonlyMap<UUID, INodeElectricalState>, targetTick: number): IBehaviorResult;
24
+ }
@@ -0,0 +1,33 @@
1
+ import { Component } from '../../../topology/Component';
2
+ import { ComponentState, INodeElectricalState } from '../../states';
3
+ import { IScheduledEvent, IUserCommand } from '../../types';
4
+ import { ComponentBehaviorMixin } from '../ComponentBehavior';
5
+ import { IBehaviorResult, IComponentBehavior } from '../types';
6
+ import { ENodeSourceType } from '../../../topology/types';
7
+ import { UUID } from '../../../utils';
8
+ /**
9
+ * Behavior implementation for switches components.
10
+ *
11
+ * @public
12
+ */
13
+ export declare class SwitchBehavior extends ComponentBehaviorMixin implements IComponentBehavior {
14
+ constructor();
15
+ /**
16
+ * Create initial state for a switch.
17
+ *
18
+ * @param component - The Switch component
19
+ * @returns Switch Initial state (open by default)
20
+ */
21
+ createInitialState(component: Component): ComponentState;
22
+ allowConductivity(_component: Component, _state: ComponentState, _conductivityType: ENodeSourceType, _pinId: string, _otherPinId: string): boolean;
23
+ /**
24
+ * used for contactor color change
25
+ * @param component
26
+ * @param state
27
+ * @param nodeStates
28
+ * @param _targetTick
29
+ */
30
+ onPinsChange(component: Component, state: ComponentState, nodeStates: ReadonlyMap<UUID, INodeElectricalState>, _targetTick: number): IBehaviorResult;
31
+ onUserCommand(component: Component, state: ComponentState, command: IUserCommand): IBehaviorResult;
32
+ onEventFiring(_component: Component, state: ComponentState, event: IScheduledEvent): IBehaviorResult;
33
+ }
@@ -0,0 +1,20 @@
1
+ import { Component } from '../../../topology/Component';
2
+ import { ComponentState } from '../../states/ComponentState.js';
3
+ import { IScheduledEvent } from '../../types';
4
+ import { ComponentBehaviorMixin } from '../ComponentBehavior';
5
+ import { ENodeSourceType } from '../../../topology/types';
6
+ import { IBehaviorResult } from '../types';
7
+ /**
8
+ * to factorize behaviors of bipolar components emitting light (lightbulb/ LEDs even if it's a big simplification...)
9
+ */
10
+ export declare abstract class BipolarLightEmitterBehaviorMixin extends ComponentBehaviorMixin {
11
+ protected getBehavior(component: Component, state: ComponentState, activationCondition: boolean, targetTick: number): IBehaviorResult;
12
+ allowConductivity(_component: Component, _state: ComponentState, _conductivityType: ENodeSourceType, _pinId: string, _otherPinId: string): boolean;
13
+ onEventFiring(_component: Component, state: ComponentState, event: IScheduledEvent): IBehaviorResult;
14
+ }
15
+ /**
16
+ * Get the tick count from command parameters.
17
+ * @param parameters - Command parameters map
18
+ * @returns Number of ticks for transition (minimum 1)
19
+ */
20
+ export declare function getTickCount(parameters: Map<string, string> | null | undefined): number;
@@ -0,0 +1,29 @@
1
+ import { Component } from '../../../topology/Component';
2
+ import { ComponentState } from '../../states/ComponentState';
3
+ import { LogicGateBehaviorMixin } from './index';
4
+ import { IBehaviorResult, IComponentBehavior } from '../types';
5
+ import { INodeElectricalState } from '../../states';
6
+ import { UUID } from '../../../utils/types';
7
+ /**
8
+ * Behavior implementation for Inverters components.
9
+ *
10
+ * @public
11
+ */
12
+ export declare class InverterBehavior extends LogicGateBehaviorMixin implements IComponentBehavior {
13
+ constructor();
14
+ /**
15
+ * Create initial state for a Inverter.
16
+ *
17
+ * @param component - The Inverter component
18
+ * @returns Inverter Initial state (HIGH if input LOW, LOW if input LOW for positive activation logic)
19
+ */
20
+ createInitialState(component: Component): ComponentState;
21
+ /**
22
+ * Inverter needs LOW on input to drive the output HIGH, and on the contrary Buffer needs HIGH on input to output HIGH
23
+ * @param component
24
+ * @param state
25
+ * @param nodeStates
26
+ * @param targetTick
27
+ */
28
+ onPinsChange(component: Component, state: ComponentState, nodeStates: ReadonlyMap<UUID, INodeElectricalState>, targetTick: number): IBehaviorResult;
29
+ }
@@ -0,0 +1,18 @@
1
+ import { Component } from '../../../topology/Component';
2
+ import { ComponentState } from '../../states/ComponentState';
3
+ import { LogicGateBehaviorMixin } from './index';
4
+ import { IBehaviorResult, IComponentBehavior } from '../types';
5
+ import { INodeElectricalState } from '../../states';
6
+ import { UUID } from '../../../utils/types';
7
+ /**
8
+ * Behavior implementation for NAND4 Gate components (4 inputs).
9
+ * With negative (default) activationLogic: NAND gate (output high when ANY input is low).
10
+ * With positive activationLogic: AND gate (output high when ALL 4 inputs are high).
11
+ *
12
+ * @public
13
+ */
14
+ export declare class Nand4GateBehavior extends LogicGateBehaviorMixin implements IComponentBehavior {
15
+ constructor();
16
+ createInitialState(component: Component): ComponentState;
17
+ onPinsChange(component: Component, state: ComponentState, nodeStates: ReadonlyMap<UUID, INodeElectricalState>, targetTick: number): IBehaviorResult;
18
+ }
@@ -0,0 +1,18 @@
1
+ import { Component } from '../../../topology/Component';
2
+ import { ComponentState } from '../../states/ComponentState';
3
+ import { LogicGateBehaviorMixin } from './index';
4
+ import { IBehaviorResult, IComponentBehavior } from '../types';
5
+ import { INodeElectricalState } from '../../states/types';
6
+ import { UUID } from '../../../utils/types';
7
+ /**
8
+ * Behavior implementation for NAND8 Gate components (8 inputs).
9
+ * With negative (default) activationLogic: NAND gate (output high when ANY input is low).
10
+ * With positive activationLogic: AND gate (output high when ALL 8 inputs are high).
11
+ *
12
+ * @public
13
+ */
14
+ export declare class Nand8GateBehavior extends LogicGateBehaviorMixin implements IComponentBehavior {
15
+ constructor();
16
+ createInitialState(component: Component): ComponentState;
17
+ onPinsChange(component: Component, state: ComponentState, nodeStates: ReadonlyMap<UUID, INodeElectricalState>, targetTick: number): IBehaviorResult;
18
+ }
@@ -0,0 +1,28 @@
1
+ import { Component } from '../../../topology/Component';
2
+ import { ComponentState } from '../../states/ComponentState';
3
+ import { LogicGateBehaviorMixin } from './index';
4
+ import { IBehaviorResult, IComponentBehavior } from '../types';
5
+ import { INodeElectricalState } from '../../states';
6
+ import { UUID } from '../../../utils/types';
7
+ /**
8
+ * Behavior implementation for NAND Gate components.
9
+ * With negative (default) activationLogic: NAND gate (output high when ANY input is low).
10
+ * With positive activationLogic: AND gate (output high when ALL inputs are high).
11
+ *
12
+ * @public
13
+ */
14
+ export declare class NandGateBehavior extends LogicGateBehaviorMixin implements IComponentBehavior {
15
+ constructor();
16
+ /**
17
+ * Create initial state for an NAND Gate.
18
+ *
19
+ * @param component - The NAND Gate component
20
+ * @returns Initial state (low by default, high for negative activation logic)
21
+ */
22
+ createInitialState(component: Component): ComponentState;
23
+ /**
24
+ * NAND gate output goes high when ANY inputs LACK voltage.
25
+ * With positive activationLogic (AND), output goes high when ALL inputs HAS voltage.
26
+ */
27
+ onPinsChange(component: Component, state: ComponentState, nodeStates: ReadonlyMap<UUID, INodeElectricalState>, targetTick: number): IBehaviorResult;
28
+ }
@@ -0,0 +1,18 @@
1
+ import { Component } from '../../../topology/Component';
2
+ import { ComponentState } from '../../states/ComponentState';
3
+ import { LogicGateBehaviorMixin } from './index';
4
+ import { IBehaviorResult, IComponentBehavior } from '../types';
5
+ import { INodeElectricalState } from '../../states';
6
+ import { UUID } from '../../../utils/types';
7
+ /**
8
+ * Behavior implementation for NOR4 Gate components (4 inputs).
9
+ * With negative (default) activationLogic: NOR gate (output high when ALL 4 inputs are low).
10
+ * With positive activationLogic: OR gate (output high when ANY of 4 inputs is high).
11
+ *
12
+ * @public
13
+ */
14
+ export declare class Nor4GateBehavior extends LogicGateBehaviorMixin implements IComponentBehavior {
15
+ constructor();
16
+ createInitialState(component: Component): ComponentState;
17
+ onPinsChange(component: Component, state: ComponentState, nodeStates: ReadonlyMap<UUID, INodeElectricalState>, targetTick: number): IBehaviorResult;
18
+ }
@@ -0,0 +1,18 @@
1
+ import { Component } from '../../../topology/Component';
2
+ import { ComponentState } from '../../states/ComponentState';
3
+ import { LogicGateBehaviorMixin } from './index';
4
+ import { IBehaviorResult, IComponentBehavior } from '../types';
5
+ import { INodeElectricalState } from '../../states';
6
+ import { UUID } from '../../../utils/types';
7
+ /**
8
+ * Behavior implementation for NOR8 Gate components (8 inputs).
9
+ * With negative (default) activationLogic: NOR gate (output high when ALL 8 inputs are low).
10
+ * With positive activationLogic: OR gate (output high when ANY of 8 inputs is high).
11
+ *
12
+ * @public
13
+ */
14
+ export declare class Nor8GateBehavior extends LogicGateBehaviorMixin implements IComponentBehavior {
15
+ constructor();
16
+ createInitialState(component: Component): ComponentState;
17
+ onPinsChange(component: Component, state: ComponentState, nodeStates: ReadonlyMap<UUID, INodeElectricalState>, targetTick: number): IBehaviorResult;
18
+ }
@@ -0,0 +1,22 @@
1
+ import { Component } from '../../../topology/Component';
2
+ import { ComponentState } from '../../states/ComponentState';
3
+ import { LogicGateBehaviorMixin } from './index';
4
+ import { IBehaviorResult, IComponentBehavior } from '../types';
5
+ import { INodeElectricalState } from '../../states/types';
6
+ import { UUID } from '../../../utils/types';
7
+ /**
8
+ * Behavior implementation for NOR Gate components.
9
+ * With negative (default) activationLogic: NOR gate (output high when ALL inputs are low).
10
+ * With positive activationLogic: OR gate (output high when ANY input is high).
11
+ *
12
+ * @public
13
+ */
14
+ export declare class NorGateBehavior extends LogicGateBehaviorMixin implements IComponentBehavior {
15
+ constructor();
16
+ createInitialState(component: Component): ComponentState;
17
+ /**
18
+ * NOR gate output goes high when ALL inputs LACK voltage.
19
+ * With positive activationLogic (OR), output goes high when ANY inputs HAS voltage.
20
+ */
21
+ onPinsChange(component: Component, state: ComponentState, nodeStates: ReadonlyMap<UUID, INodeElectricalState>, targetTick: number): IBehaviorResult;
22
+ }
@@ -0,0 +1,18 @@
1
+ import { Component } from '../../../topology/Component';
2
+ import { ComponentState } from '../../states/ComponentState';
3
+ import { LogicGateBehaviorMixin } from './index';
4
+ import { IBehaviorResult, IComponentBehavior } from '../types';
5
+ import { INodeElectricalState } from '../../states';
6
+ import { UUID } from '../../../utils/types';
7
+ /**
8
+ * Behavior implementation for XOR4 Gate components (4 inputs).
9
+ * With positive activationLogic: XOR gate (output high when odd number of inputs are high).
10
+ * With negative activationLogic: XNOR gate (output high when even number of inputs are high).
11
+ *
12
+ * @public
13
+ */
14
+ export declare class Xor4GateBehavior extends LogicGateBehaviorMixin implements IComponentBehavior {
15
+ constructor();
16
+ createInitialState(component: Component): ComponentState;
17
+ onPinsChange(component: Component, state: ComponentState, nodeStates: ReadonlyMap<UUID, INodeElectricalState>, targetTick: number): IBehaviorResult;
18
+ }
@@ -0,0 +1,18 @@
1
+ import { Component } from '../../../topology/Component';
2
+ import { ComponentState } from '../../states/ComponentState';
3
+ import { LogicGateBehaviorMixin } from './index';
4
+ import { IBehaviorResult, IComponentBehavior } from '../types';
5
+ import { INodeElectricalState } from '../../states';
6
+ import { UUID } from '../../../utils/types';
7
+ /**
8
+ * Behavior implementation for XOR8 Gate components (8 inputs).
9
+ * With positive activationLogic: XOR gate (output high when odd number of inputs are high).
10
+ * With negative activationLogic: XNOR gate (output high when even number of inputs are high).
11
+ *
12
+ * @public
13
+ */
14
+ export declare class Xor8GateBehavior extends LogicGateBehaviorMixin implements IComponentBehavior {
15
+ constructor();
16
+ createInitialState(component: Component): ComponentState;
17
+ onPinsChange(component: Component, state: ComponentState, nodeStates: ReadonlyMap<UUID, INodeElectricalState>, targetTick: number): IBehaviorResult;
18
+ }
@@ -0,0 +1,22 @@
1
+ import { Component } from '../../../topology/Component';
2
+ import { ComponentState } from '../../states/ComponentState';
3
+ import { LogicGateBehaviorMixin } from './index';
4
+ import { IBehaviorResult, IComponentBehavior } from '../types';
5
+ import { INodeElectricalState } from '../../states';
6
+ import { UUID } from '../../../utils/types';
7
+ /**
8
+ * Behavior implementation for XOR Gate components.
9
+ * With positive activationLogic: XOR gate (output high when inputs differ / odd parity).
10
+ * With negative activationLogic: XNOR gate (output high when inputs are equal / even parity).
11
+ *
12
+ * @public
13
+ */
14
+ export declare class XorGateBehavior extends LogicGateBehaviorMixin implements IComponentBehavior {
15
+ constructor();
16
+ createInitialState(component: Component): ComponentState;
17
+ /**
18
+ * XOR gate output goes high when inputs differ (odd parity).
19
+ * With negative activationLogic (XNOR), output goes high when inputs are equal (even parity).
20
+ */
21
+ onPinsChange(component: Component, state: ComponentState, nodeStates: ReadonlyMap<UUID, INodeElectricalState>, targetTick: number): IBehaviorResult;
22
+ }
@@ -0,0 +1,34 @@
1
+ import { ENodeSourceType } from '../../../topology/types';
2
+ import { Component } from '../../../topology/Component';
3
+ import { INodeElectricalState } from '../../states/types';
4
+ import { ComponentState } from '../../states/ComponentState.js';
5
+ import { IScheduledEvent } from '../../types';
6
+ import { ComponentBehaviorMixin } from '../ComponentBehavior';
7
+ import { IBehaviorResult } from '../types';
8
+ /**
9
+ * to factorize default implementations in logic gates behaviors
10
+ */
11
+ export declare abstract class LogicGateBehaviorMixin extends ComponentBehaviorMixin {
12
+ /**
13
+ * default return for all logic gates when vcc fails -> go low immediately
14
+ * @param state
15
+ * @param pinStates
16
+ * @protected
17
+ */
18
+ protected vccGuardBehavior(state: ComponentState, pinStates: Map<string, INodeElectricalState>, targetTick: number): IBehaviorResult | null;
19
+ /**
20
+ * guard scanning all inputs of logic gates to detect if Any has:
21
+ * - both voltage and ground hence with established flowing current
22
+ * - neither voltage nor ground
23
+ * it makes a not well-defined input between LOW and HIGH
24
+ * in that case gate goes to state indeterminate and output nothing too
25
+ * @param state
26
+ * @param pinStates
27
+ * @param targetTick
28
+ * @protected
29
+ */
30
+ protected nonLogicInputGuardBehavior(state: ComponentState, pinStates: Map<string, INodeElectricalState>, targetTick: number): IBehaviorResult | null;
31
+ protected getBehavior(component: Component, state: ComponentState, activationCondition: boolean, targetTick: number): IBehaviorResult;
32
+ allowConductivity(component: Component, state: ComponentState, _conductivityType: ENodeSourceType, pinId: string, otherPinId: string): boolean;
33
+ onEventFiring(_component: Component, state: ComponentState, event: IScheduledEvent): IBehaviorResult;
34
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Component behavior implementations
3
+ * @module core/simulation/behaviors
4
+ */
5
+ export type { IComponentBehavior, IBehaviorResult } from './types';
6
+ export { BehaviorRegistry } from './BehaviorRegistry.js';
7
+ export { BatteryBehavior } from './basic/BatteryBehavior';
8
+ export { LightbulbBehavior } from './basic/LightbulbBehavior';
9
+ export { RectangleLEDBehavior } from './basic/RectangleLEDBehavior';
10
+ export { RelayBehavior } from './basic/RelayBehavior';
11
+ export { SmallLEDBehavior } from './basic/SmallLEDBehavior';
12
+ export { SwitchBehavior } from './basic/SwitchBehavior';
13
+ export { DoubleThrowSwitchBehavior } from './basic/DoubleThrowSwitchBehavior';
14
+ export { ClockBehavior } from './basic/ClockBehavior';
15
+ export { InverterBehavior } from './gates/InverterBehavior';
16
+ export { NandGateBehavior } from './gates/NandGateBehavior';
17
+ export { Nand4GateBehavior } from './gates/Nand4GateBehavior';
18
+ export { Nand8GateBehavior } from './gates/Nand8GateBehavior';
19
+ export { NorGateBehavior } from './gates/NorGateBehavior';
20
+ export { Nor4GateBehavior } from './gates/Nor4GateBehavior';
21
+ export { Nor8GateBehavior } from './gates/Nor8GateBehavior';
22
+ export { XorGateBehavior } from './gates/XorGateBehavior';
23
+ export { Xor4GateBehavior } from './gates/Xor4GateBehavior';
24
+ export { Xor8GateBehavior } from './gates/Xor8GateBehavior';
25
+ export { HalfAdderBehavior } from './arithmetic/HalfAdderBehavior';
26
+ export { AdderBehavior } from './arithmetic/AdderBehavior';
27
+ export { EightBitAdderBehavior } from './arithmetic/EightBitAdderBehavior';
28
+ export { EightBitOnesComplementBehavior } from './arithmetic/EightBitOnesComplementBehavior';