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.
Files changed (161) hide show
  1. package/AGENTS.md +11 -7
  2. package/CLAUDE.md +6 -6
  3. package/README.md +5 -2
  4. package/dist/core/index.d.ts +0 -1
  5. package/dist/core/index.js +85 -2115
  6. package/dist/core/setup.d.ts +25 -0
  7. package/dist/core/simulation/CircuitRunner.d.ts +176 -0
  8. package/dist/core/simulation/DirtyTracker.d.ts +87 -0
  9. package/dist/core/simulation/EventQueue.d.ts +68 -0
  10. package/dist/core/simulation/StateManager.d.ts +100 -0
  11. package/dist/core/simulation/behaviors/BehaviorRegistry.d.ts +70 -0
  12. package/dist/core/simulation/behaviors/ComponentBehavior.d.ts +53 -0
  13. package/dist/core/simulation/behaviors/arithmetic/AdderBehavior.d.ts +28 -0
  14. package/dist/core/simulation/behaviors/arithmetic/ArithmeticBehaviorMixin.d.ts +63 -0
  15. package/dist/core/simulation/behaviors/arithmetic/EightBitAdderBehavior.d.ts +51 -0
  16. package/dist/core/simulation/behaviors/arithmetic/EightBitOnesComplementBehavior.d.ts +29 -0
  17. package/dist/core/simulation/behaviors/arithmetic/HalfAdderBehavior.d.ts +22 -0
  18. package/dist/core/simulation/behaviors/arithmetic/index.d.ts +7 -0
  19. package/dist/core/simulation/behaviors/basic/BatteryBehavior.d.ts +14 -0
  20. package/dist/core/simulation/behaviors/basic/ClockBehavior.d.ts +24 -0
  21. package/dist/core/simulation/behaviors/basic/DoubleThrowSwitchBehavior.d.ts +33 -0
  22. package/dist/core/simulation/behaviors/basic/LightbulbBehavior.d.ts +23 -0
  23. package/dist/core/simulation/behaviors/basic/RectangleLEDBehavior.d.ts +24 -0
  24. package/dist/core/simulation/behaviors/basic/RelayBehavior.d.ts +33 -0
  25. package/dist/core/simulation/behaviors/basic/SmallLEDBehavior.d.ts +24 -0
  26. package/dist/core/simulation/behaviors/basic/SwitchBehavior.d.ts +33 -0
  27. package/dist/core/simulation/behaviors/basic/index.d.ts +20 -0
  28. package/dist/core/simulation/behaviors/gates/InverterBehavior.d.ts +29 -0
  29. package/dist/core/simulation/behaviors/gates/Nand4GateBehavior.d.ts +18 -0
  30. package/dist/core/simulation/behaviors/gates/Nand8GateBehavior.d.ts +18 -0
  31. package/dist/core/simulation/behaviors/gates/NandGateBehavior.d.ts +28 -0
  32. package/dist/core/simulation/behaviors/gates/Nor4GateBehavior.d.ts +18 -0
  33. package/dist/core/simulation/behaviors/gates/Nor8GateBehavior.d.ts +18 -0
  34. package/dist/core/simulation/behaviors/gates/NorGateBehavior.d.ts +22 -0
  35. package/dist/core/simulation/behaviors/gates/Xor4GateBehavior.d.ts +18 -0
  36. package/dist/core/simulation/behaviors/gates/Xor8GateBehavior.d.ts +18 -0
  37. package/dist/core/simulation/behaviors/gates/XorGateBehavior.d.ts +22 -0
  38. package/dist/core/simulation/behaviors/gates/index.d.ts +34 -0
  39. package/dist/core/simulation/behaviors/index.d.ts +28 -0
  40. package/dist/core/simulation/behaviors/types.d.ts +101 -0
  41. package/dist/core/simulation/index.d.ts +18 -0
  42. package/dist/core/simulation/states/ComponentState.d.ts +57 -0
  43. package/dist/core/simulation/states/SimulationState.d.ts +46 -0
  44. package/dist/core/simulation/states/arithmetic/AdderState.d.ts +16 -0
  45. package/dist/core/simulation/states/arithmetic/ArithmeticState.d.ts +53 -0
  46. package/dist/core/simulation/states/arithmetic/EightBitAdderState.d.ts +25 -0
  47. package/dist/core/simulation/states/arithmetic/EightBitOnesComplementState.d.ts +18 -0
  48. package/dist/core/simulation/states/arithmetic/HalfAdderState.d.ts +16 -0
  49. package/dist/core/simulation/states/arithmetic/index.d.ts +7 -0
  50. package/dist/core/simulation/states/basic/BatteryState.d.ts +16 -0
  51. package/dist/core/simulation/states/basic/ClockState.d.ts +16 -0
  52. package/dist/core/simulation/states/basic/DoubleThrowSwitchState.d.ts +21 -0
  53. package/dist/core/simulation/states/basic/LightbulbState.d.ts +21 -0
  54. package/dist/core/simulation/states/basic/RectangleLEDState.d.ts +9 -0
  55. package/dist/core/simulation/states/basic/RelayState.d.ts +25 -0
  56. package/dist/core/simulation/states/basic/SmallLEDState.d.ts +21 -0
  57. package/dist/core/simulation/states/basic/SwitchState.d.ts +25 -0
  58. package/dist/core/simulation/states/gates/InverterState.d.ts +17 -0
  59. package/dist/core/simulation/states/gates/Nand4GateState.d.ts +10 -0
  60. package/dist/core/simulation/states/gates/Nand8GateState.d.ts +10 -0
  61. package/dist/core/simulation/states/gates/NandGateState.d.ts +16 -0
  62. package/dist/core/simulation/states/gates/Nor4GateState.d.ts +10 -0
  63. package/dist/core/simulation/states/gates/Nor8GateState.d.ts +10 -0
  64. package/dist/core/simulation/states/gates/NorGateState.d.ts +10 -0
  65. package/dist/core/simulation/states/gates/Xor4GateState.d.ts +10 -0
  66. package/dist/core/simulation/states/gates/Xor8GateState.d.ts +10 -0
  67. package/dist/core/simulation/states/gates/XorGateState.d.ts +10 -0
  68. package/dist/core/simulation/states/gates/index.d.ts +25 -0
  69. package/dist/core/simulation/states/index.d.ts +31 -0
  70. package/dist/core/simulation/states/types.d.ts +32 -0
  71. package/dist/core/simulation/types.d.ts +155 -0
  72. package/dist/core/topology/Circuit.d.ts +420 -0
  73. package/dist/core/topology/CircuitMetadata.d.ts +24 -0
  74. package/dist/core/topology/CircuitOptions.d.ts +14 -0
  75. package/dist/core/topology/Component.d.ts +153 -0
  76. package/dist/core/topology/ENode.d.ts +200 -0
  77. package/dist/core/topology/Wire.d.ts +130 -0
  78. package/dist/core/topology/delays.d.ts +52 -0
  79. package/dist/core/topology/index.d.ts +14 -0
  80. package/dist/core/topology/types.d.ts +189 -0
  81. package/dist/core/utils/CameraOptions.d.ts +83 -0
  82. package/dist/core/utils/MemoizeDecorator.d.ts +9 -0
  83. package/dist/core/utils/Position.d.ts +166 -0
  84. package/dist/core/utils/Position3D.d.ts +77 -0
  85. package/dist/core/utils/Rotation.d.ts +82 -0
  86. package/dist/core/utils/index.d.ts +24 -0
  87. package/dist/core/utils/types.d.ts +35 -0
  88. package/dist/core-b6Q8w2sn.js +3560 -0
  89. package/dist/core-b6Q8w2sn.js.map +1 -0
  90. package/dist/i18n/index.d.ts +882 -0
  91. package/dist/i18n/locales/en.json.d.ts +268 -0
  92. package/dist/i18n/locales/fr.json.d.ts +268 -0
  93. package/dist/index.d.ts +14 -6306
  94. package/dist/index.js +136 -112
  95. package/dist/scene/CircuitEngine.d.ts +283 -0
  96. package/dist/scene/index.d.ts +1 -2
  97. package/dist/scene/index.js +50 -41
  98. package/dist/scene/setup.d.ts +26 -0
  99. package/dist/scene/shared/AbstractCircuitController.d.ts +217 -0
  100. package/dist/scene/shared/BranchingPointVisualFactory.d.ts +70 -0
  101. package/dist/scene/shared/EventEmitter.d.ts +92 -0
  102. package/dist/scene/shared/HoverManager.d.ts +151 -0
  103. package/dist/scene/shared/SelectionManager.d.ts +159 -0
  104. package/dist/scene/shared/WireVisualManager.d.ts +242 -0
  105. package/dist/scene/shared/components/ComponentVisualFactory.d.ts +438 -0
  106. package/dist/scene/shared/components/DefaultVisualFactory.d.ts +51 -0
  107. package/dist/scene/shared/components/FactoryRegistry.d.ts +84 -0
  108. package/dist/scene/shared/components/GroupedFactoryRegistry.d.ts +153 -0
  109. package/dist/scene/shared/components/arithmetic/AdderVisualFactory.d.ts +54 -0
  110. package/dist/scene/shared/components/arithmetic/EightBitAdderVisualFactory.d.ts +45 -0
  111. package/dist/scene/shared/components/arithmetic/EightBitOnesComplementVisualFactory.d.ts +63 -0
  112. package/dist/scene/shared/components/arithmetic/HalfAdderVisualFactory.d.ts +55 -0
  113. package/dist/scene/shared/components/arithmetic/index.d.ts +4 -0
  114. package/dist/scene/shared/components/basic/BatteryVisualFactory.d.ts +13 -0
  115. package/dist/scene/shared/components/basic/ClockVisualFactory.d.ts +79 -0
  116. package/dist/scene/shared/components/basic/DoubleThrowSwitchVisualFactory.d.ts +87 -0
  117. package/dist/scene/shared/components/basic/LabelVisualFactory.d.ts +148 -0
  118. package/dist/scene/shared/components/basic/LightbulbVisualFactory.d.ts +72 -0
  119. package/dist/scene/shared/components/basic/RectangleLEDVisualFactory.d.ts +86 -0
  120. package/dist/scene/shared/components/basic/RelayVisualFactory.d.ts +92 -0
  121. package/dist/scene/shared/components/basic/SmallLEDVisualFactory.d.ts +86 -0
  122. package/dist/scene/shared/components/basic/SwitchVisualFactory.d.ts +85 -0
  123. package/dist/scene/shared/components/gates/InverterVisualFactory.d.ts +104 -0
  124. package/dist/scene/shared/components/gates/Nand4GateVisualFactory.d.ts +27 -0
  125. package/dist/scene/shared/components/gates/Nand8GateVisualFactory.d.ts +27 -0
  126. package/dist/scene/shared/components/gates/NandGateVisualFactory.d.ts +101 -0
  127. package/dist/scene/shared/components/gates/Nor4GateVisualFactory.d.ts +27 -0
  128. package/dist/scene/shared/components/gates/Nor8GateVisualFactory.d.ts +27 -0
  129. package/dist/scene/shared/components/gates/NorGateVisualFactory.d.ts +101 -0
  130. package/dist/scene/shared/components/gates/Xor4GateVisualFactory.d.ts +29 -0
  131. package/dist/scene/shared/components/gates/Xor8GateVisualFactory.d.ts +29 -0
  132. package/dist/scene/shared/components/gates/XorGateVisualFactory.d.ts +103 -0
  133. package/dist/scene/shared/components/index.d.ts +33 -0
  134. package/dist/scene/shared/components/types.d.ts +43 -0
  135. package/dist/scene/shared/types.d.ts +474 -0
  136. package/dist/scene/shared/utils/CameraUtils.d.ts +23 -0
  137. package/dist/scene/shared/utils/ColorUtils.d.ts +26 -0
  138. package/dist/scene/shared/utils/ControlsUtils.d.ts +8 -0
  139. package/dist/scene/shared/utils/GeometryUtils.d.ts +337 -0
  140. package/dist/scene/shared/utils/LayerConstants.d.ts +40 -0
  141. package/dist/scene/shared/utils/LightingUtils.d.ts +31 -0
  142. package/dist/scene/shared/utils/MaterialUtils.d.ts +73 -0
  143. package/dist/scene/shared/utils/Options.d.ts +16 -0
  144. package/dist/scene/simulation/CircuitRunnerController.d.ts +227 -0
  145. package/dist/scene/static/CircuitController.d.ts +228 -0
  146. package/dist/scene/static/CircuitWriter.d.ts +146 -0
  147. package/dist/scene/static/PinTooltipWidget.d.ts +31 -0
  148. package/dist/scene/static/tools/BuildTool.d.ts +290 -0
  149. package/dist/scene/static/tools/ComponentPickerWidget.d.ts +89 -0
  150. package/dist/scene/static/tools/ConfigPanelWidget.d.ts +107 -0
  151. package/dist/scene/static/tools/MultiSelectTool.d.ts +265 -0
  152. package/dist/scene-D4QcWeiq.js +8745 -0
  153. package/dist/scene-D4QcWeiq.js.map +1 -0
  154. package/package.json +29 -25
  155. package/dist/CircuitRunner-BQQlhwjD.js +0 -1981
  156. package/dist/CircuitRunner-BQQlhwjD.js.map +0 -1
  157. package/dist/core/index.js.map +0 -1
  158. package/dist/index.js.map +0 -1
  159. package/dist/scene/index.js.map +0 -1
  160. package/dist/setup-CIq_kgaw.js +0 -10230
  161. package/dist/setup-CIq_kgaw.js.map +0 -1
@@ -1,2117 +1,87 @@
1
- import { g as M, P as R, D as O, b as E, C as A, c as h, d as G, i as _, h as I, e as m, f as D, s as P, T as S } from "../CircuitRunner-BQQlhwjD.js";
2
- import { A as Me, m as Re, k as De, E as We, j as ke, a as Fe, R as Xe, S as Je, n as Ue, l as ze } from "../CircuitRunner-BQQlhwjD.js";
3
- function W(a) {
4
- let e, t, o;
5
- return typeof a == "object" ? (e = a.hashFunction, t = a.expiring, o = a.tags) : e = a, (i, n, s) => {
6
- if (s.value != null)
7
- s.value = b(s.value, e, t, o);
8
- else if (s.get != null)
9
- s.get = b(s.get, e, t, o);
10
- else
11
- throw "Only put a Memoize() decorator on a method or get accessor.";
12
- };
13
- }
14
- function be(a, e) {
15
- return W({
16
- expiring: a,
17
- hashFunction: e
18
- });
19
- }
20
- const T = /* @__PURE__ */ new Map();
21
- function b(a, e, t = 0, o) {
22
- const i = Symbol("__memoized_map__");
23
- return function(...n) {
24
- let s;
25
- this.hasOwnProperty(i) || Object.defineProperty(this, i, {
26
- configurable: !1,
27
- enumerable: !1,
28
- writable: !1,
29
- value: /* @__PURE__ */ new Map()
30
- });
31
- let c = this[i];
32
- if (Array.isArray(o))
33
- for (const r of o)
34
- T.has(r) ? T.get(r).push(c) : T.set(r, [c]);
35
- if (e || n.length > 0 || t > 0) {
36
- let r;
37
- e === !0 ? r = n.map((l) => l.toString()).join("!") : e ? r = e.apply(this, n) : r = n[0];
38
- const u = `${r}__timestamp`;
39
- let d = !1;
40
- if (t > 0)
41
- if (!c.has(u))
42
- d = !0;
43
- else {
44
- let l = c.get(u);
45
- d = Date.now() - l > t;
46
- }
47
- c.has(r) && !d ? s = c.get(r) : (s = a.apply(this, n), c.set(r, s), t > 0 && c.set(u, Date.now()));
48
- } else {
49
- const r = this;
50
- c.has(r) ? s = c.get(r) : (s = a.apply(this, n), c.set(r, s));
51
- }
52
- return s;
53
- };
54
- }
55
- class w {
56
- /**
57
- * Unique identifier for this wire.
58
- * @readonly
59
- */
60
- id;
61
- /**
62
- * First connected ENode UUID.
63
- * @readonly
64
- */
65
- node1;
66
- /**
67
- * Second connected ENode UUID.
68
- * @readonly
69
- */
70
- node2;
71
- /**
72
- * Optional intermediate positions for wire routing.
73
- * Empty array indicates straight-line connection.
74
- * @readonly
75
- */
76
- intermediatePositions;
77
- /**
78
- * Create a new wire.
79
- *
80
- * **Note**: Typically wires are created via `Circuit.addWire()` which
81
- * handles validation and bidirectional reference updates. This constructor
82
- * is used internally by Circuit.
83
- *
84
- * @param node1 - First ENode UUID
85
- * @param node2 - Second ENode UUID
86
- * @param intermediatePositions - Optional waypoints for rendering
87
- *
88
- * @example
89
- * ```typescript
90
- * // Usually created via Circuit:
91
- * const wire = circuit.addWire(nodeId1, nodeId2);
92
- *
93
- * // With intermediate positions:
94
- * const wire = circuit.addWire(
95
- * nodeId1,
96
- * nodeId2,
97
- * [new Position(5, 10), new Position(15, 10)]
98
- * );
99
- * ```
100
- */
101
- constructor(e, t, o = []) {
102
- this.id = M(), this.node1 = e, this.node2 = t, this.intermediatePositions = o;
103
- }
104
- /**
105
- * Check if this is a straight-line wire.
106
- *
107
- * @returns true if no intermediate positions, false otherwise
108
- *
109
- * @example
110
- * ```typescript
111
- * const straightWire = new Wire(node1, node2);
112
- * console.log(straightWire.isStraightLine()); // true
113
- *
114
- * const curvedWire = new Wire(node1, node2, [new Position(5, 5)]);
115
- * console.log(curvedWire.isStraightLine()); // false
116
- * ```
117
- */
118
- isStraightLine() {
119
- return this.intermediatePositions.length === 0;
120
- }
121
- /**
122
- * Serialize wire to JSON.
123
- *
124
- * @returns Plain object representation
125
- *
126
- * @example
127
- * ```typescript
128
- * const json = wire.toJSON();
129
- * console.log(json);
130
- * // {
131
- * // id: "uuid",
132
- * // node1: "node-uuid-1",
133
- * // node2: "node-uuid-2",
134
- * // intermediatePositions: [{ x: 5, y: 10 }]
135
- * // }
136
- * ```
137
- */
138
- toJSON() {
139
- return {
140
- id: this.id,
141
- node1: this.node1,
142
- node2: this.node2,
143
- intermediatePositions: this.intermediatePositions.map((e) => e.toJSON())
144
- };
145
- }
146
- /**
147
- * Deserialize wire from JSON.
148
- *
149
- * @param json - Wire data
150
- * @returns Wire instance
151
- *
152
- * @example
153
- * ```typescript
154
- * const json = {
155
- * id: "uuid",
156
- * node1: "node-uuid-1",
157
- * node2: "node-uuid-2",
158
- * intermediatePositions: [{ x: 5, y: 10 }]
159
- * };
160
- *
161
- * const wire = Wire.fromJSON(json);
162
- * ```
163
- */
164
- static fromJSON(e) {
165
- const t = e.intermediatePositions.map((i) => R.fromJSON(i)), o = new w(e.node1, e.node2, t);
166
- return Object.defineProperty(o, "id", {
167
- value: e.id,
168
- writable: !1,
169
- enumerable: !0,
170
- configurable: !1
171
- }), o;
172
- }
173
- }
174
- class C {
175
- /**
176
- * Create new circuit options.
177
- *
178
- * @param name - Circuit name (default: Untitled Circuit)
179
- * @param defaultLogicFamily - Circuit default logic family (default: CMOS1)
180
- */
181
- constructor(e = "Untitled Circuit", t = O) {
182
- this.name = e, this.defaultLogicFamily = t;
183
- }
184
- toJSON() {
185
- return {
186
- name: this.name,
187
- defaultLogicFamily: this.defaultLogicFamily
188
- };
189
- }
190
- static fromJSON(e) {
191
- return new C(e.name, e.defaultLogicFamily);
192
- }
193
- }
194
- class N {
195
- /**
196
- * Create a new CircuitMetadata holding general information about the Circuit.
197
- *
198
- * @param version - Circuit version
199
- * @param options - Circuit options
200
- * @param size - Size of the circuit grid
201
- * @param divisions - Divisions in the circuit grid
202
- * @param cameraOptions - Camera Options at startup
203
- * @throws {TypeError} If size or divisions are not integers
204
- */
205
- constructor(e, t, o, i, n) {
206
- if (this.version = e, this.options = t, this.size = o, this.divisions = i, this.cameraOptions = n, !Number.isInteger(o) || !Number.isInteger(i))
207
- throw new TypeError(
208
- `Size and divisions must be integers (got size=${o}, divisions=${i})`
209
- );
210
- }
211
- toJSON() {
212
- return {
213
- version: this.version,
214
- options: this.options.toJSON(),
215
- size: this.size,
216
- divisions: this.divisions,
217
- cameraOptions: this.cameraOptions.toJSON()
218
- };
219
- }
220
- static fromJSON(e) {
221
- E !== e.version && console.warn(`This version of the engine supports v${E} circuit version files.
222
- Unexpected behavior may occurs loading v${e.version}.`);
223
- const t = e.options ? C.fromJSON(e.options) : new C("Untitled Circuit", O);
224
- return new N(
225
- e.version,
226
- t,
227
- e.size,
228
- e.divisions,
229
- A.fromJSON(e.cameraOptions)
230
- );
231
- }
232
- toString() {
233
- return `CircuitMetadata(${this.version}, ${this.options.name}, ${this.options.defaultLogicFamily}, ${this.size}, ${this.divisions}, ${this.cameraOptions.toString()})`;
234
- }
235
- }
236
- const k = { 2: 1, 4: 1, 8: 2, 16: 2 }, F = { 2: 2, 4: 2, 8: 3, 16: 3 }, X = { 2: 1, 4: 2, 8: 2, 16: 3 }, J = { 2: 2, 4: 3, 8: 3, 16: 4 };
237
- function U(a) {
238
- const e = a.config.get("defaultLogicFamily");
239
- if (!(!e || e === "Sandbox") && z(a.type)) {
240
- const t = a.config.get("activationLogic") ?? "negative", o = H(a.type, t);
241
- return o && K(e, o.gateFamily, o.inputCount) || void 0;
242
- }
243
- }
244
- function z(a) {
245
- return [
246
- h.Inverter,
247
- h.NandGate,
248
- h.Nand4Gate,
249
- h.Nand8Gate,
250
- h.NorGate,
251
- h.Nor4Gate,
252
- h.Nor8Gate,
253
- h.XorGate,
254
- h.Xor4Gate,
255
- h.Xor8Gate
256
- ].includes(a);
257
- }
258
- function H(a, e) {
259
- switch (a) {
260
- case h.Inverter:
261
- return { gateFamily: e === "negative" ? "NOT" : "Buffer", inputCount: 1 };
262
- case h.NandGate:
263
- return { gateFamily: e === "negative" ? "NAND" : "AND", inputCount: 2 };
264
- case h.Nand4Gate:
265
- return { gateFamily: e === "negative" ? "NAND" : "AND", inputCount: 4 };
266
- case h.Nand8Gate:
267
- return { gateFamily: e === "negative" ? "NAND" : "AND", inputCount: 8 };
268
- case h.NorGate:
269
- return { gateFamily: e === "negative" ? "NOR" : "OR", inputCount: 2 };
270
- case h.Nor4Gate:
271
- return { gateFamily: e === "negative" ? "NOR" : "OR", inputCount: 4 };
272
- case h.Nor8Gate:
273
- return { gateFamily: e === "negative" ? "NOR" : "OR", inputCount: 8 };
274
- case h.XorGate:
275
- return { gateFamily: e === "negative" ? "XNOR" : "XOR", inputCount: 2 };
276
- case h.Xor4Gate:
277
- return { gateFamily: e === "negative" ? "XNOR" : "XOR", inputCount: 4 };
278
- case h.Xor8Gate:
279
- return { gateFamily: e === "negative" ? "XNOR" : "XOR", inputCount: 8 };
280
- default:
281
- return null;
282
- }
283
- }
284
- function K(a, e, t) {
285
- if (a === "Sandbox")
286
- throw new Error("computeGateDelay must not be called for Sandbox family");
287
- if (e === "NOT") return 1;
288
- if (e === "Buffer") return 2;
289
- if (e === "XOR") return Math.log2(t) * 2;
290
- if (e === "XNOR") return Math.log2(t) * 2 + 1;
291
- if (a === "CMOS1") {
292
- const o = Math.log2(t);
293
- switch (e) {
294
- case "NAND":
295
- return o;
296
- case "NOR":
297
- return o;
298
- case "AND":
299
- return o + 1;
300
- case "OR":
301
- return o + 1;
302
- }
303
- }
304
- if (a === "TTL1") {
305
- let o;
306
- switch (e) {
307
- case "NAND":
308
- o = k;
309
- break;
310
- case "AND":
311
- o = F;
312
- break;
313
- case "NOR":
314
- o = X;
315
- break;
316
- case "OR":
317
- o = J;
318
- break;
319
- }
320
- const i = o[t];
321
- if (i === void 0)
322
- throw new Error(`Unsupported input count ${t} for TTL1 ${e}`);
323
- return i;
324
- }
325
- throw new Error(`Unsupported logic family: ${a}`);
326
- }
327
- class x {
328
- /**
329
- * Circuit metadata holding general information.
330
- * @private
331
- */
332
- metadata;
333
- /**
334
- * Map of all components in the circuit (UUID → Component).
335
- * @private
336
- */
337
- components;
338
- /**
339
- * Map of all electrical nodes in the circuit (UUID → ENode).
340
- * Includes both pin nodes and branching point nodes.
341
- * @private
342
- */
343
- enodes;
344
- /**
345
- * Map of all wires in the circuit (UUID → Wire).
346
- * @private
347
- */
348
- wires;
349
- /**
350
- * Create a new empty circuit.
351
- */
352
- constructor(e) {
353
- this.metadata = new N(E, e, 10, 10, new A()), this.components = /* @__PURE__ */ new Map(), this.enodes = /* @__PURE__ */ new Map(), this.wires = /* @__PURE__ */ new Map();
354
- }
355
- get name() {
356
- return this.metadata.options.name;
357
- }
358
- set name(e) {
359
- if (typeof e != "string" || e.trim() === "")
360
- throw new TypeError("Circuit name must be a non-empty string");
361
- this.metadata.options.name = e;
362
- }
363
- /**
364
- * Add a new component to the circuit.
365
- *
366
- * Automatically creates pin ENodes for the component and links them
367
- * bidirectionally. Pin ENode UUIDs are stored in the component's pins array.
368
- * Pin labels are derived from the ComponentType metadata.
369
- *
370
- * @param type - Component type (Battery, Switch, LED, etc.)
371
- * @param position - Grid position (x, y integers)
372
- * @param rotation - Orientation angle (integer degrees)
373
- * @param config - Optional configuration map for component-specific settings
374
- * @returns The created Component
375
- * @throws {TypeError} If position/rotation coordinates are not integers
376
- *
377
- * @example
378
- * ```typescript
379
- * const lightbulb = circuit.addComponent(
380
- * new Position(10, 20),
381
- * new Rotation(90),
382
- * ComponentType.Lightbulb
383
- * );
384
- *
385
- * console.log(lightbulb.type); // ComponentType.Lightbulb
386
- * console.log(lightbulb.pins.length); // 2
387
- * console.log(lightbulb.position.x); // 10
388
- * ```
389
- */
390
- addComponent(e, t, o, i) {
391
- const n = G[e], s = new _(e, t, o, []);
392
- if (i)
393
- for (const [r, u] of i)
394
- s.config.set(r, u);
395
- s.config.has("defaultLogicFamily") && !s.config.get("defaultLogicFamily") && s.config.set("defaultLogicFamily", this.metadata.options.defaultLogicFamily), this.resolveTransitionSpan(s);
396
- const c = [];
397
- for (const [r, u] of n.pins) {
398
- const d = new I(
399
- m.Pin,
400
- s.id,
401
- r,
402
- void 0,
403
- // Pin position derived from component
404
- u.sourceType,
405
- u.subtype
406
- );
407
- this.enodes.set(d.id, d), c.push(d.id);
408
- }
409
- return Object.defineProperty(s, "pins", {
410
- value: c,
411
- writable: !1,
412
- enumerable: !0,
413
- configurable: !1
414
- }), this.components.set(s.id, s), s;
415
- }
416
- /**
417
- * Resolve and update the transitionSpan config for a component
418
- * if automatic resolution returns undefined nothing is done on the component
419
- *
420
- * @param component - Component to resolve transitionSpan for
421
- */
422
- resolveTransitionSpan(e) {
423
- if (!e.config.has("transitionSpan"))
424
- return;
425
- const t = U(e);
426
- t && e.config.set("transitionSpan", String(t));
427
- }
428
- /**
429
- * Remove a component from the circuit.
430
- *
431
- * **Cascade deletion** removes:
432
- * - All pin ENodes belonging to the component
433
- * - All Wires connected to those pins
434
- *
435
- * @param id - Component UUID
436
- * @throws {Error} If component does not exist
437
- * @returns Object containing arrays of deleted Wires and ENodes IDs
438
- *
439
- * @example
440
- * ```typescript
441
- * circuit.removeComponent(componentId);
442
- * // Component, its pins, and connected wires are all removed
443
- * ```
444
- */
445
- removeComponent(e) {
446
- const t = this.components.get(e);
447
- if (!t)
448
- throw new Error(`Component ${e} does not exist`);
449
- const o = [], i = [];
450
- for (const n of t.pins) {
451
- const s = this.enodes.get(n);
452
- if (s) {
453
- const c = Array.from(s.wires);
454
- for (const r of c)
455
- this.removeWire(r), o.push(r);
456
- }
457
- this.enodes.delete(n), i.push(n);
458
- }
459
- return this.components.delete(e), { deletedWires: o, deletedENodes: i };
460
- }
461
- hasComponent(e) {
462
- return this.components.has(e);
463
- }
464
- /**
465
- * Get a component by ID.
466
- *
467
- * @param id - Component UUID
468
- * @returns The Component or undefined if not found
469
- *
470
- * @example
471
- * ```typescript
472
- * const component = circuit.getComponent(componentId);
473
- * if (component) {
474
- * console.log(component.position);
475
- * }
476
- * ```
477
- */
478
- getComponent(e) {
479
- return this.components.get(e);
480
- }
481
- /**
482
- * Get all components in the circuit.
483
- *
484
- * Returns a new array on each call (defensive copy).
485
- *
486
- * @returns Array of all Components
487
- *
488
- * @example
489
- * ```typescript
490
- * const components = circuit.getAllComponents();
491
- * console.log(`Circuit has ${components.length} components`);
492
- *
493
- * for (const comp of components) {
494
- * console.log(comp.id, comp.position);
495
- * }
496
- * ```
497
- */
498
- getAllComponents() {
499
- return Array.from(this.components.values());
500
- }
501
- getAllComponentsByType(e) {
502
- const t = [];
503
- for (const o of this.components.values())
504
- o.type === e && t.push(o);
505
- return t;
506
- }
507
- getFirstComponentOfType(e) {
508
- for (const t of this.components.values())
509
- if (t.type === e)
510
- return t;
511
- }
512
- /**
513
- * Get an electrical node by ID.
514
- *
515
- * Note: ENodes are automatically managed and not directly created
516
- * or removed by users.
517
- *
518
- * @param id - ENode UUID
519
- * @returns The ENode or undefined if not found
520
- *
521
- * @example
522
- * ```typescript
523
- * const component = circuit.addComponent(
524
- * new Position(10, 20),
525
- * new Rotation(0),
526
- * 2
527
- * );
528
- *
529
- * const pinId = component.pins[0];
530
- * const enode = circuit.getENode(pinId);
531
- * console.log(enode.type); // ENodeType.Pin
532
- * ```
533
- */
534
- getENode(e) {
535
- return this.enodes.get(e);
536
- }
537
- /**
538
- * Get all electrical nodes in the circuit.
539
- *
540
- * Includes both pin nodes (from components) and branching point nodes
541
- * (from wire splits).
542
- *
543
- * Returns a new array on each call (defensive copy).
544
- *
545
- * @returns Array of all ENodes
546
- *
547
- * @example
548
- * ```typescript
549
- * const enodes = circuit.getAllENodes();
550
- * console.log(`Circuit has ${enodes.length} electrical nodes`);
551
- *
552
- * for (const enode of enodes) {
553
- * console.log(enode.id, enode.type);
554
- * }
555
- * ```
556
- */
557
- getAllENodes() {
558
- return Array.from(this.enodes.values());
559
- }
560
- /**
561
- * Add a branching point electrical node at a specific position.
562
- *
563
- * Branching points are used to split wires and create junctions.
564
- * @param position - Grid position for the branching point
565
- * @param sourceType - Optional source type (voltage/current)
566
- * @returns The created ENode
567
- */
568
- addBranchingPoint(e, t) {
569
- const o = new I(
570
- m.BranchingPoint,
571
- void 0,
572
- void 0,
573
- e,
574
- t
575
- );
576
- return this.enodes.set(o.id, o), o;
577
- }
578
- /**
579
- * Remove a branching point electrical node from the circuit.
580
- * Also removes all wires connected to this branching point if there are ony one or more than 2.
581
- * In the case there are exactly two wires, they will be merged before removing the branching point.
582
- *
583
- * @param id - Branching point ENode UUID
584
- * @throws {Error} If ENode does not exist or is not a branching point
585
- */
586
- removeBranchingPoint(e) {
587
- const t = this.enodes.get(e);
588
- if (!t)
589
- throw new Error(`Enode ${e} does not exist`);
590
- if (t.type !== m.BranchingPoint)
591
- throw new Error(
592
- `Enode ${e} is not a branching point, it must be removed with its component.`
593
- );
594
- const o = {}, i = this.getWiresByNode(e);
595
- if (i.length === 1 || i.length > 2) {
596
- const n = [];
597
- for (const s of i)
598
- this.removeWire(s.id), n.push(s.id);
599
- Object.assign(o, { deletedWires: n });
600
- } else if (i.length === 2) {
601
- const n = i[0], s = i[1], c = n.node1 === e ? n.node2 : n.node1, r = s.node1 === e ? s.node2 : s.node1, u = [];
602
- c === n.node1 ? u.push(...n.intermediatePositions) : c === n.node2 && u.push(...[...n.intermediatePositions].reverse()), u.push(t.getPosition(this)), r === s.node1 ? u.push(...[...s.intermediatePositions].reverse()) : r === s.node2 && u.push(...s.intermediatePositions), this.removeWire(n.id), this.removeWire(s.id);
603
- const d = this.addWire(c, r, u);
604
- if (d instanceof Error)
605
- throw new Error(`Failed to merge wires at branching point ${e}: ${d.message}`);
606
- Object.assign(o, { mergedWires: [n.id, s.id] }), Object.assign(o, { newWire: d });
607
- }
608
- return this.enodes.delete(e), o;
609
- }
610
- /**
611
- * Add a wire connecting two electrical nodes.
612
- *
613
- * Validates that both nodes exist, not a self-connection, and no duplicate.
614
- * Updates bidirectional references (Wire ↔ ENodes).
615
- *
616
- * @param node1 - First ENode UUID
617
- * @param node2 - Second ENode UUID
618
- * @param intermediatePositions - Optional path waypoints for rendering
619
- * @returns The created Wire, or Error if validation fails
620
- *
621
- * @example
622
- * ```typescript
623
- * const comp1 = circuit.addComponent(new Position(0, 0), new Rotation(0), 1);
624
- * const comp2 = circuit.addComponent(new Position(10, 10), new Rotation(0), 1);
625
- *
626
- * const wire = circuit.addWire(comp1.pins[0], comp2.pins[0]);
627
- * if (wire instanceof Error) {
628
- * console.error('Failed:', wire.message);
629
- * }
630
- * ```
631
- */
632
- addWire(e, t, o) {
633
- if (e === t)
634
- return new Error("Cannot create wire connecting node to itself");
635
- const i = this.enodes.get(e), n = this.enodes.get(t);
636
- if (!i || !n)
637
- return new Error("Wire requires at least one existing ENode");
638
- if (this.hasWireBetween(e, t))
639
- return new Error("Duplicate wire between same nodes");
640
- const s = new w(e, t, o || []);
641
- return this.wires.set(s.id, s), i.wires.add(s.id), n.wires.add(s.id), s;
642
- }
643
- /**
644
- * Remove a wire from the circuit.
645
- *
646
- * @param id - Wire UUID
647
- * @throws {Error} If wire does not exist
648
- *
649
- * @example
650
- * ```typescript
651
- * circuit.removeWire(wireId);
652
- * // Wire is removed
653
- * ```
654
- */
655
- removeWire(e) {
656
- const t = this.wires.get(e);
657
- if (!t)
658
- throw new Error(`Wire ${e} does not exist`);
659
- const o = this.enodes.get(t.node1), i = this.enodes.get(t.node2);
660
- o && o.wires.delete(e), i && i.wires.delete(e), this.wires.delete(e);
661
- }
662
- /**
663
- * Split a wire in the circuit.
664
- *
665
- * It creates two new wires connected by either the target enode or a new branching point ENode at the specified position.
666
- * Returns 2 UUIDS of the new wires.
667
- *
668
- * @param id - Wire UUID
669
- * @param position
670
- * @throws {Error} If wire does not exist
671
- *
672
- * @example
673
- * ```typescript
674
- * circuit.splitWire(wireId);
675
- * // Wire and any orphaned branching points are removed
676
- * ```
677
- */
678
- /**
679
- * Split an existing wire at a position, creating a branching point.
680
- * The original wire is removed and replaced with two new wires
681
- * connecting through the new branching point.
682
- * NB : in the special case where targetEnode belongs to a component where the wire is already connected
683
- * only one new wire will be created as this method don't allow a wire directly connecting two pins of the same component.
684
- *
685
- * @param wireId - Wire to split
686
- * @param position - Position for the new branching point : no effect if targetEnodeId provided
687
- * @param targetEnodeId - if provided, the existing enode to split the wire at
688
- * @returns Object containing the new branching point and an array of the two new wires
689
- * @throws Error if wireId not found
690
- */
691
- splitWire(e, t, o = null) {
692
- const i = this.wires.get(e);
693
- if (!i)
694
- throw new Error(`Wire ${e} does not exist`);
695
- const n = this.enodes.get(i.node1), s = this.enodes.get(i.node2);
696
- if (!n || !s)
697
- throw new Error(`Wire ${e} is connected to non-existent ENodes`);
698
- const c = [
699
- n.getPosition(this),
700
- ...i.intermediatePositions,
701
- s.getPosition(this)
702
- ], r = D(c, t), u = c.slice(1, r), d = c.slice(r, c.length - 1);
703
- this.wires.delete(e), n.wires.delete(e), s.wires.delete(e);
704
- let l;
705
- if (o)
706
- if (this.enodes.get(o))
707
- l = this.enodes.get(o);
708
- else
709
- throw new Error(`Target ENode ${o} does not exist`);
710
- else
711
- l = this.addBranchingPoint(t);
712
- const B = [];
713
- if ((!l.component || n.component !== l.component) && !this.hasWireBetween(n.id, l.id)) {
714
- const f = this.addWire(n.id, l.id, u);
715
- f instanceof w ? (this.simplifyWireIntermediatePositions(f.id), B.push(f)) : console.warn(`Failure to create wire at split : ${f.message}`);
716
- }
717
- if ((!l.component || s.component !== l.component) && !this.hasWireBetween(s.id, l.id)) {
718
- const f = this.addWire(l.id, s.id, d);
719
- f instanceof w ? (this.simplifyWireIntermediatePositions(f.id), B.push(f)) : console.warn(`Failure to create wire at split : ${f.message}`);
720
- }
721
- return {
722
- branchingPoint: l,
723
- wires: B
724
- };
725
- }
726
- getWireBetweenNodes(e, t) {
727
- const o = this.enodes.get(e);
728
- if (o)
729
- for (const i of o.wires) {
730
- const n = this.wires.get(i);
731
- if (n && (n.node2 === t || n.node1 === t))
732
- return n;
733
- }
734
- }
735
- /**
736
- * Get a wire by ID.
737
- *
738
- * @param id - Wire UUID
739
- * @returns The Wire or undefined if not found
740
- */
741
- getWire(e) {
742
- return this.wires.get(e);
743
- }
744
- /**
745
- * Get all wires in the circuit.
746
- *
747
- * Returns a new array on each call (defensive copy).
748
- *
749
- * @returns Array of all Wires
750
- */
751
- getAllWires() {
752
- return Array.from(this.wires.values());
753
- }
754
- /**
755
- * Get all wires connected to a specific ENode.
756
- *
757
- * @param nodeId - ENode UUID
758
- * @returns Array of connected Wires, or empty array if node not found
759
- */
760
- getWiresByNode(e) {
761
- const t = this.enodes.get(e);
762
- if (!t)
763
- return [];
764
- const o = [];
765
- for (const i of t.wires) {
766
- const n = this.wires.get(i);
767
- n && o.push(n);
768
- }
769
- return o;
770
- }
771
- /**
772
- * Get all wires connected to a component, e.g to any pin enode of the component.
773
- *
774
- * @param componentId - Component UUID
775
- * @returns Array of connected Wires, or empty array if component not found
776
- */
777
- getWiresByComponent(e) {
778
- const t = this.components.get(e);
779
- if (!t)
780
- return [];
781
- const o = [];
782
- for (const i of t.pins)
783
- o.push(...this.getWiresByNode(i));
784
- return o;
785
- }
786
- /**
787
- * Get both ENodes connected by a wire.
788
- *
789
- * @param wireId - Wire UUID
790
- * @returns Tuple [node1, node2] or undefined if wire not found
791
- */
792
- getNodesByWire(e) {
793
- const t = this.wires.get(e);
794
- if (!t)
795
- return;
796
- const o = this.enodes.get(t.node1), i = this.enodes.get(t.node2);
797
- if (!(!o || !i))
798
- return [o, i];
799
- }
800
- /**
801
- * Check if a wire already exists between two nodes.
802
- *
803
- * Order-independent: returns true for (A, B) or (B, A).
804
- *
805
- * @param node1 - First ENode UUID
806
- * @param node2 - Second ENode UUID
807
- * @returns true if wire exists, false otherwise
808
- */
809
- hasWireBetween(e, t) {
810
- const o = this.enodes.get(e);
811
- if (!o)
812
- return !1;
813
- for (const i of o.wires) {
814
- const n = this.wires.get(i);
815
- if (n && (n.node2 === t || n.node1 === t))
816
- return !0;
817
- }
818
- return !1;
819
- }
820
- /**
821
- * Find all components with pins among the provided enode IDs set.
822
- *
823
- * @param pinIds - Set of pins UUIDs
824
- * @returns Set of components UUIDs
825
- */
826
- getComponentsOfPins(e) {
827
- const t = /* @__PURE__ */ new Set();
828
- for (const o of e) {
829
- const i = this.enodes.get(o);
830
- i?.component && t.add(i.component);
831
- }
832
- return t;
833
- }
834
- /**
835
- * Get a component's pin ENode by its label.
836
- * @param component
837
- * @param pinLabel
838
- */
839
- getComponentPinByLabel(e, t) {
840
- let o = 0;
841
- const i = G[e.type], n = Array.from(i.pins.keys());
842
- for (const s of e.pins) {
843
- const c = this.enodes.get(s), r = n[o];
844
- if (r) {
845
- if (c && r === t)
846
- return c;
847
- o++;
848
- }
849
- }
850
- }
851
- /**
852
- * Update the intermediate positions of a wire.
853
- * Update the wire in place.
854
- *
855
- * @param wireId - Wire to update
856
- * @param intermediatePositions - New intermediate positions
857
- * @param simplify - Whether to simplify positions by removing collinear points : useful when finalizing wire routing
858
- * @returns The updated Wire
859
- * @throws Error if wireId not found
860
- */
861
- updateWireIntermediatePositions(e, t, o = !1) {
862
- const i = this.wires.get(e);
863
- if (!i)
864
- throw new Error(`Wire ${e} does not exist`);
865
- if (o) {
866
- const n = [
867
- this.enodes.get(i.node1).getPosition(this),
868
- ...t,
869
- this.enodes.get(i.node2).getPosition(this)
870
- ], s = P(n, 10);
871
- i.intermediatePositions = s.slice(
872
- 1,
873
- s.length - 1
874
- );
875
- } else
876
- i.intermediatePositions = t;
877
- return i;
878
- }
879
- /**
880
- * Simplify intermediate positions of a wire.
881
- * Update the wire in place.
882
- * @param wireId - Wire to simplify
883
- * @returns The updated Wire
884
- * @throws Error if wireId not found
885
- */
886
- simplifyWireIntermediatePositions(e) {
887
- const t = this.wires.get(e);
888
- if (!t)
889
- throw new Error(`Wire ${e} does not exist`);
890
- const o = [
891
- this.enodes.get(t.node1).getPosition(this),
892
- ...t.intermediatePositions,
893
- this.enodes.get(t.node2).getPosition(this)
894
- ], i = P(o, 5);
895
- return t.intermediatePositions = i.slice(
896
- 1,
897
- i.length - 1
898
- ), t.intermediatePositions = P(t.intermediatePositions), t;
899
- }
900
- /**
901
- * Update the source type of an ENode (branching point or component pin).
902
- * @param enodeId - ENode to update
903
- * @param sourceType - New source type (null to clear)
904
- * @throws Error if enodeId not found
905
- */
906
- updateENodeSourceType(e, t) {
907
- const o = this.enodes.get(e);
908
- if (!o)
909
- throw new Error(`ENode ${e} does not exist`);
910
- o.source = t || void 0;
911
- }
912
- /**
913
- * iterate through all components, enodes and wires positions to get the size that allows to enclose all elements.
914
- * @param margin - optional margin to add to the size
915
- * @returns size that allows to enclose all elements plus margin
916
- * @todo if calls to this method at each build operation ends causes slowness see to optimize by restricting checked elements
917
- */
918
- getEnclosingSize(e = 0) {
919
- let t = 0;
920
- for (const o of this.components.values())
921
- t = Math.max(t, Math.abs(o.position.x), Math.abs(o.position.y));
922
- for (const o of this.enodes.values()) {
923
- if (o.type === m.Pin) continue;
924
- const i = o.position;
925
- i && (t = Math.max(t, Math.abs(i.x), Math.abs(i.y)));
926
- }
927
- for (const o of this.wires.values())
928
- for (const i of o.intermediatePositions)
929
- t = Math.max(t, Math.abs(i.x), Math.abs(i.y));
930
- return Math.ceil(t * 2 + Math.max(e, 0));
931
- }
932
- /**
933
- * Serialize circuit to JSON.
934
- *
935
- * @returns JSON-serializable object containing all components, enodes, and wires
936
- *
937
- * @example
938
- * ```typescript
939
- * const json = circuit.toJSON();
940
- * localStorage.setItem('my-circuit', JSON.stringify(json));
941
- * ```
942
- */
943
- toJSON() {
944
- return {
945
- metadata: this.metadata.toJSON(),
946
- components: this.getAllComponents().map((e) => e.toJSON()),
947
- enodes: this.getAllENodes().map((e) => e.toJSON()),
948
- wires: this.getAllWires().map((e) => e.toJSON())
949
- };
950
- }
951
- /**
952
- * Deserialize circuit from JSON.
953
- *
954
- * @param json - Circuit data
955
- * @returns Circuit instance
956
- * @throws {Error} If JSON is invalid or violates invariants
957
- *
958
- * @example
959
- * ```typescript
960
- * const jsonStr = localStorage.getItem('my-circuit');
961
- * const json = JSON.parse(jsonStr);
962
- * const circuit = Circuit.fromJSON(json);
963
- * ```
964
- */
965
- static fromJSON(e) {
966
- const t = N.fromJSON(e.metadata), o = new x(t.options);
967
- o.metadata = t;
968
- for (const i of e.components) {
969
- const n = _.fromJSON(i);
970
- o.components.set(n.id, n);
971
- }
972
- for (const i of e.enodes) {
973
- const n = I.fromJSON(i);
974
- o.enodes.set(n.id, n);
975
- }
976
- if (e.wires)
977
- for (const i of e.wires) {
978
- const n = w.fromJSON(i);
979
- o.wires.set(n.id, n);
980
- const s = o.enodes.get(n.node1), c = o.enodes.get(n.node2);
981
- s && s.wires.add(n.id), c && c.wires.add(n.id);
982
- }
983
- return o;
984
- }
985
- }
986
- class v {
987
- /**
988
- * Component UUID this state belongs to.
989
- * @readonly
990
- */
991
- componentId;
992
- /**
993
- * Current operational state (varies by component type).
994
- * Examples: "on", "off", "open", "closed", "activating", "active"
995
- */
996
- state;
997
- /**
998
- * Tick when this state started.
999
- */
1000
- startTick;
1001
- /**
1002
- * Create a new component state.
1003
- *
1004
- * @param componentId - UUID of the component
1005
- * @param initialState - Initial operational state
1006
- */
1007
- constructor(e, t) {
1008
- this.componentId = e, this.state = t, this.startTick = 0;
1009
- }
1010
- hasSameComponent(e) {
1011
- return this.componentId === e.componentId;
1012
- }
1013
- }
1014
- class Y extends v {
1015
- /**
1016
- * Create a new battery state.
1017
- *
1018
- * @param componentId - UUID of the battery component
1019
- */
1020
- constructor(e) {
1021
- super(e, "on");
1022
- }
1023
- }
1024
- class q extends v {
1025
- /**
1026
- * Create a new Lightbulb state.
1027
- *
1028
- * @param componentId - UUID of the Lightbulb component
1029
- * @param initialState - Initial operational state (default: "off")
1030
- */
1031
- constructor(e, t = "off") {
1032
- super(e, t);
1033
- }
1034
- /**
1035
- * Check if Lightbulb is in lit state (on or going_on)
1036
- */
1037
- get isLit() {
1038
- return this.state === "on" || this.state === "goingOn";
1039
- }
1040
- }
1041
- class V extends v {
1042
- /**
1043
- * Create a new SmallLED state.
1044
- *
1045
- * @param componentId - UUID of the LED component
1046
- * @param initialState - Initial operational state (default: "off")
1047
- */
1048
- constructor(e, t = "off") {
1049
- super(e, t);
1050
- }
1051
- /**
1052
- * Check if LED is in lit state (on or going_on)
1053
- */
1054
- get isLit() {
1055
- return this.state === "on" || this.state === "goingOn";
1056
- }
1057
- }
1058
- class Q extends V {
1059
- }
1060
- class Z extends v {
1061
- /**
1062
- * Create a new Relay state.
1063
- *
1064
- * @param componentId - UUID of the Relay component
1065
- * @param initialState - Initial operational state (default: "open")
1066
- */
1067
- constructor(e, t = "open") {
1068
- super(e, t);
1069
- }
1070
- /**
1071
- * Check if relay is in opening or closing state
1072
- */
1073
- get isInTransition() {
1074
- return this.state === "closing" || this.state === "opening";
1075
- }
1076
- /**
1077
- * Check if relay is in closed or closing state
1078
- */
1079
- get isClosed() {
1080
- return this.state === "closed" || this.state === "closing";
1081
- }
1082
- }
1083
- class j extends v {
1084
- /**
1085
- * Create a new Switch state.
1086
- *
1087
- * @param componentId - UUID of the Switch component
1088
- * @param initialState - Initial operational state (default: "open")
1089
- */
1090
- constructor(e, t = "open") {
1091
- super(e, t);
1092
- }
1093
- /**
1094
- * Check if switch is in opening or closing state
1095
- */
1096
- get isInTransition() {
1097
- return this.state === "closing" || this.state === "opening";
1098
- }
1099
- /**
1100
- * Check if switch is in closed or closing state
1101
- */
1102
- get isClosed() {
1103
- return this.state === "closed" || this.state === "closing";
1104
- }
1105
- }
1106
- class ee extends v {
1107
- /**
1108
- * Create a new double Switch state.
1109
- *
1110
- * @param componentId - UUID of the double Switch component
1111
- * @param initialState - Initial operational state (default: "input1")
1112
- */
1113
- constructor(e, t = "input1") {
1114
- super(e, t);
1115
- }
1116
- /**
1117
- * Check if switch is in 1to2 or 2to1 state
1118
- */
1119
- get isInTransition() {
1120
- return this.state === "1to2" || this.state === "2to1";
1121
- }
1122
- }
1123
- class g extends v {
1124
- /**
1125
- * Create a new Inverter state.
1126
- *
1127
- * @param componentId - UUID of the Inverter component
1128
- * @param initialState - Initial operational state (default: "low")
1129
- */
1130
- constructor(e, t = "low") {
1131
- super(e, t);
1132
- }
1133
- /**
1134
- * Check if output is in a rising or falling transition
1135
- */
1136
- get isInTransition() {
1137
- return this.state === "rising" || this.state === "falling";
1138
- }
1139
- /**
1140
- * Check if output is high
1141
- */
1142
- get isHigh() {
1143
- return this.state === "high";
1144
- }
1145
- }
1146
- class te extends g {
1147
- /**
1148
- * Create a new Inverter state.
1149
- *
1150
- * @param componentId - UUID of the Inverter component
1151
- * @param initialState - Initial operational state (default: "low")
1152
- */
1153
- constructor(e, t = "low") {
1154
- super(e, t);
1155
- }
1156
- }
1157
- class ne extends g {
1158
- /**
1159
- * Create a new NAND Gate state.
1160
- *
1161
- * @param componentId - UUID of the NAND Gate component
1162
- * @param initialState - Initial operational state (default: "low")
1163
- */
1164
- constructor(e, t = "low") {
1165
- super(e, t);
1166
- }
1167
- }
1168
- class ie extends g {
1169
- constructor(e, t = "low") {
1170
- super(e, t);
1171
- }
1172
- }
1173
- class oe extends g {
1174
- constructor(e, t = "low") {
1175
- super(e, t);
1176
- }
1177
- }
1178
- class se extends g {
1179
- constructor(e, t = "low") {
1180
- super(e, t);
1181
- }
1182
- }
1183
- class re extends g {
1184
- constructor(e, t = "low") {
1185
- super(e, t);
1186
- }
1187
- }
1188
- class ae extends g {
1189
- constructor(e, t = "low") {
1190
- super(e, t);
1191
- }
1192
- }
1193
- class ce extends g {
1194
- constructor(e, t = "low") {
1195
- super(e, t);
1196
- }
1197
- }
1198
- class ue extends g {
1199
- constructor(e, t = "low") {
1200
- super(e, t);
1201
- }
1202
- }
1203
- class he extends g {
1204
- constructor(e, t = "low") {
1205
- super(e, t);
1206
- }
1207
- }
1208
- class Oe {
1209
- behaviors;
1210
- /**
1211
- * Create a new empty behavior registry.
1212
- */
1213
- constructor() {
1214
- this.behaviors = /* @__PURE__ */ new Map();
1215
- }
1216
- /**
1217
- * Register a behavior for a component type.
1218
- * Overwrites any existing behavior for the same type.
1219
- *
1220
- * @param behavior - The component behavior to register
1221
- * @throws TypeError if behavior is null/undefined or componentType is empty
1222
- * @returns The registry instance for chaining
1223
- */
1224
- register(e) {
1225
- if (!e)
1226
- throw new TypeError("Behavior cannot be null or undefined");
1227
- if (!e.componentType || e.componentType.trim() === "")
1228
- throw new TypeError("Behavior componentType cannot be empty");
1229
- return this.behaviors.set(e.componentType, e), this;
1230
- }
1231
- /**
1232
- * Register multiple behaviors at once.
1233
- * Convenience method for bulk registration.
1234
- *
1235
- * @param behaviors - Array of behaviors to register
1236
- */
1237
- registerAll(e) {
1238
- e.forEach((t) => this.register(t));
1239
- }
1240
- /**
1241
- * Get the behavior for a component type.
1242
- *
1243
- * @param componentType - Type identifier (e.g., "battery", "led")
1244
- * @returns The registered behavior, or undefined if not found
1245
- */
1246
- get(e) {
1247
- return this.behaviors.get(e);
1248
- }
1249
- /**
1250
- * Check if a behavior is registered for a component type.
1251
- *
1252
- * @param componentType - Type identifier to check
1253
- * @returns True if behavior is registered
1254
- */
1255
- has(e) {
1256
- return this.behaviors.has(e);
1257
- }
1258
- /**
1259
- * Unregister a behavior for a component type.
1260
- *
1261
- * @param componentType - Type identifier to unregister
1262
- * @returns True if behavior was found and removed
1263
- */
1264
- unregister(e) {
1265
- return this.behaviors.delete(e);
1266
- }
1267
- /**
1268
- * Clear all registered behaviors.
1269
- */
1270
- clear() {
1271
- this.behaviors.clear();
1272
- }
1273
- /**
1274
- * Get all registered component types.
1275
- *
1276
- * @returns Array of component type identifiers
1277
- */
1278
- getRegisteredTypes() {
1279
- return Array.from(this.behaviors.keys());
1280
- }
1281
- /**
1282
- * Get count of registered behaviors.
1283
- *
1284
- * @returns Number of registered behaviors
1285
- */
1286
- size() {
1287
- return this.behaviors.size;
1288
- }
1289
- }
1290
- class y {
1291
- /**
1292
- * Component type this behavior handles (e.g., "battery", "led", "switch").
1293
- * Used as the key in BehaviorRegistry.
1294
- */
1295
- _componentType;
1296
- constructor(e) {
1297
- this._componentType = e;
1298
- }
1299
- get componentType() {
1300
- return this._componentType;
1301
- }
1302
- get typeMetadata() {
1303
- const e = G[this._componentType];
1304
- if (!e)
1305
- throw new Error(`Unknown metadata for Component type ${this._componentType}`);
1306
- return e;
1307
- }
1308
- getPinStates(e, t) {
1309
- const o = /* @__PURE__ */ new Map();
1310
- for (const i of e.pins)
1311
- o.set(e.getPinLabel(i), t.get(i));
1312
- return o;
1313
- }
1314
- /**
1315
- * Default: nothing happens
1316
- * @param _component
1317
- * @param componentState
1318
- * @param _nodeStates
1319
- * @param _targetTick
1320
- */
1321
- onPinsChange(e, t, o, i) {
1322
- return {
1323
- componentState: t,
1324
- hasChanged: !1,
1325
- shouldCancelPending: !1,
1326
- scheduledEvents: []
1327
- };
1328
- }
1329
- /**
1330
- * Default: no conductivity between pins
1331
- * @param _component
1332
- * @param _state
1333
- * @param _conductivityType
1334
- * @param _pinId
1335
- * @param _otherPinId
1336
- */
1337
- allowConductivity(e, t, o, i, n) {
1338
- return !1;
1339
- }
1340
- onUserCommand(e, t, o) {
1341
- return {
1342
- componentState: t,
1343
- hasChanged: !1,
1344
- shouldCancelPending: !1,
1345
- scheduledEvents: []
1346
- };
1347
- }
1348
- onEventFiring(e, t, o) {
1349
- return {
1350
- componentState: t,
1351
- hasChanged: !1,
1352
- shouldCancelPending: !1,
1353
- scheduledEvents: []
1354
- };
1355
- }
1356
- }
1357
- class de extends y {
1358
- constructor() {
1359
- super(h.Battery);
1360
- }
1361
- /**
1362
- * Create initial state for a battery.
1363
- *
1364
- * @param component - The Battery component
1365
- * @returns Battery Initial state (always active and delivering voltage)
1366
- */
1367
- createInitialState(e) {
1368
- if (e.type !== this._componentType)
1369
- throw new Error(`Invalid component type for BatteryBehavior: ${e.type}`);
1370
- return new Y(e.id);
1371
- }
1372
- }
1373
- class L extends y {
1374
- getBehavior(e, t, o, i) {
1375
- let n = !1;
1376
- const s = [];
1377
- return o ? (t.state === "off" || t.state === "goingOff") && (n = !0, t.state = "goingOn", t.startTick = i, s.push({
1378
- targetId: e.id,
1379
- scheduledAtTick: i,
1380
- readyAtTick: i + 1,
1381
- // TODO handle component config later ?
1382
- type: "GoingOnEnd",
1383
- parameters: void 0
1384
- }), t.state = "goingOn") : (t.state === "on" || t.state === "goingOn") && (n = !0, t.state = "goingOff", t.startTick = i, s.push({
1385
- targetId: e.id,
1386
- scheduledAtTick: i,
1387
- readyAtTick: i + 1,
1388
- // TODO handle component config later ?
1389
- type: "GoingOffEnd",
1390
- parameters: void 0
1391
- }), t.state = "goingOff"), {
1392
- componentState: t,
1393
- hasChanged: n,
1394
- shouldCancelPending: !1,
1395
- scheduledEvents: s
1396
- };
1397
- }
1398
- allowConductivity(e, t, o, i, n) {
1399
- return !0;
1400
- }
1401
- onEventFiring(e, t, o) {
1402
- let i = !1;
1403
- return o.type === "GoingOffEnd" ? t.state !== "off" && (i = !0, t.startTick = o.readyAtTick, t.state = "off") : o.type === "GoingOnEnd" && t.state !== "on" && (i = !0, t.startTick = o.readyAtTick, t.state = "on"), {
1404
- componentState: t,
1405
- hasChanged: i,
1406
- shouldCancelPending: !1,
1407
- scheduledEvents: []
1408
- };
1409
- }
1410
- }
1411
- function $(a) {
1412
- if (!a)
1413
- return S.TRANSITION_SPAN_TICKS;
1414
- const e = parseInt(a.get("tickCount") || "", 10);
1415
- return isNaN(e) || e < 1 ? S.TRANSITION_SPAN_TICKS : e;
1416
- }
1417
- class le extends L {
1418
- constructor() {
1419
- super(h.Lightbulb);
1420
- }
1421
- /**
1422
- * Create initial state for a lightbulb.
1423
- *
1424
- * @param component - The lightbulb component
1425
- * @returns lightbulbInitial state (always active and delivering voltage)
1426
- */
1427
- createInitialState(e) {
1428
- if (e.type !== this._componentType)
1429
- throw new Error(`Invalid component type for lightbulbBehavior: ${e.type}`);
1430
- return new q(e.id);
1431
- }
1432
- /**
1433
- * @param component
1434
- * @param state
1435
- * @param nodeStates
1436
- * @param targetTick
1437
- */
1438
- onPinsChange(e, t, o, i) {
1439
- const n = this.getPinStates(e, o);
1440
- let s = n.get("pin1").hasVoltage && n.get("pin1").hasCurrent || n.get("pin2").hasVoltage && n.get("pin2").hasCurrent || n.get("pin1").hasVoltage && n.get("pin2").hasCurrent || n.get("pin2").hasVoltage && n.get("pin1").hasCurrent;
1441
- return this.getBehavior(e, t, s, i);
1442
- }
1443
- }
1444
- class ge extends L {
1445
- constructor() {
1446
- super(h.RectangleLED);
1447
- }
1448
- /**
1449
- * Create initial state for a RectangleLED.
1450
- *
1451
- * @param component - The smallLED component
1452
- * @returns LED Initial state (always active and delivering voltage)
1453
- */
1454
- createInitialState(e) {
1455
- if (e.type !== this._componentType)
1456
- throw new Error(`Invalid component type for RectangleLEDBehavior: ${e.type}`);
1457
- return new Q(e.id);
1458
- }
1459
- /**
1460
- * only symmetrical behavior of LEDS is handled for now
1461
- * @param component
1462
- * @param state
1463
- * @param nodeStates
1464
- * @param targetTick
1465
- */
1466
- onPinsChange(e, t, o, i) {
1467
- const n = this.getPinStates(e, o);
1468
- let s = n.get("pin2").hasVoltage && n.get("pin2").hasCurrent || n.get("pin1").hasVoltage && n.get("pin1").hasCurrent || n.get("pin2").hasVoltage && n.get("pin1").hasCurrent || n.get("pin1").hasVoltage && n.get("pin2").hasCurrent;
1469
- return this.getBehavior(e, t, s, i);
1470
- }
1471
- }
1472
- function pe(a) {
1473
- const e = parseInt(a.get("transitionSpan") || "", 10);
1474
- return isNaN(e) || e < 1 ? S.TRANSITION_SPAN_TICKS : e;
1475
- }
1476
- class fe extends y {
1477
- constructor() {
1478
- super(h.Relay);
1479
- }
1480
- /**
1481
- * Create initial state for a relay.
1482
- *
1483
- * @param component - The Relay component
1484
- * @returns Relay Initial state (open by default)
1485
- */
1486
- createInitialState(e) {
1487
- if (e.type !== this._componentType)
1488
- throw new Error(`Invalid component type for RelayBehavior: ${e.type}`);
1489
- const t = e.config.get("activationLogic") === "negative" ? "closed" : "open";
1490
- return new Z(e.id, t);
1491
- }
1492
- allowConductivity(e, t, o, i, n) {
1493
- if (i === n) return !0;
1494
- const s = e.getPinLabel(i), c = e.getPinLabel(n);
1495
- if (!s || !c) return !1;
1496
- const r = [s, c];
1497
- return r.includes("cmd_in") && r.includes("cmd_out") ? !0 : r.includes("power_in") && r.includes("power_out") ? t.state === "closed" || t.state === "opening" : !1;
1498
- }
1499
- /**
1500
- * Relay cmd pins need to have voltage and current so that relay contactor stays closed
1501
- * @param component
1502
- * @param state
1503
- * @param nodeStates
1504
- * @param targetTick
1505
- */
1506
- onPinsChange(e, t, o, i) {
1507
- const n = this.getPinStates(e, o), s = n.get("cmd_in").hasVoltage && n.get("cmd_in").hasCurrent || n.get("cmd_out").hasVoltage && n.get("cmd_out").hasCurrent || n.get("cmd_in").hasVoltage && n.get("cmd_out").hasCurrent || n.get("cmd_out").hasVoltage && n.get("cmd_in").hasCurrent, c = e.config.get("activationLogic") === "negative" ? !s : s;
1508
- let r = !1;
1509
- const u = [], d = pe(e.config);
1510
- return c ? (t.state === "open" || t.state === "opening") && (r = !0, t.state = "closing", t.startTick = i, u.push({
1511
- targetId: e.id,
1512
- scheduledAtTick: i,
1513
- readyAtTick: i + d,
1514
- type: "ClosingEnd",
1515
- parameters: void 0
1516
- })) : (t.state === "closed" || t.state === "closing") && (r = !0, t.state = "opening", t.startTick = i, u.push({
1517
- targetId: e.id,
1518
- scheduledAtTick: i,
1519
- readyAtTick: i + d,
1520
- type: "OpeningEnd",
1521
- parameters: void 0
1522
- })), {
1523
- componentState: t,
1524
- hasChanged: r,
1525
- shouldCancelPending: !1,
1526
- scheduledEvents: u
1527
- };
1528
- }
1529
- onEventFiring(e, t, o) {
1530
- let i = !1;
1531
- return o.type === "ClosingEnd" ? t.state !== "closed" && (i = !0, t.startTick = o.readyAtTick, t.state = "closed") : o.type === "OpeningEnd" && t.state !== "open" && (i = !0, t.startTick = o.readyAtTick, t.state = "open"), {
1532
- componentState: t,
1533
- hasChanged: i,
1534
- shouldCancelPending: !1,
1535
- scheduledEvents: []
1536
- };
1537
- }
1538
- }
1539
- class ve extends L {
1540
- constructor() {
1541
- super(h.SmallLED);
1542
- }
1543
- /**
1544
- * Create initial state for a smallLED.
1545
- *
1546
- * @param component - The smallLED component
1547
- * @returns LED Initial state (always active and delivering voltage)
1548
- */
1549
- createInitialState(e) {
1550
- if (e.type !== this._componentType)
1551
- throw new Error(`Invalid component type for SmallLEDBehavior: ${e.type}`);
1552
- return new V(e.id);
1553
- }
1554
- /**
1555
- * only symmetrical behavior of LEDS is handled for now
1556
- * @param component
1557
- * @param state
1558
- * @param nodeStates
1559
- * @param targetTick
1560
- */
1561
- onPinsChange(e, t, o, i) {
1562
- const n = this.getPinStates(e, o);
1563
- let s = n.get("pin2").hasVoltage && n.get("pin2").hasCurrent || n.get("pin1").hasVoltage && n.get("pin1").hasCurrent || n.get("pin2").hasVoltage && n.get("pin1").hasCurrent || n.get("pin1").hasVoltage && n.get("pin2").hasCurrent;
1564
- return this.getBehavior(e, t, s, i);
1565
- }
1566
- }
1567
- class we extends y {
1568
- constructor() {
1569
- super(h.Switch);
1570
- }
1571
- /**
1572
- * Create initial state for a switch.
1573
- *
1574
- * @param component - The Switch component
1575
- * @returns Switch Initial state (open by default)
1576
- */
1577
- createInitialState(e) {
1578
- if (e.type !== this._componentType)
1579
- throw new Error(`Invalid component type for SwitchBehavior: ${e.type}`);
1580
- const t = e.config.get("initialState") || "open";
1581
- return new j(e.id, t);
1582
- }
1583
- allowConductivity(e, t, o, i, n) {
1584
- return t.state === "closed" || t.state === "opening";
1585
- }
1586
- onUserCommand(e, t, o) {
1587
- let i = !1;
1588
- const n = [];
1589
- if (o.type === "toggle_switch" && ["open", "closed"].includes(t.state)) {
1590
- t.state = t.state === "open" ? "closing" : "opening", t.startTick = o.scheduledAtTick + 1, i = !0;
1591
- const s = $(o.parameters);
1592
- n.push({
1593
- targetId: e.id,
1594
- scheduledAtTick: t.startTick,
1595
- readyAtTick: t.startTick + s,
1596
- type: t.state === "closing" ? "ClosingEnd" : "OpeningEnd",
1597
- parameters: void 0
1598
- });
1599
- }
1600
- return {
1601
- componentState: t,
1602
- hasChanged: i,
1603
- shouldCancelPending: !1,
1604
- scheduledEvents: n
1605
- };
1606
- }
1607
- onEventFiring(e, t, o) {
1608
- let i = !1;
1609
- return o.type === "ClosingEnd" ? t.state !== "closed" && (i = !0, t.startTick = o.readyAtTick, t.state = "closed") : o.type === "OpeningEnd" && t.state !== "open" && (i = !0, t.startTick = o.readyAtTick, t.state = "open"), {
1610
- componentState: t,
1611
- hasChanged: i,
1612
- shouldCancelPending: !1,
1613
- scheduledEvents: []
1614
- };
1615
- }
1616
- }
1617
- class ye extends y {
1618
- constructor() {
1619
- super(h.DoubleThrowSwitch);
1620
- }
1621
- /**
1622
- * Create initial state for a double throw switch (SPDT).
1623
- *
1624
- * @param component - The double Switch component
1625
- * @returns double Switch Initial state (input1 by default)
1626
- */
1627
- createInitialState(e) {
1628
- if (e.type !== this._componentType)
1629
- throw new Error(`Invalid component type for DoubleThrowSwitchBehavior: ${e.type}`);
1630
- const t = e.config.get("initialState") || "input1";
1631
- return new ee(e.id, t);
1632
- }
1633
- allowConductivity(e, t, o, i, n) {
1634
- if (i === n) return !0;
1635
- const s = e.getPinLabel(i), c = e.getPinLabel(n);
1636
- if (!s || !c) return !1;
1637
- const r = [s, c];
1638
- return r.includes("output") && r.includes("input1") ? t.state === "input1" || t.state === "1to2" : r.includes("output") && r.includes("input2") ? t.state === "input2" || t.state === "2to1" : !1;
1639
- }
1640
- onUserCommand(e, t, o) {
1641
- let i = !1;
1642
- const n = [];
1643
- if (o.type === "toggle_switch" && ["input1", "input2"].includes(t.state)) {
1644
- t.state = t.state === "input1" ? "1to2" : "2to1", t.startTick = o.scheduledAtTick + 1, i = !0;
1645
- const s = $(o.parameters);
1646
- n.push({
1647
- targetId: e.id,
1648
- scheduledAtTick: t.startTick,
1649
- readyAtTick: t.startTick + s,
1650
- type: t.state === "1to2" ? "ContactedInput2" : "ContactedInput1",
1651
- parameters: void 0
1652
- });
1653
- }
1654
- return {
1655
- componentState: t,
1656
- hasChanged: i,
1657
- shouldCancelPending: !1,
1658
- scheduledEvents: n
1659
- };
1660
- }
1661
- onEventFiring(e, t, o) {
1662
- let i = !1;
1663
- return o.type === "ContactedInput2" ? t.state !== "input2" && (i = !0, t.startTick = o.readyAtTick, t.state = "input2") : o.type === "ContactedInput1" && t.state !== "input1" && (i = !0, t.startTick = o.readyAtTick, t.state = "input1"), {
1664
- componentState: t,
1665
- hasChanged: i,
1666
- shouldCancelPending: !1,
1667
- scheduledEvents: []
1668
- };
1669
- }
1670
- }
1671
- function me(a) {
1672
- const e = parseInt(a.get("transitionSpan") || "", 10);
1673
- return isNaN(e) || e < 1 ? S.TRANSITION_SPAN_TICKS : e;
1674
- }
1675
- class p extends y {
1676
- /**
1677
- * default return for all logic gates when vcc fails -> go low immediately
1678
- * @param state
1679
- * @param pinStates
1680
- * @protected
1681
- */
1682
- vccGuardBehavior(e, t, o) {
1683
- if (t.get("vcc").hasVoltage)
1684
- return null;
1685
- e.startTick = e.state === "low" ? e.startTick : o;
1686
- const n = e.state !== "low", s = e.state !== "low";
1687
- return e.state = "low", {
1688
- componentState: e,
1689
- hasChanged: n,
1690
- shouldCancelPending: s,
1691
- scheduledEvents: []
1692
- };
1693
- }
1694
- /**
1695
- * guard scanning all inputs of logic gates to detect if Any has:
1696
- * - both voltage and ground hence with established flowing current
1697
- * - neither voltage nor ground
1698
- * it makes a not well-defined input between LOW and HIGH
1699
- * in that case gate goes to state indeterminate and output nothing too
1700
- * @param state
1701
- * @param pinStates
1702
- * @param targetTick
1703
- * @protected
1704
- */
1705
- nonLogicInputGuardBehavior(e, t, o) {
1706
- let i = !1;
1707
- const n = this.typeMetadata.pins;
1708
- for (const [r, u] of t) {
1709
- if (!n.has(r)) continue;
1710
- const d = n.get(r);
1711
- if (d && d?.subtype === "logicInput") {
1712
- if (u.hasVoltage && u.hasCurrent) {
1713
- i = !0;
1714
- break;
1715
- }
1716
- if (!u.hasVoltage && !u.hasCurrent) {
1717
- i = !0;
1718
- break;
1719
- }
1720
- }
1721
- }
1722
- if (!i)
1723
- return null;
1724
- e.startTick = e.state === "indeterminate" ? e.startTick : o;
1725
- const s = e.state !== "indeterminate", c = e.state !== "indeterminate";
1726
- return e.state = "indeterminate", {
1727
- componentState: e,
1728
- hasChanged: s,
1729
- shouldCancelPending: c,
1730
- scheduledEvents: []
1731
- };
1732
- }
1733
- getBehavior(e, t, o, i) {
1734
- const n = me(e.config);
1735
- return ["low", "rising", "high", "falling", "indeterminate"].includes(t.state) || (t.state = "low"), o ? t.state === "low" || t.state === "indeterminate" ? (t.state = "rising", t.startTick = i, {
1736
- componentState: t,
1737
- hasChanged: !0,
1738
- shouldCancelPending: !1,
1739
- scheduledEvents: [{
1740
- targetId: e.id,
1741
- scheduledAtTick: i,
1742
- readyAtTick: i + n,
1743
- type: "RisingComplete",
1744
- parameters: void 0
1745
- }]
1746
- }) : t.state === "rising" || t.state === "high" ? {
1747
- componentState: t,
1748
- hasChanged: !1,
1749
- shouldCancelPending: !1,
1750
- scheduledEvents: []
1751
- } : (t.state = "high", {
1752
- componentState: t,
1753
- hasChanged: !0,
1754
- shouldCancelPending: !0,
1755
- // goes back to high immediately and cancel pending FallingComplete event
1756
- scheduledEvents: []
1757
- }) : t.state === "falling" || t.state === "low" ? {
1758
- componentState: t,
1759
- hasChanged: !1,
1760
- shouldCancelPending: !1,
1761
- scheduledEvents: []
1762
- } : t.state === "high" ? (t.state = "falling", t.startTick = i, {
1763
- componentState: t,
1764
- hasChanged: !0,
1765
- shouldCancelPending: !1,
1766
- scheduledEvents: [{
1767
- targetId: e.id,
1768
- scheduledAtTick: i,
1769
- readyAtTick: i + n,
1770
- type: "FallingComplete",
1771
- parameters: void 0
1772
- }]
1773
- }) : (t.state = "low", {
1774
- componentState: t,
1775
- hasChanged: !0,
1776
- shouldCancelPending: !0,
1777
- // goes back to low immediately and cancel pending RisingComplete event
1778
- scheduledEvents: []
1779
- });
1780
- }
1781
- allowConductivity(e, t, o, i, n) {
1782
- if (i === n) return !0;
1783
- const s = e.getPinLabel(i), c = e.getPinLabel(n);
1784
- if (!s || !c) return !1;
1785
- const r = [s, c];
1786
- return r.includes("vcc") && r.includes("output") ? t.state === "high" || t.state === "falling" : r.includes("gnd") && r.includes("output") ? t.state === "low" || t.state === "rising" : !1;
1787
- }
1788
- onEventFiring(e, t, o) {
1789
- let i = !1;
1790
- return o.type === "RisingComplete" ? t.state !== "high" && (i = !0, t.startTick = o.readyAtTick, t.state = "high") : o.type === "FallingComplete" && t.state !== "low" && (i = !0, t.startTick = o.readyAtTick, t.state = "low"), {
1791
- componentState: t,
1792
- hasChanged: i,
1793
- shouldCancelPending: !1,
1794
- scheduledEvents: []
1795
- };
1796
- }
1797
- }
1798
- class Se extends p {
1799
- constructor() {
1800
- super(h.Inverter);
1801
- }
1802
- /**
1803
- * Create initial state for a Inverter.
1804
- *
1805
- * @param component - The Inverter component
1806
- * @returns Inverter Initial state (HIGH if input LOW, LOW if input LOW for positive activation logic)
1807
- */
1808
- createInitialState(e) {
1809
- if (e.type !== this._componentType)
1810
- throw new Error(`Invalid component type for InverterBehavior: ${e.type}`);
1811
- const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
1812
- return new te(e.id, t);
1813
- }
1814
- /**
1815
- * Inverter needs LOW on input to drive the output HIGH, and on the contrary Buffer needs HIGH on input to output HIGH
1816
- * @param component
1817
- * @param state
1818
- * @param nodeStates
1819
- * @param targetTick
1820
- */
1821
- onPinsChange(e, t, o, i) {
1822
- const n = this.getPinStates(e, o), s = this.vccGuardBehavior(t, n, i);
1823
- if (s)
1824
- return s;
1825
- const c = this.nonLogicInputGuardBehavior(t, n, i);
1826
- if (c)
1827
- return c;
1828
- const r = n.get("input").hasVoltage, u = e.config.get("activationLogic") === "negative" ? !r : r;
1829
- return this.getBehavior(e, t, u, i);
1830
- }
1831
- }
1832
- class Ce extends p {
1833
- constructor() {
1834
- super(h.NandGate);
1835
- }
1836
- /**
1837
- * Create initial state for an NAND Gate.
1838
- *
1839
- * @param component - The NAND Gate component
1840
- * @returns Initial state (low by default, high for negative activation logic)
1841
- */
1842
- createInitialState(e) {
1843
- if (e.type !== this._componentType)
1844
- throw new Error(`Invalid component type for NandGateBehavior: ${e.type}`);
1845
- const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
1846
- return new ne(e.id, t);
1847
- }
1848
- /**
1849
- * NAND gate output goes high when ANY inputs LACK voltage.
1850
- * With positive activationLogic (AND), output goes high when ALL inputs HAS voltage.
1851
- */
1852
- onPinsChange(e, t, o, i) {
1853
- const n = this.getPinStates(e, o), s = this.vccGuardBehavior(t, n, i);
1854
- if (s)
1855
- return s;
1856
- const c = this.nonLogicInputGuardBehavior(t, n, i);
1857
- if (c)
1858
- return c;
1859
- const r = n.get("input1").hasVoltage && n.get("input2").hasVoltage, u = e.config.get("activationLogic") === "negative" ? !r : r;
1860
- return this.getBehavior(e, t, u, i);
1861
- }
1862
- }
1863
- class Ne extends p {
1864
- constructor() {
1865
- super(h.Nand4Gate);
1866
- }
1867
- createInitialState(e) {
1868
- if (e.type !== this._componentType)
1869
- throw new Error(`Invalid component type for Nand4GateBehavior: ${e.type}`);
1870
- const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
1871
- return new ie(e.id, t);
1872
- }
1873
- onPinsChange(e, t, o, i) {
1874
- const n = this.getPinStates(e, o), s = this.vccGuardBehavior(t, n, i);
1875
- if (s)
1876
- return s;
1877
- const c = this.nonLogicInputGuardBehavior(t, n, i);
1878
- if (c)
1879
- return c;
1880
- const r = n.get("input1").hasVoltage && n.get("input2").hasVoltage && n.get("input3").hasVoltage && n.get("input4").hasVoltage, u = e.config.get("activationLogic") === "negative" ? !r : r;
1881
- return this.getBehavior(e, t, u, i);
1882
- }
1883
- }
1884
- class Be extends p {
1885
- constructor() {
1886
- super(h.Nand8Gate);
1887
- }
1888
- createInitialState(e) {
1889
- if (e.type !== this._componentType)
1890
- throw new Error(`Invalid component type for Nand8GateBehavior: ${e.type}`);
1891
- const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
1892
- return new oe(e.id, t);
1893
- }
1894
- onPinsChange(e, t, o, i) {
1895
- const n = this.getPinStates(e, o), s = this.vccGuardBehavior(t, n, i);
1896
- if (s)
1897
- return s;
1898
- const c = this.nonLogicInputGuardBehavior(t, n, i);
1899
- if (c)
1900
- return c;
1901
- const r = n.get("input1").hasVoltage && n.get("input2").hasVoltage && n.get("input3").hasVoltage && n.get("input4").hasVoltage && n.get("input5").hasVoltage && n.get("input6").hasVoltage && n.get("input7").hasVoltage && n.get("input8").hasVoltage, u = e.config.get("activationLogic") === "negative" ? !r : r;
1902
- return this.getBehavior(e, t, u, i);
1903
- }
1904
- }
1905
- class Ie extends p {
1906
- constructor() {
1907
- super(h.NorGate);
1908
- }
1909
- createInitialState(e) {
1910
- if (e.type !== this._componentType)
1911
- throw new Error(`Invalid component type for NorGateBehavior: ${e.type}`);
1912
- const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
1913
- return new se(e.id, t);
1914
- }
1915
- /**
1916
- * NOR gate output goes high when ALL inputs LACK voltage.
1917
- * With positive activationLogic (OR), output goes high when ANY inputs HAS voltage.
1918
- */
1919
- onPinsChange(e, t, o, i) {
1920
- const n = this.getPinStates(e, o), s = this.vccGuardBehavior(t, n, i);
1921
- if (s)
1922
- return s;
1923
- const c = this.nonLogicInputGuardBehavior(t, n, i);
1924
- if (c)
1925
- return c;
1926
- const r = n.get("input1").hasVoltage || n.get("input2").hasVoltage, u = e.config.get("activationLogic") === "negative" ? !r : r;
1927
- return this.getBehavior(e, t, u, i);
1928
- }
1929
- }
1930
- class Pe extends p {
1931
- constructor() {
1932
- super(h.Nor4Gate);
1933
- }
1934
- createInitialState(e) {
1935
- if (e.type !== this._componentType)
1936
- throw new Error(`Invalid component type for Nor4GateBehavior: ${e.type}`);
1937
- const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
1938
- return new re(e.id, t);
1939
- }
1940
- onPinsChange(e, t, o, i) {
1941
- const n = this.getPinStates(e, o), s = this.vccGuardBehavior(t, n, i);
1942
- if (s)
1943
- return s;
1944
- const c = this.nonLogicInputGuardBehavior(t, n, i);
1945
- if (c)
1946
- return c;
1947
- const r = n.get("input1").hasVoltage || n.get("input2").hasVoltage || n.get("input3").hasVoltage || n.get("input4").hasVoltage, u = e.config.get("activationLogic") === "negative" ? !r : r;
1948
- return this.getBehavior(e, t, u, i);
1949
- }
1950
- }
1951
- class Te extends p {
1952
- constructor() {
1953
- super(h.Nor8Gate);
1954
- }
1955
- createInitialState(e) {
1956
- if (e.type !== this._componentType)
1957
- throw new Error(`Invalid component type for Nor8GateBehavior: ${e.type}`);
1958
- const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
1959
- return new ae(e.id, t);
1960
- }
1961
- onPinsChange(e, t, o, i) {
1962
- const n = this.getPinStates(e, o), s = this.vccGuardBehavior(t, n, i);
1963
- if (s)
1964
- return s;
1965
- const c = this.nonLogicInputGuardBehavior(t, n, i);
1966
- if (c)
1967
- return c;
1968
- const r = n.get("input1").hasVoltage || n.get("input2").hasVoltage || n.get("input3").hasVoltage || n.get("input4").hasVoltage || n.get("input5").hasVoltage || n.get("input6").hasVoltage || n.get("input7").hasVoltage || n.get("input8").hasVoltage, u = e.config.get("activationLogic") === "negative" ? !r : r;
1969
- return this.getBehavior(e, t, u, i);
1970
- }
1971
- }
1972
- class Ee extends p {
1973
- constructor() {
1974
- super(h.XorGate);
1975
- }
1976
- createInitialState(e) {
1977
- if (e.type !== this._componentType)
1978
- throw new Error(`Invalid component type for XorGateBehavior: ${e.type}`);
1979
- const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
1980
- return new ce(e.id, t);
1981
- }
1982
- /**
1983
- * XOR gate output goes high when inputs differ (odd parity).
1984
- * With negative activationLogic (XNOR), output goes high when inputs are equal (even parity).
1985
- */
1986
- onPinsChange(e, t, o, i) {
1987
- const n = this.getPinStates(e, o), s = this.vccGuardBehavior(t, n, i);
1988
- if (s)
1989
- return s;
1990
- const c = this.nonLogicInputGuardBehavior(t, n, i);
1991
- if (c)
1992
- return c;
1993
- const r = n.get("input1").hasVoltage, u = n.get("input2").hasVoltage, d = r !== u, l = e.config.get("activationLogic") === "negative" ? !d : d;
1994
- return this.getBehavior(e, t, l, i);
1995
- }
1996
- }
1997
- class Ge extends p {
1998
- constructor() {
1999
- super(h.Xor4Gate);
2000
- }
2001
- createInitialState(e) {
2002
- if (e.type !== this._componentType)
2003
- throw new Error(`Invalid component type for Xor4GateBehavior: ${e.type}`);
2004
- const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
2005
- return new ue(e.id, t);
2006
- }
2007
- onPinsChange(e, t, o, i) {
2008
- const n = this.getPinStates(e, o), s = this.vccGuardBehavior(t, n, i);
2009
- if (s)
2010
- return s;
2011
- const c = this.nonLogicInputGuardBehavior(t, n, i);
2012
- if (c)
2013
- return c;
2014
- const u = ((n.get("input1").hasVoltage ? 1 : 0) + (n.get("input2").hasVoltage ? 1 : 0) + (n.get("input3").hasVoltage ? 1 : 0) + (n.get("input4").hasVoltage ? 1 : 0)) % 2 === 1, d = e.config.get("activationLogic") === "negative" ? !u : u;
2015
- return this.getBehavior(e, t, d, i);
2016
- }
2017
- }
2018
- class Le extends p {
2019
- constructor() {
2020
- super(h.Xor8Gate);
2021
- }
2022
- createInitialState(e) {
2023
- if (e.type !== this._componentType)
2024
- throw new Error(`Invalid component type for Xor8GateBehavior: ${e.type}`);
2025
- const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
2026
- return new he(e.id, t);
2027
- }
2028
- onPinsChange(e, t, o, i) {
2029
- const n = this.getPinStates(e, o), s = this.vccGuardBehavior(t, n, i);
2030
- if (s)
2031
- return s;
2032
- const c = this.nonLogicInputGuardBehavior(t, n, i);
2033
- if (c)
2034
- return c;
2035
- const u = ((n.get("input1").hasVoltage ? 1 : 0) + (n.get("input2").hasVoltage ? 1 : 0) + (n.get("input3").hasVoltage ? 1 : 0) + (n.get("input4").hasVoltage ? 1 : 0) + (n.get("input5").hasVoltage ? 1 : 0) + (n.get("input6").hasVoltage ? 1 : 0) + (n.get("input7").hasVoltage ? 1 : 0) + (n.get("input8").hasVoltage ? 1 : 0)) % 2 === 1, d = e.config.get("activationLogic") === "negative" ? !u : u;
2036
- return this.getBehavior(e, t, d, i);
2037
- }
2038
- }
2039
- function Ae(a) {
2040
- return a.register(new de()).register(new le()).register(new ge()).register(new fe()).register(new ve()).register(new we()).register(new ye()), a;
2041
- }
2042
- function xe(a) {
2043
- return a.register(new Se()).register(new Ce()).register(new Ne()).register(new Be()).register(new Ie()).register(new Pe()).register(new Te()).register(new Ee()).register(new Ge()).register(new Le()), a;
2044
- }
1
+ import { $ as t, A as e, At as s, B as i, C as o, Ct as r, D as n, Dt as S, E as h, Et as B, F as v, G as d, H as l, I as E, J as m, K as c, L as G, M as p, N as C, O as N, Ot as A, P as T, Q as g, R as u, S as I, St as L, T as D, Tt as y, U as O, V as _, W as R, X as M, Y as b, Z as f, _ as w, _t as P, a as U, at as X, b as F, bt as k, c as x, ct as z, d as H, dt as Y, et as Q, f as V, ft as W, g as j, gt as q, h as J, ht as K, i as Z, it as $, j as aa, k as ta, kt as ea, l as sa, lt as ia, m as oa, mt as ra, n as na, nt as Sa, o as ha, ot as Ba, p as va, pt as da, q as la, r as Ea, rt as ma, s as ca, st as Ga, t as pa, tt as Ca, u as Na, ut as Aa, v as Ta, vt as ga, w as ua, wt as Ia, x as La, xt as Da, y as ya, yt as Oa, z as _a } from "../core-b6Q8w2sn.js";
2045
2
  export {
2046
- Me as ALL_LOGIC_FAMILIES,
2047
- de as BatteryBehavior,
2048
- Y as BatteryState,
2049
- Oe as BehaviorRegistry,
2050
- E as CIRCUIT_FILE_VERSION,
2051
- G as COMPONENT_TYPE_METADATA,
2052
- A as CameraOptions,
2053
- x as Circuit,
2054
- N as CircuitMetadata,
2055
- C as CircuitOptions,
2056
- Re as CircuitRunner,
2057
- _ as Component,
2058
- v as ComponentState,
2059
- h as ComponentType,
2060
- O as DEFAULT_LOGIC_FAMILY,
2061
- De as DirtyTracker,
2062
- ye as DoubleThrowSwitchBehavior,
2063
- ee as DoubleThrowSwitchState,
2064
- I as ENode,
2065
- We as ENodeSourceType,
2066
- m as ENodeType,
2067
- ke as EventQueue,
2068
- Se as InverterBehavior,
2069
- te as InverterState,
2070
- le as LightbulbBehavior,
2071
- q as LightbulbState,
2072
- W as Memoize,
2073
- be as MemoizeExpiring,
2074
- Ne as Nand4GateBehavior,
2075
- ie as Nand4GateState,
2076
- Be as Nand8GateBehavior,
2077
- oe as Nand8GateState,
2078
- Ce as NandGateBehavior,
2079
- ne as NandGateState,
2080
- Pe as Nor4GateBehavior,
2081
- re as Nor4GateState,
2082
- Te as Nor8GateBehavior,
2083
- ae as Nor8GateState,
2084
- Ie as NorGateBehavior,
2085
- se as NorGateState,
2086
- R as Position,
2087
- Fe as Position3D,
2088
- ge as RectangleLEDBehavior,
2089
- Q as RectangleLEDState,
2090
- fe as RelayBehavior,
2091
- Z as RelayState,
2092
- Xe as Rotation,
2093
- Je as SIMULATION_SPEED,
2094
- Ue as SimulationState,
2095
- ve as SmallLEDBehavior,
2096
- V as SmallLEDState,
2097
- ze as StateManager,
2098
- we as SwitchBehavior,
2099
- j as SwitchState,
2100
- S as TRANSITION_DEFAULTS,
2101
- w as Wire,
2102
- Ge as Xor4GateBehavior,
2103
- ue as Xor4GateState,
2104
- Le as Xor8GateBehavior,
2105
- he as Xor8GateState,
2106
- Ee as XorGateBehavior,
2107
- ce as XorGateState,
2108
- H as classifyGate,
2109
- K as computeGateDelay,
2110
- U as computeTransitionSpan,
2111
- D as findPositionBestIndex,
2112
- M as generateUUID,
2113
- Ae as registerBasicComponentsBehaviors,
2114
- xe as registerGatesComponentsBehaviors,
2115
- P as simplifyPositions
3
+ K as ALL_LOGIC_FAMILIES,
4
+ Na as AdderBehavior,
5
+ T as AdderState,
6
+ E as ArithmeticState,
7
+ ta as BatteryBehavior,
8
+ Q as BatteryState,
9
+ aa as BehaviorRegistry,
10
+ q as CIRCUIT_FILE_VERSION,
11
+ P as COMPONENT_TYPE_METADATA,
12
+ S as CameraOptions,
13
+ Ba as Circuit,
14
+ Aa as CircuitMetadata,
15
+ Y as CircuitOptions,
16
+ Z as CircuitRunner,
17
+ I as ClockBehavior,
18
+ la as ClockState,
19
+ W as Component,
20
+ Ca as ComponentState,
21
+ ga as ComponentType,
22
+ Oa as DEFAULT_LOGIC_FAMILY,
23
+ ha as DirtyTracker,
24
+ o as DoubleThrowSwitchBehavior,
25
+ m as DoubleThrowSwitchState,
26
+ ra as ENode,
27
+ k as ENodeSourceType,
28
+ Da as ENodeType,
29
+ sa as EightBitAdderBehavior,
30
+ C as EightBitAdderState,
31
+ x as EightBitOnesComplementBehavior,
32
+ p as EightBitOnesComplementState,
33
+ ca as EventQueue,
34
+ H as HalfAdderBehavior,
35
+ v as HalfAdderState,
36
+ La as InverterBehavior,
37
+ c as InverterState,
38
+ N as LightbulbBehavior,
39
+ t as LightbulbState,
40
+ ea as Memoize,
41
+ s as MemoizeExpiring,
42
+ ya as Nand4GateBehavior,
43
+ R as Nand4GateState,
44
+ Ta as Nand8GateBehavior,
45
+ O as Nand8GateState,
46
+ F as NandGateBehavior,
47
+ d as NandGateState,
48
+ j as Nor4GateBehavior,
49
+ _ as Nor4GateState,
50
+ J as Nor8GateBehavior,
51
+ i as Nor8GateState,
52
+ w as NorGateBehavior,
53
+ l as NorGateState,
54
+ Ia as Position,
55
+ A as Position3D,
56
+ n as RectangleLEDBehavior,
57
+ f as RectangleLEDState,
58
+ h as RelayBehavior,
59
+ M as RelayState,
60
+ r as Rotation,
61
+ $ as SIMULATION_SPEED,
62
+ Sa as SimulationState,
63
+ D as SmallLEDBehavior,
64
+ g as SmallLEDState,
65
+ U as StateManager,
66
+ ua as SwitchBehavior,
67
+ b as SwitchState,
68
+ X as TRANSITION_DEFAULTS,
69
+ da as Wire,
70
+ va as Xor4GateBehavior,
71
+ u as Xor4GateState,
72
+ V as Xor8GateBehavior,
73
+ G as Xor8GateState,
74
+ oa as XorGateBehavior,
75
+ _a as XorGateState,
76
+ Ga as classifyGate,
77
+ z as computeGateDelay,
78
+ ia as computeTransitionSpan,
79
+ y as findPositionBestIndex,
80
+ L as generateUUID,
81
+ e as getTransitionSpan,
82
+ pa as registerArithmeticComponentsBehaviors,
83
+ na as registerBasicComponentsBehaviors,
84
+ Ea as registerGatesComponentsBehaviors,
85
+ B as simplifyPositions,
86
+ ma as unionElectricalStates
2116
87
  };
2117
- //# sourceMappingURL=index.js.map