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.
- package/AGENTS.md +10 -7
- package/CLAUDE.md +4 -6
- package/README.md +5 -2
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +74 -2114
- package/dist/core/setup.d.ts +17 -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/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 +24 -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/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 +26 -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 +152 -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 +175 -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-Bjta9Y7_.js +2707 -0
- package/dist/core-Bjta9Y7_.js.map +1 -0
- package/dist/index.d.ts +13 -6306
- package/dist/index.js +117 -110
- package/dist/scene/CircuitEngine.d.ts +270 -0
- package/dist/scene/index.d.ts +0 -1
- package/dist/scene/index.js +43 -39
- package/dist/scene/setup.d.ts +18 -0
- package/dist/scene/shared/AbstractCircuitController.d.ts +211 -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/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 +29 -0
- package/dist/scene/shared/components/types.d.ts +43 -0
- package/dist/scene/shared/types.d.ts +476 -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 +261 -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 +227 -0
- package/dist/scene/static/CircuitWriter.d.ts +146 -0
- package/dist/scene/static/PinTooltipWidget.d.ts +26 -0
- package/dist/scene/static/tools/BuildTool.d.ts +286 -0
- package/dist/scene/static/tools/ComponentPickerWidget.d.ts +82 -0
- package/dist/scene/static/tools/ConfigPanelWidget.d.ts +93 -0
- package/dist/scene/static/tools/MultiSelectTool.d.ts +265 -0
- package/dist/scene-CVsDdySt.js +7357 -0
- package/dist/scene-CVsDdySt.js.map +1 -0
- package/package.json +24 -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,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';
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { ICameraOptions, IPosition, UUID } from '../utils';
|
|
2
|
+
/**
|
|
3
|
+
* canonic version for circuit files produced
|
|
4
|
+
*/
|
|
5
|
+
export declare const CIRCUIT_FILE_VERSION = "0.0.11";
|
|
6
|
+
/**
|
|
7
|
+
* Type of electrical pinSources in the circuit.
|
|
8
|
+
*
|
|
9
|
+
* ENodes have a sourceType which can be undefined or one of the following:
|
|
10
|
+
* - **Voltage**: ENode that provides a voltage source to the circuit. All Enodes of this type are considered at the same positive potential.
|
|
11
|
+
* - **Current**: Ground/neutral ENodes that provides a current source to the circuit. All Enodes of this type are considered as points at
|
|
12
|
+
* the same 0V-GROUND potential and are points from where electrons enters the circuit.
|
|
13
|
+
*/
|
|
14
|
+
export declare enum ENodeSourceType {
|
|
15
|
+
Voltage = "Voltage",
|
|
16
|
+
Current = "Current"
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Type of electrical node (ENode) in the circuit.
|
|
20
|
+
*
|
|
21
|
+
* ENodes represent atomic electrical connection points and come in two variants (immutable after node creation)
|
|
22
|
+
*
|
|
23
|
+
* - **Pin**: Connection point belonging to a Component. Position is derived
|
|
24
|
+
* from the parent component's position, rotation, and pin index. Automatically
|
|
25
|
+
* created when a component is added, deleted when component is removed.
|
|
26
|
+
*
|
|
27
|
+
* - **BranchingPoint**: Junction point where wires split. Has an independent
|
|
28
|
+
* position on the grid. Automatically created when wires are split, deleted
|
|
29
|
+
* when no wires remain connected (orphaned).
|
|
30
|
+
*/
|
|
31
|
+
export declare enum ENodeType {
|
|
32
|
+
/**
|
|
33
|
+
* Component pin connection point.
|
|
34
|
+
*
|
|
35
|
+
* Properties:
|
|
36
|
+
* - Has parent component reference
|
|
37
|
+
* - Has pin label within component
|
|
38
|
+
* - Position derived from component
|
|
39
|
+
* - Lifecycle tied to component (cascade deletion)
|
|
40
|
+
*/
|
|
41
|
+
Pin = "Pin",
|
|
42
|
+
/**
|
|
43
|
+
* Wire branching point (junction).
|
|
44
|
+
*
|
|
45
|
+
* Properties:
|
|
46
|
+
* - Independent position on grid
|
|
47
|
+
* - Created when wire is split
|
|
48
|
+
* - Deleted when last wire is removed (orphaned cleanup)
|
|
49
|
+
* - No parent component
|
|
50
|
+
*/
|
|
51
|
+
BranchingPoint = "BranchingPoint"
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Metadata describing a component pin's source type and subtype.
|
|
55
|
+
*
|
|
56
|
+
* @property sourceType - Voltage/Current source or undefined for passive pins
|
|
57
|
+
* @property subtype - Pin role classification: 'free', 'vcc', 'logicInput', 'logicOutput'
|
|
58
|
+
*/
|
|
59
|
+
export interface IPinMetadata {
|
|
60
|
+
readonly subtype: string;
|
|
61
|
+
readonly sourceType: ENodeSourceType | undefined;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Metadata for a component type.
|
|
65
|
+
*
|
|
66
|
+
* @property id - Unique string identifier matching the enum value
|
|
67
|
+
* @property name - Human-readable display name
|
|
68
|
+
* @property pins - Array of pin labels (order-significant)
|
|
69
|
+
* @property config - Default configuration parameters (depends on the component, e.g., initialState, activationLogic, color...)
|
|
70
|
+
*/
|
|
71
|
+
export interface IComponentTypeMetadata {
|
|
72
|
+
readonly id: string;
|
|
73
|
+
readonly name: string;
|
|
74
|
+
readonly pins: Map<string, IPinMetadata>;
|
|
75
|
+
readonly config: Map<string, string>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Available logic families
|
|
79
|
+
*
|
|
80
|
+
* - `CMOS1`: CMOS technology, base unit 1 inverter = 1 tick
|
|
81
|
+
* - `TTL1`: TTL technology, base unit 1 NAND2 = 1 tick
|
|
82
|
+
* - `Sandbox`: User-defined delays, no technology constraints
|
|
83
|
+
*/
|
|
84
|
+
export type LogicFamily = 'CMOS1' | 'TTL1' | 'Sandbox';
|
|
85
|
+
/** All supported logic families */
|
|
86
|
+
export declare const ALL_LOGIC_FAMILIES: LogicFamily[];
|
|
87
|
+
/** Default logic family applied when none is specified */
|
|
88
|
+
export declare const DEFAULT_LOGIC_FAMILY: LogicFamily;
|
|
89
|
+
/** Interface defining an ElectricalNode **/
|
|
90
|
+
export interface IENode {
|
|
91
|
+
id: UUID;
|
|
92
|
+
type: ENodeType;
|
|
93
|
+
component?: UUID | null;
|
|
94
|
+
pinLabel?: string | null;
|
|
95
|
+
position?: IPosition | null;
|
|
96
|
+
source?: ENodeSourceType | null;
|
|
97
|
+
subtype: string;
|
|
98
|
+
}
|
|
99
|
+
/** Interface defining a Wire (link between 2 ENodes supporting intermediate position to tune its path) **/
|
|
100
|
+
export interface IWire {
|
|
101
|
+
id: UUID;
|
|
102
|
+
node1: UUID;
|
|
103
|
+
node2: UUID;
|
|
104
|
+
intermediatePositions: IPosition[];
|
|
105
|
+
}
|
|
106
|
+
/** Interface defining a Component **/
|
|
107
|
+
export interface IComponent {
|
|
108
|
+
id: UUID;
|
|
109
|
+
type: ComponentType;
|
|
110
|
+
position: IPosition;
|
|
111
|
+
rotation: number;
|
|
112
|
+
pins: UUID[];
|
|
113
|
+
config: {
|
|
114
|
+
[key: string]: string;
|
|
115
|
+
};
|
|
116
|
+
editable: boolean;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* User editable options for a Circuit
|
|
120
|
+
*/
|
|
121
|
+
export type ICircuitOptions = {
|
|
122
|
+
name: string;
|
|
123
|
+
defaultLogicFamily: LogicFamily;
|
|
124
|
+
};
|
|
125
|
+
/** circuit metadata type — combines user writable options and managed metadata */
|
|
126
|
+
export type ICircuitMetadata = {
|
|
127
|
+
version: string;
|
|
128
|
+
options: ICircuitOptions;
|
|
129
|
+
cameraOptions: ICameraOptions;
|
|
130
|
+
size: number;
|
|
131
|
+
divisions: number;
|
|
132
|
+
};
|
|
133
|
+
/** circuit type */
|
|
134
|
+
export type ICircuit = {
|
|
135
|
+
metadata: ICircuitMetadata;
|
|
136
|
+
components: Iterable<IComponent>;
|
|
137
|
+
enodes: Iterable<IENode>;
|
|
138
|
+
wires: Iterable<IWire>;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Enumeration of ALL available component types.
|
|
142
|
+
*
|
|
143
|
+
* Each component type represents a specific electrical element that can be
|
|
144
|
+
* placed in a circuit (battery, LED, transistor, etc.).
|
|
145
|
+
*/
|
|
146
|
+
export declare enum ComponentType {
|
|
147
|
+
Cube = "cube",// no pins component for testing purposes mainly
|
|
148
|
+
Label = "label",// decorative text label with no pins
|
|
149
|
+
Battery = "battery",
|
|
150
|
+
Switch = "switch",
|
|
151
|
+
DoubleThrowSwitch = "doubleThrowSwitch",
|
|
152
|
+
Lightbulb = "lightbulb",
|
|
153
|
+
Relay = "relay",
|
|
154
|
+
SmallLED = "smallLED",
|
|
155
|
+
RectangleLED = "rectangleLED",
|
|
156
|
+
Clock = "clock",
|
|
157
|
+
Inverter = "inverter",
|
|
158
|
+
NandGate = "nandGate",
|
|
159
|
+
Nand4Gate = "nand4Gate",
|
|
160
|
+
Nand8Gate = "nand8Gate",
|
|
161
|
+
NorGate = "norGate",
|
|
162
|
+
Nor4Gate = "nor4Gate",
|
|
163
|
+
Nor8Gate = "nor8Gate",
|
|
164
|
+
XorGate = "xorGate",
|
|
165
|
+
Xor4Gate = "xor4Gate",
|
|
166
|
+
Xor8Gate = "xor8Gate"
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Component type metadata lookup table.
|
|
170
|
+
*
|
|
171
|
+
* Maps each ComponentType enum value to its associated metadata
|
|
172
|
+
* (id, display name, pins, and default configuration arguments).
|
|
173
|
+
*
|
|
174
|
+
*/
|
|
175
|
+
export declare const COMPONENT_TYPE_METADATA: Readonly<Record<ComponentType, IComponentTypeMetadata>>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ICameraOptions } from './types';
|
|
2
|
+
import { Position3D } from './Position3D';
|
|
3
|
+
/**
|
|
4
|
+
* Camera configuration options.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* // Create with defaults
|
|
9
|
+
* const defaultOpts = new CameraOptions();
|
|
10
|
+
*
|
|
11
|
+
* // Create with custom values
|
|
12
|
+
* const customOpts = new CameraOptions(
|
|
13
|
+
* new Position3D(0, 20, 10),
|
|
14
|
+
* new Position3D(5, 0, 0),
|
|
15
|
+
* 60,
|
|
16
|
+
* 0.5,
|
|
17
|
+
* 2000
|
|
18
|
+
* );
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare class CameraOptions {
|
|
22
|
+
readonly position: Position3D;
|
|
23
|
+
readonly lookAtPosition: Position3D;
|
|
24
|
+
readonly fov: number;
|
|
25
|
+
readonly near: number;
|
|
26
|
+
readonly far: number;
|
|
27
|
+
/**
|
|
28
|
+
* Create new camera options.
|
|
29
|
+
*
|
|
30
|
+
* @param position - Camera position (default: 0, 15, 15)
|
|
31
|
+
* @param lookAtPosition - Camera look-at target position (default: 0, 0, 0)
|
|
32
|
+
* @param fov - Field of view in degrees (default: 75)
|
|
33
|
+
* @param near - Near clipping plane distance (default: 0.1)
|
|
34
|
+
* @param far - Far clipping plane distance (default: 1000)
|
|
35
|
+
*/
|
|
36
|
+
constructor(position?: Position3D, lookAtPosition?: Position3D, fov?: number, near?: number, far?: number);
|
|
37
|
+
/**
|
|
38
|
+
* Serialize camera options to JSON.
|
|
39
|
+
*
|
|
40
|
+
* @returns Plain object with camera configuration
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const opts = new CameraOptions();
|
|
45
|
+
* const json = opts.toJSON();
|
|
46
|
+
* console.log(json);
|
|
47
|
+
* // {
|
|
48
|
+
* // position: { x: 0, y: 15, z: 0 },
|
|
49
|
+
* // lookAtPosition: { x: 0, y: 0, z: 0 },
|
|
50
|
+
* // fov: 75,
|
|
51
|
+
* // near: 0.1,
|
|
52
|
+
* // far: 1000
|
|
53
|
+
* // }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
toJSON(): ICameraOptions;
|
|
57
|
+
/**
|
|
58
|
+
* Deserialize camera options from JSON.
|
|
59
|
+
*
|
|
60
|
+
* @param json - Plain object with camera configuration
|
|
61
|
+
* @returns CameraOptions instance
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const json = {
|
|
66
|
+
* position: { x: 0, y: 20, z: 10 },
|
|
67
|
+
* lookAtPosition: { x: 5, y: 0, z: 0 },
|
|
68
|
+
* fov: 60,
|
|
69
|
+
* near: 0.5,
|
|
70
|
+
* far: 2000
|
|
71
|
+
* };
|
|
72
|
+
* const opts = CameraOptions.fromJSON(json);
|
|
73
|
+
* console.log(opts.position.y); // 20
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
static fromJSON(json: ICameraOptions): CameraOptions;
|
|
77
|
+
/**
|
|
78
|
+
* String representation for debugging.
|
|
79
|
+
*
|
|
80
|
+
* @returns String with camera configuration details
|
|
81
|
+
*/
|
|
82
|
+
toString(): string;
|
|
83
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface MemoizeArgs {
|
|
2
|
+
expiring?: number;
|
|
3
|
+
hashFunction?: boolean | ((...args: any[]) => any);
|
|
4
|
+
tags?: string[];
|
|
5
|
+
}
|
|
6
|
+
export declare function Memoize(args?: MemoizeArgs | MemoizeArgs['hashFunction']): (_target: Object, _propertyKey: string, descriptor: TypedPropertyDescriptor<any>) => void;
|
|
7
|
+
export declare function MemoizeExpiring(expiring: number, hashFunction?: MemoizeArgs['hashFunction']): (_target: Object, _propertyKey: string, descriptor: TypedPropertyDescriptor<any>) => void;
|
|
8
|
+
export declare function clear(tags: string[]): number;
|
|
9
|
+
export {};
|