simple-circuit-engine 0.0.11 → 0.0.12

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 (141) hide show
  1. package/AGENTS.md +10 -7
  2. package/CLAUDE.md +4 -6
  3. package/README.md +5 -2
  4. package/dist/core/index.d.ts +0 -1
  5. package/dist/core/index.js +74 -2114
  6. package/dist/core/setup.d.ts +17 -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/basic/BatteryBehavior.d.ts +14 -0
  14. package/dist/core/simulation/behaviors/basic/ClockBehavior.d.ts +24 -0
  15. package/dist/core/simulation/behaviors/basic/DoubleThrowSwitchBehavior.d.ts +33 -0
  16. package/dist/core/simulation/behaviors/basic/LightbulbBehavior.d.ts +23 -0
  17. package/dist/core/simulation/behaviors/basic/RectangleLEDBehavior.d.ts +24 -0
  18. package/dist/core/simulation/behaviors/basic/RelayBehavior.d.ts +33 -0
  19. package/dist/core/simulation/behaviors/basic/SmallLEDBehavior.d.ts +24 -0
  20. package/dist/core/simulation/behaviors/basic/SwitchBehavior.d.ts +33 -0
  21. package/dist/core/simulation/behaviors/basic/index.d.ts +20 -0
  22. package/dist/core/simulation/behaviors/gates/InverterBehavior.d.ts +29 -0
  23. package/dist/core/simulation/behaviors/gates/Nand4GateBehavior.d.ts +18 -0
  24. package/dist/core/simulation/behaviors/gates/Nand8GateBehavior.d.ts +18 -0
  25. package/dist/core/simulation/behaviors/gates/NandGateBehavior.d.ts +28 -0
  26. package/dist/core/simulation/behaviors/gates/Nor4GateBehavior.d.ts +18 -0
  27. package/dist/core/simulation/behaviors/gates/Nor8GateBehavior.d.ts +18 -0
  28. package/dist/core/simulation/behaviors/gates/NorGateBehavior.d.ts +22 -0
  29. package/dist/core/simulation/behaviors/gates/Xor4GateBehavior.d.ts +18 -0
  30. package/dist/core/simulation/behaviors/gates/Xor8GateBehavior.d.ts +18 -0
  31. package/dist/core/simulation/behaviors/gates/XorGateBehavior.d.ts +22 -0
  32. package/dist/core/simulation/behaviors/gates/index.d.ts +34 -0
  33. package/dist/core/simulation/behaviors/index.d.ts +24 -0
  34. package/dist/core/simulation/behaviors/types.d.ts +101 -0
  35. package/dist/core/simulation/index.d.ts +18 -0
  36. package/dist/core/simulation/states/ComponentState.d.ts +57 -0
  37. package/dist/core/simulation/states/SimulationState.d.ts +46 -0
  38. package/dist/core/simulation/states/basic/BatteryState.d.ts +16 -0
  39. package/dist/core/simulation/states/basic/ClockState.d.ts +16 -0
  40. package/dist/core/simulation/states/basic/DoubleThrowSwitchState.d.ts +21 -0
  41. package/dist/core/simulation/states/basic/LightbulbState.d.ts +21 -0
  42. package/dist/core/simulation/states/basic/RectangleLEDState.d.ts +9 -0
  43. package/dist/core/simulation/states/basic/RelayState.d.ts +25 -0
  44. package/dist/core/simulation/states/basic/SmallLEDState.d.ts +21 -0
  45. package/dist/core/simulation/states/basic/SwitchState.d.ts +25 -0
  46. package/dist/core/simulation/states/gates/InverterState.d.ts +17 -0
  47. package/dist/core/simulation/states/gates/Nand4GateState.d.ts +10 -0
  48. package/dist/core/simulation/states/gates/Nand8GateState.d.ts +10 -0
  49. package/dist/core/simulation/states/gates/NandGateState.d.ts +16 -0
  50. package/dist/core/simulation/states/gates/Nor4GateState.d.ts +10 -0
  51. package/dist/core/simulation/states/gates/Nor8GateState.d.ts +10 -0
  52. package/dist/core/simulation/states/gates/NorGateState.d.ts +10 -0
  53. package/dist/core/simulation/states/gates/Xor4GateState.d.ts +10 -0
  54. package/dist/core/simulation/states/gates/Xor8GateState.d.ts +10 -0
  55. package/dist/core/simulation/states/gates/XorGateState.d.ts +10 -0
  56. package/dist/core/simulation/states/gates/index.d.ts +25 -0
  57. package/dist/core/simulation/states/index.d.ts +26 -0
  58. package/dist/core/simulation/states/types.d.ts +32 -0
  59. package/dist/core/simulation/types.d.ts +155 -0
  60. package/dist/core/topology/Circuit.d.ts +420 -0
  61. package/dist/core/topology/CircuitMetadata.d.ts +24 -0
  62. package/dist/core/topology/CircuitOptions.d.ts +14 -0
  63. package/dist/core/topology/Component.d.ts +152 -0
  64. package/dist/core/topology/ENode.d.ts +200 -0
  65. package/dist/core/topology/Wire.d.ts +130 -0
  66. package/dist/core/topology/delays.d.ts +52 -0
  67. package/dist/core/topology/index.d.ts +14 -0
  68. package/dist/core/topology/types.d.ts +175 -0
  69. package/dist/core/utils/CameraOptions.d.ts +83 -0
  70. package/dist/core/utils/MemoizeDecorator.d.ts +9 -0
  71. package/dist/core/utils/Position.d.ts +166 -0
  72. package/dist/core/utils/Position3D.d.ts +77 -0
  73. package/dist/core/utils/Rotation.d.ts +82 -0
  74. package/dist/core/utils/index.d.ts +24 -0
  75. package/dist/core/utils/types.d.ts +35 -0
  76. package/dist/core-Bjta9Y7_.js +2707 -0
  77. package/dist/core-Bjta9Y7_.js.map +1 -0
  78. package/dist/index.d.ts +13 -6306
  79. package/dist/index.js +117 -110
  80. package/dist/scene/CircuitEngine.d.ts +270 -0
  81. package/dist/scene/index.d.ts +0 -1
  82. package/dist/scene/index.js +43 -39
  83. package/dist/scene/setup.d.ts +18 -0
  84. package/dist/scene/shared/AbstractCircuitController.d.ts +211 -0
  85. package/dist/scene/shared/BranchingPointVisualFactory.d.ts +70 -0
  86. package/dist/scene/shared/EventEmitter.d.ts +92 -0
  87. package/dist/scene/shared/HoverManager.d.ts +151 -0
  88. package/dist/scene/shared/SelectionManager.d.ts +159 -0
  89. package/dist/scene/shared/WireVisualManager.d.ts +242 -0
  90. package/dist/scene/shared/components/ComponentVisualFactory.d.ts +438 -0
  91. package/dist/scene/shared/components/DefaultVisualFactory.d.ts +51 -0
  92. package/dist/scene/shared/components/FactoryRegistry.d.ts +84 -0
  93. package/dist/scene/shared/components/GroupedFactoryRegistry.d.ts +153 -0
  94. package/dist/scene/shared/components/basic/BatteryVisualFactory.d.ts +13 -0
  95. package/dist/scene/shared/components/basic/ClockVisualFactory.d.ts +79 -0
  96. package/dist/scene/shared/components/basic/DoubleThrowSwitchVisualFactory.d.ts +87 -0
  97. package/dist/scene/shared/components/basic/LabelVisualFactory.d.ts +148 -0
  98. package/dist/scene/shared/components/basic/LightbulbVisualFactory.d.ts +72 -0
  99. package/dist/scene/shared/components/basic/RectangleLEDVisualFactory.d.ts +86 -0
  100. package/dist/scene/shared/components/basic/RelayVisualFactory.d.ts +92 -0
  101. package/dist/scene/shared/components/basic/SmallLEDVisualFactory.d.ts +86 -0
  102. package/dist/scene/shared/components/basic/SwitchVisualFactory.d.ts +85 -0
  103. package/dist/scene/shared/components/gates/InverterVisualFactory.d.ts +104 -0
  104. package/dist/scene/shared/components/gates/Nand4GateVisualFactory.d.ts +27 -0
  105. package/dist/scene/shared/components/gates/Nand8GateVisualFactory.d.ts +27 -0
  106. package/dist/scene/shared/components/gates/NandGateVisualFactory.d.ts +101 -0
  107. package/dist/scene/shared/components/gates/Nor4GateVisualFactory.d.ts +27 -0
  108. package/dist/scene/shared/components/gates/Nor8GateVisualFactory.d.ts +27 -0
  109. package/dist/scene/shared/components/gates/NorGateVisualFactory.d.ts +101 -0
  110. package/dist/scene/shared/components/gates/Xor4GateVisualFactory.d.ts +29 -0
  111. package/dist/scene/shared/components/gates/Xor8GateVisualFactory.d.ts +29 -0
  112. package/dist/scene/shared/components/gates/XorGateVisualFactory.d.ts +103 -0
  113. package/dist/scene/shared/components/index.d.ts +29 -0
  114. package/dist/scene/shared/components/types.d.ts +43 -0
  115. package/dist/scene/shared/types.d.ts +476 -0
  116. package/dist/scene/shared/utils/CameraUtils.d.ts +23 -0
  117. package/dist/scene/shared/utils/ColorUtils.d.ts +26 -0
  118. package/dist/scene/shared/utils/ControlsUtils.d.ts +8 -0
  119. package/dist/scene/shared/utils/GeometryUtils.d.ts +261 -0
  120. package/dist/scene/shared/utils/LayerConstants.d.ts +40 -0
  121. package/dist/scene/shared/utils/LightingUtils.d.ts +31 -0
  122. package/dist/scene/shared/utils/MaterialUtils.d.ts +73 -0
  123. package/dist/scene/shared/utils/Options.d.ts +16 -0
  124. package/dist/scene/simulation/CircuitRunnerController.d.ts +227 -0
  125. package/dist/scene/static/CircuitController.d.ts +227 -0
  126. package/dist/scene/static/CircuitWriter.d.ts +146 -0
  127. package/dist/scene/static/PinTooltipWidget.d.ts +26 -0
  128. package/dist/scene/static/tools/BuildTool.d.ts +286 -0
  129. package/dist/scene/static/tools/ComponentPickerWidget.d.ts +82 -0
  130. package/dist/scene/static/tools/ConfigPanelWidget.d.ts +93 -0
  131. package/dist/scene/static/tools/MultiSelectTool.d.ts +265 -0
  132. package/dist/scene-CVsDdySt.js +7357 -0
  133. package/dist/scene-CVsDdySt.js.map +1 -0
  134. package/package.json +24 -25
  135. package/dist/CircuitRunner-BQQlhwjD.js +0 -1981
  136. package/dist/CircuitRunner-BQQlhwjD.js.map +0 -1
  137. package/dist/core/index.js.map +0 -1
  138. package/dist/index.js.map +0 -1
  139. package/dist/scene/index.js.map +0 -1
  140. package/dist/setup-CIq_kgaw.js +0 -10230
  141. package/dist/setup-CIq_kgaw.js.map +0 -1
@@ -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,24 @@
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';
@@ -0,0 +1,101 @@
1
+ import { UUID } from '../../utils';
2
+ import { ComponentType, ENodeSourceType, Component } from '../../topology';
3
+ import { ComponentState, INodeElectricalState } from '../states';
4
+ import { IScheduledEvent, IUserCommand } from '../types';
5
+ /**
6
+ * Result returned by component behavior evaluation.
7
+ * Describes state changes and future events to schedule.
8
+ *
9
+ * @public
10
+ */
11
+ export interface IBehaviorResult {
12
+ /**
13
+ * Updated component state
14
+ */
15
+ readonly componentState: ComponentState;
16
+ /**
17
+ * boolean indicating
18
+ * if the component state has changed (or events scheduled ?)
19
+ */
20
+ hasChanged: boolean;
21
+ /**
22
+ * boolean indicating that all pending events on this component should be cancelled
23
+ * (example change of input during the rising/falling state of a gate)
24
+ */
25
+ shouldCancelPending: boolean;
26
+ /**
27
+ * Events to schedule for future ticks (e.g., delayed transitions).
28
+ */
29
+ readonly scheduledEvents: ReadonlyArray<IScheduledEvent>;
30
+ }
31
+ /**
32
+ * Component behavior interface for registry-based extensibility.
33
+ * Each component type (Battery, LED, Switch, etc.) implements this interface.
34
+ *
35
+ * Behaviors are stateless - all state is stored in ComponentState and SimulationState.
36
+ * The behavior's job is to compute new states based on current inputs and component state.
37
+ *
38
+ * @public
39
+ */
40
+ export interface IComponentBehavior {
41
+ /**
42
+ * Component type this behavior handles (e.g., "battery", "led", "switch").
43
+ * Used as the key in BehaviorRegistry.
44
+ */
45
+ componentType: ComponentType;
46
+ /**
47
+ * Create initial state for a component instance.
48
+ * Called when simulation is initialized.
49
+ * Initial state may use component satic configuration (e.g., initial switch position).
50
+ *
51
+ * @param component - The component to initialize
52
+ * @returns Initial ComponentState for this component
53
+ */
54
+ createInitialState(component: Component): ComponentState;
55
+ /**
56
+ * Determine if conductivity is allowed between two pins of the component.
57
+ * Called during simulation when evaluating electrical connectivity.
58
+ * @param component
59
+ * @param state current component state
60
+ * @param conductivityType
61
+ * @param pinId
62
+ * @param otherPinId
63
+ */
64
+ allowConductivity(component: Component, state: ComponentState, conductivityType: ENodeSourceType, pinId: string, otherPinId: string): boolean;
65
+ /**
66
+ * Define custom component behavior at simulation start
67
+ * For most components it's a no-op but some components to bootstrap their cycling
68
+ * Warning: if this methods return non null behavior it preempts normal initialization at tick 0
69
+ * @param component
70
+ * @param componentState
71
+ */
72
+ onStart(component: Component, componentState: ComponentState): IBehaviorResult | null;
73
+ /**
74
+ * Define component state change in response to its pins state change (after propagateConductivity)
75
+ *
76
+ * @param component - The component being evaluated
77
+ * @param state - component state prior to this evaluation
78
+ * @param nodeStates - Current electrical states of all ENodes in the simulation
79
+ * @param targetTick - target tick
80
+ * @returns Result containing updated state and scheduled events
81
+ */
82
+ onPinsChange(component: Component, state: ComponentState, nodeStates: ReadonlyMap<UUID, INodeElectricalState>, targetTick: number): IBehaviorResult;
83
+ /**
84
+ * Define component state change in response to a User command being received
85
+ *
86
+ * @param component - The component being evaluated
87
+ * @param state - component state prior to this evaluation
88
+ * @param command - IUserCommand to process
89
+ * @returns Result containing updated state and scheduled events
90
+ */
91
+ onUserCommand(component: Component, state: ComponentState, command: IUserCommand): IBehaviorResult;
92
+ /**
93
+ * Define component state change in response to a IScheduledEvent firing at ready
94
+ *
95
+ * @param component - The component being evaluated
96
+ * @param state - component state prior to this evaluation
97
+ * @param event - firing IScheduledEvent to process
98
+ * @returns Result containing updated state and scheduled events
99
+ */
100
+ onEventFiring(component: Component, state: ComponentState, event: IScheduledEvent): IBehaviorResult;
101
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Simulation Engine Module
3
+ *
4
+ * Provides discrete-time boolean circuit simulation with state propagation,
5
+ * event scheduling, and component behavior management.
6
+ *
7
+ * @module core/simulation
8
+ * @public
9
+ */
10
+ export { TRANSITION_DEFAULTS, SIMULATION_SPEED } from './types.js';
11
+ export type { IUserCommand, IRunnerOptions, IScheduledEvent, IDirtyElements } from './types.js';
12
+ export * from './states';
13
+ export * from './behaviors';
14
+ export { EventQueue } from './EventQueue.js';
15
+ export { DirtyTracker } from './DirtyTracker.js';
16
+ export { StateManager } from './StateManager.js';
17
+ export { CircuitRunner } from './CircuitRunner.js';
18
+ export { getTransitionSpan } from './behaviors/ComponentBehavior';
@@ -0,0 +1,57 @@
1
+ import { UUID } from '../../utils/types';
2
+ import { INodeElectricalState } from './types';
3
+ /**
4
+ * Base class for component simulation state.
5
+ * Extended by specific component types (BatteryState, LEDState, etc.)
6
+ * One instance per component throughout simulation that will be mutated in place.
7
+ *
8
+ * @abstract
9
+ * @public
10
+ */
11
+ export declare abstract class ComponentState {
12
+ /**
13
+ * Component UUID this state belongs to.
14
+ * @readonly
15
+ */
16
+ readonly componentId: UUID;
17
+ /**
18
+ * Current operational state (varies by component type).
19
+ * Examples: "on", "off", "open", "closed", "activating", "active"
20
+ */
21
+ protected _state: string;
22
+ /**
23
+ * Tick when this state started.
24
+ */
25
+ protected _startTick: number;
26
+ /**
27
+ * until when this state should last (-1 for no previsional expiration)
28
+ */
29
+ protected _expirationTick: number;
30
+ /**
31
+ * previsional nextState (null if current state has no expiration tick)
32
+ */
33
+ protected _nextState: string | null;
34
+ /**
35
+ * extra state parameters
36
+ */
37
+ parameters: Map<string, string>;
38
+ /**
39
+ * Pin electrical states, keyed by pin label (e.g. 'cmd_in', 'power_out').
40
+ * Composite keys use '*' separator for unions (e.g. 'cmd_in*cmd_out').
41
+ */
42
+ pinStates: Map<string, INodeElectricalState>;
43
+ /**
44
+ * Create a new component state.
45
+ *
46
+ * @param componentId - UUID of the component
47
+ * @param initialState - Initial operational state
48
+ */
49
+ protected constructor(componentId: UUID, initialState: string);
50
+ get state(): string;
51
+ setState(state: string, startTick: number): void;
52
+ get startTick(): number;
53
+ get expirationTick(): number;
54
+ get nextState(): string | null;
55
+ get hasExpiration(): boolean;
56
+ setNextState(nextState: string, expirationTick: number): void;
57
+ }
@@ -0,0 +1,46 @@
1
+ import { ComponentState, INodeElectricalState } from './index';
2
+ import { UUID } from '../../utils';
3
+ /**
4
+ * Represents the complete electrical state of the circuit at a specific time step.
5
+ * Immutable snapshot that can be stored in history.
6
+ *
7
+ * @public
8
+ */
9
+ export declare class SimulationState {
10
+ /**
11
+ * Current simulation step number (starts at 0).
12
+ * @readonly
13
+ */
14
+ tick: number;
15
+ /**
16
+ * Electrical state for each ENode (component pins and branching points).
17
+ * Key: ENode UUID, Value: INodeElectricalState
18
+ * @readonly
19
+ */
20
+ readonly nodeStates: ReadonlyMap<UUID, INodeElectricalState>;
21
+ /**
22
+ * Electrical state for each Wire connecting ENodes.
23
+ * Key: Wire UUID, Value: INodeElectricalState
24
+ * @readonly
25
+ */
26
+ readonly wireStates: ReadonlyMap<UUID, INodeElectricalState>;
27
+ /**
28
+ * Component-specific state for each component.
29
+ * Key: Component UUID, Value: ComponentState subclass
30
+ * @readonly
31
+ */
32
+ readonly componentStates: ReadonlyMap<UUID, ComponentState>;
33
+ /**
34
+ * Create a new simulation state snapshot.
35
+ *
36
+ * @param tick - Current simulation step number
37
+ */
38
+ constructor(tick: number);
39
+ setTick(tick: number): void;
40
+ /**
41
+ * Create a deep copy of this state for historical storage.
42
+ *
43
+ * @returns Cloned SimulationState
44
+ */
45
+ clone(): SimulationState;
46
+ }