simple-circuit-engine 0.0.10 → 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 +3 -0
- package/CLAUDE.md +16 -101
- package/README.md +3 -3
- package/dist/{CircuitRunner-DEb7JdNf.js → CircuitRunner-BQQlhwjD.js} +939 -767
- package/dist/CircuitRunner-BQQlhwjD.js.map +1 -0
- package/dist/core/index.d.ts +2 -22
- package/dist/core/index.js +1320 -1205
- package/dist/core/index.js.map +1 -1
- package/dist/index.d.ts +800 -780
- package/dist/index.js +108 -95
- package/dist/scene/index.d.ts +1 -1
- package/dist/scene/index.js +40 -38
- package/dist/{setup-AB1vFiis.js → setup-CIq_kgaw.js} +3123 -2811
- package/dist/setup-CIq_kgaw.js.map +1 -0
- package/package.json +1 -1
- package/dist/CircuitRunner-DEb7JdNf.js.map +0 -1
- package/dist/setup-AB1vFiis.js.map +0 -1
package/AGENTS.md
CHANGED
|
@@ -12,6 +12,7 @@ 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,
|
|
17
18
|
registerGatesComponentsBehaviors,
|
|
@@ -38,6 +39,8 @@ registerGatesComponentsBehaviors(behaviorRegistry); //... other groupsof compone
|
|
|
38
39
|
const engine = new CircuitEngine(componentsFactoryRegistry, behaviorRegistry);
|
|
39
40
|
const container = document.getElementById('canvas-container')!;
|
|
40
41
|
engine.initialize(container, engineOptions());
|
|
42
|
+
// set engine circuit to a new empty circuit
|
|
43
|
+
engine.setCircuit(new Circuit(new CircuitOptions()));
|
|
41
44
|
|
|
42
45
|
// Rendering
|
|
43
46
|
const renderer = new WebGLRenderer();
|
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,78 +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 build tool (state machine)
|
|
72
|
-
| +-- ComponentPickerWidget.ts # Widget for selecting component to add in BuildTool
|
|
73
|
-
| +-- ConfigPanelWidget.ts # Widget for changing components configuration
|
|
74
|
-
| +-- MultiSelectTool.ts # Rectangle selection + bulk operations
|
|
75
|
-
+-- simulation/
|
|
76
|
-
| +-- CircuitRunnerController.ts # Simulation mode controller
|
|
77
|
-
+-- shared/
|
|
78
|
-
| +-- AbstractCircuitController.ts # Base controller class
|
|
79
|
-
| +-- EventEmitter.ts # Type-safe event system
|
|
80
|
-
| +-- HoverManager.ts # Raycasting hover detection
|
|
81
|
-
| +-- WireVisualManager.ts # Wire Line2 visuals
|
|
82
|
-
| +-- BranchingPointVisualFactory.ts # BP visuals
|
|
83
|
-
| +-- components/
|
|
84
|
-
| | +-- ComponentVisualFactory.ts # Interface + base class
|
|
85
|
-
| | +-- GroupedFactoryRegistry.ts # Register groups of components referencing types and their visual factories
|
|
86
|
-
| | +-- ... # Components factories
|
|
87
|
-
| +-- types.ts # Shared type definitions
|
|
88
|
-
| +-- utils/ # Geometry, camera, lighting utilities
|
|
89
|
-
+-- setup.ts # Helper to register factories
|
|
90
|
-
+-- index.ts # Public API exports
|
|
91
|
-
```
|
|
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.
|
|
92
40
|
|
|
93
41
|
## Testing strategy
|
|
94
42
|
|
|
@@ -105,37 +53,4 @@ npm test && npm run lint
|
|
|
105
53
|
## Code Style
|
|
106
54
|
|
|
107
55
|
TypeScript (strict mode), targeting ES2022: Follow standard conventions
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
```typescript
|
|
111
|
-
/**
|
|
112
|
-
* GOOD practice for minimizing nested conditionals
|
|
113
|
-
* DO that because clearer, reduced learning/debugging overhead
|
|
114
|
-
* @param input
|
|
115
|
-
*/
|
|
116
|
-
function goodExample(input: number | null): string {
|
|
117
|
-
if (input === null) {
|
|
118
|
-
// early return in this case
|
|
119
|
-
return 'No input provided';
|
|
120
|
-
}
|
|
121
|
-
// process securized input
|
|
122
|
-
// Main logic (possibly big) continues here without additional nesting
|
|
123
|
-
let output = input * 2;
|
|
124
|
-
|
|
125
|
-
return `Output is ${output}`;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* BAD practice that increases nested conditionals
|
|
129
|
-
* DON'T do that because less clear, increased learning/debugging overhead
|
|
130
|
-
* @param input
|
|
131
|
-
*/
|
|
132
|
-
function badExample(input: number | null): string {
|
|
133
|
-
if (input !== null) {
|
|
134
|
-
// Main logic (possibly big) embedded under an if :
|
|
135
|
-
let output = input * 2;
|
|
136
|
-
return `Output is ${output}`;
|
|
137
|
-
} else {
|
|
138
|
-
return 'No input provided';
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
```
|
|
56
|
+
|
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ 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';
|
|
39
|
+
import { Circuit, CircuitOptions, BehaviorRegistry, registerBasicComponentsBehaviors } from 'simple-circuit-engine/core';
|
|
40
40
|
import { CircuitEngine, engineOptions, GroupedFactoryRegistry, DefaultVisualFactory, registerBasicComponentsBehaviors } from 'simple-circuit-engine/scene';
|
|
41
41
|
|
|
42
42
|
// Create component factory registry with basic components visual factories (for scene objects creation - rendering)
|
|
@@ -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 });
|