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.
- package/AGENTS.md +11 -7
- package/CLAUDE.md +6 -6
- package/README.md +5 -2
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +85 -2115
- package/dist/core/setup.d.ts +25 -0
- package/dist/core/simulation/CircuitRunner.d.ts +176 -0
- package/dist/core/simulation/DirtyTracker.d.ts +87 -0
- package/dist/core/simulation/EventQueue.d.ts +68 -0
- package/dist/core/simulation/StateManager.d.ts +100 -0
- package/dist/core/simulation/behaviors/BehaviorRegistry.d.ts +70 -0
- package/dist/core/simulation/behaviors/ComponentBehavior.d.ts +53 -0
- package/dist/core/simulation/behaviors/arithmetic/AdderBehavior.d.ts +28 -0
- package/dist/core/simulation/behaviors/arithmetic/ArithmeticBehaviorMixin.d.ts +63 -0
- package/dist/core/simulation/behaviors/arithmetic/EightBitAdderBehavior.d.ts +51 -0
- package/dist/core/simulation/behaviors/arithmetic/EightBitOnesComplementBehavior.d.ts +29 -0
- package/dist/core/simulation/behaviors/arithmetic/HalfAdderBehavior.d.ts +22 -0
- package/dist/core/simulation/behaviors/arithmetic/index.d.ts +7 -0
- package/dist/core/simulation/behaviors/basic/BatteryBehavior.d.ts +14 -0
- package/dist/core/simulation/behaviors/basic/ClockBehavior.d.ts +24 -0
- package/dist/core/simulation/behaviors/basic/DoubleThrowSwitchBehavior.d.ts +33 -0
- package/dist/core/simulation/behaviors/basic/LightbulbBehavior.d.ts +23 -0
- package/dist/core/simulation/behaviors/basic/RectangleLEDBehavior.d.ts +24 -0
- package/dist/core/simulation/behaviors/basic/RelayBehavior.d.ts +33 -0
- package/dist/core/simulation/behaviors/basic/SmallLEDBehavior.d.ts +24 -0
- package/dist/core/simulation/behaviors/basic/SwitchBehavior.d.ts +33 -0
- package/dist/core/simulation/behaviors/basic/index.d.ts +20 -0
- package/dist/core/simulation/behaviors/gates/InverterBehavior.d.ts +29 -0
- package/dist/core/simulation/behaviors/gates/Nand4GateBehavior.d.ts +18 -0
- package/dist/core/simulation/behaviors/gates/Nand8GateBehavior.d.ts +18 -0
- package/dist/core/simulation/behaviors/gates/NandGateBehavior.d.ts +28 -0
- package/dist/core/simulation/behaviors/gates/Nor4GateBehavior.d.ts +18 -0
- package/dist/core/simulation/behaviors/gates/Nor8GateBehavior.d.ts +18 -0
- package/dist/core/simulation/behaviors/gates/NorGateBehavior.d.ts +22 -0
- package/dist/core/simulation/behaviors/gates/Xor4GateBehavior.d.ts +18 -0
- package/dist/core/simulation/behaviors/gates/Xor8GateBehavior.d.ts +18 -0
- package/dist/core/simulation/behaviors/gates/XorGateBehavior.d.ts +22 -0
- package/dist/core/simulation/behaviors/gates/index.d.ts +34 -0
- package/dist/core/simulation/behaviors/index.d.ts +28 -0
- package/dist/core/simulation/behaviors/types.d.ts +101 -0
- package/dist/core/simulation/index.d.ts +18 -0
- package/dist/core/simulation/states/ComponentState.d.ts +57 -0
- package/dist/core/simulation/states/SimulationState.d.ts +46 -0
- package/dist/core/simulation/states/arithmetic/AdderState.d.ts +16 -0
- package/dist/core/simulation/states/arithmetic/ArithmeticState.d.ts +53 -0
- package/dist/core/simulation/states/arithmetic/EightBitAdderState.d.ts +25 -0
- package/dist/core/simulation/states/arithmetic/EightBitOnesComplementState.d.ts +18 -0
- package/dist/core/simulation/states/arithmetic/HalfAdderState.d.ts +16 -0
- package/dist/core/simulation/states/arithmetic/index.d.ts +7 -0
- package/dist/core/simulation/states/basic/BatteryState.d.ts +16 -0
- package/dist/core/simulation/states/basic/ClockState.d.ts +16 -0
- package/dist/core/simulation/states/basic/DoubleThrowSwitchState.d.ts +21 -0
- package/dist/core/simulation/states/basic/LightbulbState.d.ts +21 -0
- package/dist/core/simulation/states/basic/RectangleLEDState.d.ts +9 -0
- package/dist/core/simulation/states/basic/RelayState.d.ts +25 -0
- package/dist/core/simulation/states/basic/SmallLEDState.d.ts +21 -0
- package/dist/core/simulation/states/basic/SwitchState.d.ts +25 -0
- package/dist/core/simulation/states/gates/InverterState.d.ts +17 -0
- package/dist/core/simulation/states/gates/Nand4GateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/Nand8GateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/NandGateState.d.ts +16 -0
- package/dist/core/simulation/states/gates/Nor4GateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/Nor8GateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/NorGateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/Xor4GateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/Xor8GateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/XorGateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/index.d.ts +25 -0
- package/dist/core/simulation/states/index.d.ts +31 -0
- package/dist/core/simulation/states/types.d.ts +32 -0
- package/dist/core/simulation/types.d.ts +155 -0
- package/dist/core/topology/Circuit.d.ts +420 -0
- package/dist/core/topology/CircuitMetadata.d.ts +24 -0
- package/dist/core/topology/CircuitOptions.d.ts +14 -0
- package/dist/core/topology/Component.d.ts +153 -0
- package/dist/core/topology/ENode.d.ts +200 -0
- package/dist/core/topology/Wire.d.ts +130 -0
- package/dist/core/topology/delays.d.ts +52 -0
- package/dist/core/topology/index.d.ts +14 -0
- package/dist/core/topology/types.d.ts +189 -0
- package/dist/core/utils/CameraOptions.d.ts +83 -0
- package/dist/core/utils/MemoizeDecorator.d.ts +9 -0
- package/dist/core/utils/Position.d.ts +166 -0
- package/dist/core/utils/Position3D.d.ts +77 -0
- package/dist/core/utils/Rotation.d.ts +82 -0
- package/dist/core/utils/index.d.ts +24 -0
- package/dist/core/utils/types.d.ts +35 -0
- package/dist/core-b6Q8w2sn.js +3560 -0
- package/dist/core-b6Q8w2sn.js.map +1 -0
- package/dist/i18n/index.d.ts +882 -0
- package/dist/i18n/locales/en.json.d.ts +268 -0
- package/dist/i18n/locales/fr.json.d.ts +268 -0
- package/dist/index.d.ts +14 -6306
- package/dist/index.js +136 -112
- package/dist/scene/CircuitEngine.d.ts +283 -0
- package/dist/scene/index.d.ts +1 -2
- package/dist/scene/index.js +50 -41
- package/dist/scene/setup.d.ts +26 -0
- package/dist/scene/shared/AbstractCircuitController.d.ts +217 -0
- package/dist/scene/shared/BranchingPointVisualFactory.d.ts +70 -0
- package/dist/scene/shared/EventEmitter.d.ts +92 -0
- package/dist/scene/shared/HoverManager.d.ts +151 -0
- package/dist/scene/shared/SelectionManager.d.ts +159 -0
- package/dist/scene/shared/WireVisualManager.d.ts +242 -0
- package/dist/scene/shared/components/ComponentVisualFactory.d.ts +438 -0
- package/dist/scene/shared/components/DefaultVisualFactory.d.ts +51 -0
- package/dist/scene/shared/components/FactoryRegistry.d.ts +84 -0
- package/dist/scene/shared/components/GroupedFactoryRegistry.d.ts +153 -0
- package/dist/scene/shared/components/arithmetic/AdderVisualFactory.d.ts +54 -0
- package/dist/scene/shared/components/arithmetic/EightBitAdderVisualFactory.d.ts +45 -0
- package/dist/scene/shared/components/arithmetic/EightBitOnesComplementVisualFactory.d.ts +63 -0
- package/dist/scene/shared/components/arithmetic/HalfAdderVisualFactory.d.ts +55 -0
- package/dist/scene/shared/components/arithmetic/index.d.ts +4 -0
- package/dist/scene/shared/components/basic/BatteryVisualFactory.d.ts +13 -0
- package/dist/scene/shared/components/basic/ClockVisualFactory.d.ts +79 -0
- package/dist/scene/shared/components/basic/DoubleThrowSwitchVisualFactory.d.ts +87 -0
- package/dist/scene/shared/components/basic/LabelVisualFactory.d.ts +148 -0
- package/dist/scene/shared/components/basic/LightbulbVisualFactory.d.ts +72 -0
- package/dist/scene/shared/components/basic/RectangleLEDVisualFactory.d.ts +86 -0
- package/dist/scene/shared/components/basic/RelayVisualFactory.d.ts +92 -0
- package/dist/scene/shared/components/basic/SmallLEDVisualFactory.d.ts +86 -0
- package/dist/scene/shared/components/basic/SwitchVisualFactory.d.ts +85 -0
- package/dist/scene/shared/components/gates/InverterVisualFactory.d.ts +104 -0
- package/dist/scene/shared/components/gates/Nand4GateVisualFactory.d.ts +27 -0
- package/dist/scene/shared/components/gates/Nand8GateVisualFactory.d.ts +27 -0
- package/dist/scene/shared/components/gates/NandGateVisualFactory.d.ts +101 -0
- package/dist/scene/shared/components/gates/Nor4GateVisualFactory.d.ts +27 -0
- package/dist/scene/shared/components/gates/Nor8GateVisualFactory.d.ts +27 -0
- package/dist/scene/shared/components/gates/NorGateVisualFactory.d.ts +101 -0
- package/dist/scene/shared/components/gates/Xor4GateVisualFactory.d.ts +29 -0
- package/dist/scene/shared/components/gates/Xor8GateVisualFactory.d.ts +29 -0
- package/dist/scene/shared/components/gates/XorGateVisualFactory.d.ts +103 -0
- package/dist/scene/shared/components/index.d.ts +33 -0
- package/dist/scene/shared/components/types.d.ts +43 -0
- package/dist/scene/shared/types.d.ts +474 -0
- package/dist/scene/shared/utils/CameraUtils.d.ts +23 -0
- package/dist/scene/shared/utils/ColorUtils.d.ts +26 -0
- package/dist/scene/shared/utils/ControlsUtils.d.ts +8 -0
- package/dist/scene/shared/utils/GeometryUtils.d.ts +337 -0
- package/dist/scene/shared/utils/LayerConstants.d.ts +40 -0
- package/dist/scene/shared/utils/LightingUtils.d.ts +31 -0
- package/dist/scene/shared/utils/MaterialUtils.d.ts +73 -0
- package/dist/scene/shared/utils/Options.d.ts +16 -0
- package/dist/scene/simulation/CircuitRunnerController.d.ts +227 -0
- package/dist/scene/static/CircuitController.d.ts +228 -0
- package/dist/scene/static/CircuitWriter.d.ts +146 -0
- package/dist/scene/static/PinTooltipWidget.d.ts +31 -0
- package/dist/scene/static/tools/BuildTool.d.ts +290 -0
- package/dist/scene/static/tools/ComponentPickerWidget.d.ts +89 -0
- package/dist/scene/static/tools/ConfigPanelWidget.d.ts +107 -0
- package/dist/scene/static/tools/MultiSelectTool.d.ts +265 -0
- package/dist/scene-D4QcWeiq.js +8745 -0
- package/dist/scene-D4QcWeiq.js.map +1 -0
- package/package.json +29 -25
- package/dist/CircuitRunner-BQQlhwjD.js +0 -1981
- package/dist/CircuitRunner-BQQlhwjD.js.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/scene/index.js.map +0 -1
- package/dist/setup-CIq_kgaw.js +0 -10230
- package/dist/setup-CIq_kgaw.js.map +0 -1
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { UUID } from '../../../utils/types';
|
|
2
|
+
import { ArithmeticState } from './ArithmeticState';
|
|
3
|
+
/**
|
|
4
|
+
* Simulation state for Full Adder components.
|
|
5
|
+
*
|
|
6
|
+
* Hex-encoded stable states: `'0'` (both low), `'1'` (sum high),
|
|
7
|
+
* `'2'` (carry high), `'3'` (both high). All four are reachable;
|
|
8
|
+
* in particular `A = B = carryIn = 1` yields `'3'`.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export declare class AdderState extends ArithmeticState {
|
|
13
|
+
constructor(componentId: UUID, initialState?: string);
|
|
14
|
+
get sumHigh(): boolean;
|
|
15
|
+
get carryOutHigh(): boolean;
|
|
16
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { UUID } from '../../../utils/types';
|
|
2
|
+
import { ComponentState } from '../ComponentState';
|
|
3
|
+
/**
|
|
4
|
+
* Base simulation state for arithmetic components (half adder, full adder and
|
|
5
|
+
* future multi-bit adders, multiplexers, ...).
|
|
6
|
+
*
|
|
7
|
+
* Stable states are encoded as a zero-padded hexadecimal string where each
|
|
8
|
+
* bit position maps to one logic output. Simple components use one bit per
|
|
9
|
+
* output in declaration order (bit 0 = first logicOutput). For example a
|
|
10
|
+
* half-adder with sum (bit 0) and carry (bit 1) uses `'0'`..`'3'`.
|
|
11
|
+
*
|
|
12
|
+
* Components with internal carry chains (e.g. 8-bit ripple adder) use an
|
|
13
|
+
* **interleaved** encoding `CiSi` where sum occupies even bits (`2*i`) and
|
|
14
|
+
* carry occupies odd bits (`2*i + 1`). This stores intermediate carries for
|
|
15
|
+
* ripple animation, giving `outputCount = 2 * stageCount` (e.g. 16 bits /
|
|
16
|
+
* 4 hex digits for 8 stages, states `'0000'`..`'ffff'`).
|
|
17
|
+
*
|
|
18
|
+
* Transient (in-flight) states follow the `to${nextState}` convention so
|
|
19
|
+
* animations can be driven generically from `state`/`nextState`. The
|
|
20
|
+
* previously-held stable state is preserved in `parameters.prevState` so the
|
|
21
|
+
* behavior's `allowConductivity` keeps the old outputs energized until the
|
|
22
|
+
* transition fires.
|
|
23
|
+
*
|
|
24
|
+
* A special `'indeterminate'` state is used when any logic input is ill-defined.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export declare abstract class ArithmeticState extends ComponentState {
|
|
29
|
+
/**
|
|
30
|
+
* Number of logic outputs for this state
|
|
31
|
+
* (e.g. 2 for half/full adder, 9 for an 8-bit adder: 8 sum bits + carry out).
|
|
32
|
+
*/
|
|
33
|
+
readonly outputCount: number;
|
|
34
|
+
/** Number of hex digits needed to encode all outputs. */
|
|
35
|
+
readonly hexDigitCount: number;
|
|
36
|
+
/** All-outputs-low state string (e.g. `'0'` for 2 outputs, `'000'` for 9). */
|
|
37
|
+
readonly allLowState: string;
|
|
38
|
+
protected constructor(componentId: UUID, outputCount: number, initialState: string);
|
|
39
|
+
/** True when the current state is a transient `to${stable}` transition. */
|
|
40
|
+
get isInTransition(): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Stable state that effectively drives the outputs right now:
|
|
43
|
+
* - stable state → returns that state
|
|
44
|
+
* - transient `to<hex>` → returns the previous stable kept in parameters
|
|
45
|
+
* - `'indeterminate'` → returns `'indeterminate'`
|
|
46
|
+
*/
|
|
47
|
+
get effectiveState(): string;
|
|
48
|
+
/**
|
|
49
|
+
* Whether the `index`-th output is high in the current effective state.
|
|
50
|
+
* Returns `false` when effective state is `'indeterminate'`.
|
|
51
|
+
*/
|
|
52
|
+
isOutputHigh(index: number): boolean;
|
|
53
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { UUID } from '../../../utils/types';
|
|
2
|
+
import { ArithmeticState } from './ArithmeticState';
|
|
3
|
+
/**
|
|
4
|
+
* Simulation state for the 8-bit ripple carry adder.
|
|
5
|
+
*
|
|
6
|
+
* Uses an interleaved 16-bit encoding `C7S7 C6S6 … C1S1 C0S0` where each
|
|
7
|
+
* stage occupies two bits: sum at even position (`2*i`) and carry at odd
|
|
8
|
+
* position (`2*i + 1`). This stores intermediate carries so the ripple
|
|
9
|
+
* animation can show carry propagation stage by stage.
|
|
10
|
+
*
|
|
11
|
+
* Stable states range from `'0000'` (all low) to `'ffff'` (all high).
|
|
12
|
+
* The external outputs are `sum-0`..`sum-7` (bits 0,2,4,…,14) and
|
|
13
|
+
* `carryOut` (bit 15 = C7).
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export declare class EightBitAdderState extends ArithmeticState {
|
|
18
|
+
constructor(componentId: UUID, initialState?: string);
|
|
19
|
+
/** Whether stage `i`'s sum output is high in the current effective state. */
|
|
20
|
+
isSumHigh(stageIndex: number): boolean;
|
|
21
|
+
/** Whether stage `i`'s internal carry is high in the current effective state. */
|
|
22
|
+
isStageCarryHigh(stageIndex: number): boolean;
|
|
23
|
+
/** Whether the final carry out (C7) is high — drives the `carryOut` pin. */
|
|
24
|
+
isCarryOutHigh(): boolean;
|
|
25
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { UUID } from '../../../utils/types';
|
|
2
|
+
import { ArithmeticState } from './ArithmeticState';
|
|
3
|
+
/**
|
|
4
|
+
* Simulation state for the 8-bit one's complement (8 parallel XOR gates).
|
|
5
|
+
*
|
|
6
|
+
* Uses a 9-bit encoding stored as a 3-digit hex string (`'000'`..`'1ff'`):
|
|
7
|
+
* - Bits 0–7: output values (`output-i = input-i XOR invert`)
|
|
8
|
+
* - Bit 8: current invert input value (stored for animation)
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export declare class EightBitOnesComplementState extends ArithmeticState {
|
|
13
|
+
constructor(componentId: UUID, initialState?: string);
|
|
14
|
+
/** Whether output bit `index` (0–7) is high in the current effective state. */
|
|
15
|
+
isOutputBitHigh(index: number): boolean;
|
|
16
|
+
/** Whether the invert flag (bit 8) is high in the current effective state. */
|
|
17
|
+
isInvertHigh(): boolean;
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { UUID } from '../../../utils/types';
|
|
2
|
+
import { ArithmeticState } from './ArithmeticState';
|
|
3
|
+
/**
|
|
4
|
+
* Simulation state for Half Adder components.
|
|
5
|
+
*
|
|
6
|
+
* Hex-encoded stable states: `'0'` (both low), `'1'` (sum high),
|
|
7
|
+
* `'2'` (carry high). `'3'` is unreachable because `sum = A XOR B`
|
|
8
|
+
* and `carry = A AND B` can never both be true.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export declare class HalfAdderState extends ArithmeticState {
|
|
13
|
+
constructor(componentId: UUID, initialState?: string);
|
|
14
|
+
get sumHigh(): boolean;
|
|
15
|
+
get carryHigh(): boolean;
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ComponentState } from '../ComponentState';
|
|
2
|
+
import { UUID } from '../../../utils/types';
|
|
3
|
+
/**
|
|
4
|
+
* Simulation state for Battery components.
|
|
5
|
+
* Batteries are stateless always-on pinSources.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare class BatteryState extends ComponentState {
|
|
10
|
+
/**
|
|
11
|
+
* Create a new battery state.
|
|
12
|
+
*
|
|
13
|
+
* @param componentId - UUID of the battery component
|
|
14
|
+
*/
|
|
15
|
+
constructor(componentId: UUID);
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { UUID } from '../../../utils';
|
|
2
|
+
import { ComponentState } from '../ComponentState';
|
|
3
|
+
/**
|
|
4
|
+
* Simulation state for Clock components.
|
|
5
|
+
* Clock output either voltage (LOGIC HIGH) or LOGIC LOW switching periodically
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare class ClockState extends ComponentState {
|
|
10
|
+
/**
|
|
11
|
+
* Create a new Clock state, either gnd or vcc
|
|
12
|
+
*
|
|
13
|
+
* @param componentId - UUID of the Clock component
|
|
14
|
+
*/
|
|
15
|
+
constructor(componentId: UUID);
|
|
16
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ComponentState } from '../ComponentState';
|
|
2
|
+
import { UUID } from '../../../utils/types';
|
|
3
|
+
/**
|
|
4
|
+
* Simulation state for DoubleSwitch (SPDT - Single-Pole Double-Throw - switch) components.
|
|
5
|
+
* These switches can be "input1", "1to2", "input2" or "2to1"
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare class DoubleThrowSwitchState extends ComponentState {
|
|
10
|
+
/**
|
|
11
|
+
* Create a new double Switch state.
|
|
12
|
+
*
|
|
13
|
+
* @param componentId - UUID of the double Switch component
|
|
14
|
+
* @param initialState - Initial operational state (default: "input1")
|
|
15
|
+
*/
|
|
16
|
+
constructor(componentId: UUID, initialState?: string);
|
|
17
|
+
/**
|
|
18
|
+
* Check if switch is in 1to2 or 2to1 state
|
|
19
|
+
*/
|
|
20
|
+
get isInTransition(): boolean;
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ComponentState } from '../ComponentState';
|
|
2
|
+
import { UUID } from '../../../utils/types';
|
|
3
|
+
/**
|
|
4
|
+
* Simulation state for Lightbulb components.
|
|
5
|
+
* Lightbulbs can be "on" (emitting light) or "off".
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare class LightbulbState extends ComponentState {
|
|
10
|
+
/**
|
|
11
|
+
* Create a new Lightbulb state.
|
|
12
|
+
*
|
|
13
|
+
* @param componentId - UUID of the Lightbulb component
|
|
14
|
+
* @param initialState - Initial operational state (default: "off")
|
|
15
|
+
*/
|
|
16
|
+
constructor(componentId: UUID, initialState?: string);
|
|
17
|
+
/**
|
|
18
|
+
* Check if Lightbulb is in lit state (on or going_on)
|
|
19
|
+
*/
|
|
20
|
+
get isLit(): boolean;
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SmallLEDState } from './SmallLEDState';
|
|
2
|
+
/**
|
|
3
|
+
* Simulation state for RectangleLED components. Same as SmallLEDState.
|
|
4
|
+
* LEDs can be "on" (emitting light) or "off".
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare class RectangleLEDState extends SmallLEDState {
|
|
9
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ComponentState } from '../ComponentState';
|
|
2
|
+
import { UUID } from '../../../utils/types';
|
|
3
|
+
/**
|
|
4
|
+
* Simulation state for mechanical Relay components.
|
|
5
|
+
* Relays can be "open", "closing", "closed", or "opening".
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare class RelayState extends ComponentState {
|
|
10
|
+
/**
|
|
11
|
+
* Create a new Relay state.
|
|
12
|
+
*
|
|
13
|
+
* @param componentId - UUID of the Relay component
|
|
14
|
+
* @param initialState - Initial operational state (default: "open")
|
|
15
|
+
*/
|
|
16
|
+
constructor(componentId: UUID, initialState?: string);
|
|
17
|
+
/**
|
|
18
|
+
* Check if relay is in opening or closing state
|
|
19
|
+
*/
|
|
20
|
+
get isInTransition(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Check if relay is in closed or closing state
|
|
23
|
+
*/
|
|
24
|
+
get isClosed(): boolean;
|
|
25
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ComponentState } from '../ComponentState';
|
|
2
|
+
import { UUID } from '../../../utils/types';
|
|
3
|
+
/**
|
|
4
|
+
* Simulation state for SmallLED components.
|
|
5
|
+
* LEDs can be "on" (emitting light) or "off".
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare class SmallLEDState extends ComponentState {
|
|
10
|
+
/**
|
|
11
|
+
* Create a new SmallLED state.
|
|
12
|
+
*
|
|
13
|
+
* @param componentId - UUID of the LED component
|
|
14
|
+
* @param initialState - Initial operational state (default: "off")
|
|
15
|
+
*/
|
|
16
|
+
constructor(componentId: UUID, initialState?: string);
|
|
17
|
+
/**
|
|
18
|
+
* Check if LED is in lit state (on or going_on)
|
|
19
|
+
*/
|
|
20
|
+
get isLit(): boolean;
|
|
21
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ComponentState } from '../ComponentState';
|
|
2
|
+
import { UUID } from '../../../utils/types';
|
|
3
|
+
/**
|
|
4
|
+
* Simulation state for Switch components.
|
|
5
|
+
* Switches can be "open", "closing", "closed", or "opening".
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare class SwitchState extends ComponentState {
|
|
10
|
+
/**
|
|
11
|
+
* Create a new Switch state.
|
|
12
|
+
*
|
|
13
|
+
* @param componentId - UUID of the Switch component
|
|
14
|
+
* @param initialState - Initial operational state (default: "open")
|
|
15
|
+
*/
|
|
16
|
+
constructor(componentId: UUID, initialState?: string);
|
|
17
|
+
/**
|
|
18
|
+
* Check if switch is in opening or closing state
|
|
19
|
+
*/
|
|
20
|
+
get isInTransition(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Check if switch is in closed or closing state
|
|
23
|
+
*/
|
|
24
|
+
get isClosed(): boolean;
|
|
25
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LogicGateState } from './index';
|
|
2
|
+
import { UUID } from '../../../utils/types';
|
|
3
|
+
/**
|
|
4
|
+
* Simulation state for Inverter components
|
|
5
|
+
* Inverters can be "low", "rising", "high", or "falling".
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare class InverterState extends LogicGateState {
|
|
10
|
+
/**
|
|
11
|
+
* Create a new Inverter state.
|
|
12
|
+
*
|
|
13
|
+
* @param componentId - UUID of the Inverter component
|
|
14
|
+
* @param initialState - Initial operational state (default: "low")
|
|
15
|
+
*/
|
|
16
|
+
constructor(componentId: UUID, initialState?: string);
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LogicGateState } from './index';
|
|
2
|
+
import { UUID } from '../../../utils/types';
|
|
3
|
+
/**
|
|
4
|
+
* Simulation state for NAND4 Gate components (4 inputs).
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare class Nand4GateState extends LogicGateState {
|
|
9
|
+
constructor(componentId: UUID, initialState?: string);
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LogicGateState } from './index';
|
|
2
|
+
import { UUID } from '../../../utils/types';
|
|
3
|
+
/**
|
|
4
|
+
* Simulation state for NAND8 Gate components (8 inputs).
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare class Nand8GateState extends LogicGateState {
|
|
9
|
+
constructor(componentId: UUID, initialState?: string);
|
|
10
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { LogicGateState } from './index';
|
|
2
|
+
import { UUID } from '../../../utils/types';
|
|
3
|
+
/**
|
|
4
|
+
* Simulation state for NAND Gate components.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare class NandGateState extends LogicGateState {
|
|
9
|
+
/**
|
|
10
|
+
* Create a new NAND Gate state.
|
|
11
|
+
*
|
|
12
|
+
* @param componentId - UUID of the NAND Gate component
|
|
13
|
+
* @param initialState - Initial operational state (default: "low")
|
|
14
|
+
*/
|
|
15
|
+
constructor(componentId: UUID, initialState?: string);
|
|
16
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LogicGateState } from './index';
|
|
2
|
+
import { UUID } from '../../../utils/types';
|
|
3
|
+
/**
|
|
4
|
+
* Simulation state for NOR4 Gate components (4 inputs).
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare class Nor4GateState extends LogicGateState {
|
|
9
|
+
constructor(componentId: UUID, initialState?: string);
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LogicGateState } from './index';
|
|
2
|
+
import { UUID } from '../../../utils/types';
|
|
3
|
+
/**
|
|
4
|
+
* Simulation state for NOR8 Gate components (8 inputs).
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare class Nor8GateState extends LogicGateState {
|
|
9
|
+
constructor(componentId: UUID, initialState?: string);
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LogicGateState } from './index';
|
|
2
|
+
import { UUID } from '../../../utils/types';
|
|
3
|
+
/**
|
|
4
|
+
* Simulation state for NOR Gate components.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare class NorGateState extends LogicGateState {
|
|
9
|
+
constructor(componentId: UUID, initialState?: string);
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LogicGateState } from './index';
|
|
2
|
+
import { UUID } from '../../../utils/types';
|
|
3
|
+
/**
|
|
4
|
+
* Simulation state for XOR4 Gate components (4 inputs).
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare class Xor4GateState extends LogicGateState {
|
|
9
|
+
constructor(componentId: UUID, initialState?: string);
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LogicGateState } from './index';
|
|
2
|
+
import { UUID } from '../../../utils/types';
|
|
3
|
+
/**
|
|
4
|
+
* Simulation state for XOR8 Gate components (8 inputs).
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare class Xor8GateState extends LogicGateState {
|
|
9
|
+
constructor(componentId: UUID, initialState?: string);
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LogicGateState } from './index';
|
|
2
|
+
import { UUID } from '../../../utils/types';
|
|
3
|
+
/**
|
|
4
|
+
* Simulation state for XOR Gate components.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare class XorGateState extends LogicGateState {
|
|
9
|
+
constructor(componentId: UUID, initialState?: string);
|
|
10
|
+
}
|