simple-circuit-engine 0.0.9 → 0.0.11
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 +22 -11
- package/CLAUDE.md +16 -100
- package/README.md +7 -7
- package/dist/{CircuitRunner-FXM_s5ll.js → CircuitRunner-BQQlhwjD.js} +1031 -527
- package/dist/CircuitRunner-BQQlhwjD.js.map +1 -0
- package/dist/core/index.d.ts +2 -22
- package/dist/core/index.js +1274 -840
- package/dist/core/index.js.map +1 -1
- package/dist/index.d.ts +1332 -673
- package/dist/index.js +110 -69
- package/dist/scene/index.d.ts +3 -2
- package/dist/scene/index.js +40 -27
- package/dist/{setup-YQJVUHFM.js → setup-CIq_kgaw.js} +4392 -2475
- package/dist/setup-CIq_kgaw.js.map +1 -0
- package/package.json +1 -1
- package/dist/CircuitRunner-FXM_s5ll.js.map +0 -1
- package/dist/setup-YQJVUHFM.js.map +0 -1
package/AGENTS.md
CHANGED
|
@@ -12,27 +12,35 @@ Educational electronic / computer circuit Build & Simulation engine with THREE.j
|
|
|
12
12
|
import { WebGLRenderer } from 'three';
|
|
13
13
|
import {
|
|
14
14
|
Circuit,
|
|
15
|
+
CircuitOptions,
|
|
15
16
|
BehaviorRegistry,
|
|
16
17
|
registerBasicComponentsBehaviors,
|
|
18
|
+
registerGatesComponentsBehaviors,
|
|
17
19
|
} from 'simple-circuit-engine/core';
|
|
18
20
|
import {
|
|
19
21
|
CircuitEngine,
|
|
20
22
|
engineOptions,
|
|
21
|
-
|
|
23
|
+
GroupedFactoryRegistry,
|
|
22
24
|
DefaultVisualFactory,
|
|
23
25
|
registerBasicComponentsFactories,
|
|
26
|
+
registerGatesComponentsFactories,
|
|
24
27
|
} from 'simple-circuit-engine/scene';
|
|
25
28
|
|
|
26
29
|
// Create component factory registry and behavior registry with basic components
|
|
27
30
|
const componentsFactoryRegistry = registerBasicComponentsFactories(
|
|
28
|
-
new
|
|
31
|
+
new GroupedFactoryRegistry(new DefaultVisualFactory())
|
|
29
32
|
);
|
|
33
|
+
registerGatesComponentsFactories(componentsFactoryRegistry); //... other groups of components if needed
|
|
34
|
+
|
|
30
35
|
const behaviorRegistry = registerBasicComponentsBehaviors(new BehaviorRegistry());
|
|
36
|
+
registerGatesComponentsBehaviors(behaviorRegistry); //... other groupsof components if needed
|
|
31
37
|
|
|
32
38
|
// Instanciate and Initialize CircuitEngine (it creates and uses a new Circuit by default)
|
|
33
39
|
const engine = new CircuitEngine(componentsFactoryRegistry, behaviorRegistry);
|
|
34
40
|
const container = document.getElementById('canvas-container')!;
|
|
35
41
|
engine.initialize(container, engineOptions());
|
|
42
|
+
// set engine circuit to a new empty circuit
|
|
43
|
+
engine.setCircuit(new Circuit(new CircuitOptions()));
|
|
36
44
|
|
|
37
45
|
// Rendering
|
|
38
46
|
const renderer = new WebGLRenderer();
|
|
@@ -67,7 +75,7 @@ animate();
|
|
|
67
75
|
- `CircuitRunner` - Tick-based simulation orchestrator
|
|
68
76
|
- `SimulationState` - Circuit state at a given tick
|
|
69
77
|
- `BehaviorRegistry` - Maps ComponentType → behavior logic
|
|
70
|
-
- `registerBasicComponentsBehaviors()` - Registers built-in behaviors
|
|
78
|
+
- `registerBasicComponentsBehaviors()` - Registers basic components built-in behaviors
|
|
71
79
|
|
|
72
80
|
### Types
|
|
73
81
|
|
|
@@ -84,15 +92,19 @@ animate();
|
|
|
84
92
|
|
|
85
93
|
### Visual Factories
|
|
86
94
|
|
|
87
|
-
- `
|
|
95
|
+
- `GroupedFactoryRegistry` - Register groups of components referencing types and their visual factories
|
|
88
96
|
- `DefaultVisualFactory` - Fallback factory for unknown types
|
|
89
|
-
- `registerBasicComponentsFactories()` - Registers built-in factories
|
|
97
|
+
- `registerBasicComponentsFactories()` - Registers basic components built-in factories
|
|
90
98
|
|
|
91
99
|
### Tools (Edit Mode)
|
|
92
100
|
|
|
93
|
-
- `BuildTool` - Primary editing tool
|
|
94
|
-
- `
|
|
95
|
-
|
|
101
|
+
- `BuildTool` - Primary unified editing tool (add/drag/move/rotate/remove/wire/copy-cut/paste one element)
|
|
102
|
+
- `MultiSelectTool` - Rectangle selection + bulk ops (drag, copy-cut/paste, remove multiple elements)
|
|
103
|
+
|
|
104
|
+
### Widgets
|
|
105
|
+
|
|
106
|
+
- `ComponentPicketWidget` - Widget for selecting component to add in BuildTool (edit mode)
|
|
107
|
+
- `ConfigPanelWidget.ts` - Widget for editing components configuration (edit mode)
|
|
96
108
|
|
|
97
109
|
### Managers
|
|
98
110
|
|
|
@@ -130,10 +142,9 @@ engine.on('simulationTick', (state) => { ... });
|
|
|
130
142
|
### Non-Goals
|
|
131
143
|
|
|
132
144
|
- **NOT realistic physics**: This is a discrete graph model, not SPICE
|
|
133
|
-
- **
|
|
145
|
+
- **No analog simulation**: No voltage drops, current limiting, etc.
|
|
134
146
|
- **Circuit states are boolean**: Tension/current are on/off, not continuous values
|
|
135
|
-
- **
|
|
136
|
-
|
|
147
|
+
- **NOT for production circuits**: Educational purposes only
|
|
137
148
|
|
|
138
149
|
### Do NOT
|
|
139
150
|
|
package/CLAUDE.md
CHANGED
|
@@ -4,7 +4,14 @@ Provide a simple and easy-to-use electronic circuit simulation library for educa
|
|
|
4
4
|
It allows users to create, edit and simulate electronic circuits in a web environment.
|
|
5
5
|
The library should be easily importable and usable in client applications and follow open-source typeScript libraries good practices.
|
|
6
6
|
|
|
7
|
-
Last updated: 2026-
|
|
7
|
+
Last updated: 2026-03-14
|
|
8
|
+
|
|
9
|
+
## Goals and principles
|
|
10
|
+
|
|
11
|
+
To provide a vulgarization library that teaches the frontier between electronics and low level coding.
|
|
12
|
+
The electrical model is very simplified (no level of voltage/current, resistance, capacitance or inductance, type or frequency of current)
|
|
13
|
+
and reduced to a logic state (has voltage/electrons sink true or false, has ground/electrons source true or false)/event engine.
|
|
14
|
+
However, it aims to teach real-world electronic design principles so modeling of components propagation delay and logic families is emphasized.
|
|
8
15
|
|
|
9
16
|
## Active Technologies
|
|
10
17
|
|
|
@@ -17,77 +24,19 @@ Last updated: 2026-01-18
|
|
|
17
24
|
|
|
18
25
|
Simple Circuit Engine follows a **Model-Controller** architecture with clear separation between:
|
|
19
26
|
|
|
20
|
-
- **Core module** (`src/core/`): Pure TypeScript domain **Model** and simulation engine (no dependencies)
|
|
21
|
-
- **Scene module** (`src/scene/`): Three.js visualization layer with editing **
|
|
27
|
+
- **Core module** (`src/core/`): Pure TypeScript domain **Model** and simulation engine (no dependencies).
|
|
28
|
+
- **Scene module** (`src/scene/`): Three.js visualization layer with editing **Controller** and its tools and the simulation animated **Controller**.
|
|
22
29
|
|
|
23
30
|
### Core Module (`src/core/`)
|
|
24
31
|
|
|
25
|
-
The core module is **dependency-free** and contains all domain logic
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
src/core/
|
|
29
|
-
+-- Circuit.ts # Central model: manages the three elements of the circuit : components, enodes, and wires
|
|
30
|
-
+-- Component.ts # Electrical component (battery, switch, LED, etc.)
|
|
31
|
-
+-- ENode.ts # Electrical node (Pin or BranchingPoint)
|
|
32
|
-
+-- Wire.ts # Connection between two enodes
|
|
33
|
-
+-- Position.ts # 2D grid position
|
|
34
|
-
+-- Rotation.ts # Discrete rotation
|
|
35
|
-
+-- types/
|
|
36
|
-
| +-- ComponentType.ts # Component type enum and metadata
|
|
37
|
-
| +-- ENodeSourceType.ts # Voltage/Current source types
|
|
38
|
-
| +-- ENodeType.ts # Pin vs BranchingPoint
|
|
39
|
-
| +-- Identifier.ts # UUID type alias
|
|
40
|
-
+-- simulation/
|
|
41
|
-
| +-- CircuitRunner.ts # Tick-based simulation orchestrator
|
|
42
|
-
| +-- DirtyTracker.ts # Utility used by CircuitRunner to keep tracks of simulation changed components (optimization)
|
|
43
|
-
| +-- EventQueue.ts # Used by CircuitRunner to queue simulation delayed transitions events
|
|
44
|
-
| +-- SimulationState.ts # Data Class representing the simulation state of entire circuit at a given time
|
|
45
|
-
| +-- StateManager.ts # Utility used by CircuitRunner to manage SimulationState updates
|
|
46
|
-
| +-- states/
|
|
47
|
-
| +-- ComponentState.ts # Abstract class for component state
|
|
48
|
-
| +-- ... # Components states
|
|
49
|
-
| +-- behaviors/
|
|
50
|
-
| +-- BehaviorRegistry.ts # Maps component types to behaviors
|
|
51
|
-
| +-- ComponentBehavior.ts # Interface for component logic
|
|
52
|
-
| +-- SwitchBehavior.ts # Switch toggle logic
|
|
53
|
-
| +-- ... # Other components behaviors
|
|
54
|
-
| +-- types/ # Various enums, data classes ...
|
|
55
|
-
+-- setup.ts # Helper to register behaviors
|
|
56
|
-
+-- index.ts # Public API exports
|
|
57
|
-
```
|
|
32
|
+
The core module is **dependency-free** and contains all domain logic.
|
|
33
|
+
Refer to its [CLAUDE.md](src/core/CLAUDE.md) for more details.
|
|
34
|
+
|
|
58
35
|
|
|
59
36
|
### Scene Module (`src/scene/`)
|
|
60
37
|
|
|
61
|
-
The scene module handles Three.js visualization and
|
|
62
|
-
|
|
63
|
-
```
|
|
64
|
-
src/scene/
|
|
65
|
-
+-- CircuitEngine.ts # Unified facade with mode switching
|
|
66
|
-
+-- static/
|
|
67
|
-
| +-- CircuitController.ts # Edit mode controller
|
|
68
|
-
| +-- CircuitWriter.ts # Writes scene changes to core model
|
|
69
|
-
| +-- SelectionManager.ts # Tracks selected elements
|
|
70
|
-
| +-- tools/
|
|
71
|
-
| +-- BuildTool.ts # Unified edit tool (state machine)
|
|
72
|
-
| +-- MultiSelectTool.ts # Rectangle selection + bulk operations
|
|
73
|
-
| +-- AddComponentTool.ts # Component placement tool
|
|
74
|
-
+-- simulation/
|
|
75
|
-
| +-- CircuitRunnerController.ts # Simulation mode controller
|
|
76
|
-
+-- shared/
|
|
77
|
-
| +-- AbstractCircuitController.ts # Base controller class
|
|
78
|
-
| +-- EventEmitter.ts # Type-safe event system
|
|
79
|
-
| +-- HoverManager.ts # Raycasting hover detection
|
|
80
|
-
| +-- WireVisualManager.ts # Wire Line2 visuals
|
|
81
|
-
| +-- BranchingPointVisualFactory.ts # BP visuals
|
|
82
|
-
| +-- components/
|
|
83
|
-
| | +-- ComponentVisualFactory.ts # Interface + base class
|
|
84
|
-
| | +-- FactoryRegistry.ts # Maps types to factories
|
|
85
|
-
| | +-- ... # Components factories
|
|
86
|
-
| +-- types.ts # Shared type definitions
|
|
87
|
-
| +-- utils/ # Geometry, camera, lighting utilities
|
|
88
|
-
+-- setup.ts # Helper to register factories
|
|
89
|
-
+-- index.ts # Public API exports
|
|
90
|
-
```
|
|
38
|
+
The scene module handles Three.js visualization, user interaction and simulation animation.
|
|
39
|
+
Refer to its [CLAUDE.md](src/scene/CLAUDE.md) for more details.
|
|
91
40
|
|
|
92
41
|
## Testing strategy
|
|
93
42
|
|
|
@@ -104,37 +53,4 @@ npm test && npm run lint
|
|
|
104
53
|
## Code Style
|
|
105
54
|
|
|
106
55
|
TypeScript (strict mode), targeting ES2022: Follow standard conventions
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
```typescript
|
|
110
|
-
/**
|
|
111
|
-
* GOOD practice for minimizing nested conditionals
|
|
112
|
-
* DO that because clearer, reduced learning/debugging overhead
|
|
113
|
-
* @param input
|
|
114
|
-
*/
|
|
115
|
-
function goodExample(input: number | null): string {
|
|
116
|
-
if (input === null) {
|
|
117
|
-
// early return in this case
|
|
118
|
-
return 'No input provided';
|
|
119
|
-
}
|
|
120
|
-
// process securized input
|
|
121
|
-
// Main logic (possibly big) continues here without additional nesting
|
|
122
|
-
let output = input * 2;
|
|
123
|
-
|
|
124
|
-
return `Output is ${output}`;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* BAD practice that increases nested conditionals
|
|
128
|
-
* DON'T do that because less clear, increased learning/debugging overhead
|
|
129
|
-
* @param input
|
|
130
|
-
*/
|
|
131
|
-
function badExample(input: number | null): string {
|
|
132
|
-
if (input !== null) {
|
|
133
|
-
// Main logic (possibly big) embedded under an if :
|
|
134
|
-
let output = input * 2;
|
|
135
|
-
return `Output is ${output}`;
|
|
136
|
-
} else {
|
|
137
|
-
return 'No input provided';
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
```
|
|
56
|
+
|
package/README.md
CHANGED
|
@@ -36,12 +36,12 @@ This code set up the main CircuitEngine instance in edit mode on a new Circuit,
|
|
|
36
36
|
|
|
37
37
|
```javascript
|
|
38
38
|
import { WebGLRenderer } from 'three';
|
|
39
|
-
import { Circuit, BehaviorRegistry, registerBasicComponentsBehaviors } from 'simple-circuit-engine/core';
|
|
40
|
-
import { CircuitEngine, engineOptions,
|
|
39
|
+
import { Circuit, CircuitOptions, BehaviorRegistry, registerBasicComponentsBehaviors } from 'simple-circuit-engine/core';
|
|
40
|
+
import { CircuitEngine, engineOptions, GroupedFactoryRegistry, DefaultVisualFactory, registerBasicComponentsBehaviors } from 'simple-circuit-engine/scene';
|
|
41
41
|
|
|
42
|
-
// Create component factory registry with
|
|
43
|
-
const componentsFactoryRegistry = registerBasicComponentsFactories(new
|
|
44
|
-
// Create behavior registry with
|
|
42
|
+
// Create component factory registry with basic components visual factories (for scene objects creation - rendering)
|
|
43
|
+
const componentsFactoryRegistry = registerBasicComponentsFactories(new GroupedFactoryRegistry(new DefaultVisualFactory()));
|
|
44
|
+
// Create behavior registry with basic components behaviors (for simulation)
|
|
45
45
|
const behaviorRegistry = registerBasicComponentsBehaviors(new BehaviorRegistry());
|
|
46
46
|
|
|
47
47
|
// Initialize CircuitEngine
|
|
@@ -50,8 +50,8 @@ const behaviorRegistry = registerBasicComponentsBehaviors(new BehaviorRegistry()
|
|
|
50
50
|
const container = document.getElementById('canva-container')!;
|
|
51
51
|
const engine = new CircuitEngine(componentsFactoryRegistry, behaviorRegistry);
|
|
52
52
|
engine.initialize(container, engineOptions());
|
|
53
|
-
// set engine circuit to a new empty circuit
|
|
54
|
-
engine.setCircuit(new Circuit());
|
|
53
|
+
// set engine circuit to a new empty circuit
|
|
54
|
+
engine.setCircuit(new Circuit(new CircuitOptions()));
|
|
55
55
|
|
|
56
56
|
// Create and setup WebGL renderer
|
|
57
57
|
const renderer = new WebGLRenderer({ antialias: true, alpha: false });
|