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.
@@ -1,5 +1,57 @@
1
- import { e as O, P as k, C as b, c as B, i as P, j as S, d as y, f as G, b as V, s as C, a as h, T as f } from "../CircuitRunner-DEb7JdNf.js";
2
- import { k as me, D as we, E as ye, n as ve, h as Se, R as Ce, m as Te, S as Ee, l as Ie, g as Ae } from "../CircuitRunner-DEb7JdNf.js";
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
+ }
3
55
  class w {
4
56
  /**
5
57
  * Unique identifier for this wire.
@@ -46,8 +98,8 @@ class w {
46
98
  * );
47
99
  * ```
48
100
  */
49
- constructor(t, e, i = []) {
50
- this.id = O(), this.node1 = t, this.node2 = e, this.intermediatePositions = i;
101
+ constructor(e, t, o = []) {
102
+ this.id = M(), this.node1 = e, this.node2 = t, this.intermediatePositions = o;
51
103
  }
52
104
  /**
53
105
  * Check if this is a straight-line wire.
@@ -88,7 +140,7 @@ class w {
88
140
  id: this.id,
89
141
  node1: this.node1,
90
142
  node2: this.node2,
91
- intermediatePositions: this.intermediatePositions.map((t) => t.toJSON())
143
+ intermediatePositions: this.intermediatePositions.map((e) => e.toJSON())
92
144
  };
93
145
  }
94
146
  /**
@@ -109,53 +161,170 @@ class w {
109
161
  * const wire = Wire.fromJSON(json);
110
162
  * ```
111
163
  */
112
- static fromJSON(t) {
113
- const e = t.intermediatePositions.map((n) => k.fromJSON(n)), i = new w(t.node1, t.node2, e);
114
- return Object.defineProperty(i, "id", {
115
- value: t.id,
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,
116
168
  writable: !1,
117
169
  enumerable: !0,
118
170
  configurable: !1
119
- }), i;
171
+ }), o;
120
172
  }
121
173
  }
122
- class v {
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 {
123
195
  /**
124
196
  * Create a new CircuitMetadata holding general information about the Circuit.
125
197
  *
126
- * @param name - Name of the circuit
198
+ * @param version - Circuit version
199
+ * @param options - Circuit options
127
200
  * @param size - Size of the circuit grid
128
201
  * @param divisions - Divisions in the circuit grid
129
202
  * @param cameraOptions - Camera Options at startup
130
203
  * @throws {TypeError} If size or divisions are not integers
131
204
  */
132
- constructor(t, e, i, n) {
133
- if (this.name = t, this.size = e, this.divisions = i, this.cameraOptions = n, !Number.isInteger(e) || !Number.isInteger(i))
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))
134
207
  throw new TypeError(
135
- `Size and divisions must be integers (got size=${e}, divisions=${i})`
208
+ `Size and divisions must be integers (got size=${o}, divisions=${i})`
136
209
  );
137
210
  }
138
211
  toJSON() {
139
212
  return {
140
- name: this.name,
213
+ version: this.version,
214
+ options: this.options.toJSON(),
141
215
  size: this.size,
142
216
  divisions: this.divisions,
143
217
  cameraOptions: this.cameraOptions.toJSON()
144
218
  };
145
219
  }
146
- static fromJSON(t) {
147
- return new v(
148
- t.name,
149
- t.size,
150
- t.divisions,
151
- b.fromJSON(t.cameraOptions)
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)
152
230
  );
153
231
  }
154
232
  toString() {
155
- return `CircuitMetadata(${this.name}, ${this.size}, ${this.divisions}, ${this.cameraOptions.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;
156
324
  }
325
+ throw new Error(`Unsupported logic family: ${a}`);
157
326
  }
158
- class _ {
327
+ class x {
159
328
  /**
160
329
  * Circuit metadata holding general information.
161
330
  * @private
@@ -180,16 +349,16 @@ class _ {
180
349
  /**
181
350
  * Create a new empty circuit.
182
351
  */
183
- constructor(t = "Untitled Circuit") {
184
- this.metadata = new v(t, 10, 10, new b()), this.components = /* @__PURE__ */ new Map(), this.enodes = /* @__PURE__ */ new Map(), this.wires = /* @__PURE__ */ new Map();
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();
185
354
  }
186
355
  get name() {
187
- return this.metadata.name;
356
+ return this.metadata.options.name;
188
357
  }
189
- set name(t) {
190
- if (typeof t != "string" || t.trim() === "")
358
+ set name(e) {
359
+ if (typeof e != "string" || e.trim() === "")
191
360
  throw new TypeError("Circuit name must be a non-empty string");
192
- this.metadata.name = t;
361
+ this.metadata.options.name = e;
193
362
  }
194
363
  /**
195
364
  * Add a new component to the circuit.
@@ -218,27 +387,43 @@ class _ {
218
387
  * console.log(lightbulb.position.x); // 10
219
388
  * ```
220
389
  */
221
- addComponent(t, e, i, n) {
222
- const s = B(t), o = new P(t, e, i, []);
223
- n && (o.config = new Map(n));
224
- const a = [];
225
- for (const [r, d] of s.pins) {
226
- const g = new S(
227
- y.Pin,
228
- o.id,
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,
229
401
  r,
230
402
  void 0,
231
- // Pin position derived from component,
232
- d
403
+ // Pin position derived from component
404
+ u.sourceType,
405
+ u.subtype
233
406
  );
234
- this.enodes.set(g.id, g), a.push(g.id);
407
+ this.enodes.set(d.id, d), c.push(d.id);
235
408
  }
236
- return Object.defineProperty(o, "pins", {
237
- value: a,
409
+ return Object.defineProperty(s, "pins", {
410
+ value: c,
238
411
  writable: !1,
239
412
  enumerable: !0,
240
413
  configurable: !1
241
- }), this.components.set(o.id, o), o;
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));
242
427
  }
243
428
  /**
244
429
  * Remove a component from the circuit.
@@ -257,24 +442,24 @@ class _ {
257
442
  * // Component, its pins, and connected wires are all removed
258
443
  * ```
259
444
  */
260
- removeComponent(t) {
261
- const e = this.components.get(t);
262
- if (!e)
263
- throw new Error(`Component ${t} does not exist`);
264
- const i = [], n = [];
265
- for (const s of e.pins) {
266
- const o = this.enodes.get(s);
267
- if (o) {
268
- const a = Array.from(o.wires);
269
- for (const r of a)
270
- this.removeWire(r), i.push(r);
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);
271
456
  }
272
- this.enodes.delete(s), n.push(s);
457
+ this.enodes.delete(n), i.push(n);
273
458
  }
274
- return this.components.delete(t), { deletedWires: i, deletedENodes: n };
459
+ return this.components.delete(e), { deletedWires: o, deletedENodes: i };
275
460
  }
276
- hasComponent(t) {
277
- return this.components.has(t);
461
+ hasComponent(e) {
462
+ return this.components.has(e);
278
463
  }
279
464
  /**
280
465
  * Get a component by ID.
@@ -290,8 +475,8 @@ class _ {
290
475
  * }
291
476
  * ```
292
477
  */
293
- getComponent(t) {
294
- return this.components.get(t);
478
+ getComponent(e) {
479
+ return this.components.get(e);
295
480
  }
296
481
  /**
297
482
  * Get all components in the circuit.
@@ -313,16 +498,16 @@ class _ {
313
498
  getAllComponents() {
314
499
  return Array.from(this.components.values());
315
500
  }
316
- getAllComponentsByType(t) {
317
- const e = [];
318
- for (const i of this.components.values())
319
- i.type === t && e.push(i);
320
- return e;
501
+ getAllComponentsByType(e) {
502
+ const t = [];
503
+ for (const o of this.components.values())
504
+ o.type === e && t.push(o);
505
+ return t;
321
506
  }
322
- getFirstComponentOfType(t) {
323
- for (const e of this.components.values())
324
- if (e.type === t)
325
- return e;
507
+ getFirstComponentOfType(e) {
508
+ for (const t of this.components.values())
509
+ if (t.type === e)
510
+ return t;
326
511
  }
327
512
  /**
328
513
  * Get an electrical node by ID.
@@ -346,8 +531,8 @@ class _ {
346
531
  * console.log(enode.type); // ENodeType.Pin
347
532
  * ```
348
533
  */
349
- getENode(t) {
350
- return this.enodes.get(t);
534
+ getENode(e) {
535
+ return this.enodes.get(e);
351
536
  }
352
537
  /**
353
538
  * Get all electrical nodes in the circuit.
@@ -380,15 +565,15 @@ class _ {
380
565
  * @param sourceType - Optional source type (voltage/current)
381
566
  * @returns The created ENode
382
567
  */
383
- addBranchingPoint(t, e) {
384
- const i = new S(
385
- y.BranchingPoint,
568
+ addBranchingPoint(e, t) {
569
+ const o = new I(
570
+ m.BranchingPoint,
386
571
  void 0,
387
572
  void 0,
388
- t,
389
- e
573
+ e,
574
+ t
390
575
  );
391
- return this.enodes.set(i.id, i), i;
576
+ return this.enodes.set(o.id, o), o;
392
577
  }
393
578
  /**
394
579
  * Remove a branching point electrical node from the circuit.
@@ -398,29 +583,29 @@ class _ {
398
583
  * @param id - Branching point ENode UUID
399
584
  * @throws {Error} If ENode does not exist or is not a branching point
400
585
  */
401
- removeBranchingPoint(t) {
402
- const e = this.enodes.get(t);
403
- if (!e)
404
- throw new Error(`Enode ${t} does not exist`);
405
- if (e.type !== y.BranchingPoint)
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)
406
591
  throw new Error(
407
- `Enode ${t} is not a branching point, it must be removed with its component.`
592
+ `Enode ${e} is not a branching point, it must be removed with its component.`
408
593
  );
409
- const i = {}, n = this.getWiresByNode(t);
410
- if (n.length === 1 || n.length > 2) {
411
- const s = [];
412
- for (const o of n)
413
- this.removeWire(o.id), s.push(o.id);
414
- Object.assign(i, { deletedWires: s });
415
- } else if (n.length === 2) {
416
- const s = n[0], o = n[1], a = s.node1 === t ? s.node2 : s.node1, r = o.node1 === t ? o.node2 : o.node1, d = [];
417
- a === s.node1 ? d.push(...s.intermediatePositions) : a === s.node2 && d.push(...[...s.intermediatePositions].reverse()), d.push(e.getPosition(this)), r === o.node1 ? d.push(...[...o.intermediatePositions].reverse()) : r === o.node2 && d.push(...o.intermediatePositions), this.removeWire(s.id), this.removeWire(o.id);
418
- const g = this.addWire(a, r, d);
419
- if (g instanceof Error)
420
- throw new Error(`Failed to merge wires at branching point ${t}: ${g.message}`);
421
- Object.assign(i, { mergedWires: [s.id, o.id] }), Object.assign(i, { newWire: g });
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 });
422
607
  }
423
- return this.enodes.delete(t), i;
608
+ return this.enodes.delete(e), o;
424
609
  }
425
610
  /**
426
611
  * Add a wire connecting two electrical nodes.
@@ -444,16 +629,16 @@ class _ {
444
629
  * }
445
630
  * ```
446
631
  */
447
- addWire(t, e, i) {
448
- if (t === e)
632
+ addWire(e, t, o) {
633
+ if (e === t)
449
634
  return new Error("Cannot create wire connecting node to itself");
450
- const n = this.enodes.get(t), s = this.enodes.get(e);
451
- if (!n || !s)
635
+ const i = this.enodes.get(e), n = this.enodes.get(t);
636
+ if (!i || !n)
452
637
  return new Error("Wire requires at least one existing ENode");
453
- if (this.hasWireBetween(t, e))
638
+ if (this.hasWireBetween(e, t))
454
639
  return new Error("Duplicate wire between same nodes");
455
- const o = new w(t, e, i || []);
456
- return this.wires.set(o.id, o), n.wires.add(o.id), s.wires.add(o.id), o;
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;
457
642
  }
458
643
  /**
459
644
  * Remove a wire from the circuit.
@@ -467,12 +652,12 @@ class _ {
467
652
  * // Wire is removed
468
653
  * ```
469
654
  */
470
- removeWire(t) {
471
- const e = this.wires.get(t);
472
- if (!e)
473
- throw new Error(`Wire ${t} does not exist`);
474
- const i = this.enodes.get(e.node1), n = this.enodes.get(e.node2);
475
- i && i.wires.delete(t), n && n.wires.delete(t), this.wires.delete(t);
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);
476
661
  }
477
662
  /**
478
663
  * Split a wire in the circuit.
@@ -503,48 +688,48 @@ class _ {
503
688
  * @returns Object containing the new branching point and an array of the two new wires
504
689
  * @throws Error if wireId not found
505
690
  */
506
- splitWire(t, e, i = null) {
507
- const n = this.wires.get(t);
508
- if (!n)
509
- throw new Error(`Wire ${t} does not exist`);
510
- const s = this.enodes.get(n.node1), o = this.enodes.get(n.node2);
511
- if (!s || !o)
512
- throw new Error(`Wire ${t} is connected to non-existent ENodes`);
513
- const a = [
514
- s.getPosition(this),
515
- ...n.intermediatePositions,
516
- o.getPosition(this)
517
- ], r = G(a, e), d = a.slice(1, r), g = a.slice(r, a.length - 1);
518
- this.wires.delete(t), s.wires.delete(t), o.wires.delete(t);
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);
519
704
  let l;
520
- if (i)
521
- if (this.enodes.get(i))
522
- l = this.enodes.get(i);
705
+ if (o)
706
+ if (this.enodes.get(o))
707
+ l = this.enodes.get(o);
523
708
  else
524
- throw new Error(`Target ENode ${i} does not exist`);
709
+ throw new Error(`Target ENode ${o} does not exist`);
525
710
  else
526
- l = this.addBranchingPoint(e);
527
- const m = [];
528
- if ((!l.component || s.component !== l.component) && !this.hasWireBetween(s.id, l.id)) {
529
- const u = this.addWire(s.id, l.id, d);
530
- u instanceof w ? (this.simplifyWireIntermediatePositions(u.id), m.push(u)) : console.warn(`Failure to create wire at split : ${u.message}`);
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}`);
531
716
  }
532
- if ((!l.component || o.component !== l.component) && !this.hasWireBetween(o.id, l.id)) {
533
- const u = this.addWire(l.id, o.id, g);
534
- u instanceof w ? (this.simplifyWireIntermediatePositions(u.id), m.push(u)) : console.warn(`Failure to create wire at split : ${u.message}`);
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}`);
535
720
  }
536
721
  return {
537
722
  branchingPoint: l,
538
- wires: m
723
+ wires: B
539
724
  };
540
725
  }
541
- getWireBetweenNodes(t, e) {
542
- const i = this.enodes.get(t);
543
- if (i)
544
- for (const n of i.wires) {
545
- const s = this.wires.get(n);
546
- if (s && (s.node2 === e || s.node1 === e))
547
- return s;
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;
548
733
  }
549
734
  }
550
735
  /**
@@ -553,8 +738,8 @@ class _ {
553
738
  * @param id - Wire UUID
554
739
  * @returns The Wire or undefined if not found
555
740
  */
556
- getWire(t) {
557
- return this.wires.get(t);
741
+ getWire(e) {
742
+ return this.wires.get(e);
558
743
  }
559
744
  /**
560
745
  * Get all wires in the circuit.
@@ -572,16 +757,16 @@ class _ {
572
757
  * @param nodeId - ENode UUID
573
758
  * @returns Array of connected Wires, or empty array if node not found
574
759
  */
575
- getWiresByNode(t) {
576
- const e = this.enodes.get(t);
577
- if (!e)
760
+ getWiresByNode(e) {
761
+ const t = this.enodes.get(e);
762
+ if (!t)
578
763
  return [];
579
- const i = [];
580
- for (const n of e.wires) {
581
- const s = this.wires.get(n);
582
- s && i.push(s);
764
+ const o = [];
765
+ for (const i of t.wires) {
766
+ const n = this.wires.get(i);
767
+ n && o.push(n);
583
768
  }
584
- return i;
769
+ return o;
585
770
  }
586
771
  /**
587
772
  * Get all wires connected to a component, e.g to any pin enode of the component.
@@ -589,14 +774,14 @@ class _ {
589
774
  * @param componentId - Component UUID
590
775
  * @returns Array of connected Wires, or empty array if component not found
591
776
  */
592
- getWiresByComponent(t) {
593
- const e = this.components.get(t);
594
- if (!e)
777
+ getWiresByComponent(e) {
778
+ const t = this.components.get(e);
779
+ if (!t)
595
780
  return [];
596
- const i = [];
597
- for (const n of e.pins)
598
- i.push(...this.getWiresByNode(n));
599
- return i;
781
+ const o = [];
782
+ for (const i of t.pins)
783
+ o.push(...this.getWiresByNode(i));
784
+ return o;
600
785
  }
601
786
  /**
602
787
  * Get both ENodes connected by a wire.
@@ -604,13 +789,13 @@ class _ {
604
789
  * @param wireId - Wire UUID
605
790
  * @returns Tuple [node1, node2] or undefined if wire not found
606
791
  */
607
- getNodesByWire(t) {
608
- const e = this.wires.get(t);
609
- if (!e)
792
+ getNodesByWire(e) {
793
+ const t = this.wires.get(e);
794
+ if (!t)
610
795
  return;
611
- const i = this.enodes.get(e.node1), n = this.enodes.get(e.node2);
612
- if (!(!i || !n))
613
- return [i, n];
796
+ const o = this.enodes.get(t.node1), i = this.enodes.get(t.node2);
797
+ if (!(!o || !i))
798
+ return [o, i];
614
799
  }
615
800
  /**
616
801
  * Check if a wire already exists between two nodes.
@@ -621,13 +806,13 @@ class _ {
621
806
  * @param node2 - Second ENode UUID
622
807
  * @returns true if wire exists, false otherwise
623
808
  */
624
- hasWireBetween(t, e) {
625
- const i = this.enodes.get(t);
626
- if (!i)
809
+ hasWireBetween(e, t) {
810
+ const o = this.enodes.get(e);
811
+ if (!o)
627
812
  return !1;
628
- for (const n of i.wires) {
629
- const s = this.wires.get(n);
630
- if (s && (s.node2 === e || s.node1 === e))
813
+ for (const i of o.wires) {
814
+ const n = this.wires.get(i);
815
+ if (n && (n.node2 === t || n.node1 === t))
631
816
  return !0;
632
817
  }
633
818
  return !1;
@@ -638,28 +823,28 @@ class _ {
638
823
  * @param pinIds - Set of pins UUIDs
639
824
  * @returns Set of components UUIDs
640
825
  */
641
- getComponentsOfPins(t) {
642
- const e = /* @__PURE__ */ new Set();
643
- for (const i of t) {
644
- const n = this.enodes.get(i);
645
- n?.component && e.add(n.component);
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);
646
831
  }
647
- return e;
832
+ return t;
648
833
  }
649
834
  /**
650
835
  * Get a component's pin ENode by its label.
651
836
  * @param component
652
837
  * @param pinLabel
653
838
  */
654
- getComponentPinByLabel(t, e) {
655
- let i = 0;
656
- const n = V[t.type], s = Array.from(n.pins.keys());
657
- for (const o of t.pins) {
658
- const a = this.enodes.get(o), r = s[i];
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];
659
844
  if (r) {
660
- if (a && r === e)
661
- return a;
662
- i++;
845
+ if (c && r === t)
846
+ return c;
847
+ o++;
663
848
  }
664
849
  }
665
850
  }
@@ -673,23 +858,23 @@ class _ {
673
858
  * @returns The updated Wire
674
859
  * @throws Error if wireId not found
675
860
  */
676
- updateWireIntermediatePositions(t, e, i = !1) {
677
- const n = this.wires.get(t);
678
- if (!n)
679
- throw new Error(`Wire ${t} does not exist`);
680
- if (i) {
681
- const s = [
682
- this.enodes.get(n.node1).getPosition(this),
683
- ...e,
684
- this.enodes.get(n.node2).getPosition(this)
685
- ], o = C(s, 10);
686
- n.intermediatePositions = o.slice(
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(
687
872
  1,
688
- o.length - 1
873
+ s.length - 1
689
874
  );
690
875
  } else
691
- n.intermediatePositions = e;
692
- return n;
876
+ i.intermediatePositions = t;
877
+ return i;
693
878
  }
694
879
  /**
695
880
  * Simplify intermediate positions of a wire.
@@ -698,19 +883,19 @@ class _ {
698
883
  * @returns The updated Wire
699
884
  * @throws Error if wireId not found
700
885
  */
701
- simplifyWireIntermediatePositions(t) {
702
- const e = this.wires.get(t);
703
- if (!e)
704
- throw new Error(`Wire ${t} does not exist`);
705
- const i = [
706
- this.enodes.get(e.node1).getPosition(this),
707
- ...e.intermediatePositions,
708
- this.enodes.get(e.node2).getPosition(this)
709
- ], n = C(i, 5);
710
- return e.intermediatePositions = n.slice(
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(
711
896
  1,
712
- n.length - 1
713
- ), e.intermediatePositions = C(e.intermediatePositions), e;
897
+ i.length - 1
898
+ ), t.intermediatePositions = P(t.intermediatePositions), t;
714
899
  }
715
900
  /**
716
901
  * Update the source type of an ENode (branching point or component pin).
@@ -718,11 +903,11 @@ class _ {
718
903
  * @param sourceType - New source type (null to clear)
719
904
  * @throws Error if enodeId not found
720
905
  */
721
- updateENodeSourceType(t, e) {
722
- const i = this.enodes.get(t);
723
- if (!i)
724
- throw new Error(`ENode ${t} does not exist`);
725
- i.source = e || void 0;
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;
726
911
  }
727
912
  /**
728
913
  * iterate through all components, enodes and wires positions to get the size that allows to enclose all elements.
@@ -730,19 +915,19 @@ class _ {
730
915
  * @returns size that allows to enclose all elements plus margin
731
916
  * @todo if calls to this method at each build operation ends causes slowness see to optimize by restricting checked elements
732
917
  */
733
- getEnclosingSize(t = 0) {
734
- let e = 0;
735
- for (const i of this.components.values())
736
- e = Math.max(e, Math.abs(i.position.x), Math.abs(i.position.y));
737
- for (const i of this.enodes.values()) {
738
- if (i.type === y.Pin) continue;
739
- const n = i.position;
740
- n && (e = Math.max(e, Math.abs(n.x), Math.abs(n.y)));
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)));
741
926
  }
742
- for (const i of this.wires.values())
743
- for (const n of i.intermediatePositions)
744
- e = Math.max(e, Math.abs(n.x), Math.abs(n.y));
745
- return Math.ceil(e * 2 + Math.max(t, 0));
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));
746
931
  }
747
932
  /**
748
933
  * Serialize circuit to JSON.
@@ -758,9 +943,9 @@ class _ {
758
943
  toJSON() {
759
944
  return {
760
945
  metadata: this.metadata.toJSON(),
761
- components: this.getAllComponents().map((t) => t.toJSON()),
762
- enodes: this.getAllENodes().map((t) => t.toJSON()),
763
- wires: this.getAllWires().map((t) => t.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())
764
949
  };
765
950
  }
766
951
  /**
@@ -777,34 +962,250 @@ class _ {
777
962
  * const circuit = Circuit.fromJSON(json);
778
963
  * ```
779
964
  */
780
- static fromJSON(t) {
781
- const e = new _();
782
- e.metadata = v.fromJSON(t.metadata);
783
- for (const i of t.components) {
784
- const n = P.fromJSON(
785
- i
786
- );
787
- e.components.set(n.id, n);
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);
788
971
  }
789
- for (const i of t.enodes) {
790
- const n = S.fromJSON(
791
- i
792
- );
793
- e.enodes.set(n.id, n);
972
+ for (const i of e.enodes) {
973
+ const n = I.fromJSON(i);
974
+ o.enodes.set(n.id, n);
794
975
  }
795
- if (t.wires)
796
- for (const i of t.wires) {
797
- const n = w.fromJSON(
798
- i
799
- );
800
- e.wires.set(n.id, n);
801
- const s = e.enodes.get(n.node1), o = e.enodes.get(n.node2);
802
- s && s.wires.add(n.id), o && o.wires.add(n.id);
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);
803
982
  }
804
- return e;
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);
805
1196
  }
806
1197
  }
807
- class ge {
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 {
808
1209
  behaviors;
809
1210
  /**
810
1211
  * Create a new empty behavior registry.
@@ -820,12 +1221,12 @@ class ge {
820
1221
  * @throws TypeError if behavior is null/undefined or componentType is empty
821
1222
  * @returns The registry instance for chaining
822
1223
  */
823
- register(t) {
824
- if (!t)
1224
+ register(e) {
1225
+ if (!e)
825
1226
  throw new TypeError("Behavior cannot be null or undefined");
826
- if (!t.componentType || t.componentType.trim() === "")
1227
+ if (!e.componentType || e.componentType.trim() === "")
827
1228
  throw new TypeError("Behavior componentType cannot be empty");
828
- return this.behaviors.set(t.componentType, t), this;
1229
+ return this.behaviors.set(e.componentType, e), this;
829
1230
  }
830
1231
  /**
831
1232
  * Register multiple behaviors at once.
@@ -833,8 +1234,8 @@ class ge {
833
1234
  *
834
1235
  * @param behaviors - Array of behaviors to register
835
1236
  */
836
- registerAll(t) {
837
- t.forEach((e) => this.register(e));
1237
+ registerAll(e) {
1238
+ e.forEach((t) => this.register(t));
838
1239
  }
839
1240
  /**
840
1241
  * Get the behavior for a component type.
@@ -842,8 +1243,8 @@ class ge {
842
1243
  * @param componentType - Type identifier (e.g., "battery", "led")
843
1244
  * @returns The registered behavior, or undefined if not found
844
1245
  */
845
- get(t) {
846
- return this.behaviors.get(t);
1246
+ get(e) {
1247
+ return this.behaviors.get(e);
847
1248
  }
848
1249
  /**
849
1250
  * Check if a behavior is registered for a component type.
@@ -851,8 +1252,8 @@ class ge {
851
1252
  * @param componentType - Type identifier to check
852
1253
  * @returns True if behavior is registered
853
1254
  */
854
- has(t) {
855
- return this.behaviors.has(t);
1255
+ has(e) {
1256
+ return this.behaviors.has(e);
856
1257
  }
857
1258
  /**
858
1259
  * Unregister a behavior for a component type.
@@ -860,8 +1261,8 @@ class ge {
860
1261
  * @param componentType - Type identifier to unregister
861
1262
  * @returns True if behavior was found and removed
862
1263
  */
863
- unregister(t) {
864
- return this.behaviors.delete(t);
1264
+ unregister(e) {
1265
+ return this.behaviors.delete(e);
865
1266
  }
866
1267
  /**
867
1268
  * Clear all registered behaviors.
@@ -886,318 +1287,214 @@ class ge {
886
1287
  return this.behaviors.size;
887
1288
  }
888
1289
  }
889
- class p {
1290
+ class y {
890
1291
  /**
891
- * Component UUID this state belongs to.
892
- * @readonly
1292
+ * Component type this behavior handles (e.g., "battery", "led", "switch").
1293
+ * Used as the key in BehaviorRegistry.
893
1294
  */
894
- componentId;
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
+ }
895
1314
  /**
896
- * Current operational state (varies by component type).
897
- * Examples: "on", "off", "open", "closed", "activating", "active"
1315
+ * Default: nothing happens
1316
+ * @param _component
1317
+ * @param componentState
1318
+ * @param _nodeStates
1319
+ * @param _targetTick
898
1320
  */
899
- state;
1321
+ onPinsChange(e, t, o, i) {
1322
+ return {
1323
+ componentState: t,
1324
+ hasChanged: !1,
1325
+ shouldCancelPending: !1,
1326
+ scheduledEvents: []
1327
+ };
1328
+ }
900
1329
  /**
901
- * Tick when this state started.
1330
+ * Default: no conductivity between pins
1331
+ * @param _component
1332
+ * @param _state
1333
+ * @param _conductivityType
1334
+ * @param _pinId
1335
+ * @param _otherPinId
902
1336
  */
903
- startTick;
904
- /**
905
- * Create a new component state.
906
- *
907
- * @param componentId - UUID of the component
908
- * @param initialState - Initial operational state
909
- */
910
- constructor(t, e) {
911
- this.componentId = t, this.state = e, this.startTick = 0;
912
- }
913
- hasSameComponent(t) {
914
- return this.componentId === t.componentId;
915
- }
916
- }
917
- class x extends p {
918
- /**
919
- * Create a new battery state.
920
- *
921
- * @param componentId - UUID of the battery component
922
- */
923
- constructor(t) {
924
- super(t, "on");
925
- }
926
- }
927
- class W {
928
- componentType = h.Battery;
929
- /**
930
- * Create initial state for a battery.
931
- *
932
- * @param component - The Battery component
933
- * @returns Battery Initial state (always active and delivering voltage)
934
- */
935
- createInitialState(t) {
936
- if (t.type !== h.Battery)
937
- throw new Error(`Invalid component type for BatteryBehavior: ${t.type}`);
938
- return new x(t.id);
939
- }
940
- allowConductivity(t, e, i, n, s) {
1337
+ allowConductivity(e, t, o, i, n) {
941
1338
  return !1;
942
1339
  }
943
- /**
944
- * Batteries are always on, and their pins are locked so this is more of a decorative function
945
- * @param component
946
- * @param componentState
947
- * @param nodeStates
948
- * @param _targetTick
949
- */
950
- onPinsChange(t, e, i, n) {
951
- const s = /* @__PURE__ */ new Map();
952
- for (const o in t.pins)
953
- s.set(t.getPinLabel(o), i.get(o));
1340
+ onUserCommand(e, t, o) {
954
1341
  return {
955
- componentState: e,
1342
+ componentState: t,
956
1343
  hasChanged: !1,
1344
+ shouldCancelPending: !1,
957
1345
  scheduledEvents: []
958
1346
  };
959
1347
  }
960
- onUserCommand(t, e, i) {
1348
+ onEventFiring(e, t, o) {
961
1349
  return {
962
- componentState: e,
963
- hasChanged: !1,
964
- scheduledEvents: []
965
- };
966
- }
967
- onEventFiring(t, e, i) {
968
- return {
969
- componentState: e,
1350
+ componentState: t,
970
1351
  hasChanged: !1,
1352
+ shouldCancelPending: !1,
971
1353
  scheduledEvents: []
972
1354
  };
973
1355
  }
974
1356
  }
975
- class $ extends p {
976
- /**
977
- * Create a new Lightbulb state.
978
- *
979
- * @param componentId - UUID of the Lightbulb component
980
- * @param initialState - Initial operational state (default: "off")
981
- */
982
- constructor(t, e = "off") {
983
- super(t, e);
984
- }
985
- /**
986
- * Check if Lightbulb is in lit state (on or going_on)
987
- */
988
- get isLit() {
989
- return this.state === "on" || this.state === "goingOn";
1357
+ class de extends y {
1358
+ constructor() {
1359
+ super(h.Battery);
990
1360
  }
991
- }
992
- class M {
993
- componentType = h.Lightbulb;
994
1361
  /**
995
- * Create initial state for a lightbulb.
1362
+ * Create initial state for a battery.
996
1363
  *
997
- * @param component - The lightbulb component
998
- * @returns lightbulbInitial state (always active and delivering voltage)
1364
+ * @param component - The Battery component
1365
+ * @returns Battery Initial state (always active and delivering voltage)
999
1366
  */
1000
- createInitialState(t) {
1001
- if (t.type !== h.Lightbulb)
1002
- throw new Error(`Invalid component type for lightbulbBehavior: ${t.type}`);
1003
- return new $(t.id);
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);
1004
1371
  }
1005
- allowConductivity(t, e, i, n, s) {
1006
- return !0;
1007
- }
1008
- /**
1009
- * @param component
1010
- * @param state
1011
- * @param nodeStates
1012
- * @param targetTick
1013
- */
1014
- onPinsChange(t, e, i, n) {
1015
- const s = /* @__PURE__ */ new Map();
1016
- for (const d of t.pins)
1017
- s.set(t.getPinLabel(d), i.get(d));
1018
- let o = s.get("pin1").hasVoltage && s.get("pin1").hasCurrent || s.get("pin2").hasVoltage && s.get("pin2").hasCurrent || s.get("pin1").hasVoltage && s.get("pin2").hasCurrent || s.get("pin2").hasVoltage && s.get("pin1").hasCurrent, a = !1;
1019
- const r = [];
1020
- return o ? (e.state === "off" || e.state === "goingOff") && (a = !0, e.state = "goingOn", e.startTick = n, r.push({
1021
- targetId: t.id,
1022
- scheduledAtTick: n,
1023
- readyAtTick: n + 1,
1024
- // TODO handle component config later
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 ?
1025
1382
  type: "GoingOnEnd",
1026
1383
  parameters: void 0
1027
- }), e.state = "goingOn") : (e.state === "on" || e.state === "goingOn") && (a = !0, e.state = "goingOff", e.startTick = n, r.push({
1028
- targetId: t.id,
1029
- scheduledAtTick: n,
1030
- readyAtTick: n + 1,
1031
- // TODO handle component config later
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 ?
1032
1389
  type: "GoingOffEnd",
1033
1390
  parameters: void 0
1034
- }), e.state = "goingOff"), {
1035
- componentState: e,
1036
- hasChanged: a,
1037
- scheduledEvents: r
1391
+ }), t.state = "goingOff"), {
1392
+ componentState: t,
1393
+ hasChanged: n,
1394
+ shouldCancelPending: !1,
1395
+ scheduledEvents: s
1038
1396
  };
1039
1397
  }
1040
- onUserCommand(t, e, i) {
1041
- return {
1042
- componentState: e,
1043
- hasChanged: !1,
1044
- scheduledEvents: []
1045
- };
1398
+ allowConductivity(e, t, o, i, n) {
1399
+ return !0;
1046
1400
  }
1047
- onEventFiring(t, e, i) {
1048
- let n = !1;
1049
- return i.type === "GoingOffEnd" ? e.state !== "off" && (n = !0, e.startTick = i.readyAtTick, e.state = "off") : i.type === "GoingOnEnd" && e.state !== "on" && (n = !0, e.startTick = i.readyAtTick, e.state = "on"), {
1050
- componentState: e,
1051
- hasChanged: n,
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,
1052
1407
  scheduledEvents: []
1053
1408
  };
1054
1409
  }
1055
1410
  }
1056
- class L extends p {
1057
- /**
1058
- * Create a new SmallLED state.
1059
- *
1060
- * @param componentId - UUID of the LED component
1061
- * @param initialState - Initial operational state (default: "off")
1062
- */
1063
- constructor(t, e = "off") {
1064
- super(t, e);
1065
- }
1066
- /**
1067
- * Check if LED is in lit state (on or going_on)
1068
- */
1069
- get isLit() {
1070
- return this.state === "on" || this.state === "goingOn";
1071
- }
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;
1072
1416
  }
1073
- class N {
1074
- componentType = h.SmallLED;
1417
+ class le extends L {
1418
+ constructor() {
1419
+ super(h.Lightbulb);
1420
+ }
1075
1421
  /**
1076
- * Create initial state for a smallLED.
1422
+ * Create initial state for a lightbulb.
1077
1423
  *
1078
- * @param component - The smallLED component
1079
- * @returns LED Initial state (always active and delivering voltage)
1424
+ * @param component - The lightbulb component
1425
+ * @returns lightbulbInitial state (always active and delivering voltage)
1080
1426
  */
1081
- createInitialState(t) {
1082
- if (t.type !== h.SmallLED)
1083
- throw new Error(`Invalid component type for SmallLEDBehavior: ${t.type}`);
1084
- return new L(t.id);
1085
- }
1086
- allowConductivity(t, e, i, n, s) {
1087
- return !0;
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);
1088
1431
  }
1089
1432
  /**
1090
- * only symmetrical behavior of LEDS is handled for now
1091
1433
  * @param component
1092
1434
  * @param state
1093
1435
  * @param nodeStates
1094
1436
  * @param targetTick
1095
1437
  */
1096
- onPinsChange(t, e, i, n) {
1097
- const s = /* @__PURE__ */ new Map();
1098
- for (const d of t.pins)
1099
- s.set(t.getPinLabel(d), i.get(d));
1100
- let o = s.get("anode").hasVoltage && s.get("anode").hasCurrent || s.get("cathode").hasVoltage && s.get("cathode").hasCurrent || s.get("anode").hasVoltage && s.get("cathode").hasCurrent || s.get("cathode").hasVoltage && s.get("anode").hasCurrent, a = !1;
1101
- const r = [];
1102
- return o ? (e.state === "off" || e.state === "goingOff") && (a = !0, e.state = "goingOn", e.startTick = n, r.push({
1103
- targetId: t.id,
1104
- scheduledAtTick: n,
1105
- readyAtTick: n + 1,
1106
- // TODO handle component config later
1107
- type: "GoingOnEnd",
1108
- parameters: void 0
1109
- })) : (e.state === "on" || e.state === "goingOn") && (a = !0, e.state = "goingOff", e.startTick = n, r.push({
1110
- targetId: t.id,
1111
- scheduledAtTick: n,
1112
- readyAtTick: n + 1,
1113
- // TODO handle component config later
1114
- type: "GoingOffEnd",
1115
- parameters: void 0
1116
- })), {
1117
- componentState: e,
1118
- hasChanged: a,
1119
- scheduledEvents: r
1120
- };
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);
1121
1442
  }
1122
- onUserCommand(t, e, i) {
1123
- return {
1124
- componentState: e,
1125
- hasChanged: !1,
1126
- scheduledEvents: []
1127
- };
1128
- }
1129
- onEventFiring(t, e, i) {
1130
- let n = !1;
1131
- return i.type === "GoingOffEnd" ? e.state !== "off" && (n = !0, e.startTick = i.readyAtTick, e.state = "off") : i.type === "GoingOnEnd" && e.state !== "on" && (n = !0, e.startTick = i.readyAtTick, e.state = "on"), {
1132
- componentState: e,
1133
- hasChanged: n,
1134
- scheduledEvents: []
1135
- };
1136
- }
1137
- }
1138
- class R extends L {
1139
1443
  }
1140
- class F extends N {
1141
- componentType = h.RectangleLED;
1444
+ class ge extends L {
1445
+ constructor() {
1446
+ super(h.RectangleLED);
1447
+ }
1142
1448
  /**
1143
1449
  * Create initial state for a RectangleLED.
1144
1450
  *
1145
1451
  * @param component - The smallLED component
1146
1452
  * @returns LED Initial state (always active and delivering voltage)
1147
1453
  */
1148
- createInitialState(t) {
1149
- if (t.type !== h.RectangleLED)
1150
- throw new Error(`Invalid component type for RectangleLEDBehavior: ${t.type}`);
1151
- return new R(t.id);
1152
- }
1153
- }
1154
- class D extends p {
1155
- /**
1156
- * Create a new Relay state.
1157
- *
1158
- * @param componentId - UUID of the Relay component
1159
- * @param initialState - Initial operational state (default: "open")
1160
- */
1161
- constructor(t, e = "open") {
1162
- super(t, e);
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);
1163
1458
  }
1164
1459
  /**
1165
- * Check if relay is in opening or closing state
1166
- */
1167
- get isInTransition() {
1168
- return this.state === "closing" || this.state === "opening";
1169
- }
1170
- /**
1171
- * Check if relay is in closed or closing state
1460
+ * only symmetrical behavior of LEDS is handled for now
1461
+ * @param component
1462
+ * @param state
1463
+ * @param nodeStates
1464
+ * @param targetTick
1172
1465
  */
1173
- get isClosed() {
1174
- return this.state === "closed" || this.state === "closing";
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);
1175
1470
  }
1176
1471
  }
1177
- function J(c) {
1178
- const t = parseInt(c.get("transitionSpan") || "", 10);
1179
- return isNaN(t) || t < 1 ? f.TRANSITION_SPAN_TICKS : t;
1472
+ function pe(a) {
1473
+ const e = parseInt(a.get("transitionSpan") || "", 10);
1474
+ return isNaN(e) || e < 1 ? S.TRANSITION_SPAN_TICKS : e;
1180
1475
  }
1181
- class U {
1182
- componentType = h.Relay;
1476
+ class fe extends y {
1477
+ constructor() {
1478
+ super(h.Relay);
1479
+ }
1183
1480
  /**
1184
1481
  * Create initial state for a relay.
1185
1482
  *
1186
1483
  * @param component - The Relay component
1187
1484
  * @returns Relay Initial state (open by default)
1188
1485
  */
1189
- createInitialState(t) {
1190
- if (t.type !== h.Relay)
1191
- throw new Error(`Invalid component type for RelayBehavior: ${t.type}`);
1192
- const e = t.config.get("activationLogic") === "negative" ? "closed" : "open";
1193
- return new D(t.id, e);
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);
1194
1491
  }
1195
- allowConductivity(t, e, i, n, s) {
1196
- if (n === s) return !0;
1197
- const o = t.getPinLabel(n), a = t.getPinLabel(s);
1198
- if (!o || !a) return !1;
1199
- const r = [o, a];
1200
- return r.includes("cmd_in") && r.includes("cmd_out") ? !0 : r.includes("power_in") && r.includes("power_out") ? e.state === "closed" || e.state === "opening" : !1;
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;
1201
1498
  }
1202
1499
  /**
1203
1500
  * Relay cmd pins need to have voltage and current so that relay contactor stays closed
@@ -1206,797 +1503,615 @@ class U {
1206
1503
  * @param nodeStates
1207
1504
  * @param targetTick
1208
1505
  */
1209
- onPinsChange(t, e, i, n) {
1210
- const s = /* @__PURE__ */ new Map();
1211
- for (const l of t.pins)
1212
- s.set(t.getPinLabel(l), i.get(l));
1213
- const o = s.get("cmd_in").hasVoltage && s.get("cmd_in").hasCurrent || s.get("cmd_out").hasVoltage && s.get("cmd_out").hasCurrent || s.get("cmd_in").hasVoltage && s.get("cmd_out").hasCurrent || s.get("cmd_out").hasVoltage && s.get("cmd_in").hasCurrent, a = t.config.get("activationLogic") === "negative" ? !o : o;
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;
1214
1508
  let r = !1;
1215
- const d = [], g = J(t.config);
1216
- return a ? (e.state === "open" || e.state === "opening") && (r = !0, e.state = "closing", e.startTick = n, d.push({
1217
- targetId: t.id,
1218
- scheduledAtTick: n,
1219
- readyAtTick: n + g,
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,
1220
1514
  type: "ClosingEnd",
1221
1515
  parameters: void 0
1222
- })) : (e.state === "closed" || e.state === "closing") && (r = !0, e.state = "opening", e.startTick = n, d.push({
1223
- targetId: t.id,
1224
- scheduledAtTick: n,
1225
- readyAtTick: n + g,
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,
1226
1520
  type: "OpeningEnd",
1227
1521
  parameters: void 0
1228
1522
  })), {
1229
- componentState: e,
1523
+ componentState: t,
1230
1524
  hasChanged: r,
1231
- scheduledEvents: d
1525
+ shouldCancelPending: !1,
1526
+ scheduledEvents: u
1232
1527
  };
1233
1528
  }
1234
- onUserCommand(t, e, i) {
1235
- return {
1236
- componentState: e,
1237
- hasChanged: !1,
1238
- scheduledEvents: []
1239
- };
1240
- }
1241
- onEventFiring(t, e, i) {
1242
- let n = !1;
1243
- return i.type === "ClosingEnd" ? e.state !== "closed" && (n = !0, e.startTick = i.readyAtTick, e.state = "closed") : i.type === "OpeningEnd" && e.state !== "open" && (n = !0, e.startTick = i.readyAtTick, e.state = "open"), {
1244
- componentState: e,
1245
- hasChanged: n,
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,
1246
1535
  scheduledEvents: []
1247
1536
  };
1248
1537
  }
1249
1538
  }
1250
- class H extends p {
1251
- /**
1252
- * Create a new Switch state.
1253
- *
1254
- * @param componentId - UUID of the Switch component
1255
- * @param initialState - Initial operational state (default: "open")
1256
- */
1257
- constructor(t, e = "open") {
1258
- super(t, e);
1259
- }
1260
- /**
1261
- * Check if switch is in opening or closing state
1262
- */
1263
- get isInTransition() {
1264
- return this.state === "closing" || this.state === "opening";
1265
- }
1266
- /**
1267
- * Check if switch is in closed or closing state
1268
- */
1269
- get isClosed() {
1270
- return this.state === "closed" || this.state === "closing";
1271
- }
1272
- }
1273
- class z extends p {
1274
- /**
1275
- * Create a new Transistor state.
1276
- *
1277
- * @param componentId - UUID of the Transistor component
1278
- * @param initialState - Initial operational state (default: "open")
1279
- */
1280
- constructor(t, e = "open") {
1281
- super(t, e);
1282
- }
1283
- /**
1284
- * Check if transistor is in opening or closing state
1285
- */
1286
- get isInTransition() {
1287
- return this.state === "closing" || this.state === "opening";
1288
- }
1289
- /**
1290
- * Check if transistor is in closed or closing state
1291
- */
1292
- get isClosed() {
1293
- return this.state === "closed" || this.state === "closing";
1294
- }
1295
- }
1296
- class K extends p {
1297
- /**
1298
- * Create a new Buffer state.
1299
- *
1300
- * @param componentId - UUID of the Buffer component
1301
- * @param initialState - Initial operational state (default: "low")
1302
- */
1303
- constructor(t, e = "low") {
1304
- super(t, e);
1305
- }
1306
- /**
1307
- * Check if output is in a rising or falling transition
1308
- */
1309
- get isInTransition() {
1310
- return this.state === "rising" || this.state === "falling";
1311
- }
1312
- /**
1313
- * Check if output is high
1314
- */
1315
- get isHigh() {
1316
- return this.state === "high";
1539
+ class ve extends L {
1540
+ constructor() {
1541
+ super(h.SmallLED);
1317
1542
  }
1318
- }
1319
- class T extends p {
1320
1543
  /**
1321
- * Create a new AND Gate state.
1544
+ * Create initial state for a smallLED.
1322
1545
  *
1323
- * @param componentId - UUID of the AND Gate component
1324
- * @param initialState - Initial operational state (default: "low")
1325
- */
1326
- constructor(t, e = "low") {
1327
- super(t, e);
1328
- }
1329
- /**
1330
- * Check if output is in a rising or falling transition
1546
+ * @param component - The smallLED component
1547
+ * @returns LED Initial state (always active and delivering voltage)
1331
1548
  */
1332
- get isInTransition() {
1333
- return this.state === "rising" || this.state === "falling";
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);
1334
1553
  }
1335
1554
  /**
1336
- * Check if output is high
1555
+ * only symmetrical behavior of LEDS is handled for now
1556
+ * @param component
1557
+ * @param state
1558
+ * @param nodeStates
1559
+ * @param targetTick
1337
1560
  */
1338
- get isHigh() {
1339
- return this.state === "high";
1340
- }
1341
- }
1342
- class X extends T {
1343
- constructor(t, e = "low") {
1344
- super(t, e);
1345
- }
1346
- }
1347
- class q extends T {
1348
- constructor(t, e = "low") {
1349
- super(t, e);
1350
- }
1351
- }
1352
- class E extends p {
1353
- constructor(t, e = "low") {
1354
- super(t, e);
1355
- }
1356
- get isInTransition() {
1357
- return this.state === "rising" || this.state === "falling";
1358
- }
1359
- get isHigh() {
1360
- return this.state === "high";
1361
- }
1362
- }
1363
- class Q extends E {
1364
- constructor(t, e = "low") {
1365
- super(t, e);
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);
1366
1565
  }
1367
1566
  }
1368
- class Y extends E {
1369
- constructor(t, e = "low") {
1370
- super(t, e);
1371
- }
1372
- }
1373
- class Z extends p {
1374
- constructor(t, e = "low") {
1375
- super(t, e);
1376
- }
1377
- get isInTransition() {
1378
- return this.state === "rising" || this.state === "falling";
1379
- }
1380
- get isHigh() {
1381
- return this.state === "high";
1567
+ class we extends y {
1568
+ constructor() {
1569
+ super(h.Switch);
1382
1570
  }
1383
- }
1384
- function j(c) {
1385
- if (!c)
1386
- return f.TRANSITION_SPAN_TICKS;
1387
- const t = parseInt(c.get("tickCount") || "", 10);
1388
- return isNaN(t) || t < 1 ? f.TRANSITION_SPAN_TICKS : t;
1389
- }
1390
- class ee {
1391
- componentType = h.Switch;
1392
1571
  /**
1393
1572
  * Create initial state for a switch.
1394
1573
  *
1395
1574
  * @param component - The Switch component
1396
1575
  * @returns Switch Initial state (open by default)
1397
1576
  */
1398
- createInitialState(t) {
1399
- if (t.type !== h.Switch)
1400
- throw new Error(`Invalid component type for SwitchBehavior: ${t.type}`);
1401
- const e = t.config.get("initialState") || "open";
1402
- return new H(t.id, e);
1403
- }
1404
- allowConductivity(t, e, i, n, s) {
1405
- return e.state === "closed" || e.state === "opening";
1406
- }
1407
- /**
1408
- * Switches states depend on user interaction, not their pins so this is more of a decorative function
1409
- * @param _component
1410
- * @param componentState
1411
- * @param _nodeStates
1412
- * @param _targetTick
1413
- */
1414
- onPinsChange(t, e, i, n) {
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
+ }
1415
1600
  return {
1416
- componentState: e,
1417
- hasChanged: !1,
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,
1418
1613
  scheduledEvents: []
1419
1614
  };
1420
1615
  }
1421
- onUserCommand(t, e, i) {
1422
- let n = !1;
1423
- const s = [];
1424
- if (i.type === "toggle_switch" && ["open", "closed"].includes(e.state)) {
1425
- e.state = e.state === "open" ? "closing" : "opening", e.startTick = i.scheduledAtTick + 1, n = !0;
1426
- const o = j(i.parameters);
1427
- s.push({
1428
- targetId: t.id,
1429
- scheduledAtTick: e.startTick,
1430
- readyAtTick: e.startTick + o,
1431
- type: e.state === "closing" ? "ClosingEnd" : "OpeningEnd",
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",
1432
1651
  parameters: void 0
1433
1652
  });
1434
1653
  }
1435
1654
  return {
1436
- componentState: e,
1437
- hasChanged: n,
1438
- scheduledEvents: s
1655
+ componentState: t,
1656
+ hasChanged: i,
1657
+ shouldCancelPending: !1,
1658
+ scheduledEvents: n
1439
1659
  };
1440
1660
  }
1441
- onEventFiring(t, e, i) {
1442
- let n = !1;
1443
- return i.type === "ClosingEnd" ? e.state !== "closed" && (n = !0, e.startTick = i.readyAtTick, e.state = "closed") : i.type === "OpeningEnd" && e.state !== "open" && (n = !0, e.startTick = i.readyAtTick, e.state = "open"), {
1444
- componentState: e,
1445
- hasChanged: n,
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,
1446
1667
  scheduledEvents: []
1447
1668
  };
1448
1669
  }
1449
1670
  }
1450
- function te(c) {
1451
- const t = parseInt(c.get("transitionSpan") || "", 10);
1452
- return isNaN(t) || t < 1 ? f.TRANSITION_SPAN_TICKS : t;
1671
+ function me(a) {
1672
+ const e = parseInt(a.get("transitionSpan") || "", 10);
1673
+ return isNaN(e) || e < 1 ? S.TRANSITION_SPAN_TICKS : e;
1453
1674
  }
1454
- class ne {
1455
- componentType = h.Transistor;
1675
+ class p extends y {
1456
1676
  /**
1457
- * Create initial state for a transistor.
1458
- *
1459
- * @param component - The Transistor component
1460
- * @returns Transistor Initial state (open by default)
1461
- */
1462
- createInitialState(t) {
1463
- if (t.type !== h.Transistor)
1464
- throw new Error(`Invalid component type for TransistorBehavior: ${t.type}`);
1465
- const e = t.config.get("activationLogic") === "negative" ? "closed" : "open";
1466
- return new z(t.id, e);
1467
- }
1468
- allowConductivity(t, e, i, n, s) {
1469
- if (n === s) return !0;
1470
- const o = t.getPinLabel(n), a = t.getPinLabel(s);
1471
- if (!o || !a) return !1;
1472
- const r = [o, a];
1473
- return r.includes("collector") && r.includes("emitter") ? e.state === "closed" || e.state === "opening" : !1;
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
+ };
1474
1693
  }
1475
1694
  /**
1476
- * Transistor Base need to have only voltage so that transistor contactor stays closed
1477
- * @param component
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
1478
1700
  * @param state
1479
- * @param nodeStates
1701
+ * @param pinStates
1480
1702
  * @param targetTick
1481
- */
1482
- onPinsChange(t, e, i, n) {
1483
- const s = /* @__PURE__ */ new Map();
1484
- for (const l of t.pins)
1485
- s.set(t.getPinLabel(l), i.get(l));
1486
- const o = s.get("base").hasVoltage, a = t.config.get("activationLogic") === "negative" ? !o : o;
1487
- let r = !1;
1488
- const d = [], g = te(t.config);
1489
- return a ? (e.state === "open" || e.state === "opening") && (r = !0, e.state = "closing", e.startTick = n, d.push({
1490
- targetId: t.id,
1491
- scheduledAtTick: n,
1492
- readyAtTick: n + g,
1493
- type: "ClosingEnd",
1494
- parameters: void 0
1495
- })) : (e.state === "closed" || e.state === "closing") && (r = !0, e.state = "opening", e.startTick = n, d.push({
1496
- targetId: t.id,
1497
- scheduledAtTick: n,
1498
- readyAtTick: n + g,
1499
- type: "OpeningEnd",
1500
- parameters: void 0
1501
- })), {
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", {
1502
1727
  componentState: e,
1503
- hasChanged: r,
1504
- scheduledEvents: d
1728
+ hasChanged: s,
1729
+ shouldCancelPending: c,
1730
+ scheduledEvents: []
1505
1731
  };
1506
1732
  }
1507
- onUserCommand(t, e, i) {
1508
- return {
1509
- componentState: e,
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,
1510
1748
  hasChanged: !1,
1749
+ shouldCancelPending: !1,
1511
1750
  scheduledEvents: []
1512
- };
1513
- }
1514
- onEventFiring(t, e, i) {
1515
- let n = !1;
1516
- return i.type === "ClosingEnd" ? e.state !== "closed" && (n = !0, e.startTick = i.readyAtTick, e.state = "closed") : i.type === "OpeningEnd" && e.state !== "open" && (n = !0, e.startTick = i.readyAtTick, e.state = "open"), {
1517
- componentState: e,
1518
- hasChanged: n,
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,
1519
1794
  scheduledEvents: []
1520
1795
  };
1521
1796
  }
1522
1797
  }
1523
- function ie(c) {
1524
- const t = parseInt(c.get("transitionSpan") || "", 10);
1525
- return isNaN(t) || t < 1 ? f.TRANSITION_SPAN_TICKS : t;
1526
- }
1527
- class se {
1528
- componentType = h.Buffer;
1798
+ class Se extends p {
1799
+ constructor() {
1800
+ super(h.Inverter);
1801
+ }
1529
1802
  /**
1530
- * Create initial state for a Buffer.
1803
+ * Create initial state for a Inverter.
1531
1804
  *
1532
- * @param component - The Buffer component
1533
- * @returns Buffer Initial state (low by default, high for negative activation logic)
1805
+ * @param component - The Inverter component
1806
+ * @returns Inverter Initial state (HIGH if input LOW, LOW if input LOW for positive activation logic)
1534
1807
  */
1535
- createInitialState(t) {
1536
- if (t.type !== h.Buffer)
1537
- throw new Error(`Invalid component type for BufferBehavior: ${t.type}`);
1538
- const e = t.config.get("activationLogic") === "negative" ? "high" : "low";
1539
- return new K(t.id, e);
1540
- }
1541
- allowConductivity(t, e, i, n, s) {
1542
- if (n === s) return !0;
1543
- const o = t.getPinLabel(n), a = t.getPinLabel(s);
1544
- if (!o || !a) return !1;
1545
- const r = [o, a];
1546
- return r.includes("vcc") && r.includes("output") ? e.state === "high" || e.state === "falling" : !1;
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);
1547
1813
  }
1548
1814
  /**
1549
- * Relayer needs voltage on input to drive the output high, and on the contrary Inverter needs no voltage on input
1815
+ * Inverter needs LOW on input to drive the output HIGH, and on the contrary Buffer needs HIGH on input to output HIGH
1550
1816
  * @param component
1551
1817
  * @param state
1552
1818
  * @param nodeStates
1553
1819
  * @param targetTick
1554
1820
  */
1555
- onPinsChange(t, e, i, n) {
1556
- const s = /* @__PURE__ */ new Map();
1557
- for (const l of t.pins)
1558
- s.set(t.getPinLabel(l), i.get(l));
1559
- const o = s.get("input").hasVoltage, a = t.config.get("activationLogic") === "negative" ? !o : o;
1560
- let r = !1;
1561
- const d = [], g = ie(t.config);
1562
- return a ? (e.state === "low" || e.state === "falling") && (r = !0, e.state = "rising", e.startTick = n, d.push({
1563
- targetId: t.id,
1564
- scheduledAtTick: n,
1565
- readyAtTick: n + g,
1566
- type: "RisingComplete",
1567
- parameters: void 0
1568
- })) : (e.state === "high" || e.state === "rising") && (r = !0, e.state = "falling", e.startTick = n, d.push({
1569
- targetId: t.id,
1570
- scheduledAtTick: n,
1571
- readyAtTick: n + g,
1572
- type: "FallingComplete",
1573
- parameters: void 0
1574
- })), {
1575
- componentState: e,
1576
- hasChanged: r,
1577
- scheduledEvents: d
1578
- };
1579
- }
1580
- onUserCommand(t, e, i) {
1581
- return {
1582
- componentState: e,
1583
- hasChanged: !1,
1584
- scheduledEvents: []
1585
- };
1586
- }
1587
- onEventFiring(t, e, i) {
1588
- let n = !1;
1589
- return i.type === "RisingComplete" ? e.state !== "high" && (n = !0, e.startTick = i.readyAtTick, e.state = "high") : i.type === "FallingComplete" && e.state !== "low" && (n = !0, e.startTick = i.readyAtTick, e.state = "low"), {
1590
- componentState: e,
1591
- hasChanged: n,
1592
- scheduledEvents: []
1593
- };
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);
1594
1830
  }
1595
1831
  }
1596
- class I {
1597
- componentType = h.AndGate;
1832
+ class Ce extends p {
1833
+ constructor() {
1834
+ super(h.NandGate);
1835
+ }
1598
1836
  /**
1599
- * Create initial state for an AND Gate.
1837
+ * Create initial state for an NAND Gate.
1600
1838
  *
1601
- * @param component - The AND Gate component
1839
+ * @param component - The NAND Gate component
1602
1840
  * @returns Initial state (low by default, high for negative activation logic)
1603
1841
  */
1604
- createInitialState(t) {
1605
- if (t.type !== h.AndGate)
1606
- throw new Error(`Invalid component type for AndGateBehavior: ${t.type}`);
1607
- const e = t.config.get("activationLogic") === "negative" ? "high" : "low";
1608
- return new T(t.id, e);
1609
- }
1610
- allowConductivity(t, e, i, n, s) {
1611
- if (n === s) return !0;
1612
- const o = t.getPinLabel(n), a = t.getPinLabel(s);
1613
- if (!o || !a) return !1;
1614
- const r = [o, a];
1615
- return r.includes("vcc") && r.includes("output") ? e.state === "high" || e.state === "falling" : !1;
1616
- }
1617
- /**
1618
- * Get the transition span from component config.
1619
- * @param config - Component config map
1620
- * @returns Number of ticks for transition (minimum 1)
1621
- */
1622
- getTransitionSpan(t) {
1623
- const e = parseInt(t.get("transitionSpan") || "", 10);
1624
- return isNaN(e) || e < 1 ? f.TRANSITION_SPAN_TICKS : e;
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);
1625
1847
  }
1626
1848
  /**
1627
- * AND gate output goes high when ALL inputs have voltage.
1628
- * With negative activationLogic (NAND), output goes high when ANY input lacks voltage.
1849
+ * NAND gate output goes high when ANY inputs LACK voltage.
1850
+ * With positive activationLogic (AND), output goes high when ALL inputs HAS voltage.
1629
1851
  */
1630
- onPinsChange(t, e, i, n) {
1631
- const s = /* @__PURE__ */ new Map();
1632
- for (const l of t.pins)
1633
- s.set(t.getPinLabel(l), i.get(l));
1634
- const o = s.get("input1").hasVoltage && s.get("input2").hasVoltage, a = t.config.get("activationLogic") === "negative" ? !o : o;
1635
- let r = !1;
1636
- const d = [], g = this.getTransitionSpan(t.config);
1637
- return a ? (e.state === "low" || e.state === "falling") && (r = !0, e.state = "rising", e.startTick = n, d.push({
1638
- targetId: t.id,
1639
- scheduledAtTick: n,
1640
- readyAtTick: n + g,
1641
- type: "RisingComplete",
1642
- parameters: void 0
1643
- })) : (e.state === "high" || e.state === "rising") && (r = !0, e.state = "falling", e.startTick = n, d.push({
1644
- targetId: t.id,
1645
- scheduledAtTick: n,
1646
- readyAtTick: n + g,
1647
- type: "FallingComplete",
1648
- parameters: void 0
1649
- })), {
1650
- componentState: e,
1651
- hasChanged: r,
1652
- scheduledEvents: d
1653
- };
1654
- }
1655
- onUserCommand(t, e, i) {
1656
- return {
1657
- componentState: e,
1658
- hasChanged: !1,
1659
- scheduledEvents: []
1660
- };
1661
- }
1662
- onEventFiring(t, e, i) {
1663
- let n = !1;
1664
- return i.type === "RisingComplete" ? e.state !== "high" && (n = !0, e.startTick = i.readyAtTick, e.state = "high") : i.type === "FallingComplete" && e.state !== "low" && (n = !0, e.startTick = i.readyAtTick, e.state = "low"), {
1665
- componentState: e,
1666
- hasChanged: n,
1667
- scheduledEvents: []
1668
- };
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);
1669
1861
  }
1670
1862
  }
1671
- class oe extends I {
1672
- componentType = h.And4Gate;
1673
- createInitialState(t) {
1674
- if (t.type !== h.And4Gate)
1675
- throw new Error(`Invalid component type for And4GateBehavior: ${t.type}`);
1676
- const e = t.config.get("activationLogic") === "negative" ? "high" : "low";
1677
- return new X(t.id, e);
1678
- }
1679
- onPinsChange(t, e, i, n) {
1680
- const s = /* @__PURE__ */ new Map();
1681
- for (const l of t.pins)
1682
- s.set(t.getPinLabel(l), i.get(l));
1683
- const o = s.get("input1").hasVoltage && s.get("input2").hasVoltage && s.get("input3").hasVoltage && s.get("input4").hasVoltage, a = t.config.get("activationLogic") === "negative" ? !o : o;
1684
- let r = !1;
1685
- const d = [], g = this.getTransitionSpan(t.config);
1686
- return a ? (e.state === "low" || e.state === "falling") && (r = !0, e.state = "rising", e.startTick = n, d.push({
1687
- targetId: t.id,
1688
- scheduledAtTick: n,
1689
- readyAtTick: n + g,
1690
- type: "RisingComplete",
1691
- parameters: void 0
1692
- })) : (e.state === "high" || e.state === "rising") && (r = !0, e.state = "falling", e.startTick = n, d.push({
1693
- targetId: t.id,
1694
- scheduledAtTick: n,
1695
- readyAtTick: n + g,
1696
- type: "FallingComplete",
1697
- parameters: void 0
1698
- })), {
1699
- componentState: e,
1700
- hasChanged: r,
1701
- scheduledEvents: d
1702
- };
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);
1703
1882
  }
1704
1883
  }
1705
- class re extends I {
1706
- componentType = h.And8Gate;
1707
- createInitialState(t) {
1708
- if (t.type !== h.And8Gate)
1709
- throw new Error(`Invalid component type for And8GateBehavior: ${t.type}`);
1710
- const e = t.config.get("activationLogic") === "negative" ? "high" : "low";
1711
- return new q(t.id, e);
1712
- }
1713
- onPinsChange(t, e, i, n) {
1714
- const s = /* @__PURE__ */ new Map();
1715
- for (const l of t.pins)
1716
- s.set(t.getPinLabel(l), i.get(l));
1717
- const o = s.get("input1").hasVoltage && s.get("input2").hasVoltage && s.get("input3").hasVoltage && s.get("input4").hasVoltage && s.get("input5").hasVoltage && s.get("input6").hasVoltage && s.get("input7").hasVoltage && s.get("input8").hasVoltage, a = t.config.get("activationLogic") === "negative" ? !o : o;
1718
- let r = !1;
1719
- const d = [], g = this.getTransitionSpan(t.config);
1720
- return a ? (e.state === "low" || e.state === "falling") && (r = !0, e.state = "rising", e.startTick = n, d.push({
1721
- targetId: t.id,
1722
- scheduledAtTick: n,
1723
- readyAtTick: n + g,
1724
- type: "RisingComplete",
1725
- parameters: void 0
1726
- })) : (e.state === "high" || e.state === "rising") && (r = !0, e.state = "falling", e.startTick = n, d.push({
1727
- targetId: t.id,
1728
- scheduledAtTick: n,
1729
- readyAtTick: n + g,
1730
- type: "FallingComplete",
1731
- parameters: void 0
1732
- })), {
1733
- componentState: e,
1734
- hasChanged: r,
1735
- scheduledEvents: d
1736
- };
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);
1737
1903
  }
1738
1904
  }
1739
- class A {
1740
- componentType = h.OrGate;
1741
- createInitialState(t) {
1742
- if (t.type !== h.OrGate)
1743
- throw new Error(`Invalid component type for OrGateBehavior: ${t.type}`);
1744
- const e = t.config.get("activationLogic") === "negative" ? "high" : "low";
1745
- return new E(t.id, e);
1746
- }
1747
- allowConductivity(t, e, i, n, s) {
1748
- if (n === s) return !0;
1749
- const o = t.getPinLabel(n), a = t.getPinLabel(s);
1750
- if (!o || !a) return !1;
1751
- const r = [o, a];
1752
- return r.includes("vcc") && r.includes("output") ? e.state === "high" || e.state === "falling" : !1;
1753
- }
1754
- getTransitionSpan(t) {
1755
- const e = parseInt(t.get("transitionSpan") || "", 10);
1756
- return isNaN(e) || e < 1 ? f.TRANSITION_SPAN_TICKS : e;
1757
- }
1758
- /**
1759
- * OR gate output goes high when ANY input has voltage.
1760
- * With negative activationLogic (NOR), output goes high when ALL inputs lack voltage.
1761
- */
1762
- onPinsChange(t, e, i, n) {
1763
- const s = /* @__PURE__ */ new Map();
1764
- for (const l of t.pins)
1765
- s.set(t.getPinLabel(l), i.get(l));
1766
- const o = s.get("input1").hasVoltage || s.get("input2").hasVoltage, a = t.config.get("activationLogic") === "negative" ? !o : o;
1767
- let r = !1;
1768
- const d = [], g = this.getTransitionSpan(t.config);
1769
- return a ? (e.state === "low" || e.state === "falling") && (r = !0, e.state = "rising", e.startTick = n, d.push({
1770
- targetId: t.id,
1771
- scheduledAtTick: n,
1772
- readyAtTick: n + g,
1773
- type: "RisingComplete",
1774
- parameters: void 0
1775
- })) : (e.state === "high" || e.state === "rising") && (r = !0, e.state = "falling", e.startTick = n, d.push({
1776
- targetId: t.id,
1777
- scheduledAtTick: n,
1778
- readyAtTick: n + g,
1779
- type: "FallingComplete",
1780
- parameters: void 0
1781
- })), {
1782
- componentState: e,
1783
- hasChanged: r,
1784
- scheduledEvents: d
1785
- };
1905
+ class Ie extends p {
1906
+ constructor() {
1907
+ super(h.NorGate);
1786
1908
  }
1787
- onUserCommand(t, e, i) {
1788
- return {
1789
- componentState: e,
1790
- hasChanged: !1,
1791
- scheduledEvents: []
1792
- };
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);
1793
1914
  }
1794
- onEventFiring(t, e, i) {
1795
- let n = !1;
1796
- return i.type === "RisingComplete" ? e.state !== "high" && (n = !0, e.startTick = i.readyAtTick, e.state = "high") : i.type === "FallingComplete" && e.state !== "low" && (n = !0, e.startTick = i.readyAtTick, e.state = "low"), {
1797
- componentState: e,
1798
- hasChanged: n,
1799
- scheduledEvents: []
1800
- };
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);
1801
1928
  }
1802
1929
  }
1803
- class ae extends A {
1804
- componentType = h.Or4Gate;
1805
- createInitialState(t) {
1806
- if (t.type !== h.Or4Gate)
1807
- throw new Error(`Invalid component type for Or4GateBehavior: ${t.type}`);
1808
- const e = t.config.get("activationLogic") === "negative" ? "high" : "low";
1809
- return new Q(t.id, e);
1810
- }
1811
- onPinsChange(t, e, i, n) {
1812
- const s = /* @__PURE__ */ new Map();
1813
- for (const l of t.pins)
1814
- s.set(t.getPinLabel(l), i.get(l));
1815
- const o = s.get("input1").hasVoltage || s.get("input2").hasVoltage || s.get("input3").hasVoltage || s.get("input4").hasVoltage, a = t.config.get("activationLogic") === "negative" ? !o : o;
1816
- let r = !1;
1817
- const d = [], g = this.getTransitionSpan(t.config);
1818
- return a ? (e.state === "low" || e.state === "falling") && (r = !0, e.state = "rising", e.startTick = n, d.push({
1819
- targetId: t.id,
1820
- scheduledAtTick: n,
1821
- readyAtTick: n + g,
1822
- type: "RisingComplete",
1823
- parameters: void 0
1824
- })) : (e.state === "high" || e.state === "rising") && (r = !0, e.state = "falling", e.startTick = n, d.push({
1825
- targetId: t.id,
1826
- scheduledAtTick: n,
1827
- readyAtTick: n + g,
1828
- type: "FallingComplete",
1829
- parameters: void 0
1830
- })), {
1831
- componentState: e,
1832
- hasChanged: r,
1833
- scheduledEvents: d
1834
- };
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);
1835
1949
  }
1836
1950
  }
1837
- class de extends A {
1838
- componentType = h.Or8Gate;
1839
- createInitialState(t) {
1840
- if (t.type !== h.Or8Gate)
1841
- throw new Error(`Invalid component type for Or8GateBehavior: ${t.type}`);
1842
- const e = t.config.get("activationLogic") === "negative" ? "high" : "low";
1843
- return new Y(t.id, e);
1844
- }
1845
- onPinsChange(t, e, i, n) {
1846
- const s = /* @__PURE__ */ new Map();
1847
- for (const l of t.pins)
1848
- s.set(t.getPinLabel(l), i.get(l));
1849
- const o = s.get("input1").hasVoltage || s.get("input2").hasVoltage || s.get("input3").hasVoltage || s.get("input4").hasVoltage || s.get("input5").hasVoltage || s.get("input6").hasVoltage || s.get("input7").hasVoltage || s.get("input8").hasVoltage, a = t.config.get("activationLogic") === "negative" ? !o : o;
1850
- let r = !1;
1851
- const d = [], g = this.getTransitionSpan(t.config);
1852
- return a ? (e.state === "low" || e.state === "falling") && (r = !0, e.state = "rising", e.startTick = n, d.push({
1853
- targetId: t.id,
1854
- scheduledAtTick: n,
1855
- readyAtTick: n + g,
1856
- type: "RisingComplete",
1857
- parameters: void 0
1858
- })) : (e.state === "high" || e.state === "rising") && (r = !0, e.state = "falling", e.startTick = n, d.push({
1859
- targetId: t.id,
1860
- scheduledAtTick: n,
1861
- readyAtTick: n + g,
1862
- type: "FallingComplete",
1863
- parameters: void 0
1864
- })), {
1865
- componentState: e,
1866
- hasChanged: r,
1867
- scheduledEvents: d
1868
- };
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);
1869
1970
  }
1870
1971
  }
1871
- class ce {
1872
- componentType = h.XorGate;
1873
- createInitialState(t) {
1874
- if (t.type !== h.XorGate)
1875
- throw new Error(`Invalid component type for XorGateBehavior: ${t.type}`);
1876
- const e = t.config.get("activationLogic") === "negative" ? "high" : "low";
1877
- return new Z(t.id, e);
1878
- }
1879
- allowConductivity(t, e, i, n, s) {
1880
- if (n === s) return !0;
1881
- const o = t.getPinLabel(n), a = t.getPinLabel(s);
1882
- if (!o || !a) return !1;
1883
- const r = [o, a];
1884
- return r.includes("vcc") && r.includes("output") ? e.state === "high" || e.state === "falling" : !1;
1885
- }
1886
- getTransitionSpan(t) {
1887
- const e = parseInt(t.get("transitionSpan") || "", 10);
1888
- return isNaN(e) || e < 1 ? f.TRANSITION_SPAN_TICKS : e;
1889
- }
1890
- /**
1891
- * XOR gate output goes high when inputs differ (one high, one low).
1892
- * With negative activationLogic (XNOR), output goes high when inputs are equal.
1893
- */
1894
- onPinsChange(t, e, i, n) {
1895
- const s = /* @__PURE__ */ new Map();
1896
- for (const u of t.pins)
1897
- s.set(t.getPinLabel(u), i.get(u));
1898
- const o = s.get("input1").hasVoltage, a = s.get("input2").hasVoltage, r = o !== a, d = t.config.get("activationLogic") === "negative" ? !r : r;
1899
- let g = !1;
1900
- const l = [], m = this.getTransitionSpan(t.config);
1901
- return d ? (e.state === "low" || e.state === "falling") && (g = !0, e.state = "rising", e.startTick = n, l.push({
1902
- targetId: t.id,
1903
- scheduledAtTick: n,
1904
- readyAtTick: n + m,
1905
- type: "RisingComplete",
1906
- parameters: void 0
1907
- })) : (e.state === "high" || e.state === "rising") && (g = !0, e.state = "falling", e.startTick = n, l.push({
1908
- targetId: t.id,
1909
- scheduledAtTick: n,
1910
- readyAtTick: n + m,
1911
- type: "FallingComplete",
1912
- parameters: void 0
1913
- })), {
1914
- componentState: e,
1915
- hasChanged: g,
1916
- scheduledEvents: l
1917
- };
1972
+ class Ee extends p {
1973
+ constructor() {
1974
+ super(h.XorGate);
1918
1975
  }
1919
- onUserCommand(t, e, i) {
1920
- return {
1921
- componentState: e,
1922
- hasChanged: !1,
1923
- scheduledEvents: []
1924
- };
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);
1925
1981
  }
1926
- onEventFiring(t, e, i) {
1927
- let n = !1;
1928
- return i.type === "RisingComplete" ? e.state !== "high" && (n = !0, e.startTick = i.readyAtTick, e.state = "high") : i.type === "FallingComplete" && e.state !== "low" && (n = !0, e.startTick = i.readyAtTick, e.state = "low"), {
1929
- componentState: e,
1930
- hasChanged: n,
1931
- scheduledEvents: []
1932
- };
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);
1933
2037
  }
1934
2038
  }
1935
- function he(c) {
1936
- return c.register(new W()).register(new M()).register(new F()).register(new U()).register(new N()).register(new ee()).register(new ne()).register(new se()), c;
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;
1937
2041
  }
1938
- function ue(c) {
1939
- return c.register(new I()).register(new oe()).register(new re()).register(new A()).register(new ae()).register(new de()).register(new ce()), c;
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;
1940
2044
  }
1941
2045
  export {
1942
- oe as And4GateBehavior,
1943
- X as And4GateState,
1944
- re as And8GateBehavior,
1945
- q as And8GateState,
1946
- I as AndGateBehavior,
1947
- T as AndGateState,
1948
- W as BatteryBehavior,
1949
- x as BatteryState,
1950
- ge as BehaviorRegistry,
1951
- se as BufferBehavior,
1952
- K as BufferState,
1953
- V as COMPONENT_TYPE_METADATA,
1954
- b as CameraOptions,
1955
- _ as Circuit,
1956
- v as CircuitMetadata,
1957
- me as CircuitRunner,
1958
- P as Component,
1959
- p as ComponentState,
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,
1960
2059
  h as ComponentType,
1961
- we as DirtyTracker,
1962
- S as ENode,
1963
- ye as ENodeSourceType,
1964
- y as ENodeType,
1965
- ve as EventQueue,
1966
- M as LightbulbBehavior,
1967
- $ as LightbulbState,
1968
- ae as Or4GateBehavior,
1969
- Q as Or4GateState,
1970
- de as Or8GateBehavior,
1971
- Y as Or8GateState,
1972
- A as OrGateBehavior,
1973
- E as OrGateState,
1974
- k as Position,
1975
- Se as Position3D,
1976
- F as RectangleLEDBehavior,
1977
- R as RectangleLEDState,
1978
- U as RelayBehavior,
1979
- D as RelayState,
1980
- Ce as Rotation,
1981
- Te as SIMULATION_SPEED,
1982
- Ee as SimulationState,
1983
- N as SmallLEDBehavior,
1984
- L as SmallLEDState,
1985
- Ie as StateManager,
1986
- ee as SwitchBehavior,
1987
- H as SwitchState,
1988
- f as TRANSITION_DEFAULTS,
1989
- ne as TransistorBehavior,
1990
- z as TransistorState,
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,
1991
2101
  w as Wire,
1992
- ce as XorGateBehavior,
1993
- Z as XorGateState,
1994
- G as findPositionBestIndex,
1995
- O as generateUUID,
1996
- Ae as getAllComponentTypes,
1997
- B as getComponentTypeMetadata,
1998
- he as registerBasicComponentsBehaviors,
1999
- ue as registerGatesComponentsBehaviors,
2000
- C as simplifyPositions
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
2001
2116
  };
2002
2117
  //# sourceMappingURL=index.js.map