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,14 @@
|
|
|
1
|
+
import { ICircuitOptions, LogicFamily } from './types';
|
|
2
|
+
export declare class CircuitOptions implements ICircuitOptions {
|
|
3
|
+
name: string;
|
|
4
|
+
defaultLogicFamily: LogicFamily;
|
|
5
|
+
/**
|
|
6
|
+
* Create new circuit options.
|
|
7
|
+
*
|
|
8
|
+
* @param name - Circuit name (default: Untitled Circuit)
|
|
9
|
+
* @param defaultLogicFamily - Circuit default logic family (default: CMOS1)
|
|
10
|
+
*/
|
|
11
|
+
constructor(name?: string, defaultLogicFamily?: LogicFamily);
|
|
12
|
+
toJSON(): ICircuitOptions;
|
|
13
|
+
static fromJSON(json: ICircuitOptions): CircuitOptions;
|
|
14
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { UUID, Position, Rotation } from '../utils';
|
|
2
|
+
import { ComponentType, IComponent, IPinMetadata } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Electrical component placed on the circuit grid.
|
|
5
|
+
*
|
|
6
|
+
* Components represent physical circuit elements (lightbulbs, transistors, etc.)
|
|
7
|
+
* with a specific position, orientation, and set of electrical connection pins.
|
|
8
|
+
*
|
|
9
|
+
* **Lifecycle**: Components are created and removed via the Circuit class.
|
|
10
|
+
* When a component is added to a circuit, pin ENodes are automatically created
|
|
11
|
+
* for each pin. When removed, pins and connected wires are cascade-deleted.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const position = new Position(10, 20);
|
|
16
|
+
* const rotation = new Rotation(90);
|
|
17
|
+
* const pins = ['pin-uuid-1', 'pin-uuid-2'];
|
|
18
|
+
*
|
|
19
|
+
* const component = new Component(position, rotation, pins);
|
|
20
|
+
*
|
|
21
|
+
* console.log(component.id); // "550e8400-..."
|
|
22
|
+
* console.log(component.position); // Position { x: 10, y: 20 }
|
|
23
|
+
* console.log(component.rotation); // Rotation { angle: 90 }
|
|
24
|
+
* console.log(component.pins); // ['pin-uuid-1', 'pin-uuid-2']
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare class Component {
|
|
28
|
+
/**
|
|
29
|
+
* Unique identifier for this component.
|
|
30
|
+
* @readonly
|
|
31
|
+
*/
|
|
32
|
+
readonly id: UUID;
|
|
33
|
+
/**
|
|
34
|
+
* Component type (Battery, Switch, LED, etc.).
|
|
35
|
+
* @readonly
|
|
36
|
+
*/
|
|
37
|
+
readonly type: ComponentType;
|
|
38
|
+
/**
|
|
39
|
+
* Position on the 2D discrete grid.
|
|
40
|
+
* @readonly
|
|
41
|
+
*/
|
|
42
|
+
readonly position: Position;
|
|
43
|
+
/**
|
|
44
|
+
* Orientation angle in degrees.
|
|
45
|
+
* @readonly
|
|
46
|
+
*/
|
|
47
|
+
readonly rotation: Rotation;
|
|
48
|
+
/**
|
|
49
|
+
* Array of pin ENode UUIDs.
|
|
50
|
+
* Pin order is significant (index 0 is first pin, etc.).
|
|
51
|
+
* @readonly
|
|
52
|
+
*/
|
|
53
|
+
readonly pins: ReadonlyArray<UUID>;
|
|
54
|
+
/**
|
|
55
|
+
* Configuration parameters for this component instance.
|
|
56
|
+
*
|
|
57
|
+
* This map holds key-value pairs representing configurable settings
|
|
58
|
+
* The available configuration keys depend on the component type see IComponentTypeMetadata for details.
|
|
59
|
+
*
|
|
60
|
+
*/
|
|
61
|
+
config: Map<string, string>;
|
|
62
|
+
/**
|
|
63
|
+
* allow to flag a component as non editable (feature to implement)
|
|
64
|
+
*/
|
|
65
|
+
editable: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Create a new component.
|
|
68
|
+
*
|
|
69
|
+
* **Note**: Typically components are created via `Circuit.addComponent()`
|
|
70
|
+
* which handles pin ENode creation automatically. This constructor is used
|
|
71
|
+
* internally by Circuit.
|
|
72
|
+
*
|
|
73
|
+
* @param type - Component type (Battery, Switch, LED, etc.)
|
|
74
|
+
* @param position - Grid position (integer x, y)
|
|
75
|
+
* @param rotation - Orientation angle (integer degrees)
|
|
76
|
+
* @param pins - Array of pin ENode UUIDs
|
|
77
|
+
*
|
|
78
|
+
* @param editable
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* // Usually created via Circuit:
|
|
82
|
+
* const component = circuit.addComponent(
|
|
83
|
+
* new Position(10, 20),
|
|
84
|
+
* new Rotation(90),
|
|
85
|
+
* ComponentType.Battery
|
|
86
|
+
* );
|
|
87
|
+
*
|
|
88
|
+
* // Direct construction (for deserialization):
|
|
89
|
+
* const component = new Component(
|
|
90
|
+
* ComponentType.Battery,
|
|
91
|
+
* new Position(10, 20),
|
|
92
|
+
* new Rotation(90),
|
|
93
|
+
* ['pin-id-1', 'pin-id-2']
|
|
94
|
+
* );
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
constructor(type: ComponentType, position: Position, rotation: Rotation, pins: ReadonlyArray<UUID>, editable?: boolean);
|
|
98
|
+
getPinLabel(pinId: UUID): string | undefined;
|
|
99
|
+
getPinMetadata(pinId: UUID): IPinMetadata | undefined;
|
|
100
|
+
setAllParameters(config: Map<string, string>): void;
|
|
101
|
+
setParameter(key: string, value: string): void;
|
|
102
|
+
/**
|
|
103
|
+
* Update the component's position.
|
|
104
|
+
*
|
|
105
|
+
* @param newPosition - The new position for the component
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const component = circuit.getComponent(componentId);
|
|
110
|
+
* component.setPosition(new Position(15, 25));
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
setPosition(newPosition: Position): void;
|
|
114
|
+
/**
|
|
115
|
+
* Update the component's rotation.
|
|
116
|
+
*
|
|
117
|
+
* @param newRotation - The new rotation for the component
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* const component = circuit.getComponent(componentId);
|
|
122
|
+
* component.setRotation(new Rotation(90));
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
setRotation(newRotation: Rotation): void;
|
|
126
|
+
/**
|
|
127
|
+
* Serialize component to JSON.
|
|
128
|
+
*
|
|
129
|
+
* @returns Plain object representation
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* const json = component.toJSON();
|
|
134
|
+
* console.log(json);
|
|
135
|
+
* // {
|
|
136
|
+
* // id: "550e8400-...",
|
|
137
|
+
* // type: "battery",
|
|
138
|
+
* // position: { x: 10, y: 20 },
|
|
139
|
+
* // rotation: 90,
|
|
140
|
+
* // pins: ['pin-uuid-1', 'pin-uuid-2']
|
|
141
|
+
* // }
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
toJSON(): IComponent;
|
|
145
|
+
/**
|
|
146
|
+
* Deserialize component from JSON.
|
|
147
|
+
*
|
|
148
|
+
* @param json - Component data
|
|
149
|
+
* @returns Component instance
|
|
150
|
+
*
|
|
151
|
+
*/
|
|
152
|
+
static fromJSON(json: IComponent): Component;
|
|
153
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { UUID, Position } from '../utils';
|
|
2
|
+
import { ENodeSourceType, ENodeType, IENode } from './types';
|
|
3
|
+
import { Circuit } from './Circuit';
|
|
4
|
+
/**
|
|
5
|
+
* Electrical connection point (component pin or wire branching point).
|
|
6
|
+
*
|
|
7
|
+
* ENodes are automatically managed by the Circuit:
|
|
8
|
+
* - **Pin nodes**: Created when components are added, deleted when components removed
|
|
9
|
+
* - **Branching nodes**: Created when wires split, deleted when orphaned (no wires)
|
|
10
|
+
*
|
|
11
|
+
* **Position Handling**:
|
|
12
|
+
* - Pin nodes: Position derived from parent component
|
|
13
|
+
* - Branching nodes: Independent position stored directly
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Pin node (created automatically by Circuit)
|
|
18
|
+
* const circuit = new Circuit();
|
|
19
|
+
* const component = circuit.addComponent(new Position(10, 20), new Rotation(0), 2);
|
|
20
|
+
* const pinNode = circuit.getENode(component.pins[0]);
|
|
21
|
+
*
|
|
22
|
+
* console.log(pinNode.type); // ENodeType.Pin
|
|
23
|
+
* console.log(pinNode.component); // component UUID
|
|
24
|
+
* console.log(pinNode.pinLabel); // '0'
|
|
25
|
+
*
|
|
26
|
+
* // Branching node (created during wire split)
|
|
27
|
+
* const branchNode = new ENode(
|
|
28
|
+
* ENodeType.BranchingPoint,
|
|
29
|
+
* undefined,
|
|
30
|
+
* undefined,
|
|
31
|
+
* new Position(15, 25)
|
|
32
|
+
* );
|
|
33
|
+
* console.log(branchNode.position); // Position { x: 15, y: 25 }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare class ENode {
|
|
37
|
+
/**
|
|
38
|
+
* Unique identifier for this ENode.
|
|
39
|
+
* @readonly
|
|
40
|
+
*/
|
|
41
|
+
readonly id: UUID;
|
|
42
|
+
/**
|
|
43
|
+
* Type of electrical node (Pin or BranchingPoint).
|
|
44
|
+
* @readonly
|
|
45
|
+
*/
|
|
46
|
+
readonly type: ENodeType;
|
|
47
|
+
/**
|
|
48
|
+
* Parent component UUID (only for pin nodes).
|
|
49
|
+
* Undefined for branching point nodes.
|
|
50
|
+
* @readonly
|
|
51
|
+
*/
|
|
52
|
+
readonly component: UUID | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Pin label within component (only for pin nodes).
|
|
55
|
+
* Undefined for branching point nodes.
|
|
56
|
+
* @readonly
|
|
57
|
+
*/
|
|
58
|
+
readonly pinLabel: string | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Grid position (only for branching point nodes).
|
|
61
|
+
* Undefined for pin nodes (position derived from component).
|
|
62
|
+
* @readonly
|
|
63
|
+
*/
|
|
64
|
+
readonly position: Position | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Set of wire UUIDs connected to this node.
|
|
67
|
+
* Mutable to allow wire connections/disconnections.
|
|
68
|
+
*/
|
|
69
|
+
readonly wires: Set<UUID>;
|
|
70
|
+
/**
|
|
71
|
+
* Is the ENode a source of voltage or current?
|
|
72
|
+
*/
|
|
73
|
+
source: ENodeSourceType | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Pin role classification: free, mainVcc, vcc, mainGnd, gnd, logicInput, logicOutput.
|
|
76
|
+
* @readonly
|
|
77
|
+
*/
|
|
78
|
+
readonly subtype: string;
|
|
79
|
+
/**
|
|
80
|
+
* Create a new electrical node.
|
|
81
|
+
*
|
|
82
|
+
* **Note**: Typically ENodes are created automatically by Circuit.
|
|
83
|
+
* This constructor is used internally.
|
|
84
|
+
*
|
|
85
|
+
* @param type - Node type (Pin or BranchingPoint)
|
|
86
|
+
* @param component - Parent component UUID (pin nodes only)
|
|
87
|
+
* @param pinLabel - Pin label (pin nodes only)
|
|
88
|
+
* @param position - Grid position (branching points only)
|
|
89
|
+
* @param source - Source type (Voltage/Current) or undefined
|
|
90
|
+
*
|
|
91
|
+
* @param subtype
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* // Pin node (internal to Circuit)
|
|
95
|
+
* const pinNode = new ENode(
|
|
96
|
+
* ENodeType.Pin,
|
|
97
|
+
* componentId,
|
|
98
|
+
* '0', // first pin
|
|
99
|
+
* undefined,
|
|
100
|
+
* undefined
|
|
101
|
+
* );
|
|
102
|
+
*
|
|
103
|
+
* // Branching point node
|
|
104
|
+
* const branchNode = new ENode(
|
|
105
|
+
* ENodeType.BranchingPoint,
|
|
106
|
+
* undefined,
|
|
107
|
+
* undefined,
|
|
108
|
+
* new Position(15, 25),
|
|
109
|
+
* undefined
|
|
110
|
+
* );
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
constructor(type: ENodeType, component: UUID | undefined, pinLabel: string | undefined, position: Position | undefined, source?: ENodeSourceType | undefined, subtype?: string);
|
|
114
|
+
/**
|
|
115
|
+
* Get the position of this electrical node.
|
|
116
|
+
*
|
|
117
|
+
* **Pin nodes**: Derives position from parent component.
|
|
118
|
+
* **Branching nodes**: Returns stored position directly.
|
|
119
|
+
*
|
|
120
|
+
* @param circuit - Circuit instance (needed to look up component for pin nodes)
|
|
121
|
+
* @returns Position on the grid
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const circuit = new Circuit();
|
|
126
|
+
* const component = circuit.addComponent(
|
|
127
|
+
* new Position(10, 20),
|
|
128
|
+
* new Rotation(0),
|
|
129
|
+
* 1
|
|
130
|
+
* );
|
|
131
|
+
*
|
|
132
|
+
* const pinNode = circuit.getENode(component.pins[0]);
|
|
133
|
+
* const position = pinNode.getPosition(circuit);
|
|
134
|
+
* console.log(position.x); // 10 (derived from component)
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
getPosition(circuit: Circuit): Position;
|
|
138
|
+
/**
|
|
139
|
+
* Update the enode (branching point only)'s position.
|
|
140
|
+
*
|
|
141
|
+
* @param newPosition - The new position for the enode
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* const component = circuit.getComponent(componentId);
|
|
146
|
+
* component.setPosition(new Position(15, 25));
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
setPosition(newPosition: Position): void;
|
|
150
|
+
/**
|
|
151
|
+
* Update the enode's source type.
|
|
152
|
+
* @param sourceType
|
|
153
|
+
*/
|
|
154
|
+
setSourceType(sourceType?: ENodeSourceType | undefined): void;
|
|
155
|
+
/**
|
|
156
|
+
* Serialize ENode to JSON.
|
|
157
|
+
*
|
|
158
|
+
* @returns Plain object representation
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* const json = enode.toJSON();
|
|
163
|
+
* console.log(json);
|
|
164
|
+
* // Pin node:
|
|
165
|
+
* // {
|
|
166
|
+
* // id: "uuid",
|
|
167
|
+
* // type: "Pin",
|
|
168
|
+
* // component: "component-uuid",
|
|
169
|
+
* // pinLabel: "0"
|
|
170
|
+
* // }
|
|
171
|
+
*
|
|
172
|
+
* // Branching node:
|
|
173
|
+
* // {
|
|
174
|
+
* // id: "uuid",
|
|
175
|
+
* // type: "BranchingPoint",
|
|
176
|
+
* // position: { x: 15, y: 25 }
|
|
177
|
+
* // }
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
toJSON(): IENode;
|
|
181
|
+
/**
|
|
182
|
+
* Deserialize ENode from JSON.
|
|
183
|
+
*
|
|
184
|
+
* @param json - ENode data
|
|
185
|
+
* @returns ENode instance
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* const json = {
|
|
190
|
+
* id: "uuid",
|
|
191
|
+
* type: "Pin",
|
|
192
|
+
* component: "component-uuid",
|
|
193
|
+
* pinLabel: "0"
|
|
194
|
+
* };
|
|
195
|
+
*
|
|
196
|
+
* const enode = ENode.fromJSON(json);
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
static fromJSON(json: IENode): ENode;
|
|
200
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { UUID, Position } from '../utils';
|
|
2
|
+
import { IWire } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Electrical connection between two ENodes.
|
|
5
|
+
*
|
|
6
|
+
* Wires connect exactly two electrical nodes (component pins or branching points).
|
|
7
|
+
* They support intermediate positions for ad-hoc routing paths in rendering.
|
|
8
|
+
*
|
|
9
|
+
* **Lifecycle**: Wires are created and removed via the Circuit class.
|
|
10
|
+
* - Creating a wire updates bidirectional references (Wire ↔ ENodes)
|
|
11
|
+
* - Removing a wire triggers orphaned branching point cleanup
|
|
12
|
+
* - Splitting a wire creates new branching ENode and multiple wires
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const circuit = new Circuit();
|
|
17
|
+
* const comp1 = circuit.addComponent(new Position(0, 0), new Rotation(0), 1);
|
|
18
|
+
* const comp2 = circuit.addComponent(new Position(10, 10), new Rotation(0), 1);
|
|
19
|
+
*
|
|
20
|
+
* // Straight wire
|
|
21
|
+
* const wire = circuit.addWire(comp1.pins[0], comp2.pins[0]);
|
|
22
|
+
*
|
|
23
|
+
* // Wire with custom path
|
|
24
|
+
* const curvedWire = circuit.addWire(
|
|
25
|
+
* comp1.pins[0],
|
|
26
|
+
* comp2.pins[0],
|
|
27
|
+
* [new Position(5, 5), new Position(8, 7)]
|
|
28
|
+
* );
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare class Wire {
|
|
32
|
+
/**
|
|
33
|
+
* Unique identifier for this wire.
|
|
34
|
+
* @readonly
|
|
35
|
+
*/
|
|
36
|
+
readonly id: UUID;
|
|
37
|
+
/**
|
|
38
|
+
* First connected ENode UUID.
|
|
39
|
+
* @readonly
|
|
40
|
+
*/
|
|
41
|
+
readonly node1: UUID;
|
|
42
|
+
/**
|
|
43
|
+
* Second connected ENode UUID.
|
|
44
|
+
* @readonly
|
|
45
|
+
*/
|
|
46
|
+
readonly node2: UUID;
|
|
47
|
+
/**
|
|
48
|
+
* Optional intermediate positions for wire routing.
|
|
49
|
+
* Empty array indicates straight-line connection.
|
|
50
|
+
* @readonly
|
|
51
|
+
*/
|
|
52
|
+
intermediatePositions: Array<Position>;
|
|
53
|
+
/**
|
|
54
|
+
* Create a new wire.
|
|
55
|
+
*
|
|
56
|
+
* **Note**: Typically wires are created via `Circuit.addWire()` which
|
|
57
|
+
* handles validation and bidirectional reference updates. This constructor
|
|
58
|
+
* is used internally by Circuit.
|
|
59
|
+
*
|
|
60
|
+
* @param node1 - First ENode UUID
|
|
61
|
+
* @param node2 - Second ENode UUID
|
|
62
|
+
* @param intermediatePositions - Optional waypoints for rendering
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* // Usually created via Circuit:
|
|
67
|
+
* const wire = circuit.addWire(nodeId1, nodeId2);
|
|
68
|
+
*
|
|
69
|
+
* // With intermediate positions:
|
|
70
|
+
* const wire = circuit.addWire(
|
|
71
|
+
* nodeId1,
|
|
72
|
+
* nodeId2,
|
|
73
|
+
* [new Position(5, 10), new Position(15, 10)]
|
|
74
|
+
* );
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
constructor(node1: UUID, node2: UUID, intermediatePositions?: Array<Position>);
|
|
78
|
+
/**
|
|
79
|
+
* Check if this is a straight-line wire.
|
|
80
|
+
*
|
|
81
|
+
* @returns true if no intermediate positions, false otherwise
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const straightWire = new Wire(node1, node2);
|
|
86
|
+
* console.log(straightWire.isStraightLine()); // true
|
|
87
|
+
*
|
|
88
|
+
* const curvedWire = new Wire(node1, node2, [new Position(5, 5)]);
|
|
89
|
+
* console.log(curvedWire.isStraightLine()); // false
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
isStraightLine(): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Serialize wire to JSON.
|
|
95
|
+
*
|
|
96
|
+
* @returns Plain object representation
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const json = wire.toJSON();
|
|
101
|
+
* console.log(json);
|
|
102
|
+
* // {
|
|
103
|
+
* // id: "uuid",
|
|
104
|
+
* // node1: "node-uuid-1",
|
|
105
|
+
* // node2: "node-uuid-2",
|
|
106
|
+
* // intermediatePositions: [{ x: 5, y: 10 }]
|
|
107
|
+
* // }
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
toJSON(): IWire;
|
|
111
|
+
/**
|
|
112
|
+
* Deserialize wire from JSON.
|
|
113
|
+
*
|
|
114
|
+
* @param json - Wire data
|
|
115
|
+
* @returns Wire instance
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const json = {
|
|
120
|
+
* id: "uuid",
|
|
121
|
+
* node1: "node-uuid-1",
|
|
122
|
+
* node2: "node-uuid-2",
|
|
123
|
+
* intermediatePositions: [{ x: 5, y: 10 }]
|
|
124
|
+
* };
|
|
125
|
+
*
|
|
126
|
+
* const wire = Wire.fromJSON(json);
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
static fromJSON(json: IWire): Wire;
|
|
130
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ComponentType, LogicFamily } from './types';
|
|
2
|
+
import { Component } from './Component';
|
|
3
|
+
/**
|
|
4
|
+
* Gate family classification used for delay table lookup.
|
|
5
|
+
* Maps to the logical function regardless of physical implementation.
|
|
6
|
+
*/
|
|
7
|
+
type GateFamily = 'NOT' | 'Buffer' | 'NAND' | 'AND' | 'NOR' | 'OR' | 'XOR' | 'XNOR';
|
|
8
|
+
/**
|
|
9
|
+
* Given a component compute the basis transitionSpan from its logicFamily if applicable
|
|
10
|
+
* if not applicable / already implemented returns undefined
|
|
11
|
+
* @param component
|
|
12
|
+
*/
|
|
13
|
+
export declare function computeTransitionSpan(component: Component): number | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Classify a ComponentType + activationLogic combination into a GateFamily and input count.
|
|
16
|
+
*
|
|
17
|
+
* Returns null for non-gate component types (Battery, Switch, LED, etc.).
|
|
18
|
+
*
|
|
19
|
+
* @param componentType - The component type to classify
|
|
20
|
+
* @param activationLogic - 'positive' or 'negative' from the component config
|
|
21
|
+
* @returns Object with gateFamily and inputCount, or null if not a gate
|
|
22
|
+
*/
|
|
23
|
+
export declare function classifyGate(componentType: ComponentType, activationLogic: string): {
|
|
24
|
+
gateFamily: GateFamily;
|
|
25
|
+
inputCount: number;
|
|
26
|
+
} | null;
|
|
27
|
+
/**
|
|
28
|
+
* Compute the propagation delay in ticks for a gate given its logic family, gate family, and input count.
|
|
29
|
+
*
|
|
30
|
+
* CMOS1 formulas (base unit: 1 inverter = 1 tick):
|
|
31
|
+
* - NOT: 1 (constant)
|
|
32
|
+
* - Buffer: 2 (constant)
|
|
33
|
+
* - NAND/NOR: log2(n)
|
|
34
|
+
* - AND/OR: log2(n) + 1
|
|
35
|
+
* - XOR: log2(n) * 2
|
|
36
|
+
* - XNOR: log2(n) * 2 + 1
|
|
37
|
+
*
|
|
38
|
+
* This table assumes inverter, NAND, NAND4, NAND8, NOR, NOR4, NOR8 and XOR(2) are transistor level primitives
|
|
39
|
+
*
|
|
40
|
+
* TTL1 uses lookup tables (base unit: NAND2 = 1 tick).
|
|
41
|
+
* NOT and Buffer: same as CMOS1 (1 and 2 ticks).
|
|
42
|
+
* XOR/XNOR: same as CMOS1.
|
|
43
|
+
*
|
|
44
|
+
* @param logicFamily - The technology family
|
|
45
|
+
* @param gateFamily - The logical gate function
|
|
46
|
+
* @param inputCount - Number of data inputs (not counting Vcc)
|
|
47
|
+
* @returns Propagation delay in ticks (integer >= 1)
|
|
48
|
+
* @throws {Error} If called with Sandbox family (caller must not invoke for Sandbox)
|
|
49
|
+
* @throws {Error} If input count is unsupported for the given family
|
|
50
|
+
*/
|
|
51
|
+
export declare function computeGateDelay(logicFamily: LogicFamily, gateFamily: GateFamily, inputCount: number): number;
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module defining the core objects modelling electrical/logical topology: circuit, components, enodes and wires
|
|
3
|
+
*
|
|
4
|
+
* @module core/topology
|
|
5
|
+
*/
|
|
6
|
+
export { CIRCUIT_FILE_VERSION, ALL_LOGIC_FAMILIES, DEFAULT_LOGIC_FAMILY, ComponentType, COMPONENT_TYPE_METADATA, ENodeSourceType, ENodeType, } from './types.js';
|
|
7
|
+
export type { LogicFamily, IPinMetadata, IComponentTypeMetadata, IENode, IWire, IComponent, ICircuitOptions, ICircuitMetadata, ICircuit, } from './types.js';
|
|
8
|
+
export { ENode } from './ENode.js';
|
|
9
|
+
export { Wire } from './Wire.js';
|
|
10
|
+
export { Component } from './Component.js';
|
|
11
|
+
export { CircuitOptions } from './CircuitOptions.js';
|
|
12
|
+
export { CircuitMetadata } from './CircuitMetadata.js';
|
|
13
|
+
export { Circuit } from './Circuit.js';
|
|
14
|
+
export { computeTransitionSpan, classifyGate, computeGateDelay } from './delays.js';
|