simple-circuit-engine 0.0.11 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/AGENTS.md +11 -7
  2. package/CLAUDE.md +6 -6
  3. package/README.md +5 -2
  4. package/dist/core/index.d.ts +0 -1
  5. package/dist/core/index.js +85 -2115
  6. package/dist/core/setup.d.ts +25 -0
  7. package/dist/core/simulation/CircuitRunner.d.ts +176 -0
  8. package/dist/core/simulation/DirtyTracker.d.ts +87 -0
  9. package/dist/core/simulation/EventQueue.d.ts +68 -0
  10. package/dist/core/simulation/StateManager.d.ts +100 -0
  11. package/dist/core/simulation/behaviors/BehaviorRegistry.d.ts +70 -0
  12. package/dist/core/simulation/behaviors/ComponentBehavior.d.ts +53 -0
  13. package/dist/core/simulation/behaviors/arithmetic/AdderBehavior.d.ts +28 -0
  14. package/dist/core/simulation/behaviors/arithmetic/ArithmeticBehaviorMixin.d.ts +63 -0
  15. package/dist/core/simulation/behaviors/arithmetic/EightBitAdderBehavior.d.ts +51 -0
  16. package/dist/core/simulation/behaviors/arithmetic/EightBitOnesComplementBehavior.d.ts +29 -0
  17. package/dist/core/simulation/behaviors/arithmetic/HalfAdderBehavior.d.ts +22 -0
  18. package/dist/core/simulation/behaviors/arithmetic/index.d.ts +7 -0
  19. package/dist/core/simulation/behaviors/basic/BatteryBehavior.d.ts +14 -0
  20. package/dist/core/simulation/behaviors/basic/ClockBehavior.d.ts +24 -0
  21. package/dist/core/simulation/behaviors/basic/DoubleThrowSwitchBehavior.d.ts +33 -0
  22. package/dist/core/simulation/behaviors/basic/LightbulbBehavior.d.ts +23 -0
  23. package/dist/core/simulation/behaviors/basic/RectangleLEDBehavior.d.ts +24 -0
  24. package/dist/core/simulation/behaviors/basic/RelayBehavior.d.ts +33 -0
  25. package/dist/core/simulation/behaviors/basic/SmallLEDBehavior.d.ts +24 -0
  26. package/dist/core/simulation/behaviors/basic/SwitchBehavior.d.ts +33 -0
  27. package/dist/core/simulation/behaviors/basic/index.d.ts +20 -0
  28. package/dist/core/simulation/behaviors/gates/InverterBehavior.d.ts +29 -0
  29. package/dist/core/simulation/behaviors/gates/Nand4GateBehavior.d.ts +18 -0
  30. package/dist/core/simulation/behaviors/gates/Nand8GateBehavior.d.ts +18 -0
  31. package/dist/core/simulation/behaviors/gates/NandGateBehavior.d.ts +28 -0
  32. package/dist/core/simulation/behaviors/gates/Nor4GateBehavior.d.ts +18 -0
  33. package/dist/core/simulation/behaviors/gates/Nor8GateBehavior.d.ts +18 -0
  34. package/dist/core/simulation/behaviors/gates/NorGateBehavior.d.ts +22 -0
  35. package/dist/core/simulation/behaviors/gates/Xor4GateBehavior.d.ts +18 -0
  36. package/dist/core/simulation/behaviors/gates/Xor8GateBehavior.d.ts +18 -0
  37. package/dist/core/simulation/behaviors/gates/XorGateBehavior.d.ts +22 -0
  38. package/dist/core/simulation/behaviors/gates/index.d.ts +34 -0
  39. package/dist/core/simulation/behaviors/index.d.ts +28 -0
  40. package/dist/core/simulation/behaviors/types.d.ts +101 -0
  41. package/dist/core/simulation/index.d.ts +18 -0
  42. package/dist/core/simulation/states/ComponentState.d.ts +57 -0
  43. package/dist/core/simulation/states/SimulationState.d.ts +46 -0
  44. package/dist/core/simulation/states/arithmetic/AdderState.d.ts +16 -0
  45. package/dist/core/simulation/states/arithmetic/ArithmeticState.d.ts +53 -0
  46. package/dist/core/simulation/states/arithmetic/EightBitAdderState.d.ts +25 -0
  47. package/dist/core/simulation/states/arithmetic/EightBitOnesComplementState.d.ts +18 -0
  48. package/dist/core/simulation/states/arithmetic/HalfAdderState.d.ts +16 -0
  49. package/dist/core/simulation/states/arithmetic/index.d.ts +7 -0
  50. package/dist/core/simulation/states/basic/BatteryState.d.ts +16 -0
  51. package/dist/core/simulation/states/basic/ClockState.d.ts +16 -0
  52. package/dist/core/simulation/states/basic/DoubleThrowSwitchState.d.ts +21 -0
  53. package/dist/core/simulation/states/basic/LightbulbState.d.ts +21 -0
  54. package/dist/core/simulation/states/basic/RectangleLEDState.d.ts +9 -0
  55. package/dist/core/simulation/states/basic/RelayState.d.ts +25 -0
  56. package/dist/core/simulation/states/basic/SmallLEDState.d.ts +21 -0
  57. package/dist/core/simulation/states/basic/SwitchState.d.ts +25 -0
  58. package/dist/core/simulation/states/gates/InverterState.d.ts +17 -0
  59. package/dist/core/simulation/states/gates/Nand4GateState.d.ts +10 -0
  60. package/dist/core/simulation/states/gates/Nand8GateState.d.ts +10 -0
  61. package/dist/core/simulation/states/gates/NandGateState.d.ts +16 -0
  62. package/dist/core/simulation/states/gates/Nor4GateState.d.ts +10 -0
  63. package/dist/core/simulation/states/gates/Nor8GateState.d.ts +10 -0
  64. package/dist/core/simulation/states/gates/NorGateState.d.ts +10 -0
  65. package/dist/core/simulation/states/gates/Xor4GateState.d.ts +10 -0
  66. package/dist/core/simulation/states/gates/Xor8GateState.d.ts +10 -0
  67. package/dist/core/simulation/states/gates/XorGateState.d.ts +10 -0
  68. package/dist/core/simulation/states/gates/index.d.ts +25 -0
  69. package/dist/core/simulation/states/index.d.ts +31 -0
  70. package/dist/core/simulation/states/types.d.ts +32 -0
  71. package/dist/core/simulation/types.d.ts +155 -0
  72. package/dist/core/topology/Circuit.d.ts +420 -0
  73. package/dist/core/topology/CircuitMetadata.d.ts +24 -0
  74. package/dist/core/topology/CircuitOptions.d.ts +14 -0
  75. package/dist/core/topology/Component.d.ts +153 -0
  76. package/dist/core/topology/ENode.d.ts +200 -0
  77. package/dist/core/topology/Wire.d.ts +130 -0
  78. package/dist/core/topology/delays.d.ts +52 -0
  79. package/dist/core/topology/index.d.ts +14 -0
  80. package/dist/core/topology/types.d.ts +189 -0
  81. package/dist/core/utils/CameraOptions.d.ts +83 -0
  82. package/dist/core/utils/MemoizeDecorator.d.ts +9 -0
  83. package/dist/core/utils/Position.d.ts +166 -0
  84. package/dist/core/utils/Position3D.d.ts +77 -0
  85. package/dist/core/utils/Rotation.d.ts +82 -0
  86. package/dist/core/utils/index.d.ts +24 -0
  87. package/dist/core/utils/types.d.ts +35 -0
  88. package/dist/core-b6Q8w2sn.js +3560 -0
  89. package/dist/core-b6Q8w2sn.js.map +1 -0
  90. package/dist/i18n/index.d.ts +882 -0
  91. package/dist/i18n/locales/en.json.d.ts +268 -0
  92. package/dist/i18n/locales/fr.json.d.ts +268 -0
  93. package/dist/index.d.ts +14 -6306
  94. package/dist/index.js +136 -112
  95. package/dist/scene/CircuitEngine.d.ts +283 -0
  96. package/dist/scene/index.d.ts +1 -2
  97. package/dist/scene/index.js +50 -41
  98. package/dist/scene/setup.d.ts +26 -0
  99. package/dist/scene/shared/AbstractCircuitController.d.ts +217 -0
  100. package/dist/scene/shared/BranchingPointVisualFactory.d.ts +70 -0
  101. package/dist/scene/shared/EventEmitter.d.ts +92 -0
  102. package/dist/scene/shared/HoverManager.d.ts +151 -0
  103. package/dist/scene/shared/SelectionManager.d.ts +159 -0
  104. package/dist/scene/shared/WireVisualManager.d.ts +242 -0
  105. package/dist/scene/shared/components/ComponentVisualFactory.d.ts +438 -0
  106. package/dist/scene/shared/components/DefaultVisualFactory.d.ts +51 -0
  107. package/dist/scene/shared/components/FactoryRegistry.d.ts +84 -0
  108. package/dist/scene/shared/components/GroupedFactoryRegistry.d.ts +153 -0
  109. package/dist/scene/shared/components/arithmetic/AdderVisualFactory.d.ts +54 -0
  110. package/dist/scene/shared/components/arithmetic/EightBitAdderVisualFactory.d.ts +45 -0
  111. package/dist/scene/shared/components/arithmetic/EightBitOnesComplementVisualFactory.d.ts +63 -0
  112. package/dist/scene/shared/components/arithmetic/HalfAdderVisualFactory.d.ts +55 -0
  113. package/dist/scene/shared/components/arithmetic/index.d.ts +4 -0
  114. package/dist/scene/shared/components/basic/BatteryVisualFactory.d.ts +13 -0
  115. package/dist/scene/shared/components/basic/ClockVisualFactory.d.ts +79 -0
  116. package/dist/scene/shared/components/basic/DoubleThrowSwitchVisualFactory.d.ts +87 -0
  117. package/dist/scene/shared/components/basic/LabelVisualFactory.d.ts +148 -0
  118. package/dist/scene/shared/components/basic/LightbulbVisualFactory.d.ts +72 -0
  119. package/dist/scene/shared/components/basic/RectangleLEDVisualFactory.d.ts +86 -0
  120. package/dist/scene/shared/components/basic/RelayVisualFactory.d.ts +92 -0
  121. package/dist/scene/shared/components/basic/SmallLEDVisualFactory.d.ts +86 -0
  122. package/dist/scene/shared/components/basic/SwitchVisualFactory.d.ts +85 -0
  123. package/dist/scene/shared/components/gates/InverterVisualFactory.d.ts +104 -0
  124. package/dist/scene/shared/components/gates/Nand4GateVisualFactory.d.ts +27 -0
  125. package/dist/scene/shared/components/gates/Nand8GateVisualFactory.d.ts +27 -0
  126. package/dist/scene/shared/components/gates/NandGateVisualFactory.d.ts +101 -0
  127. package/dist/scene/shared/components/gates/Nor4GateVisualFactory.d.ts +27 -0
  128. package/dist/scene/shared/components/gates/Nor8GateVisualFactory.d.ts +27 -0
  129. package/dist/scene/shared/components/gates/NorGateVisualFactory.d.ts +101 -0
  130. package/dist/scene/shared/components/gates/Xor4GateVisualFactory.d.ts +29 -0
  131. package/dist/scene/shared/components/gates/Xor8GateVisualFactory.d.ts +29 -0
  132. package/dist/scene/shared/components/gates/XorGateVisualFactory.d.ts +103 -0
  133. package/dist/scene/shared/components/index.d.ts +33 -0
  134. package/dist/scene/shared/components/types.d.ts +43 -0
  135. package/dist/scene/shared/types.d.ts +474 -0
  136. package/dist/scene/shared/utils/CameraUtils.d.ts +23 -0
  137. package/dist/scene/shared/utils/ColorUtils.d.ts +26 -0
  138. package/dist/scene/shared/utils/ControlsUtils.d.ts +8 -0
  139. package/dist/scene/shared/utils/GeometryUtils.d.ts +337 -0
  140. package/dist/scene/shared/utils/LayerConstants.d.ts +40 -0
  141. package/dist/scene/shared/utils/LightingUtils.d.ts +31 -0
  142. package/dist/scene/shared/utils/MaterialUtils.d.ts +73 -0
  143. package/dist/scene/shared/utils/Options.d.ts +16 -0
  144. package/dist/scene/simulation/CircuitRunnerController.d.ts +227 -0
  145. package/dist/scene/static/CircuitController.d.ts +228 -0
  146. package/dist/scene/static/CircuitWriter.d.ts +146 -0
  147. package/dist/scene/static/PinTooltipWidget.d.ts +31 -0
  148. package/dist/scene/static/tools/BuildTool.d.ts +290 -0
  149. package/dist/scene/static/tools/ComponentPickerWidget.d.ts +89 -0
  150. package/dist/scene/static/tools/ConfigPanelWidget.d.ts +107 -0
  151. package/dist/scene/static/tools/MultiSelectTool.d.ts +265 -0
  152. package/dist/scene-D4QcWeiq.js +8745 -0
  153. package/dist/scene-D4QcWeiq.js.map +1 -0
  154. package/package.json +29 -25
  155. package/dist/CircuitRunner-BQQlhwjD.js +0 -1981
  156. package/dist/CircuitRunner-BQQlhwjD.js.map +0 -1
  157. package/dist/core/index.js.map +0 -1
  158. package/dist/index.js.map +0 -1
  159. package/dist/scene/index.js.map +0 -1
  160. package/dist/setup-CIq_kgaw.js +0 -10230
  161. package/dist/setup-CIq_kgaw.js.map +0 -1
@@ -0,0 +1,3560 @@
1
+ function dt(e) {
2
+ let t, n, i;
3
+ return typeof e == "object" ? (t = e.hashFunction, n = e.expiring, i = e.tags) : t = e, (s, r, a) => {
4
+ if (a.value != null) a.value = W(a.value, t, n, i);
5
+ else if (a.get != null) a.get = W(a.get, t, n, i);
6
+ else throw "Only put a Memoize() decorator on a method or get accessor.";
7
+ };
8
+ }
9
+ function Se(e, t) {
10
+ return dt({
11
+ expiring: e,
12
+ hashFunction: t
13
+ });
14
+ }
15
+ var D = /* @__PURE__ */ new Map();
16
+ function W(e, t, n = 0, i) {
17
+ const s = /* @__PURE__ */ Symbol("__memoized_map__");
18
+ return function(...r) {
19
+ let a;
20
+ this.hasOwnProperty(s) || Object.defineProperty(this, s, {
21
+ configurable: !1,
22
+ enumerable: !1,
23
+ writable: !1,
24
+ value: /* @__PURE__ */ new Map()
25
+ });
26
+ let o = this[s];
27
+ if (Array.isArray(i)) for (const c of i) D.has(c) ? D.get(c).push(o) : D.set(c, [o]);
28
+ if (t || r.length > 0 || n > 0) {
29
+ let c;
30
+ t === !0 ? c = r.map((d) => d.toString()).join("!") : t ? c = t.apply(this, r) : c = r[0];
31
+ const p = `${c}__timestamp`;
32
+ let l = !1;
33
+ if (n > 0) if (!o.has(p)) l = !0;
34
+ else {
35
+ let d = o.get(p);
36
+ l = Date.now() - d > n;
37
+ }
38
+ o.has(c) && !l ? a = o.get(c) : (a = e.apply(this, r), o.set(c, a), n > 0 && o.set(p, Date.now()));
39
+ } else {
40
+ const c = this;
41
+ o.has(c) ? a = o.get(c) : (a = e.apply(this, r), o.set(c, a));
42
+ }
43
+ return a;
44
+ };
45
+ }
46
+ var O = class X {
47
+ constructor(t, n, i) {
48
+ this.x = t, this.y = n, this.z = i;
49
+ }
50
+ equals(t) {
51
+ return this.x === t.x && this.y === t.y && this.z === t.z;
52
+ }
53
+ toJSON() {
54
+ return {
55
+ x: this.x,
56
+ y: this.y,
57
+ z: this.z
58
+ };
59
+ }
60
+ static fromJSON(t) {
61
+ return new X(t.x, t.y, t.z);
62
+ }
63
+ toString() {
64
+ return `Position(${this.x}, ${this.y}, ${this.z})`;
65
+ }
66
+ }, Q = class q {
67
+ constructor(t = new O(0, 15, 15), n = new O(0, 0, 0), i = 75, s = 0.1, r = 1e3) {
68
+ this.position = t, this.lookAtPosition = n, this.fov = i, this.near = s, this.far = r;
69
+ }
70
+ toJSON() {
71
+ return {
72
+ position: this.position.toJSON(),
73
+ lookAtPosition: this.lookAtPosition.toJSON(),
74
+ fov: this.fov,
75
+ near: this.near,
76
+ far: this.far
77
+ };
78
+ }
79
+ static fromJSON(t) {
80
+ return new q(O.fromJSON(t.position), O.fromJSON(t.lookAtPosition), t.fov, t.near, t.far);
81
+ }
82
+ toString() {
83
+ return `CameraOptions(position: ${this.position.toString()}, lookAt: ${this.lookAtPosition.toString()}, fov: ${this.fov}, near: ${this.near}, far: ${this.far})`;
84
+ }
85
+ }, V = class K {
86
+ constructor(t, n) {
87
+ if (this.x = t, this.y = n, !Number.isInteger(t) || !Number.isInteger(n)) throw new TypeError(`Position coordinates must be integers (got x=${t}, y=${n})`);
88
+ }
89
+ equals(t) {
90
+ return this.x === t.x && this.y === t.y;
91
+ }
92
+ toJSON() {
93
+ return {
94
+ x: this.x,
95
+ y: this.y
96
+ };
97
+ }
98
+ static fromJSON(t) {
99
+ return new K(t.x, t.y);
100
+ }
101
+ toString() {
102
+ return `Position(${this.x}, ${this.y})`;
103
+ }
104
+ };
105
+ function ht(e, t, n = 1 / 0) {
106
+ if (e.length === 0) return 0;
107
+ if (e.length === 1) return 1;
108
+ let i = 1;
109
+ for (let s = 0; s < e.length - 1; s++) {
110
+ const r = e[s], a = e[s + 1], o = gt(t, r, a);
111
+ o < n && (n = o, i = s + 1);
112
+ }
113
+ return i;
114
+ }
115
+ function gt(e, t, n) {
116
+ const i = n.x - t.x, s = n.y - t.y, r = i * i + s * s;
117
+ if (r === 0) return Math.sqrt((e.x - t.x) ** 2 + (e.y - t.y) ** 2);
118
+ const a = Math.max(0, Math.min(1, ((e.x - t.x) * i + (e.y - t.y) * s) / r)), o = t.x + a * i, c = t.y + a * s;
119
+ return Math.sqrt((e.x - o) ** 2 + (e.y - c) ** 2);
120
+ }
121
+ function M(e, t = 5) {
122
+ if (e.length <= 2) return [...e];
123
+ const n = [e[0]];
124
+ for (let i = 1; i < e.length - 1; i++) {
125
+ const s = n[n.length - 1], r = e[i], a = e[i + 1];
126
+ ft(s, r, a, t) || n.push(r);
127
+ }
128
+ return n.push(e[e.length - 1]), n;
129
+ }
130
+ function ft(e, t, n, i = 5) {
131
+ const s = (t.x - e.x) * (n.y - e.y) - (t.y - e.y) * (n.x - e.x);
132
+ return Math.abs(s) <= i;
133
+ }
134
+ var yt = class Y {
135
+ constructor(t) {
136
+ if (this.angle = t, !Number.isInteger(t)) throw new TypeError(`Rotation angle must be an integer (got ${t})`);
137
+ }
138
+ toJSON() {
139
+ return this.angle;
140
+ }
141
+ static fromJSON(t) {
142
+ return new Y(t);
143
+ }
144
+ equals(t) {
145
+ return this.angle === t.angle;
146
+ }
147
+ toString() {
148
+ return `Rotation(${this.angle}°)`;
149
+ }
150
+ };
151
+ function $() {
152
+ if (typeof crypto < "u" && crypto.randomUUID) return crypto.randomUUID();
153
+ const e = "0123456789abcdef", t = [
154
+ 8,
155
+ 4,
156
+ 4,
157
+ 4,
158
+ 12
159
+ ], n = [];
160
+ for (const s of t) {
161
+ let r = "";
162
+ for (let a = 0; a < s; a++) {
163
+ const o = Math.floor(Math.random() * 16);
164
+ r += e[o];
165
+ }
166
+ n.push(r);
167
+ }
168
+ const i = n.join("-").split("");
169
+ return i[14] = "4", i[19] = e[parseInt(i[19] ?? "0", 16) & 3 | 8] ?? "0", i.join("");
170
+ }
171
+ var Z = "0.0.11", g = /* @__PURE__ */ (function(e) {
172
+ return e.Voltage = "Voltage", e.Current = "Current", e;
173
+ })({}), P = /* @__PURE__ */ (function(e) {
174
+ return e.Pin = "Pin", e.BranchingPoint = "BranchingPoint", e;
175
+ })({}), we = [
176
+ "CMOS1",
177
+ "TTL1",
178
+ "Sandbox"
179
+ ], j = "CMOS1", u = /* @__PURE__ */ (function(e) {
180
+ return e.Cube = "cube", e.Label = "label", e.Battery = "battery", e.Switch = "switch", e.DoubleThrowSwitch = "doubleThrowSwitch", e.Lightbulb = "lightbulb", e.Relay = "relay", e.SmallLED = "smallLED", e.RectangleLED = "rectangleLED", e.Clock = "clock", e.Inverter = "inverter", e.NandGate = "nandGate", e.Nand4Gate = "nand4Gate", e.Nand8Gate = "nand8Gate", e.NorGate = "norGate", e.Nor4Gate = "nor4Gate", e.Nor8Gate = "nor8Gate", e.XorGate = "xorGate", e.Xor4Gate = "xor4Gate", e.Xor8Gate = "xor8Gate", e.HalfAdder = "halfAdder", e.Adder = "adder", e.EightBitAdder = "eightBitAdder", e.EightBitOnesComplement = "eightBitOnesComplement", e;
181
+ })({}), I = {
182
+ [u.Switch]: {
183
+ id: u.Switch,
184
+ pins: /* @__PURE__ */ new Map([["input", { subtype: "free" }], ["output", { subtype: "free" }]]),
185
+ config: /* @__PURE__ */ new Map([
186
+ ["initialState", "open"],
187
+ ["transitionSpan", "1"],
188
+ ["size", "1"]
189
+ ])
190
+ },
191
+ [u.DoubleThrowSwitch]: {
192
+ id: u.DoubleThrowSwitch,
193
+ pins: /* @__PURE__ */ new Map([
194
+ ["input1", { subtype: "free" }],
195
+ ["input2", { subtype: "free" }],
196
+ ["output", { subtype: "free" }]
197
+ ]),
198
+ config: /* @__PURE__ */ new Map([
199
+ ["initialState", "input1"],
200
+ ["transitionSpan", "1"],
201
+ ["size", "1"]
202
+ ])
203
+ },
204
+ [u.Battery]: {
205
+ id: u.Battery,
206
+ pins: /* @__PURE__ */ new Map([["cathode", {
207
+ subtype: "mainVcc",
208
+ sourceType: g.Voltage
209
+ }], ["anode", {
210
+ subtype: "mainGnd",
211
+ sourceType: g.Current
212
+ }]]),
213
+ config: /* @__PURE__ */ new Map([])
214
+ },
215
+ [u.Lightbulb]: {
216
+ id: u.Lightbulb,
217
+ pins: /* @__PURE__ */ new Map([["pin1", { subtype: "free" }], ["pin2", { subtype: "free" }]]),
218
+ config: /* @__PURE__ */ new Map([["transitionSpan", "1"], ["size", "1"]])
219
+ },
220
+ [u.Relay]: {
221
+ id: u.Relay,
222
+ pins: /* @__PURE__ */ new Map([
223
+ ["cmd_in", { subtype: "free" }],
224
+ ["cmd_out", { subtype: "free" }],
225
+ ["power_in", { subtype: "free" }],
226
+ ["power_out", { subtype: "free" }]
227
+ ]),
228
+ config: /* @__PURE__ */ new Map([
229
+ ["activationLogic", "positive"],
230
+ ["transitionSpan", "1"],
231
+ ["initializationOrder", ""]
232
+ ])
233
+ },
234
+ [u.SmallLED]: {
235
+ id: u.SmallLED,
236
+ pins: /* @__PURE__ */ new Map([["pin1", { subtype: "free" }], ["pin2", { subtype: "free" }]]),
237
+ config: /* @__PURE__ */ new Map([
238
+ ["transitionSpan", "1"],
239
+ ["idleColor", "white"],
240
+ ["activeColor", "#ffff00"],
241
+ ["size", "1"],
242
+ ["ywRatio", "1"]
243
+ ])
244
+ },
245
+ [u.RectangleLED]: {
246
+ id: u.RectangleLED,
247
+ pins: /* @__PURE__ */ new Map([["pin1", { subtype: "free" }], ["pin2", { subtype: "free" }]]),
248
+ config: /* @__PURE__ */ new Map([
249
+ ["transitionSpan", "1"],
250
+ ["idleColor", "white"],
251
+ ["activeColor", "#ffff00"],
252
+ ["size", "1"],
253
+ ["hwRatio", "1"],
254
+ ["ywRatio", "1"]
255
+ ])
256
+ },
257
+ [u.Cube]: {
258
+ id: u.Cube,
259
+ pins: /* @__PURE__ */ new Map([]),
260
+ config: /* @__PURE__ */ new Map([["color", "red"]])
261
+ },
262
+ [u.Label]: {
263
+ id: u.Label,
264
+ pins: /* @__PURE__ */ new Map([]),
265
+ config: /* @__PURE__ */ new Map([["text", "Label"], ["size", "1"]])
266
+ },
267
+ [u.Clock]: {
268
+ id: u.Clock,
269
+ pins: /* @__PURE__ */ new Map([
270
+ ["vcc", {
271
+ subtype: "vcc",
272
+ sourceType: g.Voltage
273
+ }],
274
+ ["output", {
275
+ subtype: "logicOutput",
276
+ logicPinData: {
277
+ interface: "output",
278
+ index: 0
279
+ }
280
+ }],
281
+ ["gnd", {
282
+ subtype: "gnd",
283
+ sourceType: g.Current
284
+ }]
285
+ ]),
286
+ config: /* @__PURE__ */ new Map([["startHigh", "true"], ["halfPeriod", "2"]])
287
+ },
288
+ [u.Inverter]: {
289
+ id: u.Inverter,
290
+ pins: /* @__PURE__ */ new Map([
291
+ ["vcc", {
292
+ subtype: "vcc",
293
+ sourceType: g.Voltage
294
+ }],
295
+ ["input", {
296
+ subtype: "logicInput",
297
+ logicPinData: {
298
+ interface: "input",
299
+ index: 0
300
+ }
301
+ }],
302
+ ["output", {
303
+ subtype: "logicOutput",
304
+ logicPinData: {
305
+ interface: "output",
306
+ index: 0
307
+ }
308
+ }],
309
+ ["gnd", {
310
+ subtype: "gnd",
311
+ sourceType: g.Current
312
+ }]
313
+ ]),
314
+ config: /* @__PURE__ */ new Map([
315
+ ["defaultLogicFamily", "CMOS1"],
316
+ ["activationLogic", "negative"],
317
+ ["transitionSpan", "1"],
318
+ ["initializationOrder", ""]
319
+ ])
320
+ },
321
+ [u.NandGate]: {
322
+ id: u.NandGate,
323
+ pins: /* @__PURE__ */ new Map([
324
+ ["vcc", {
325
+ subtype: "vcc",
326
+ sourceType: g.Voltage
327
+ }],
328
+ ["input1", {
329
+ subtype: "logicInput",
330
+ logicPinData: {
331
+ interface: "input",
332
+ index: 0
333
+ }
334
+ }],
335
+ ["input2", {
336
+ subtype: "logicInput",
337
+ logicPinData: {
338
+ interface: "input",
339
+ index: 1
340
+ }
341
+ }],
342
+ ["output", {
343
+ subtype: "logicOutput",
344
+ logicPinData: {
345
+ interface: "output",
346
+ index: 0
347
+ }
348
+ }],
349
+ ["gnd", {
350
+ subtype: "gnd",
351
+ sourceType: g.Current
352
+ }]
353
+ ]),
354
+ config: /* @__PURE__ */ new Map([
355
+ ["defaultLogicFamily", "CMOS1"],
356
+ ["activationLogic", "negative"],
357
+ ["transitionSpan", "1"],
358
+ ["initializationOrder", ""]
359
+ ])
360
+ },
361
+ [u.Nand4Gate]: {
362
+ id: u.Nand4Gate,
363
+ pins: /* @__PURE__ */ new Map([
364
+ ["vcc", {
365
+ subtype: "vcc",
366
+ sourceType: g.Voltage
367
+ }],
368
+ ["input1", {
369
+ subtype: "logicInput",
370
+ logicPinData: {
371
+ interface: "input",
372
+ index: 0
373
+ }
374
+ }],
375
+ ["input2", {
376
+ subtype: "logicInput",
377
+ logicPinData: {
378
+ interface: "input",
379
+ index: 1
380
+ }
381
+ }],
382
+ ["input3", {
383
+ subtype: "logicInput",
384
+ logicPinData: {
385
+ interface: "input",
386
+ index: 2
387
+ }
388
+ }],
389
+ ["input4", {
390
+ subtype: "logicInput",
391
+ logicPinData: {
392
+ interface: "input",
393
+ index: 3
394
+ }
395
+ }],
396
+ ["output", {
397
+ subtype: "logicOutput",
398
+ logicPinData: {
399
+ interface: "output",
400
+ index: 0
401
+ }
402
+ }],
403
+ ["gnd", {
404
+ subtype: "gnd",
405
+ sourceType: g.Current
406
+ }]
407
+ ]),
408
+ config: /* @__PURE__ */ new Map([
409
+ ["defaultLogicFamily", "CMOS1"],
410
+ ["activationLogic", "negative"],
411
+ ["transitionSpan", "2"],
412
+ ["initializationOrder", ""]
413
+ ])
414
+ },
415
+ [u.Nand8Gate]: {
416
+ id: u.Nand8Gate,
417
+ pins: /* @__PURE__ */ new Map([
418
+ ["vcc", {
419
+ subtype: "vcc",
420
+ sourceType: g.Voltage
421
+ }],
422
+ ["input1", {
423
+ subtype: "logicInput",
424
+ logicPinData: {
425
+ interface: "input",
426
+ index: 0
427
+ }
428
+ }],
429
+ ["input2", {
430
+ subtype: "logicInput",
431
+ logicPinData: {
432
+ interface: "input",
433
+ index: 1
434
+ }
435
+ }],
436
+ ["input3", {
437
+ subtype: "logicInput",
438
+ logicPinData: {
439
+ interface: "input",
440
+ index: 2
441
+ }
442
+ }],
443
+ ["input4", {
444
+ subtype: "logicInput",
445
+ logicPinData: {
446
+ interface: "input",
447
+ index: 3
448
+ }
449
+ }],
450
+ ["input5", {
451
+ subtype: "logicInput",
452
+ logicPinData: {
453
+ interface: "input",
454
+ index: 4
455
+ }
456
+ }],
457
+ ["input6", {
458
+ subtype: "logicInput",
459
+ logicPinData: {
460
+ interface: "input",
461
+ index: 5
462
+ }
463
+ }],
464
+ ["input7", {
465
+ subtype: "logicInput",
466
+ logicPinData: {
467
+ interface: "input",
468
+ index: 6
469
+ }
470
+ }],
471
+ ["input8", {
472
+ subtype: "logicInput",
473
+ logicPinData: {
474
+ interface: "input",
475
+ index: 7
476
+ }
477
+ }],
478
+ ["output", {
479
+ subtype: "logicOutput",
480
+ logicPinData: {
481
+ interface: "output",
482
+ index: 0
483
+ }
484
+ }],
485
+ ["gnd", {
486
+ subtype: "gnd",
487
+ sourceType: g.Current
488
+ }]
489
+ ]),
490
+ config: /* @__PURE__ */ new Map([
491
+ ["defaultLogicFamily", "CMOS1"],
492
+ ["activationLogic", "negative"],
493
+ ["transitionSpan", "3"],
494
+ ["initializationOrder", ""]
495
+ ])
496
+ },
497
+ [u.NorGate]: {
498
+ id: u.NorGate,
499
+ pins: /* @__PURE__ */ new Map([
500
+ ["vcc", {
501
+ subtype: "vcc",
502
+ sourceType: g.Voltage
503
+ }],
504
+ ["input1", {
505
+ subtype: "logicInput",
506
+ logicPinData: {
507
+ interface: "input",
508
+ index: 0
509
+ }
510
+ }],
511
+ ["input2", {
512
+ subtype: "logicInput",
513
+ logicPinData: {
514
+ interface: "input",
515
+ index: 1
516
+ }
517
+ }],
518
+ ["output", {
519
+ subtype: "logicOutput",
520
+ logicPinData: {
521
+ interface: "output",
522
+ index: 0
523
+ }
524
+ }],
525
+ ["gnd", {
526
+ subtype: "gnd",
527
+ sourceType: g.Current
528
+ }]
529
+ ]),
530
+ config: /* @__PURE__ */ new Map([
531
+ ["defaultLogicFamily", "CMOS1"],
532
+ ["activationLogic", "negative"],
533
+ ["transitionSpan", "1"],
534
+ ["initializationOrder", ""]
535
+ ])
536
+ },
537
+ [u.Nor4Gate]: {
538
+ id: u.Nor4Gate,
539
+ pins: /* @__PURE__ */ new Map([
540
+ ["vcc", {
541
+ subtype: "vcc",
542
+ sourceType: g.Voltage
543
+ }],
544
+ ["input1", {
545
+ subtype: "logicInput",
546
+ logicPinData: {
547
+ interface: "input",
548
+ index: 0
549
+ }
550
+ }],
551
+ ["input2", {
552
+ subtype: "logicInput",
553
+ logicPinData: {
554
+ interface: "input",
555
+ index: 1
556
+ }
557
+ }],
558
+ ["input3", {
559
+ subtype: "logicInput",
560
+ logicPinData: {
561
+ interface: "input",
562
+ index: 2
563
+ }
564
+ }],
565
+ ["input4", {
566
+ subtype: "logicInput",
567
+ logicPinData: {
568
+ interface: "input",
569
+ index: 3
570
+ }
571
+ }],
572
+ ["output", {
573
+ subtype: "logicOutput",
574
+ logicPinData: {
575
+ interface: "output",
576
+ index: 0
577
+ }
578
+ }],
579
+ ["gnd", {
580
+ subtype: "gnd",
581
+ sourceType: g.Current
582
+ }]
583
+ ]),
584
+ config: /* @__PURE__ */ new Map([
585
+ ["defaultLogicFamily", "CMOS1"],
586
+ ["activationLogic", "negative"],
587
+ ["transitionSpan", "2"],
588
+ ["initializationOrder", ""]
589
+ ])
590
+ },
591
+ [u.Nor8Gate]: {
592
+ id: u.Nor8Gate,
593
+ pins: /* @__PURE__ */ new Map([
594
+ ["vcc", {
595
+ subtype: "vcc",
596
+ sourceType: g.Voltage
597
+ }],
598
+ ["input1", {
599
+ subtype: "logicInput",
600
+ logicPinData: {
601
+ interface: "input",
602
+ index: 0
603
+ }
604
+ }],
605
+ ["input2", {
606
+ subtype: "logicInput",
607
+ logicPinData: {
608
+ interface: "input",
609
+ index: 1
610
+ }
611
+ }],
612
+ ["input3", {
613
+ subtype: "logicInput",
614
+ logicPinData: {
615
+ interface: "input",
616
+ index: 2
617
+ }
618
+ }],
619
+ ["input4", {
620
+ subtype: "logicInput",
621
+ logicPinData: {
622
+ interface: "input",
623
+ index: 3
624
+ }
625
+ }],
626
+ ["input5", {
627
+ subtype: "logicInput",
628
+ logicPinData: {
629
+ interface: "input",
630
+ index: 4
631
+ }
632
+ }],
633
+ ["input6", {
634
+ subtype: "logicInput",
635
+ logicPinData: {
636
+ interface: "input",
637
+ index: 5
638
+ }
639
+ }],
640
+ ["input7", {
641
+ subtype: "logicInput",
642
+ logicPinData: {
643
+ interface: "input",
644
+ index: 6
645
+ }
646
+ }],
647
+ ["input8", {
648
+ subtype: "logicInput",
649
+ logicPinData: {
650
+ interface: "input",
651
+ index: 7
652
+ }
653
+ }],
654
+ ["output", {
655
+ subtype: "logicOutput",
656
+ logicPinData: {
657
+ interface: "output",
658
+ index: 0
659
+ }
660
+ }],
661
+ ["gnd", {
662
+ subtype: "gnd",
663
+ sourceType: g.Current
664
+ }]
665
+ ]),
666
+ config: /* @__PURE__ */ new Map([
667
+ ["defaultLogicFamily", "CMOS1"],
668
+ ["activationLogic", "negative"],
669
+ ["transitionSpan", "3"],
670
+ ["initializationOrder", ""]
671
+ ])
672
+ },
673
+ [u.XorGate]: {
674
+ id: u.XorGate,
675
+ pins: /* @__PURE__ */ new Map([
676
+ ["vcc", {
677
+ subtype: "vcc",
678
+ sourceType: g.Voltage
679
+ }],
680
+ ["input1", {
681
+ subtype: "logicInput",
682
+ logicPinData: {
683
+ interface: "input",
684
+ index: 0
685
+ }
686
+ }],
687
+ ["input2", {
688
+ subtype: "logicInput",
689
+ logicPinData: {
690
+ interface: "input",
691
+ index: 1
692
+ }
693
+ }],
694
+ ["output", {
695
+ subtype: "logicOutput",
696
+ logicPinData: {
697
+ interface: "output",
698
+ index: 0
699
+ }
700
+ }],
701
+ ["gnd", {
702
+ subtype: "gnd",
703
+ sourceType: g.Current
704
+ }]
705
+ ]),
706
+ config: /* @__PURE__ */ new Map([
707
+ ["defaultLogicFamily", "CMOS1"],
708
+ ["activationLogic", "positive"],
709
+ ["transitionSpan", "2"],
710
+ ["initializationOrder", ""]
711
+ ])
712
+ },
713
+ [u.Xor4Gate]: {
714
+ id: u.Xor4Gate,
715
+ pins: /* @__PURE__ */ new Map([
716
+ ["vcc", {
717
+ subtype: "vcc",
718
+ sourceType: g.Voltage
719
+ }],
720
+ ["input1", {
721
+ subtype: "logicInput",
722
+ logicPinData: {
723
+ interface: "input",
724
+ index: 0
725
+ }
726
+ }],
727
+ ["input2", {
728
+ subtype: "logicInput",
729
+ logicPinData: {
730
+ interface: "input",
731
+ index: 1
732
+ }
733
+ }],
734
+ ["input3", {
735
+ subtype: "logicInput",
736
+ logicPinData: {
737
+ interface: "input",
738
+ index: 2
739
+ }
740
+ }],
741
+ ["input4", {
742
+ subtype: "logicInput",
743
+ logicPinData: {
744
+ interface: "input",
745
+ index: 3
746
+ }
747
+ }],
748
+ ["output", {
749
+ subtype: "logicOutput",
750
+ logicPinData: {
751
+ interface: "output",
752
+ index: 0
753
+ }
754
+ }],
755
+ ["gnd", {
756
+ subtype: "gnd",
757
+ sourceType: g.Current
758
+ }]
759
+ ]),
760
+ config: /* @__PURE__ */ new Map([
761
+ ["defaultLogicFamily", "CMOS1"],
762
+ ["activationLogic", "positive"],
763
+ ["transitionSpan", "4"],
764
+ ["initializationOrder", ""]
765
+ ])
766
+ },
767
+ [u.Xor8Gate]: {
768
+ id: u.Xor8Gate,
769
+ pins: /* @__PURE__ */ new Map([
770
+ ["vcc", {
771
+ subtype: "vcc",
772
+ sourceType: g.Voltage
773
+ }],
774
+ ["input1", {
775
+ subtype: "logicInput",
776
+ logicPinData: {
777
+ interface: "input",
778
+ index: 0
779
+ }
780
+ }],
781
+ ["input2", {
782
+ subtype: "logicInput",
783
+ logicPinData: {
784
+ interface: "input",
785
+ index: 1
786
+ }
787
+ }],
788
+ ["input3", {
789
+ subtype: "logicInput",
790
+ logicPinData: {
791
+ interface: "input",
792
+ index: 2
793
+ }
794
+ }],
795
+ ["input4", {
796
+ subtype: "logicInput",
797
+ logicPinData: {
798
+ interface: "input",
799
+ index: 3
800
+ }
801
+ }],
802
+ ["input5", {
803
+ subtype: "logicInput",
804
+ logicPinData: {
805
+ interface: "input",
806
+ index: 4
807
+ }
808
+ }],
809
+ ["input6", {
810
+ subtype: "logicInput",
811
+ logicPinData: {
812
+ interface: "input",
813
+ index: 5
814
+ }
815
+ }],
816
+ ["input7", {
817
+ subtype: "logicInput",
818
+ logicPinData: {
819
+ interface: "input",
820
+ index: 6
821
+ }
822
+ }],
823
+ ["input8", {
824
+ subtype: "logicInput",
825
+ logicPinData: {
826
+ interface: "input",
827
+ index: 7
828
+ }
829
+ }],
830
+ ["output", {
831
+ subtype: "logicOutput",
832
+ logicPinData: {
833
+ interface: "output",
834
+ index: 0
835
+ }
836
+ }],
837
+ ["gnd", {
838
+ subtype: "gnd",
839
+ sourceType: g.Current
840
+ }]
841
+ ]),
842
+ config: /* @__PURE__ */ new Map([
843
+ ["defaultLogicFamily", "CMOS1"],
844
+ ["activationLogic", "positive"],
845
+ ["transitionSpan", "6"],
846
+ ["initializationOrder", ""]
847
+ ])
848
+ },
849
+ [u.HalfAdder]: {
850
+ id: u.HalfAdder,
851
+ pins: /* @__PURE__ */ new Map([
852
+ ["vcc", {
853
+ subtype: "vcc",
854
+ sourceType: g.Voltage
855
+ }],
856
+ ["inputA", {
857
+ subtype: "logicInput",
858
+ logicPinData: {
859
+ interface: "input",
860
+ index: 0
861
+ }
862
+ }],
863
+ ["inputB", {
864
+ subtype: "logicInput",
865
+ logicPinData: {
866
+ interface: "input",
867
+ index: 1
868
+ }
869
+ }],
870
+ ["sum", {
871
+ subtype: "logicOutput",
872
+ logicPinData: {
873
+ interface: "sum",
874
+ index: 0
875
+ }
876
+ }],
877
+ ["carry", {
878
+ subtype: "logicOutput",
879
+ logicPinData: {
880
+ interface: "carry",
881
+ index: 0
882
+ }
883
+ }],
884
+ ["gnd", {
885
+ subtype: "gnd",
886
+ sourceType: g.Current
887
+ }]
888
+ ]),
889
+ config: /* @__PURE__ */ new Map([
890
+ ["defaultLogicFamily", "CMOS1"],
891
+ ["transitionSpan", "2"],
892
+ ["initializationOrder", ""]
893
+ ])
894
+ },
895
+ [u.Adder]: {
896
+ id: u.Adder,
897
+ pins: /* @__PURE__ */ new Map([
898
+ ["vcc", {
899
+ subtype: "vcc",
900
+ sourceType: g.Voltage
901
+ }],
902
+ ["carryIn", {
903
+ subtype: "logicInput",
904
+ logicPinData: {
905
+ interface: "carryIn",
906
+ index: 0
907
+ }
908
+ }],
909
+ ["inputA", {
910
+ subtype: "logicInput",
911
+ logicPinData: {
912
+ interface: "input",
913
+ index: 0
914
+ }
915
+ }],
916
+ ["inputB", {
917
+ subtype: "logicInput",
918
+ logicPinData: {
919
+ interface: "input",
920
+ index: 1
921
+ }
922
+ }],
923
+ ["sum", {
924
+ subtype: "logicOutput",
925
+ logicPinData: {
926
+ interface: "sum",
927
+ index: 0
928
+ }
929
+ }],
930
+ ["carryOut", {
931
+ subtype: "logicOutput",
932
+ logicPinData: {
933
+ interface: "carryOut",
934
+ index: 0
935
+ }
936
+ }],
937
+ ["gnd", {
938
+ subtype: "gnd",
939
+ sourceType: g.Current
940
+ }]
941
+ ]),
942
+ config: /* @__PURE__ */ new Map([
943
+ ["defaultLogicFamily", "CMOS1"],
944
+ ["transitionSpan", "4"],
945
+ ["initializationOrder", ""]
946
+ ])
947
+ },
948
+ [u.EightBitAdder]: {
949
+ id: u.EightBitAdder,
950
+ pins: /* @__PURE__ */ new Map([
951
+ ["vcc", {
952
+ subtype: "vcc",
953
+ sourceType: g.Voltage
954
+ }],
955
+ ["carryIn", {
956
+ subtype: "logicInput",
957
+ logicPinData: {
958
+ interface: "carryIn",
959
+ index: 0
960
+ }
961
+ }],
962
+ ["inputA-0", {
963
+ subtype: "logicInput",
964
+ logicPinData: {
965
+ interface: "inputA",
966
+ index: 0
967
+ }
968
+ }],
969
+ ["inputA-1", {
970
+ subtype: "logicInput",
971
+ logicPinData: {
972
+ interface: "inputA",
973
+ index: 1
974
+ }
975
+ }],
976
+ ["inputA-2", {
977
+ subtype: "logicInput",
978
+ logicPinData: {
979
+ interface: "inputA",
980
+ index: 2
981
+ }
982
+ }],
983
+ ["inputA-3", {
984
+ subtype: "logicInput",
985
+ logicPinData: {
986
+ interface: "inputA",
987
+ index: 3
988
+ }
989
+ }],
990
+ ["inputA-4", {
991
+ subtype: "logicInput",
992
+ logicPinData: {
993
+ interface: "inputA",
994
+ index: 4
995
+ }
996
+ }],
997
+ ["inputA-5", {
998
+ subtype: "logicInput",
999
+ logicPinData: {
1000
+ interface: "inputA",
1001
+ index: 5
1002
+ }
1003
+ }],
1004
+ ["inputA-6", {
1005
+ subtype: "logicInput",
1006
+ logicPinData: {
1007
+ interface: "inputA",
1008
+ index: 6
1009
+ }
1010
+ }],
1011
+ ["inputA-7", {
1012
+ subtype: "logicInput",
1013
+ logicPinData: {
1014
+ interface: "inputA",
1015
+ index: 7
1016
+ }
1017
+ }],
1018
+ ["inputB-0", {
1019
+ subtype: "logicInput",
1020
+ logicPinData: {
1021
+ interface: "inputB",
1022
+ index: 0
1023
+ }
1024
+ }],
1025
+ ["inputB-1", {
1026
+ subtype: "logicInput",
1027
+ logicPinData: {
1028
+ interface: "inputB",
1029
+ index: 1
1030
+ }
1031
+ }],
1032
+ ["inputB-2", {
1033
+ subtype: "logicInput",
1034
+ logicPinData: {
1035
+ interface: "inputB",
1036
+ index: 2
1037
+ }
1038
+ }],
1039
+ ["inputB-3", {
1040
+ subtype: "logicInput",
1041
+ logicPinData: {
1042
+ interface: "inputB",
1043
+ index: 3
1044
+ }
1045
+ }],
1046
+ ["inputB-4", {
1047
+ subtype: "logicInput",
1048
+ logicPinData: {
1049
+ interface: "inputB",
1050
+ index: 4
1051
+ }
1052
+ }],
1053
+ ["inputB-5", {
1054
+ subtype: "logicInput",
1055
+ logicPinData: {
1056
+ interface: "inputB",
1057
+ index: 5
1058
+ }
1059
+ }],
1060
+ ["inputB-6", {
1061
+ subtype: "logicInput",
1062
+ logicPinData: {
1063
+ interface: "inputB",
1064
+ index: 6
1065
+ }
1066
+ }],
1067
+ ["inputB-7", {
1068
+ subtype: "logicInput",
1069
+ logicPinData: {
1070
+ interface: "inputB",
1071
+ index: 7
1072
+ }
1073
+ }],
1074
+ ["sum-0", {
1075
+ subtype: "logicOutput",
1076
+ logicPinData: {
1077
+ interface: "sum",
1078
+ index: 0
1079
+ }
1080
+ }],
1081
+ ["sum-1", {
1082
+ subtype: "logicOutput",
1083
+ logicPinData: {
1084
+ interface: "sum",
1085
+ index: 1
1086
+ }
1087
+ }],
1088
+ ["sum-2", {
1089
+ subtype: "logicOutput",
1090
+ logicPinData: {
1091
+ interface: "sum",
1092
+ index: 2
1093
+ }
1094
+ }],
1095
+ ["sum-3", {
1096
+ subtype: "logicOutput",
1097
+ logicPinData: {
1098
+ interface: "sum",
1099
+ index: 3
1100
+ }
1101
+ }],
1102
+ ["sum-4", {
1103
+ subtype: "logicOutput",
1104
+ logicPinData: {
1105
+ interface: "sum",
1106
+ index: 4
1107
+ }
1108
+ }],
1109
+ ["sum-5", {
1110
+ subtype: "logicOutput",
1111
+ logicPinData: {
1112
+ interface: "sum",
1113
+ index: 5
1114
+ }
1115
+ }],
1116
+ ["sum-6", {
1117
+ subtype: "logicOutput",
1118
+ logicPinData: {
1119
+ interface: "sum",
1120
+ index: 6
1121
+ }
1122
+ }],
1123
+ ["sum-7", {
1124
+ subtype: "logicOutput",
1125
+ logicPinData: {
1126
+ interface: "sum",
1127
+ index: 7
1128
+ }
1129
+ }],
1130
+ ["carryOut", {
1131
+ subtype: "logicOutput",
1132
+ logicPinData: {
1133
+ interface: "carryOut",
1134
+ index: 0
1135
+ }
1136
+ }],
1137
+ ["gnd", {
1138
+ subtype: "gnd",
1139
+ sourceType: g.Current
1140
+ }]
1141
+ ]),
1142
+ config: /* @__PURE__ */ new Map([
1143
+ ["defaultLogicFamily", "CMOS1"],
1144
+ ["transitionSpan", "4"],
1145
+ ["initializationOrder", ""]
1146
+ ])
1147
+ },
1148
+ [u.EightBitOnesComplement]: {
1149
+ id: u.EightBitOnesComplement,
1150
+ pins: /* @__PURE__ */ new Map([
1151
+ ["vcc", {
1152
+ subtype: "vcc",
1153
+ sourceType: g.Voltage
1154
+ }],
1155
+ ["invert", {
1156
+ subtype: "logicInput",
1157
+ logicPinData: {
1158
+ interface: "invert",
1159
+ index: 0
1160
+ }
1161
+ }],
1162
+ ["input-0", {
1163
+ subtype: "logicInput",
1164
+ logicPinData: {
1165
+ interface: "input",
1166
+ index: 0
1167
+ }
1168
+ }],
1169
+ ["input-1", {
1170
+ subtype: "logicInput",
1171
+ logicPinData: {
1172
+ interface: "input",
1173
+ index: 1
1174
+ }
1175
+ }],
1176
+ ["input-2", {
1177
+ subtype: "logicInput",
1178
+ logicPinData: {
1179
+ interface: "input",
1180
+ index: 2
1181
+ }
1182
+ }],
1183
+ ["input-3", {
1184
+ subtype: "logicInput",
1185
+ logicPinData: {
1186
+ interface: "input",
1187
+ index: 3
1188
+ }
1189
+ }],
1190
+ ["input-4", {
1191
+ subtype: "logicInput",
1192
+ logicPinData: {
1193
+ interface: "input",
1194
+ index: 4
1195
+ }
1196
+ }],
1197
+ ["input-5", {
1198
+ subtype: "logicInput",
1199
+ logicPinData: {
1200
+ interface: "input",
1201
+ index: 5
1202
+ }
1203
+ }],
1204
+ ["input-6", {
1205
+ subtype: "logicInput",
1206
+ logicPinData: {
1207
+ interface: "input",
1208
+ index: 6
1209
+ }
1210
+ }],
1211
+ ["input-7", {
1212
+ subtype: "logicInput",
1213
+ logicPinData: {
1214
+ interface: "input",
1215
+ index: 7
1216
+ }
1217
+ }],
1218
+ ["output-0", {
1219
+ subtype: "logicOutput",
1220
+ logicPinData: {
1221
+ interface: "output",
1222
+ index: 0
1223
+ }
1224
+ }],
1225
+ ["output-1", {
1226
+ subtype: "logicOutput",
1227
+ logicPinData: {
1228
+ interface: "output",
1229
+ index: 1
1230
+ }
1231
+ }],
1232
+ ["output-2", {
1233
+ subtype: "logicOutput",
1234
+ logicPinData: {
1235
+ interface: "output",
1236
+ index: 2
1237
+ }
1238
+ }],
1239
+ ["output-3", {
1240
+ subtype: "logicOutput",
1241
+ logicPinData: {
1242
+ interface: "output",
1243
+ index: 3
1244
+ }
1245
+ }],
1246
+ ["output-4", {
1247
+ subtype: "logicOutput",
1248
+ logicPinData: {
1249
+ interface: "output",
1250
+ index: 4
1251
+ }
1252
+ }],
1253
+ ["output-5", {
1254
+ subtype: "logicOutput",
1255
+ logicPinData: {
1256
+ interface: "output",
1257
+ index: 5
1258
+ }
1259
+ }],
1260
+ ["output-6", {
1261
+ subtype: "logicOutput",
1262
+ logicPinData: {
1263
+ interface: "output",
1264
+ index: 6
1265
+ }
1266
+ }],
1267
+ ["output-7", {
1268
+ subtype: "logicOutput",
1269
+ logicPinData: {
1270
+ interface: "output",
1271
+ index: 7
1272
+ }
1273
+ }],
1274
+ ["gnd", {
1275
+ subtype: "gnd",
1276
+ sourceType: g.Current
1277
+ }]
1278
+ ]),
1279
+ config: /* @__PURE__ */ new Map([
1280
+ ["defaultLogicFamily", "CMOS1"],
1281
+ ["transitionSpan", "3"],
1282
+ ["initializationOrder", ""]
1283
+ ])
1284
+ }
1285
+ }, L = class tt {
1286
+ id;
1287
+ type;
1288
+ component;
1289
+ pinLabel;
1290
+ position;
1291
+ wires;
1292
+ source;
1293
+ subtype;
1294
+ constructor(t, n, i, s, r = void 0, a = "free") {
1295
+ this.id = $(), this.type = t, this.component = n, this.pinLabel = i, this.position = s, this.wires = /* @__PURE__ */ new Set(), this.source = r, this.subtype = a;
1296
+ }
1297
+ getPosition(t) {
1298
+ if (this.type === P.Pin) {
1299
+ if (!this.component) throw new Error("Pin node missing component reference");
1300
+ const n = t.getComponent(this.component);
1301
+ if (!n) throw new Error(`Component ${this.component} not found for pin node ${this.id}`);
1302
+ return n.position;
1303
+ }
1304
+ if (!this.position) throw new Error("Branching point node missing position");
1305
+ return this.position;
1306
+ }
1307
+ setPosition(t) {
1308
+ Object.defineProperty(this, "position", {
1309
+ value: t,
1310
+ writable: !1,
1311
+ enumerable: !0,
1312
+ configurable: !0
1313
+ });
1314
+ }
1315
+ setSourceType(t) {
1316
+ Object.defineProperty(this, "source", {
1317
+ value: t,
1318
+ writable: !0,
1319
+ enumerable: !0,
1320
+ configurable: !0
1321
+ });
1322
+ }
1323
+ toJSON() {
1324
+ const t = {
1325
+ id: this.id,
1326
+ type: this.type,
1327
+ source: this.source || null,
1328
+ subtype: this.subtype
1329
+ };
1330
+ return this.type === P.Pin ? (t.component = this.component || null, t.pinLabel = this.pinLabel || null) : t.position = this.position?.toJSON() || null, t;
1331
+ }
1332
+ static fromJSON(t) {
1333
+ const n = t.position ? V.fromJSON(t.position) : void 0, i = new tt(t.type, t.component || void 0, t.pinLabel || void 0, n, t.source || void 0, t.subtype ?? "free");
1334
+ return Object.defineProperty(i, "id", {
1335
+ value: t.id,
1336
+ writable: !1,
1337
+ enumerable: !0,
1338
+ configurable: !1
1339
+ }), i;
1340
+ }
1341
+ }, E = class et {
1342
+ id;
1343
+ node1;
1344
+ node2;
1345
+ intermediatePositions;
1346
+ constructor(t, n, i = []) {
1347
+ this.id = $(), this.node1 = t, this.node2 = n, this.intermediatePositions = i;
1348
+ }
1349
+ isStraightLine() {
1350
+ return this.intermediatePositions.length === 0;
1351
+ }
1352
+ toJSON() {
1353
+ return {
1354
+ id: this.id,
1355
+ node1: this.node1,
1356
+ node2: this.node2,
1357
+ intermediatePositions: this.intermediatePositions.map((t) => t.toJSON())
1358
+ };
1359
+ }
1360
+ static fromJSON(t) {
1361
+ const n = t.intermediatePositions.map((s) => V.fromJSON(s)), i = new et(t.node1, t.node2, n);
1362
+ return Object.defineProperty(i, "id", {
1363
+ value: t.id,
1364
+ writable: !1,
1365
+ enumerable: !0,
1366
+ configurable: !1
1367
+ }), i;
1368
+ }
1369
+ }, z = class it {
1370
+ id;
1371
+ type;
1372
+ position;
1373
+ rotation;
1374
+ pins;
1375
+ config;
1376
+ editable;
1377
+ constructor(t, n, i, s, r = !0) {
1378
+ if (this.id = $(), this.type = t, this.position = n, this.rotation = i, new Set(s).size !== s.length) {
1379
+ const a = s.filter((o, c) => s.indexOf(o) !== c);
1380
+ throw new Error(`Duplicate pin names are not allowed: ${[...new Set(a)].join(", ")}`);
1381
+ }
1382
+ this.pins = s, this.config = new Map(I[t].config), this.editable = r;
1383
+ }
1384
+ getPinLabel(t) {
1385
+ const n = this.pins.indexOf(t);
1386
+ if (n === -1) return;
1387
+ const i = I[this.type].pins.keys();
1388
+ return Array.from(i)[n] || void 0;
1389
+ }
1390
+ getPinMetadata(t) {
1391
+ const n = this.getPinLabel(t);
1392
+ if (n)
1393
+ return I[this.type].pins.get(n);
1394
+ }
1395
+ setAllParameters(t) {
1396
+ this.config = new Map(t);
1397
+ }
1398
+ setParameter(t, n) {
1399
+ this.config.set(t, n);
1400
+ }
1401
+ setPosition(t) {
1402
+ Object.defineProperty(this, "position", {
1403
+ value: t,
1404
+ writable: !1,
1405
+ enumerable: !0,
1406
+ configurable: !0
1407
+ });
1408
+ }
1409
+ setRotation(t) {
1410
+ Object.defineProperty(this, "rotation", {
1411
+ value: t,
1412
+ writable: !1,
1413
+ enumerable: !0,
1414
+ configurable: !0
1415
+ });
1416
+ }
1417
+ toJSON() {
1418
+ return {
1419
+ id: this.id,
1420
+ type: this.type,
1421
+ position: this.position.toJSON(),
1422
+ rotation: this.rotation.toJSON(),
1423
+ pins: [...this.pins],
1424
+ config: Object.fromEntries(this.config),
1425
+ editable: this.editable
1426
+ };
1427
+ }
1428
+ static fromJSON(t) {
1429
+ const n = new it(t.type, V.fromJSON(t.position), yt.fromJSON(t.rotation), t.pins, t.editable);
1430
+ return n.config = new Map(Object.entries(t.config)), Object.defineProperty(n, "id", {
1431
+ value: t.id,
1432
+ writable: !1,
1433
+ enumerable: !0,
1434
+ configurable: !1
1435
+ }), n;
1436
+ }
1437
+ }, H = class nt {
1438
+ constructor(t = "Untitled Circuit", n = j) {
1439
+ this.name = t, this.defaultLogicFamily = n;
1440
+ }
1441
+ toJSON() {
1442
+ return {
1443
+ name: this.name,
1444
+ defaultLogicFamily: this.defaultLogicFamily
1445
+ };
1446
+ }
1447
+ static fromJSON(t) {
1448
+ return new nt(t.name, t.defaultLogicFamily);
1449
+ }
1450
+ }, F = class st {
1451
+ constructor(t, n, i, s, r) {
1452
+ if (this.version = t, this.options = n, this.size = i, this.divisions = s, this.cameraOptions = r, !Number.isInteger(i) || !Number.isInteger(s)) throw new TypeError(`Size and divisions must be integers (got size=${i}, divisions=${s})`);
1453
+ }
1454
+ toJSON() {
1455
+ return {
1456
+ version: this.version,
1457
+ options: this.options.toJSON(),
1458
+ size: this.size,
1459
+ divisions: this.divisions,
1460
+ cameraOptions: this.cameraOptions.toJSON()
1461
+ };
1462
+ }
1463
+ static fromJSON(t) {
1464
+ t.version !== "0.0.11" && console.warn(`This version of the engine supports v${Z} circuit version files.
1465
+ Unexpected behavior may occurs loading v${t.version}.`);
1466
+ const n = t.options ? H.fromJSON(t.options) : new H("Untitled Circuit", j);
1467
+ return new st(t.version, n, t.size, t.divisions, Q.fromJSON(t.cameraOptions));
1468
+ }
1469
+ toString() {
1470
+ return `CircuitMetadata(${this.version}, ${this.options.name}, ${this.options.defaultLogicFamily}, ${this.size}, ${this.divisions}, ${this.cameraOptions.toString()})`;
1471
+ }
1472
+ }, vt = {
1473
+ 2: 1,
1474
+ 4: 1,
1475
+ 8: 2,
1476
+ 16: 2
1477
+ }, St = {
1478
+ 2: 2,
1479
+ 4: 2,
1480
+ 8: 3,
1481
+ 16: 3
1482
+ }, wt = {
1483
+ 2: 1,
1484
+ 4: 2,
1485
+ 8: 2,
1486
+ 16: 3
1487
+ }, mt = {
1488
+ 2: 2,
1489
+ 4: 3,
1490
+ 8: 3,
1491
+ 16: 4
1492
+ };
1493
+ function bt(e) {
1494
+ const t = e.config.get("defaultLogicFamily");
1495
+ if (!(!t || t === "Sandbox") && Ct(e.type)) {
1496
+ const n = e.config.get("activationLogic") ?? "negative", i = Pt(e.type, n);
1497
+ return i && xt(t, i.gateFamily, i.inputCount) || void 0;
1498
+ }
1499
+ }
1500
+ function Ct(e) {
1501
+ return [
1502
+ u.Inverter,
1503
+ u.NandGate,
1504
+ u.Nand4Gate,
1505
+ u.Nand8Gate,
1506
+ u.NorGate,
1507
+ u.Nor4Gate,
1508
+ u.Nor8Gate,
1509
+ u.XorGate,
1510
+ u.Xor4Gate,
1511
+ u.Xor8Gate
1512
+ ].includes(e);
1513
+ }
1514
+ function Pt(e, t) {
1515
+ switch (e) {
1516
+ case u.Inverter:
1517
+ return {
1518
+ gateFamily: t === "negative" ? "NOT" : "Buffer",
1519
+ inputCount: 1
1520
+ };
1521
+ case u.NandGate:
1522
+ return {
1523
+ gateFamily: t === "negative" ? "NAND" : "AND",
1524
+ inputCount: 2
1525
+ };
1526
+ case u.Nand4Gate:
1527
+ return {
1528
+ gateFamily: t === "negative" ? "NAND" : "AND",
1529
+ inputCount: 4
1530
+ };
1531
+ case u.Nand8Gate:
1532
+ return {
1533
+ gateFamily: t === "negative" ? "NAND" : "AND",
1534
+ inputCount: 8
1535
+ };
1536
+ case u.NorGate:
1537
+ return {
1538
+ gateFamily: t === "negative" ? "NOR" : "OR",
1539
+ inputCount: 2
1540
+ };
1541
+ case u.Nor4Gate:
1542
+ return {
1543
+ gateFamily: t === "negative" ? "NOR" : "OR",
1544
+ inputCount: 4
1545
+ };
1546
+ case u.Nor8Gate:
1547
+ return {
1548
+ gateFamily: t === "negative" ? "NOR" : "OR",
1549
+ inputCount: 8
1550
+ };
1551
+ case u.XorGate:
1552
+ return {
1553
+ gateFamily: t === "negative" ? "XNOR" : "XOR",
1554
+ inputCount: 2
1555
+ };
1556
+ case u.Xor4Gate:
1557
+ return {
1558
+ gateFamily: t === "negative" ? "XNOR" : "XOR",
1559
+ inputCount: 4
1560
+ };
1561
+ case u.Xor8Gate:
1562
+ return {
1563
+ gateFamily: t === "negative" ? "XNOR" : "XOR",
1564
+ inputCount: 8
1565
+ };
1566
+ default:
1567
+ return null;
1568
+ }
1569
+ }
1570
+ function xt(e, t, n) {
1571
+ if (e === "Sandbox") throw new Error("computeGateDelay must not be called for Sandbox family");
1572
+ if (t === "NOT") return 1;
1573
+ if (t === "Buffer") return 2;
1574
+ if (t === "XOR") return Math.log2(n) * 2;
1575
+ if (t === "XNOR") return Math.log2(n) * 2 + 1;
1576
+ if (e === "CMOS1") {
1577
+ const i = Math.log2(n);
1578
+ switch (t) {
1579
+ case "NAND":
1580
+ return i;
1581
+ case "NOR":
1582
+ return i;
1583
+ case "AND":
1584
+ return i + 1;
1585
+ case "OR":
1586
+ return i + 1;
1587
+ }
1588
+ }
1589
+ if (e === "TTL1") {
1590
+ let i;
1591
+ switch (t) {
1592
+ case "NAND":
1593
+ i = vt;
1594
+ break;
1595
+ case "AND":
1596
+ i = St;
1597
+ break;
1598
+ case "NOR":
1599
+ i = wt;
1600
+ break;
1601
+ case "OR":
1602
+ i = mt;
1603
+ break;
1604
+ }
1605
+ const s = i[n];
1606
+ if (s === void 0) throw new Error(`Unsupported input count ${n} for TTL1 ${t}`);
1607
+ return s;
1608
+ }
1609
+ throw new Error(`Unsupported logic family: ${e}`);
1610
+ }
1611
+ var me = class rt {
1612
+ metadata;
1613
+ components;
1614
+ enodes;
1615
+ wires;
1616
+ constructor(t) {
1617
+ this.metadata = new F(Z, t, 10, 10, new Q()), this.components = /* @__PURE__ */ new Map(), this.enodes = /* @__PURE__ */ new Map(), this.wires = /* @__PURE__ */ new Map();
1618
+ }
1619
+ get name() {
1620
+ return this.metadata.options.name;
1621
+ }
1622
+ set name(t) {
1623
+ if (typeof t != "string" || t.trim() === "") throw new TypeError("Circuit name must be a non-empty string");
1624
+ this.metadata.options.name = t;
1625
+ }
1626
+ addComponent(t, n, i, s) {
1627
+ const r = I[t], a = new z(t, n, i, []);
1628
+ if (s) for (const [c, p] of s) a.config.set(c, p);
1629
+ a.config.has("defaultLogicFamily") && !a.config.get("defaultLogicFamily") && a.config.set("defaultLogicFamily", this.metadata.options.defaultLogicFamily), this.resolveTransitionSpan(a);
1630
+ const o = [];
1631
+ for (const [c, p] of r.pins) {
1632
+ const l = new L(P.Pin, a.id, c, void 0, p.sourceType, p.subtype);
1633
+ this.enodes.set(l.id, l), o.push(l.id);
1634
+ }
1635
+ return Object.defineProperty(a, "pins", {
1636
+ value: o,
1637
+ writable: !1,
1638
+ enumerable: !0,
1639
+ configurable: !1
1640
+ }), this.components.set(a.id, a), a;
1641
+ }
1642
+ resolveTransitionSpan(t) {
1643
+ if (!t.config.has("transitionSpan")) return;
1644
+ const n = bt(t);
1645
+ n && t.config.set("transitionSpan", String(n));
1646
+ }
1647
+ removeComponent(t) {
1648
+ const n = this.components.get(t);
1649
+ if (!n) throw new Error(`Component ${t} does not exist`);
1650
+ const i = [], s = [];
1651
+ for (const r of n.pins) {
1652
+ const a = this.enodes.get(r);
1653
+ if (a) {
1654
+ const o = Array.from(a.wires);
1655
+ for (const c of o)
1656
+ this.removeWire(c), i.push(c);
1657
+ }
1658
+ this.enodes.delete(r), s.push(r);
1659
+ }
1660
+ return this.components.delete(t), {
1661
+ deletedWires: i,
1662
+ deletedENodes: s
1663
+ };
1664
+ }
1665
+ hasComponent(t) {
1666
+ return this.components.has(t);
1667
+ }
1668
+ getComponent(t) {
1669
+ return this.components.get(t);
1670
+ }
1671
+ getAllComponents() {
1672
+ return Array.from(this.components.values());
1673
+ }
1674
+ getAllComponentsByType(t) {
1675
+ const n = [];
1676
+ for (const i of this.components.values()) i.type === t && n.push(i);
1677
+ return n;
1678
+ }
1679
+ getFirstComponentOfType(t) {
1680
+ for (const n of this.components.values()) if (n.type === t) return n;
1681
+ }
1682
+ getENode(t) {
1683
+ return this.enodes.get(t);
1684
+ }
1685
+ getAllENodes() {
1686
+ return Array.from(this.enodes.values());
1687
+ }
1688
+ addBranchingPoint(t, n) {
1689
+ const i = new L(P.BranchingPoint, void 0, void 0, t, n);
1690
+ return this.enodes.set(i.id, i), i;
1691
+ }
1692
+ removeBranchingPoint(t) {
1693
+ const n = this.enodes.get(t);
1694
+ if (!n) throw new Error(`Enode ${t} does not exist`);
1695
+ if (n.type !== P.BranchingPoint) throw new Error(`Enode ${t} is not a branching point, it must be removed with its component.`);
1696
+ const i = {}, s = this.getWiresByNode(t);
1697
+ if (s.length === 1 || s.length > 2) {
1698
+ const r = [];
1699
+ for (const a of s)
1700
+ this.removeWire(a.id), r.push(a.id);
1701
+ Object.assign(i, { deletedWires: r });
1702
+ } else if (s.length === 2) {
1703
+ const r = s[0], a = s[1], o = r.node1 === t ? r.node2 : r.node1, c = a.node1 === t ? a.node2 : a.node1, p = [];
1704
+ o === r.node1 ? p.push(...r.intermediatePositions) : o === r.node2 && p.push(...[...r.intermediatePositions].reverse()), p.push(n.getPosition(this)), c === a.node1 ? p.push(...[...a.intermediatePositions].reverse()) : c === a.node2 && p.push(...a.intermediatePositions), this.removeWire(r.id), this.removeWire(a.id);
1705
+ const l = this.addWire(o, c, p);
1706
+ if (l instanceof Error) throw new Error(`Failed to merge wires at branching point ${t}: ${l.message}`);
1707
+ Object.assign(i, { mergedWires: [r.id, a.id] }), Object.assign(i, { newWire: l });
1708
+ }
1709
+ return this.enodes.delete(t), i;
1710
+ }
1711
+ addWire(t, n, i) {
1712
+ if (t === n) return /* @__PURE__ */ new Error("Cannot create wire connecting node to itself");
1713
+ const s = this.enodes.get(t), r = this.enodes.get(n);
1714
+ if (!s || !r) return /* @__PURE__ */ new Error("Wire requires at least one existing ENode");
1715
+ if (this.hasWireBetween(t, n)) return /* @__PURE__ */ new Error("Duplicate wire between same nodes");
1716
+ const a = new E(t, n, i || []);
1717
+ return this.wires.set(a.id, a), s.wires.add(a.id), r.wires.add(a.id), a;
1718
+ }
1719
+ removeWire(t) {
1720
+ const n = this.wires.get(t);
1721
+ if (!n) throw new Error(`Wire ${t} does not exist`);
1722
+ const i = this.enodes.get(n.node1), s = this.enodes.get(n.node2);
1723
+ i && i.wires.delete(t), s && s.wires.delete(t), this.wires.delete(t);
1724
+ }
1725
+ splitWire(t, n, i = null) {
1726
+ const s = this.wires.get(t);
1727
+ if (!s) throw new Error(`Wire ${t} does not exist`);
1728
+ const r = this.enodes.get(s.node1), a = this.enodes.get(s.node2);
1729
+ if (!r || !a) throw new Error(`Wire ${t} is connected to non-existent ENodes`);
1730
+ const o = [
1731
+ r.getPosition(this),
1732
+ ...s.intermediatePositions,
1733
+ a.getPosition(this)
1734
+ ], c = ht(o, n), p = o.slice(1, c), l = o.slice(c, o.length - 1);
1735
+ this.wires.delete(t), r.wires.delete(t), a.wires.delete(t);
1736
+ let d;
1737
+ if (i) if (this.enodes.get(i)) d = this.enodes.get(i);
1738
+ else throw new Error(`Target ENode ${i} does not exist`);
1739
+ else d = this.addBranchingPoint(n);
1740
+ const y = [];
1741
+ if ((!d.component || r.component !== d.component) && !this.hasWireBetween(r.id, d.id)) {
1742
+ const f = this.addWire(r.id, d.id, p);
1743
+ f instanceof E ? (this.simplifyWireIntermediatePositions(f.id), y.push(f)) : console.warn(`Failure to create wire at split : ${f.message}`);
1744
+ }
1745
+ if ((!d.component || a.component !== d.component) && !this.hasWireBetween(a.id, d.id)) {
1746
+ const f = this.addWire(d.id, a.id, l);
1747
+ f instanceof E ? (this.simplifyWireIntermediatePositions(f.id), y.push(f)) : console.warn(`Failure to create wire at split : ${f.message}`);
1748
+ }
1749
+ return {
1750
+ branchingPoint: d,
1751
+ wires: y
1752
+ };
1753
+ }
1754
+ getWireBetweenNodes(t, n) {
1755
+ const i = this.enodes.get(t);
1756
+ if (i)
1757
+ for (const s of i.wires) {
1758
+ const r = this.wires.get(s);
1759
+ if (r && (r.node2 === n || r.node1 === n)) return r;
1760
+ }
1761
+ }
1762
+ getWire(t) {
1763
+ return this.wires.get(t);
1764
+ }
1765
+ getAllWires() {
1766
+ return Array.from(this.wires.values());
1767
+ }
1768
+ getWiresByNode(t) {
1769
+ const n = this.enodes.get(t);
1770
+ if (!n) return [];
1771
+ const i = [];
1772
+ for (const s of n.wires) {
1773
+ const r = this.wires.get(s);
1774
+ r && i.push(r);
1775
+ }
1776
+ return i;
1777
+ }
1778
+ getWiresByComponent(t) {
1779
+ const n = this.components.get(t);
1780
+ if (!n) return [];
1781
+ const i = [];
1782
+ for (const s of n.pins) i.push(...this.getWiresByNode(s));
1783
+ return i;
1784
+ }
1785
+ getNodesByWire(t) {
1786
+ const n = this.wires.get(t);
1787
+ if (!n) return;
1788
+ const i = this.enodes.get(n.node1), s = this.enodes.get(n.node2);
1789
+ if (!(!i || !s))
1790
+ return [i, s];
1791
+ }
1792
+ hasWireBetween(t, n) {
1793
+ const i = this.enodes.get(t);
1794
+ if (!i) return !1;
1795
+ for (const s of i.wires) {
1796
+ const r = this.wires.get(s);
1797
+ if (r && (r.node2 === n || r.node1 === n)) return !0;
1798
+ }
1799
+ return !1;
1800
+ }
1801
+ getComponentsOfPins(t) {
1802
+ const n = /* @__PURE__ */ new Set();
1803
+ for (const i of t) {
1804
+ const s = this.enodes.get(i);
1805
+ s?.component && n.add(s.component);
1806
+ }
1807
+ return n;
1808
+ }
1809
+ getComponentPinByLabel(t, n) {
1810
+ let i = 0;
1811
+ const s = I[t.type], r = Array.from(s.pins.keys());
1812
+ for (const a of t.pins) {
1813
+ const o = this.enodes.get(a), c = r[i];
1814
+ if (c) {
1815
+ if (o && c === n) return o;
1816
+ i++;
1817
+ }
1818
+ }
1819
+ }
1820
+ updateWireIntermediatePositions(t, n, i = !1) {
1821
+ const s = this.wires.get(t);
1822
+ if (!s) throw new Error(`Wire ${t} does not exist`);
1823
+ if (i) {
1824
+ const r = M([
1825
+ this.enodes.get(s.node1).getPosition(this),
1826
+ ...n,
1827
+ this.enodes.get(s.node2).getPosition(this)
1828
+ ], 10);
1829
+ s.intermediatePositions = r.slice(1, r.length - 1);
1830
+ } else s.intermediatePositions = n;
1831
+ return s;
1832
+ }
1833
+ simplifyWireIntermediatePositions(t) {
1834
+ const n = this.wires.get(t);
1835
+ if (!n) throw new Error(`Wire ${t} does not exist`);
1836
+ const i = M([
1837
+ this.enodes.get(n.node1).getPosition(this),
1838
+ ...n.intermediatePositions,
1839
+ this.enodes.get(n.node2).getPosition(this)
1840
+ ], 5);
1841
+ return n.intermediatePositions = i.slice(1, i.length - 1), n.intermediatePositions = M(n.intermediatePositions), n;
1842
+ }
1843
+ updateENodeSourceType(t, n) {
1844
+ const i = this.enodes.get(t);
1845
+ if (!i) throw new Error(`ENode ${t} does not exist`);
1846
+ i.source = n || void 0;
1847
+ }
1848
+ getEnclosingSize(t = 0) {
1849
+ let n = 0;
1850
+ for (const i of this.components.values()) n = Math.max(n, Math.abs(i.position.x), Math.abs(i.position.y));
1851
+ for (const i of this.enodes.values()) {
1852
+ if (i.type === P.Pin) continue;
1853
+ const s = i.position;
1854
+ s && (n = Math.max(n, Math.abs(s.x), Math.abs(s.y)));
1855
+ }
1856
+ for (const i of this.wires.values()) for (const s of i.intermediatePositions) n = Math.max(n, Math.abs(s.x), Math.abs(s.y));
1857
+ return Math.ceil(n * 2 + Math.max(t, 0));
1858
+ }
1859
+ toJSON() {
1860
+ return {
1861
+ metadata: this.metadata.toJSON(),
1862
+ components: this.getAllComponents().map((t) => t.toJSON()),
1863
+ enodes: this.getAllENodes().map((t) => t.toJSON()),
1864
+ wires: this.getAllWires().map((t) => t.toJSON())
1865
+ };
1866
+ }
1867
+ static fromJSON(t) {
1868
+ const n = F.fromJSON(t.metadata), i = new rt(n.options);
1869
+ i.metadata = n;
1870
+ for (const s of t.components) {
1871
+ const r = z.fromJSON(s);
1872
+ i.components.set(r.id, r);
1873
+ }
1874
+ for (const s of t.enodes) {
1875
+ const r = L.fromJSON(s);
1876
+ i.enodes.set(r.id, r);
1877
+ }
1878
+ if (t.wires) for (const s of t.wires) {
1879
+ const r = E.fromJSON(s);
1880
+ i.wires.set(r.id, r);
1881
+ const a = i.enodes.get(r.node1), o = i.enodes.get(r.node2);
1882
+ a && a.wires.add(r.id), o && o.wires.add(r.id);
1883
+ }
1884
+ return i;
1885
+ }
1886
+ }, be = {
1887
+ MIN_TPS: 1,
1888
+ MAX_TPS: 100,
1889
+ DEFAULT_TPS: 3,
1890
+ DEFAULT_INTERVAL_MS: 500
1891
+ }, at = {
1892
+ TRANSITION_SPAN_TICKS: 1,
1893
+ TRANSITION_USER_SPAN_MS: 200
1894
+ };
1895
+ function T(...e) {
1896
+ return {
1897
+ hasVoltage: e.some((t) => t.hasVoltage),
1898
+ hasCurrent: e.some((t) => t.hasCurrent),
1899
+ locked: !1
1900
+ };
1901
+ }
1902
+ var J = class ot {
1903
+ tick;
1904
+ nodeStates;
1905
+ wireStates;
1906
+ componentStates;
1907
+ constructor(t) {
1908
+ if (t < 0 || !Number.isInteger(t)) throw new RangeError(`Tick must be a non-negative integer (got ${t})`);
1909
+ this.tick = t, this.nodeStates = /* @__PURE__ */ new Map(), this.wireStates = /* @__PURE__ */ new Map(), this.componentStates = /* @__PURE__ */ new Map();
1910
+ }
1911
+ setTick(t) {
1912
+ this.tick = t;
1913
+ }
1914
+ clone() {
1915
+ const t = new ot(this.tick), n = /* @__PURE__ */ new Map();
1916
+ for (const [r, a] of this.nodeStates.entries()) n.set(r, { ...a });
1917
+ const i = /* @__PURE__ */ new Map();
1918
+ for (const [r, a] of this.wireStates.entries()) i.set(r, { ...a });
1919
+ const s = /* @__PURE__ */ new Map();
1920
+ for (const [r, a] of this.componentStates.entries()) s.set(r, Object.assign(Object.create(Object.getPrototypeOf(a)), a));
1921
+ return Object.defineProperty(t, "nodeStates", {
1922
+ value: n,
1923
+ writable: !1,
1924
+ configurable: !1,
1925
+ enumerable: !0
1926
+ }), Object.defineProperty(t, "wireStates", {
1927
+ value: i,
1928
+ writable: !1,
1929
+ configurable: !1,
1930
+ enumerable: !0
1931
+ }), Object.defineProperty(t, "componentStates", {
1932
+ value: s,
1933
+ writable: !1,
1934
+ configurable: !1,
1935
+ enumerable: !0
1936
+ }), t;
1937
+ }
1938
+ }, b = class {
1939
+ componentId;
1940
+ _state;
1941
+ _startTick;
1942
+ _expirationTick;
1943
+ _nextState;
1944
+ parameters = /* @__PURE__ */ new Map();
1945
+ pinStates = /* @__PURE__ */ new Map();
1946
+ constructor(e, t) {
1947
+ this.componentId = e, this._state = t, this._startTick = 0, this._expirationTick = -1, this._nextState = null;
1948
+ }
1949
+ get state() {
1950
+ return this._state;
1951
+ }
1952
+ setState(e, t) {
1953
+ this._state = e, this._startTick = t, this._expirationTick = -1, this._nextState = null;
1954
+ }
1955
+ get startTick() {
1956
+ return this._startTick;
1957
+ }
1958
+ get expirationTick() {
1959
+ return this._expirationTick;
1960
+ }
1961
+ get nextState() {
1962
+ return this._nextState;
1963
+ }
1964
+ get hasExpiration() {
1965
+ return this._expirationTick >= 0 && !!this._nextState && this._nextState !== this.state;
1966
+ }
1967
+ setNextState(e, t) {
1968
+ this._nextState = e, this._expirationTick = t;
1969
+ }
1970
+ }, It = class extends b {
1971
+ constructor(e) {
1972
+ super(e, "on");
1973
+ }
1974
+ }, Tt = class extends b {
1975
+ constructor(e, t = "off") {
1976
+ super(e, t);
1977
+ }
1978
+ get isLit() {
1979
+ return this.state === "on" || this.state === "goingOn";
1980
+ }
1981
+ }, ct = class extends b {
1982
+ constructor(e, t = "off") {
1983
+ super(e, t);
1984
+ }
1985
+ get isLit() {
1986
+ return this.state === "on" || this.state === "goingOn";
1987
+ }
1988
+ }, Ot = class extends ct {
1989
+ }, Et = class extends b {
1990
+ constructor(e, t = "open") {
1991
+ super(e, t);
1992
+ }
1993
+ get isInTransition() {
1994
+ return this.state === "closing" || this.state === "opening";
1995
+ }
1996
+ get isClosed() {
1997
+ return this.state === "closed" || this.state === "closing";
1998
+ }
1999
+ }, Nt = class extends b {
2000
+ constructor(e, t = "open") {
2001
+ super(e, t);
2002
+ }
2003
+ get isInTransition() {
2004
+ return this.state === "closing" || this.state === "opening";
2005
+ }
2006
+ get isClosed() {
2007
+ return this.state === "closed" || this.state === "closing";
2008
+ }
2009
+ }, At = class extends b {
2010
+ constructor(e, t = "input1") {
2011
+ super(e, t);
2012
+ }
2013
+ get isInTransition() {
2014
+ return this.state === "1to2" || this.state === "2to1";
2015
+ }
2016
+ }, Bt = class extends b {
2017
+ constructor(e) {
2018
+ super(e, "high");
2019
+ }
2020
+ }, w = class extends b {
2021
+ constructor(e, t = "low") {
2022
+ super(e, t);
2023
+ }
2024
+ get isInTransition() {
2025
+ return this.state === "rising" || this.state === "falling";
2026
+ }
2027
+ get isHigh() {
2028
+ return this.state === "high";
2029
+ }
2030
+ }, Dt = class extends w {
2031
+ constructor(e, t = "low") {
2032
+ super(e, t);
2033
+ }
2034
+ }, Mt = class extends w {
2035
+ constructor(e, t = "low") {
2036
+ super(e, t);
2037
+ }
2038
+ }, Lt = class extends w {
2039
+ constructor(e, t = "low") {
2040
+ super(e, t);
2041
+ }
2042
+ }, kt = class extends w {
2043
+ constructor(e, t = "low") {
2044
+ super(e, t);
2045
+ }
2046
+ }, Gt = class extends w {
2047
+ constructor(e, t = "low") {
2048
+ super(e, t);
2049
+ }
2050
+ }, _t = class extends w {
2051
+ constructor(e, t = "low") {
2052
+ super(e, t);
2053
+ }
2054
+ }, Vt = class extends w {
2055
+ constructor(e, t = "low") {
2056
+ super(e, t);
2057
+ }
2058
+ }, $t = class extends w {
2059
+ constructor(e, t = "low") {
2060
+ super(e, t);
2061
+ }
2062
+ }, Rt = class extends w {
2063
+ constructor(e, t = "low") {
2064
+ super(e, t);
2065
+ }
2066
+ }, Wt = class extends w {
2067
+ constructor(e, t = "low") {
2068
+ super(e, t);
2069
+ }
2070
+ }, A = class extends b {
2071
+ outputCount;
2072
+ hexDigitCount;
2073
+ allLowState;
2074
+ constructor(e, t, n) {
2075
+ super(e, n), this.outputCount = t, this.hexDigitCount = Math.ceil(t / 4), this.allLowState = "0".repeat(this.hexDigitCount);
2076
+ }
2077
+ get isInTransition() {
2078
+ return this.state.startsWith("to");
2079
+ }
2080
+ get effectiveState() {
2081
+ return this.isInTransition ? this.parameters.get("prevState") ?? this.allLowState : this.state;
2082
+ }
2083
+ isOutputHigh(e) {
2084
+ const t = this.effectiveState;
2085
+ return t === "indeterminate" ? !1 : (parseInt(t, 16) >> e & 1) === 1;
2086
+ }
2087
+ }, zt = class extends A {
2088
+ constructor(e, t = "0") {
2089
+ super(e, 2, t);
2090
+ }
2091
+ get sumHigh() {
2092
+ return this.isOutputHigh(0);
2093
+ }
2094
+ get carryHigh() {
2095
+ return this.isOutputHigh(1);
2096
+ }
2097
+ }, Ht = class extends A {
2098
+ constructor(e, t = "0") {
2099
+ super(e, 2, t);
2100
+ }
2101
+ get sumHigh() {
2102
+ return this.isOutputHigh(0);
2103
+ }
2104
+ get carryOutHigh() {
2105
+ return this.isOutputHigh(1);
2106
+ }
2107
+ }, Ft = class extends A {
2108
+ constructor(e, t = "0000") {
2109
+ super(e, 16, t);
2110
+ }
2111
+ isSumHigh(e) {
2112
+ return this.isOutputHigh(2 * e);
2113
+ }
2114
+ isStageCarryHigh(e) {
2115
+ return this.isOutputHigh(2 * e + 1);
2116
+ }
2117
+ isCarryOutHigh() {
2118
+ return this.isStageCarryHigh(7);
2119
+ }
2120
+ }, Jt = class extends A {
2121
+ constructor(e, t = "000") {
2122
+ super(e, 9, t);
2123
+ }
2124
+ isOutputBitHigh(e) {
2125
+ return this.isOutputHigh(e);
2126
+ }
2127
+ isInvertHigh() {
2128
+ return this.isOutputHigh(8);
2129
+ }
2130
+ }, Ce = class {
2131
+ behaviors;
2132
+ constructor() {
2133
+ this.behaviors = /* @__PURE__ */ new Map();
2134
+ }
2135
+ register(e) {
2136
+ if (!e) throw new TypeError("Behavior cannot be null or undefined");
2137
+ if (!e.componentType || e.componentType.trim() === "") throw new TypeError("Behavior componentType cannot be empty");
2138
+ return this.behaviors.set(e.componentType, e), this;
2139
+ }
2140
+ registerAll(e) {
2141
+ e.forEach((t) => this.register(t));
2142
+ }
2143
+ get(e) {
2144
+ return this.behaviors.get(e);
2145
+ }
2146
+ has(e) {
2147
+ return this.behaviors.has(e);
2148
+ }
2149
+ unregister(e) {
2150
+ return this.behaviors.delete(e);
2151
+ }
2152
+ clear() {
2153
+ this.behaviors.clear();
2154
+ }
2155
+ getRegisteredTypes() {
2156
+ return Array.from(this.behaviors.keys());
2157
+ }
2158
+ size() {
2159
+ return this.behaviors.size;
2160
+ }
2161
+ }, C = class {
2162
+ _componentType;
2163
+ constructor(e) {
2164
+ this._componentType = e;
2165
+ }
2166
+ get componentType() {
2167
+ return this._componentType;
2168
+ }
2169
+ get typeMetadata() {
2170
+ const e = I[this._componentType];
2171
+ if (!e) throw new Error(`Unknown metadata for Component type ${this._componentType}`);
2172
+ return e;
2173
+ }
2174
+ getPinStates(e, t) {
2175
+ const n = /* @__PURE__ */ new Map();
2176
+ for (const i of e.pins) n.set(e.getPinLabel(i), t.get(i));
2177
+ return n;
2178
+ }
2179
+ getChangedPins(e, t) {
2180
+ const n = /* @__PURE__ */ new Set();
2181
+ for (const [i, s] of e) {
2182
+ if (!t.has(i)) continue;
2183
+ const r = t.get(i);
2184
+ (s.hasVoltage !== r?.hasVoltage || s.hasCurrent !== r?.hasCurrent) && n.add(i);
2185
+ }
2186
+ return n;
2187
+ }
2188
+ onStart(e, t) {
2189
+ return null;
2190
+ }
2191
+ onPinsChange(e, t, n, i) {
2192
+ return {
2193
+ componentState: t,
2194
+ hasChanged: !1,
2195
+ shouldCancelPending: !1,
2196
+ scheduledEvents: []
2197
+ };
2198
+ }
2199
+ allowConductivity(e, t, n, i, s) {
2200
+ return !1;
2201
+ }
2202
+ onUserCommand(e, t, n) {
2203
+ return {
2204
+ componentState: t,
2205
+ hasChanged: !1,
2206
+ shouldCancelPending: !1,
2207
+ scheduledEvents: []
2208
+ };
2209
+ }
2210
+ onEventFiring(e, t, n) {
2211
+ return {
2212
+ componentState: t,
2213
+ hasChanged: !1,
2214
+ shouldCancelPending: !1,
2215
+ scheduledEvents: []
2216
+ };
2217
+ }
2218
+ };
2219
+ function x(e) {
2220
+ const t = parseInt(e.get("transitionSpan") || "", 10);
2221
+ return isNaN(t) || t < 1 ? at.TRANSITION_SPAN_TICKS : t;
2222
+ }
2223
+ var Ut = class extends C {
2224
+ constructor() {
2225
+ super(u.Battery);
2226
+ }
2227
+ createInitialState(e) {
2228
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for BatteryBehavior: ${e.type}`);
2229
+ return new It(e.id);
2230
+ }
2231
+ }, R = class extends C {
2232
+ getBehavior(e, t, n, i) {
2233
+ let s = !1;
2234
+ const r = [], a = x(e.config), o = t.expirationTick < 1 ? a : Math.max(i - t.startTick, 1);
2235
+ return n ? (t.state === "off" || t.state === "goingOff") && (s = !0, t.setState("goingOn", i), t.setNextState("on", i + o), r.push({
2236
+ targetId: e.id,
2237
+ scheduledAtTick: t.startTick,
2238
+ readyAtTick: t.expirationTick,
2239
+ type: "GoingOnEnd",
2240
+ parameters: void 0
2241
+ })) : (t.state === "on" || t.state === "goingOn") && (s = !0, t.setState("goingOff", i), t.setNextState("off", i + o), r.push({
2242
+ targetId: e.id,
2243
+ scheduledAtTick: t.startTick,
2244
+ readyAtTick: t.expirationTick,
2245
+ type: "GoingOffEnd",
2246
+ parameters: void 0
2247
+ })), {
2248
+ componentState: t,
2249
+ hasChanged: s,
2250
+ shouldCancelPending: !0,
2251
+ scheduledEvents: r
2252
+ };
2253
+ }
2254
+ allowConductivity(e, t, n, i, s) {
2255
+ return !0;
2256
+ }
2257
+ onEventFiring(e, t, n) {
2258
+ let i = !1;
2259
+ return n.type === "GoingOffEnd" ? t.state !== "off" && (i = !0, t.setState("off", n.readyAtTick)) : n.type === "GoingOnEnd" && t.state !== "on" && (i = !0, t.setState("on", n.readyAtTick)), {
2260
+ componentState: t,
2261
+ hasChanged: i,
2262
+ shouldCancelPending: !1,
2263
+ scheduledEvents: []
2264
+ };
2265
+ }
2266
+ }, Xt = class extends R {
2267
+ constructor() {
2268
+ super(u.Lightbulb);
2269
+ }
2270
+ createInitialState(e) {
2271
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for lightbulbBehavior: ${e.type}`);
2272
+ return new Tt(e.id);
2273
+ }
2274
+ onPinsChange(e, t, n, i) {
2275
+ const s = this.getPinStates(e, n);
2276
+ t.pinStates = s;
2277
+ const r = T(s.get("pin1"), s.get("pin2")), a = r.hasVoltage && r.hasCurrent;
2278
+ return this.getBehavior(e, t, a, i);
2279
+ }
2280
+ }, Qt = class extends R {
2281
+ constructor() {
2282
+ super(u.RectangleLED);
2283
+ }
2284
+ createInitialState(e) {
2285
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for RectangleLEDBehavior: ${e.type}`);
2286
+ return new Ot(e.id);
2287
+ }
2288
+ onPinsChange(e, t, n, i) {
2289
+ const s = this.getPinStates(e, n);
2290
+ t.pinStates = s;
2291
+ const r = T(s.get("pin1"), s.get("pin2")), a = r.hasVoltage && r.hasCurrent;
2292
+ return this.getBehavior(e, t, a, i);
2293
+ }
2294
+ };
2295
+ function qt(e) {
2296
+ const t = parseInt(e.get("transitionSpan") || "", 10);
2297
+ return isNaN(t) || t < 1 ? at.TRANSITION_SPAN_TICKS : t;
2298
+ }
2299
+ var Kt = class extends C {
2300
+ constructor() {
2301
+ super(u.Relay);
2302
+ }
2303
+ createInitialState(e) {
2304
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for RelayBehavior: ${e.type}`);
2305
+ const t = e.config.get("activationLogic") === "negative" ? "closed" : "open";
2306
+ return new Et(e.id, t);
2307
+ }
2308
+ allowConductivity(e, t, n, i, s) {
2309
+ if (i === s) return !0;
2310
+ const r = e.getPinLabel(i), a = e.getPinLabel(s);
2311
+ if (!r || !a) return !1;
2312
+ const o = [r, a];
2313
+ return o.includes("cmd_in") && o.includes("cmd_out") ? !0 : o.includes("power_in") && o.includes("power_out") ? t.state === "closed" || t.state === "opening" : !1;
2314
+ }
2315
+ onPinsChange(e, t, n, i) {
2316
+ const s = this.getPinStates(e, n);
2317
+ s.set("cmd_in*cmd_out", T(s.get("cmd_in"), s.get("cmd_out"))), s.set("power_in*power_out", T(s.get("power_in"), s.get("power_out")));
2318
+ const r = t.pinStates;
2319
+ t.pinStates = s;
2320
+ const a = this.getChangedPins(s, r), o = s.get("cmd_in*cmd_out"), c = o.hasVoltage && o.hasCurrent, p = e.config.get("activationLogic") === "negative" ? !c : c;
2321
+ let l = a.size > 0;
2322
+ const d = [], y = qt(e.config);
2323
+ if (p) {
2324
+ if (t.state === "open" || t.state === "opening") {
2325
+ let f = t.state === "open" ? y : Math.max(i - t.startTick, 1);
2326
+ l = !0, t.setState("closing", i), t.setNextState("closed", i + f), d.push({
2327
+ targetId: e.id,
2328
+ scheduledAtTick: t.startTick,
2329
+ readyAtTick: t.expirationTick,
2330
+ type: "ClosingEnd",
2331
+ parameters: /* @__PURE__ */ new Map([["exclusive", "true"]])
2332
+ });
2333
+ }
2334
+ } else if (t.state === "closed" || t.state === "closing") {
2335
+ let f = t.state === "closed" ? y : Math.max(i - t.startTick, 1);
2336
+ l = !0, t.setState("opening", i), t.setNextState("open", i + f), d.push({
2337
+ targetId: e.id,
2338
+ scheduledAtTick: t.startTick,
2339
+ readyAtTick: t.expirationTick,
2340
+ type: "OpeningEnd",
2341
+ parameters: /* @__PURE__ */ new Map([["exclusive", "true"]])
2342
+ });
2343
+ }
2344
+ return {
2345
+ componentState: t,
2346
+ hasChanged: l,
2347
+ shouldCancelPending: l,
2348
+ scheduledEvents: d
2349
+ };
2350
+ }
2351
+ onEventFiring(e, t, n) {
2352
+ let i = !1;
2353
+ return n.type === "ClosingEnd" ? t.state !== "closed" && (t.setState("closed", n.readyAtTick), i = !0) : n.type === "OpeningEnd" && t.state !== "open" && (t.setState("open", n.readyAtTick), i = !0), {
2354
+ componentState: t,
2355
+ hasChanged: i,
2356
+ shouldCancelPending: !1,
2357
+ scheduledEvents: []
2358
+ };
2359
+ }
2360
+ }, Yt = class extends R {
2361
+ constructor() {
2362
+ super(u.SmallLED);
2363
+ }
2364
+ createInitialState(e) {
2365
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for SmallLEDBehavior: ${e.type}`);
2366
+ return new ct(e.id);
2367
+ }
2368
+ onPinsChange(e, t, n, i) {
2369
+ const s = this.getPinStates(e, n);
2370
+ t.pinStates = s;
2371
+ const r = T(s.get("pin1"), s.get("pin2")), a = r.hasVoltage && r.hasCurrent;
2372
+ return this.getBehavior(e, t, a, i);
2373
+ }
2374
+ }, Zt = class extends C {
2375
+ constructor() {
2376
+ super(u.Switch);
2377
+ }
2378
+ createInitialState(e) {
2379
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for SwitchBehavior: ${e.type}`);
2380
+ const t = e.config.get("initialState") || "open";
2381
+ return new Nt(e.id, t);
2382
+ }
2383
+ allowConductivity(e, t, n, i, s) {
2384
+ return t.state === "closed" || t.state === "opening";
2385
+ }
2386
+ onPinsChange(e, t, n, i) {
2387
+ const s = this.getPinStates(e, n), r = t.pinStates;
2388
+ t.pinStates = s;
2389
+ const a = this.getChangedPins(s, r);
2390
+ return a.size < 1 || !a.has("output") ? {
2391
+ componentState: t,
2392
+ hasChanged: !1,
2393
+ shouldCancelPending: !1,
2394
+ scheduledEvents: []
2395
+ } : {
2396
+ componentState: t,
2397
+ hasChanged: !0,
2398
+ shouldCancelPending: !1,
2399
+ scheduledEvents: []
2400
+ };
2401
+ }
2402
+ onUserCommand(e, t, n) {
2403
+ let i = !1;
2404
+ const s = [], r = x(e.config);
2405
+ return n.type === "toggle_switch" && ["open", "closed"].includes(t.state) && (t.setState(t.state === "open" ? "closing" : "opening", n.scheduledAtTick), t.setNextState(t.state === "closing" ? "closed" : "open", n.scheduledAtTick + r), i = !0, s.push({
2406
+ targetId: e.id,
2407
+ scheduledAtTick: t.startTick,
2408
+ readyAtTick: t.expirationTick,
2409
+ type: t.state === "closing" ? "ClosingEnd" : "OpeningEnd",
2410
+ parameters: /* @__PURE__ */ new Map([["exclusive", "true"]])
2411
+ })), {
2412
+ componentState: t,
2413
+ hasChanged: i,
2414
+ shouldCancelPending: !0,
2415
+ scheduledEvents: s
2416
+ };
2417
+ }
2418
+ onEventFiring(e, t, n) {
2419
+ let i = !1;
2420
+ return n.type === "ClosingEnd" ? t.state !== "closed" && (t.setState("closed", n.readyAtTick), i = !0) : n.type === "OpeningEnd" && t.state !== "open" && (t.setState("open", n.readyAtTick), i = !0), {
2421
+ componentState: t,
2422
+ hasChanged: i,
2423
+ shouldCancelPending: !1,
2424
+ scheduledEvents: []
2425
+ };
2426
+ }
2427
+ }, jt = class extends C {
2428
+ constructor() {
2429
+ super(u.DoubleThrowSwitch);
2430
+ }
2431
+ createInitialState(e) {
2432
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for DoubleThrowSwitchBehavior: ${e.type}`);
2433
+ const t = e.config.get("initialState") || "input1";
2434
+ return new At(e.id, t);
2435
+ }
2436
+ allowConductivity(e, t, n, i, s) {
2437
+ if (i === s) return !0;
2438
+ const r = e.getPinLabel(i), a = e.getPinLabel(s);
2439
+ if (!r || !a) return !1;
2440
+ const o = [r, a];
2441
+ return o.includes("output") && o.includes("input1") ? t.state === "input1" || t.state === "1to2" : o.includes("output") && o.includes("input2") ? t.state === "input2" || t.state === "2to1" : !1;
2442
+ }
2443
+ onPinsChange(e, t, n, i) {
2444
+ const s = this.getPinStates(e, n), r = t.pinStates;
2445
+ t.pinStates = s;
2446
+ const a = this.getChangedPins(s, r);
2447
+ return a.size < 1 || !a.has("output") ? {
2448
+ componentState: t,
2449
+ hasChanged: !1,
2450
+ shouldCancelPending: !1,
2451
+ scheduledEvents: []
2452
+ } : {
2453
+ componentState: t,
2454
+ hasChanged: !0,
2455
+ shouldCancelPending: !1,
2456
+ scheduledEvents: []
2457
+ };
2458
+ }
2459
+ onUserCommand(e, t, n) {
2460
+ let i = !1;
2461
+ const s = [], r = x(e.config);
2462
+ return n.type === "toggle_switch" && ["input1", "input2"].includes(t.state) && (t.setState(t.state === "input1" ? "1to2" : "2to1", n.scheduledAtTick), t.setNextState(t.state === "1to2" ? "input2" : "input1", n.scheduledAtTick + r), i = !0, s.push({
2463
+ targetId: e.id,
2464
+ scheduledAtTick: t.startTick,
2465
+ readyAtTick: t.expirationTick,
2466
+ type: t.state === "1to2" ? "ContactedInput2" : "ContactedInput1",
2467
+ parameters: /* @__PURE__ */ new Map([["exclusive", "true"]])
2468
+ })), {
2469
+ componentState: t,
2470
+ hasChanged: i,
2471
+ shouldCancelPending: !0,
2472
+ scheduledEvents: s
2473
+ };
2474
+ }
2475
+ onEventFiring(e, t, n) {
2476
+ let i = !1;
2477
+ return n.type === "ContactedInput2" ? t.state !== "input2" && (t.setState("input2", n.readyAtTick), i = !0) : n.type === "ContactedInput1" && t.state !== "input1" && (t.setState("input1", n.readyAtTick), i = !0), {
2478
+ componentState: t,
2479
+ hasChanged: i,
2480
+ shouldCancelPending: !1,
2481
+ scheduledEvents: []
2482
+ };
2483
+ }
2484
+ }, te = class extends C {
2485
+ constructor() {
2486
+ super(u.Clock);
2487
+ }
2488
+ createInitialState(e) {
2489
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for ClockBehavior: ${e.type}`);
2490
+ const t = new Bt(e.id), n = e.config.get("startHigh") == "true";
2491
+ t.setState(n ? "high" : "low", 0);
2492
+ const i = Number(e.config.get("halfPeriod"));
2493
+ return t.setNextState(n ? "low" : "high", i), t;
2494
+ }
2495
+ allowConductivity(e, t, n, i, s) {
2496
+ if (i === s) return !0;
2497
+ const r = e.getPinLabel(i), a = e.getPinLabel(s);
2498
+ if (!r || !a) return !1;
2499
+ const o = [r, a];
2500
+ return o.includes("gnd") && o.includes("vcc") ? !1 : o.includes("gnd") && o.includes("output") ? t.state === "low" : o.includes("vcc") && o.includes("output") ? t.state === "high" : !1;
2501
+ }
2502
+ onStart(e, t) {
2503
+ const i = Number(e.config.get("halfPeriod"));
2504
+ return t.setNextState(t.state === "high" ? "low" : "high", 0 + i), {
2505
+ componentState: t,
2506
+ hasChanged: !0,
2507
+ shouldCancelPending: !0,
2508
+ scheduledEvents: [{
2509
+ targetId: e.id,
2510
+ scheduledAtTick: t.startTick,
2511
+ readyAtTick: t.expirationTick,
2512
+ type: "tick",
2513
+ parameters: /* @__PURE__ */ new Map([["exclusive", "true"]])
2514
+ }]
2515
+ };
2516
+ }
2517
+ onEventFiring(e, t, n) {
2518
+ if (n.type !== "tick") return {
2519
+ componentState: t,
2520
+ hasChanged: !1,
2521
+ shouldCancelPending: !1,
2522
+ scheduledEvents: []
2523
+ };
2524
+ const i = Number(e.config.get("halfPeriod"));
2525
+ return t.setState(t.state === "high" ? "low" : "high", n.readyAtTick), t.setNextState(t.state === "high" ? "low" : "high", n.readyAtTick + i), {
2526
+ componentState: t,
2527
+ hasChanged: !0,
2528
+ shouldCancelPending: !0,
2529
+ scheduledEvents: [{
2530
+ targetId: e.id,
2531
+ scheduledAtTick: t.startTick,
2532
+ readyAtTick: t.expirationTick,
2533
+ type: "tick",
2534
+ parameters: /* @__PURE__ */ new Map([["exclusive", "true"]])
2535
+ }]
2536
+ };
2537
+ }
2538
+ }, m = class extends C {
2539
+ vccGuardBehavior(e, t, n) {
2540
+ if (t.get("vcc").hasVoltage) return null;
2541
+ let i = !1, s = !1;
2542
+ return e.state !== "low" && (e.setState("low", n), i = !0, s = !0), {
2543
+ componentState: e,
2544
+ hasChanged: i,
2545
+ shouldCancelPending: s,
2546
+ scheduledEvents: []
2547
+ };
2548
+ }
2549
+ nonLogicInputGuardBehavior(e, t, n) {
2550
+ let i = !1;
2551
+ const s = this.typeMetadata.pins;
2552
+ for (const [o, c] of t) {
2553
+ if (!s.has(o)) continue;
2554
+ const p = s.get(o);
2555
+ if (p && p?.subtype === "logicInput") {
2556
+ if (c.hasVoltage && c.hasCurrent) {
2557
+ i = !0;
2558
+ break;
2559
+ }
2560
+ if (!c.hasVoltage && !c.hasCurrent) {
2561
+ i = !0;
2562
+ break;
2563
+ }
2564
+ }
2565
+ }
2566
+ if (!i) return null;
2567
+ let r = !1, a = !1;
2568
+ return e.state !== "indeterminate" && (e.setState("indeterminate", n), r = !0, a = !0), {
2569
+ componentState: e,
2570
+ hasChanged: r,
2571
+ shouldCancelPending: a,
2572
+ scheduledEvents: []
2573
+ };
2574
+ }
2575
+ getBehavior(e, t, n, i) {
2576
+ if (![
2577
+ "low",
2578
+ "rising",
2579
+ "high",
2580
+ "falling",
2581
+ "indeterminate"
2582
+ ].includes(t.state))
2583
+ return t.setState("low", i), {
2584
+ componentState: t,
2585
+ hasChanged: !0,
2586
+ shouldCancelPending: !0,
2587
+ scheduledEvents: []
2588
+ };
2589
+ const s = x(e.config), r = t.expirationTick < 1 ? s : Math.max(i - t.startTick, 1);
2590
+ if (n) {
2591
+ if (t.state === "low" || t.state === "falling" || t.state === "indeterminate")
2592
+ return t.setState("rising", i), t.setNextState("high", i + r), {
2593
+ componentState: t,
2594
+ hasChanged: !0,
2595
+ shouldCancelPending: !0,
2596
+ scheduledEvents: [{
2597
+ targetId: e.id,
2598
+ scheduledAtTick: t.startTick,
2599
+ readyAtTick: t.expirationTick,
2600
+ type: "RisingComplete",
2601
+ parameters: void 0
2602
+ }]
2603
+ };
2604
+ if (t.state === "rising" || t.state === "high") return {
2605
+ componentState: t,
2606
+ hasChanged: !1,
2607
+ shouldCancelPending: !1,
2608
+ scheduledEvents: []
2609
+ };
2610
+ }
2611
+ return t.state === "falling" || t.state === "low" ? {
2612
+ componentState: t,
2613
+ hasChanged: !1,
2614
+ shouldCancelPending: !1,
2615
+ scheduledEvents: []
2616
+ } : t.state === "high" || t.state === "rising" || t.state === "indeterminate" ? (t.setState("falling", i), t.setNextState("low", i + r), {
2617
+ componentState: t,
2618
+ hasChanged: !0,
2619
+ shouldCancelPending: !0,
2620
+ scheduledEvents: [{
2621
+ targetId: e.id,
2622
+ scheduledAtTick: t.startTick,
2623
+ readyAtTick: t.expirationTick,
2624
+ type: "FallingComplete",
2625
+ parameters: void 0
2626
+ }]
2627
+ }) : (t.setState("low", i), {
2628
+ componentState: t,
2629
+ hasChanged: !0,
2630
+ shouldCancelPending: !0,
2631
+ scheduledEvents: []
2632
+ });
2633
+ }
2634
+ allowConductivity(e, t, n, i, s) {
2635
+ if (i === s) return !0;
2636
+ const r = e.getPinLabel(i), a = e.getPinLabel(s);
2637
+ if (!r || !a) return !1;
2638
+ const o = [r, a];
2639
+ return o.includes("vcc") && o.includes("output") ? t.state === "high" || t.state === "falling" : o.includes("gnd") && o.includes("output") ? t.state === "low" || t.state === "rising" : !1;
2640
+ }
2641
+ onEventFiring(e, t, n) {
2642
+ let i = !1;
2643
+ return n.type === "RisingComplete" ? t.state !== "high" && (i = !0, t.setState("high", n.readyAtTick)) : n.type === "FallingComplete" && t.state !== "low" && (i = !0, t.setState("low", n.readyAtTick)), {
2644
+ componentState: t,
2645
+ hasChanged: i,
2646
+ shouldCancelPending: !1,
2647
+ scheduledEvents: []
2648
+ };
2649
+ }
2650
+ }, ee = class extends m {
2651
+ constructor() {
2652
+ super(u.Inverter);
2653
+ }
2654
+ createInitialState(e) {
2655
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for InverterBehavior: ${e.type}`);
2656
+ const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
2657
+ return new Dt(e.id, t);
2658
+ }
2659
+ onPinsChange(e, t, n, i) {
2660
+ const s = this.getPinStates(e, n);
2661
+ t.pinStates = s;
2662
+ const r = this.vccGuardBehavior(t, s, i);
2663
+ if (r) return r;
2664
+ const a = this.nonLogicInputGuardBehavior(t, s, i);
2665
+ if (a) return a;
2666
+ const o = s.get("input").hasVoltage, c = e.config.get("activationLogic") === "negative" ? !o : o;
2667
+ return this.getBehavior(e, t, c, i);
2668
+ }
2669
+ }, ie = class extends m {
2670
+ constructor() {
2671
+ super(u.NandGate);
2672
+ }
2673
+ createInitialState(e) {
2674
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for NandGateBehavior: ${e.type}`);
2675
+ const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
2676
+ return new Mt(e.id, t);
2677
+ }
2678
+ onPinsChange(e, t, n, i) {
2679
+ const s = this.getPinStates(e, n);
2680
+ t.pinStates = s;
2681
+ const r = this.vccGuardBehavior(t, s, i);
2682
+ if (r) return r;
2683
+ const a = this.nonLogicInputGuardBehavior(t, s, i);
2684
+ if (a) return a;
2685
+ const o = s.get("input1").hasVoltage && s.get("input2").hasVoltage, c = e.config.get("activationLogic") === "negative" ? !o : o;
2686
+ return this.getBehavior(e, t, c, i);
2687
+ }
2688
+ }, ne = class extends m {
2689
+ constructor() {
2690
+ super(u.Nand4Gate);
2691
+ }
2692
+ createInitialState(e) {
2693
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for Nand4GateBehavior: ${e.type}`);
2694
+ const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
2695
+ return new Lt(e.id, t);
2696
+ }
2697
+ onPinsChange(e, t, n, i) {
2698
+ const s = this.getPinStates(e, n);
2699
+ t.pinStates = s;
2700
+ const r = this.vccGuardBehavior(t, s, i);
2701
+ if (r) return r;
2702
+ const a = this.nonLogicInputGuardBehavior(t, s, i);
2703
+ if (a) return a;
2704
+ const o = s.get("input1").hasVoltage && s.get("input2").hasVoltage && s.get("input3").hasVoltage && s.get("input4").hasVoltage, c = e.config.get("activationLogic") === "negative" ? !o : o;
2705
+ return this.getBehavior(e, t, c, i);
2706
+ }
2707
+ }, se = class extends m {
2708
+ constructor() {
2709
+ super(u.Nand8Gate);
2710
+ }
2711
+ createInitialState(e) {
2712
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for Nand8GateBehavior: ${e.type}`);
2713
+ const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
2714
+ return new kt(e.id, t);
2715
+ }
2716
+ onPinsChange(e, t, n, i) {
2717
+ const s = this.getPinStates(e, n);
2718
+ t.pinStates = s;
2719
+ const r = this.vccGuardBehavior(t, s, i);
2720
+ if (r) return r;
2721
+ const a = this.nonLogicInputGuardBehavior(t, s, i);
2722
+ if (a) return a;
2723
+ 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, c = e.config.get("activationLogic") === "negative" ? !o : o;
2724
+ return this.getBehavior(e, t, c, i);
2725
+ }
2726
+ }, re = class extends m {
2727
+ constructor() {
2728
+ super(u.NorGate);
2729
+ }
2730
+ createInitialState(e) {
2731
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for NorGateBehavior: ${e.type}`);
2732
+ const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
2733
+ return new Gt(e.id, t);
2734
+ }
2735
+ onPinsChange(e, t, n, i) {
2736
+ const s = this.getPinStates(e, n);
2737
+ t.pinStates = s;
2738
+ const r = this.vccGuardBehavior(t, s, i);
2739
+ if (r) return r;
2740
+ const a = this.nonLogicInputGuardBehavior(t, s, i);
2741
+ if (a) return a;
2742
+ const o = s.get("input1").hasVoltage || s.get("input2").hasVoltage, c = e.config.get("activationLogic") === "negative" ? !o : o;
2743
+ return this.getBehavior(e, t, c, i);
2744
+ }
2745
+ }, ae = class extends m {
2746
+ constructor() {
2747
+ super(u.Nor4Gate);
2748
+ }
2749
+ createInitialState(e) {
2750
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for Nor4GateBehavior: ${e.type}`);
2751
+ const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
2752
+ return new _t(e.id, t);
2753
+ }
2754
+ onPinsChange(e, t, n, i) {
2755
+ const s = this.getPinStates(e, n);
2756
+ t.pinStates = s;
2757
+ const r = this.vccGuardBehavior(t, s, i);
2758
+ if (r) return r;
2759
+ const a = this.nonLogicInputGuardBehavior(t, s, i);
2760
+ if (a) return a;
2761
+ const o = s.get("input1").hasVoltage || s.get("input2").hasVoltage || s.get("input3").hasVoltage || s.get("input4").hasVoltage, c = e.config.get("activationLogic") === "negative" ? !o : o;
2762
+ return this.getBehavior(e, t, c, i);
2763
+ }
2764
+ }, oe = class extends m {
2765
+ constructor() {
2766
+ super(u.Nor8Gate);
2767
+ }
2768
+ createInitialState(e) {
2769
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for Nor8GateBehavior: ${e.type}`);
2770
+ const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
2771
+ return new Vt(e.id, t);
2772
+ }
2773
+ onPinsChange(e, t, n, i) {
2774
+ const s = this.getPinStates(e, n);
2775
+ t.pinStates = s;
2776
+ const r = this.vccGuardBehavior(t, s, i);
2777
+ if (r) return r;
2778
+ const a = this.nonLogicInputGuardBehavior(t, s, i);
2779
+ if (a) return a;
2780
+ 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, c = e.config.get("activationLogic") === "negative" ? !o : o;
2781
+ return this.getBehavior(e, t, c, i);
2782
+ }
2783
+ }, ce = class extends m {
2784
+ constructor() {
2785
+ super(u.XorGate);
2786
+ }
2787
+ createInitialState(e) {
2788
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for XorGateBehavior: ${e.type}`);
2789
+ const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
2790
+ return new $t(e.id, t);
2791
+ }
2792
+ onPinsChange(e, t, n, i) {
2793
+ const s = this.getPinStates(e, n);
2794
+ t.pinStates = s;
2795
+ const r = this.vccGuardBehavior(t, s, i);
2796
+ if (r) return r;
2797
+ const a = this.nonLogicInputGuardBehavior(t, s, i);
2798
+ if (a) return a;
2799
+ const o = s.get("input1").hasVoltage !== s.get("input2").hasVoltage, c = e.config.get("activationLogic") === "negative" ? !o : o;
2800
+ return this.getBehavior(e, t, c, i);
2801
+ }
2802
+ }, ue = class extends m {
2803
+ constructor() {
2804
+ super(u.Xor4Gate);
2805
+ }
2806
+ createInitialState(e) {
2807
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for Xor4GateBehavior: ${e.type}`);
2808
+ const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
2809
+ return new Rt(e.id, t);
2810
+ }
2811
+ onPinsChange(e, t, n, i) {
2812
+ const s = this.getPinStates(e, n);
2813
+ t.pinStates = s;
2814
+ const r = this.vccGuardBehavior(t, s, i);
2815
+ if (r) return r;
2816
+ const a = this.nonLogicInputGuardBehavior(t, s, i);
2817
+ if (a) return a;
2818
+ const o = ((s.get("input1").hasVoltage ? 1 : 0) + (s.get("input2").hasVoltage ? 1 : 0) + (s.get("input3").hasVoltage ? 1 : 0) + (s.get("input4").hasVoltage ? 1 : 0)) % 2 === 1, c = e.config.get("activationLogic") === "negative" ? !o : o;
2819
+ return this.getBehavior(e, t, c, i);
2820
+ }
2821
+ }, le = class extends m {
2822
+ constructor() {
2823
+ super(u.Xor8Gate);
2824
+ }
2825
+ createInitialState(e) {
2826
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for Xor8GateBehavior: ${e.type}`);
2827
+ const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
2828
+ return new Wt(e.id, t);
2829
+ }
2830
+ onPinsChange(e, t, n, i) {
2831
+ const s = this.getPinStates(e, n);
2832
+ t.pinStates = s;
2833
+ const r = this.vccGuardBehavior(t, s, i);
2834
+ if (r) return r;
2835
+ const a = this.nonLogicInputGuardBehavior(t, s, i);
2836
+ if (a) return a;
2837
+ const o = ((s.get("input1").hasVoltage ? 1 : 0) + (s.get("input2").hasVoltage ? 1 : 0) + (s.get("input3").hasVoltage ? 1 : 0) + (s.get("input4").hasVoltage ? 1 : 0) + (s.get("input5").hasVoltage ? 1 : 0) + (s.get("input6").hasVoltage ? 1 : 0) + (s.get("input7").hasVoltage ? 1 : 0) + (s.get("input8").hasVoltage ? 1 : 0)) % 2 === 1, c = e.config.get("activationLogic") === "negative" ? !o : o;
2838
+ return this.getBehavior(e, t, c, i);
2839
+ }
2840
+ }, B = class extends C {
2841
+ onPinsChange(e, t, n, i) {
2842
+ const s = this.getPinStates(e, n);
2843
+ t.pinStates = s;
2844
+ const r = t, a = this.vccGuardBehavior(r, s, i);
2845
+ if (a) return a;
2846
+ const o = this.nonLogicInputGuardBehavior(r, s, i);
2847
+ if (o) return o;
2848
+ const c = this.computeTargetStableState(s);
2849
+ return this.scheduleTransition(e, r, c, i);
2850
+ }
2851
+ onEventFiring(e, t, n) {
2852
+ if (!n.type.startsWith("to")) return this.noChange(t);
2853
+ const i = n.type.slice(2);
2854
+ return t.state === i ? this.noChange(t) : (t.setState(i, n.readyAtTick), t.parameters.delete("prevState"), {
2855
+ componentState: t,
2856
+ hasChanged: !0,
2857
+ shouldCancelPending: !1,
2858
+ scheduledEvents: []
2859
+ });
2860
+ }
2861
+ allowConductivity(e, t, n, i, s) {
2862
+ if (i === s) return !0;
2863
+ const r = t.effectiveState;
2864
+ if (r === "indeterminate") return !1;
2865
+ const a = e.getPinMetadata(i), o = e.getPinMetadata(s);
2866
+ if (!a || !o) return !1;
2867
+ let c, p = 0;
2868
+ if (a.subtype === "logicOutput" && (p++, c = a), o.subtype === "logicOutput" && (p++, c = o), p !== 1 || !c?.logicPinData) return !1;
2869
+ let l = 0;
2870
+ if (l += a.subtype === "vcc" ? 1 : a.subtype === "gnd" ? -1 : 0, l += o.subtype === "vcc" ? 1 : o.subtype === "gnd" ? -1 : 0, l !== 1 && l !== -1) return !1;
2871
+ const d = t;
2872
+ return (parseInt(r, 16) >> (c.logicPinData.interface === "sum" ? c.logicPinData.index * 2 : d.outputCount - 1) & 1) === 1 ? l === 1 : l === -1;
2873
+ }
2874
+ vccGuardBehavior(e, t, n) {
2875
+ if (t.get("vcc").hasVoltage) return null;
2876
+ const i = e.allLowState;
2877
+ return e.state === i ? {
2878
+ componentState: e,
2879
+ hasChanged: !1,
2880
+ shouldCancelPending: !1,
2881
+ scheduledEvents: []
2882
+ } : (e.setState(i, n), e.parameters.delete("prevState"), {
2883
+ componentState: e,
2884
+ hasChanged: !0,
2885
+ shouldCancelPending: !0,
2886
+ scheduledEvents: []
2887
+ });
2888
+ }
2889
+ nonLogicInputGuardBehavior(e, t, n) {
2890
+ const i = this.typeMetadata.pins;
2891
+ let s = !1;
2892
+ for (const [r, a] of t) {
2893
+ const o = i.get(r);
2894
+ if (!(!o || o.subtype !== "logicInput") && (a.hasVoltage && a.hasCurrent || !a.hasVoltage && !a.hasCurrent)) {
2895
+ s = !0;
2896
+ break;
2897
+ }
2898
+ }
2899
+ return s ? e.state === "indeterminate" ? {
2900
+ componentState: e,
2901
+ hasChanged: !1,
2902
+ shouldCancelPending: !1,
2903
+ scheduledEvents: []
2904
+ } : (e.setState("indeterminate", n), e.parameters.delete("prevState"), {
2905
+ componentState: e,
2906
+ hasChanged: !0,
2907
+ shouldCancelPending: !0,
2908
+ scheduledEvents: []
2909
+ }) : null;
2910
+ }
2911
+ scheduleTransition(e, t, n, i) {
2912
+ const s = `to${n}`;
2913
+ if (t.state === n || t.state === s) return this.noChange(t);
2914
+ const r = x(e.config), a = t.expirationTick < 1 ? r : Math.max(i - t.startTick, 1), o = t.effectiveState, c = o === "indeterminate" ? t.allLowState : o;
2915
+ return t.setState(s, i), t.setNextState(n, i + a), t.parameters.set("prevState", c), {
2916
+ componentState: t,
2917
+ hasChanged: !0,
2918
+ shouldCancelPending: !0,
2919
+ scheduledEvents: [{
2920
+ targetId: e.id,
2921
+ scheduledAtTick: t.startTick,
2922
+ readyAtTick: t.expirationTick,
2923
+ type: s,
2924
+ parameters: void 0
2925
+ }]
2926
+ };
2927
+ }
2928
+ noChange(e) {
2929
+ return {
2930
+ componentState: e,
2931
+ hasChanged: !1,
2932
+ shouldCancelPending: !1,
2933
+ scheduledEvents: []
2934
+ };
2935
+ }
2936
+ }, pe = class extends B {
2937
+ constructor() {
2938
+ super(u.HalfAdder);
2939
+ }
2940
+ createInitialState(e) {
2941
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for HalfAdderBehavior: ${e.type}`);
2942
+ return new zt(e.id, "0");
2943
+ }
2944
+ computeTargetStableState(e) {
2945
+ const t = e.get("inputA").hasVoltage, n = e.get("inputB").hasVoltage;
2946
+ return ((t !== n ? 1 : 0) | (t && n ? 2 : 0)).toString(16);
2947
+ }
2948
+ }, de = class extends B {
2949
+ constructor() {
2950
+ super(u.Adder);
2951
+ }
2952
+ createInitialState(e) {
2953
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for AdderBehavior: ${e.type}`);
2954
+ return new Ht(e.id, "0");
2955
+ }
2956
+ computeTargetStableState(e) {
2957
+ const t = e.get("inputA").hasVoltage, n = e.get("inputB").hasVoltage, i = e.get("carryIn").hasVoltage, s = (t ? 1 : 0) + (n ? 1 : 0) + (i ? 1 : 0);
2958
+ return ((s % 2 === 1 ? 1 : 0) | (s >= 2 ? 2 : 0)).toString(16);
2959
+ }
2960
+ }, N = 8, he = class extends B {
2961
+ constructor() {
2962
+ super(u.EightBitAdder);
2963
+ }
2964
+ createInitialState(e) {
2965
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for EightBitAdderBehavior: ${e.type}`);
2966
+ return new Ft(e.id, "0000");
2967
+ }
2968
+ onPinsChange(e, t, n, i) {
2969
+ const s = this.getPinStates(e, n);
2970
+ t.pinStates = s;
2971
+ const r = t, a = this.vccGuardBehavior(r, s, i);
2972
+ if (a) return a;
2973
+ const o = this.nonLogicInputGuardBehavior(r, s, i);
2974
+ if (o) return o;
2975
+ if (i === 0) {
2976
+ const h = this.computeTargetStableState(s);
2977
+ return this.scheduleTransition(e, r, h, i);
2978
+ }
2979
+ const c = r.effectiveState, p = c === "indeterminate" ? 0 : parseInt(c, 16), l = s.get("carryIn").hasVoltage;
2980
+ let d = 0;
2981
+ for (let h = 0; h < N; h++) {
2982
+ const S = s.get(`inputA-${h}`).hasVoltage, ut = s.get(`inputB-${h}`).hasVoltage, { sum: lt, carry: pt } = k(S, ut, h === 0 ? l : (p >> 2 * (h - 1) + 1 & 1) === 1);
2983
+ d = G(d, h, lt, pt);
2984
+ }
2985
+ const y = _(d);
2986
+ if (y === c) return this.noChange(t);
2987
+ const f = x(e.config), v = c === "indeterminate" ? r.allLowState : c;
2988
+ return r.setState(`to${y}`, i), r.setNextState(y, i + f), r.parameters.set("prevState", v), {
2989
+ componentState: r,
2990
+ hasChanged: !0,
2991
+ shouldCancelPending: !0,
2992
+ scheduledEvents: [{
2993
+ targetId: e.id,
2994
+ scheduledAtTick: i,
2995
+ readyAtTick: i + f,
2996
+ type: `to${y}`,
2997
+ parameters: /* @__PURE__ */ new Map([["nextStage", "1"]])
2998
+ }]
2999
+ };
3000
+ }
3001
+ onEventFiring(e, t, n) {
3002
+ if (!n.type.startsWith("to")) return this.noChange(t);
3003
+ const i = n.type.slice(2), s = parseInt(n.parameters?.get("nextStage") ?? `${N}`), r = t;
3004
+ if (r.state === i) return this.noChange(r);
3005
+ if (r.setState(i, n.readyAtTick), r.parameters.delete("prevState"), s >= N) return {
3006
+ componentState: r,
3007
+ hasChanged: !0,
3008
+ shouldCancelPending: !1,
3009
+ scheduledEvents: []
3010
+ };
3011
+ const a = parseInt(i, 16), o = (a >> 2 * (s - 1) + 1 & 1) === 1, c = r.pinStates.get(`inputA-${s}`).hasVoltage, p = r.pinStates.get(`inputB-${s}`).hasVoltage, { sum: l, carry: d } = k(c, p, o), y = (a >> 2 * s & 1) === 1, f = (a >> 2 * s + 1 & 1) === 1;
3012
+ if (l === y && d === f) return {
3013
+ componentState: r,
3014
+ hasChanged: !0,
3015
+ shouldCancelPending: !1,
3016
+ scheduledEvents: []
3017
+ };
3018
+ const v = _(G(a, s, l, d)), h = x(e.config);
3019
+ return r.setState(`to${v}`, n.readyAtTick), r.setNextState(v, n.readyAtTick + h), r.parameters.set("prevState", i), {
3020
+ componentState: r,
3021
+ hasChanged: !0,
3022
+ shouldCancelPending: !1,
3023
+ scheduledEvents: [{
3024
+ targetId: e.id,
3025
+ scheduledAtTick: n.readyAtTick,
3026
+ readyAtTick: n.readyAtTick + h,
3027
+ type: `to${v}`,
3028
+ parameters: /* @__PURE__ */ new Map([["nextStage", `${s + 1}`]])
3029
+ }]
3030
+ };
3031
+ }
3032
+ computeTargetStableState(e) {
3033
+ let t = e.get("carryIn").hasVoltage, n = 0;
3034
+ for (let i = 0; i < N; i++) {
3035
+ const s = e.get(`inputA-${i}`).hasVoltage, r = e.get(`inputB-${i}`).hasVoltage, a = k(s, r, t);
3036
+ n = G(n, i, a.sum, a.carry), t = a.carry;
3037
+ }
3038
+ return _(n);
3039
+ }
3040
+ };
3041
+ function k(e, t, n) {
3042
+ return {
3043
+ sum: e !== t !== n,
3044
+ carry: e && t || e && n || t && n
3045
+ };
3046
+ }
3047
+ function G(e, t, n, i) {
3048
+ const s = 2 * t, r = s + 1;
3049
+ let a = e;
3050
+ return a = a & ~(1 << s) | (n ? 1 : 0) << s, a = a & ~(1 << r) | (i ? 1 : 0) << r, a;
3051
+ }
3052
+ function _(e) {
3053
+ return e.toString(16).padStart(4, "0");
3054
+ }
3055
+ var U = 8, ge = class extends B {
3056
+ constructor() {
3057
+ super(u.EightBitOnesComplement);
3058
+ }
3059
+ createInitialState(e) {
3060
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for EightBitOnesComplementBehavior: ${e.type}`);
3061
+ return new Jt(e.id, "000");
3062
+ }
3063
+ allowConductivity(e, t, n, i, s) {
3064
+ if (i === s) return !0;
3065
+ const r = t.effectiveState;
3066
+ if (r === "indeterminate") return !1;
3067
+ const a = e.getPinMetadata(i), o = e.getPinMetadata(s);
3068
+ if (!a || !o) return !1;
3069
+ let c, p = 0;
3070
+ if (a.subtype === "logicOutput" && (p++, c = a), o.subtype === "logicOutput" && (p++, c = o), p !== 1 || !c?.logicPinData) return !1;
3071
+ let l = 0;
3072
+ return l += a.subtype === "vcc" ? 1 : a.subtype === "gnd" ? -1 : 0, l += o.subtype === "vcc" ? 1 : o.subtype === "gnd" ? -1 : 0, l !== 1 && l !== -1 ? !1 : (parseInt(r, 16) >> c.logicPinData.index & 1) === 1 ? l === 1 : l === -1;
3073
+ }
3074
+ computeTargetStableState(e) {
3075
+ const t = e.get("invert").hasVoltage;
3076
+ let n = 0;
3077
+ for (let i = 0; i < U; i++) e.get(`input-${i}`).hasVoltage !== t && (n |= 1 << i);
3078
+ return t && (n |= 1 << U), n.toString(16).padStart(3, "0");
3079
+ }
3080
+ }, fe = class {
3081
+ heap;
3082
+ constructor() {
3083
+ this.heap = [];
3084
+ }
3085
+ schedule(e) {
3086
+ if (e.readyAtTick < e.scheduledAtTick) throw new RangeError(`readyAtTick (${e.readyAtTick}) cannot be before scheduledAtTick (${e.scheduledAtTick})`);
3087
+ this.heap.push(e), this.bubbleUp(this.heap.length - 1);
3088
+ }
3089
+ getReadyEvents(e) {
3090
+ const t = [];
3091
+ for (; this.heap.length > 0 && this.heap[0].readyAtTick <= e; ) {
3092
+ const n = this.extractMin();
3093
+ n && t.push(n);
3094
+ }
3095
+ return t.sort((n, i) => n.readyAtTick === i.readyAtTick ? n.scheduledAtTick - i.scheduledAtTick : n.readyAtTick - i.readyAtTick), t;
3096
+ }
3097
+ hasEvents() {
3098
+ return this.heap.length > 0;
3099
+ }
3100
+ clear() {
3101
+ this.heap = [];
3102
+ }
3103
+ scheduleMany(e, t) {
3104
+ for (const n of e) if (n.readyAtTick < n.scheduledAtTick) throw new RangeError(`readyAtTick (${n.readyAtTick}) cannot be before scheduledAtTick (${n.scheduledAtTick})`);
3105
+ t && t.size > 0 && (this.heap = this.heap.filter((n) => !t.has(n.targetId)));
3106
+ for (const n of e) this.heap.push(n);
3107
+ (e.length > 0 || t && t.size > 0) && this.rebuildHeap();
3108
+ }
3109
+ removeEventsForTarget(e) {
3110
+ const t = this.heap.length;
3111
+ return this.heap = this.heap.filter((n) => n.targetId !== e), this.heap.length !== t && this.rebuildHeap(), t - this.heap.length;
3112
+ }
3113
+ size() {
3114
+ return this.heap.length;
3115
+ }
3116
+ rebuildHeap() {
3117
+ for (let e = Math.floor(this.heap.length / 2) - 1; e >= 0; e--) this.bubbleDown(e);
3118
+ }
3119
+ bubbleUp(e) {
3120
+ for (; e > 0; ) {
3121
+ const t = Math.floor((e - 1) / 2);
3122
+ if (this.heap[e].readyAtTick < this.heap[t].readyAtTick)
3123
+ [this.heap[e], this.heap[t]] = [this.heap[t], this.heap[e]], e = t;
3124
+ else break;
3125
+ }
3126
+ }
3127
+ bubbleDown(e) {
3128
+ const t = this.heap.length;
3129
+ for (; ; ) {
3130
+ const n = 2 * e + 1, i = 2 * e + 2;
3131
+ let s = e;
3132
+ if (n < t && this.heap[n].readyAtTick < this.heap[s].readyAtTick && (s = n), i < t && this.heap[i].readyAtTick < this.heap[s].readyAtTick && (s = i), s !== e)
3133
+ [this.heap[e], this.heap[s]] = [this.heap[s], this.heap[e]], e = s;
3134
+ else break;
3135
+ }
3136
+ }
3137
+ extractMin() {
3138
+ if (this.heap.length === 0) return;
3139
+ const e = this.heap[0], t = this.heap.pop();
3140
+ return this.heap.length > 0 && t && (this.heap[0] = t, this.bubbleDown(0)), e;
3141
+ }
3142
+ }, ye = class {
3143
+ dirtyComponents;
3144
+ dirtyWires;
3145
+ dirtyEnodes;
3146
+ constructor() {
3147
+ this.dirtyComponents = /* @__PURE__ */ new Set(), this.dirtyWires = /* @__PURE__ */ new Set(), this.dirtyEnodes = /* @__PURE__ */ new Set();
3148
+ }
3149
+ markComponentDirty(e) {
3150
+ this.dirtyComponents.add(e);
3151
+ }
3152
+ markWireDirty(e) {
3153
+ this.dirtyWires.add(e);
3154
+ }
3155
+ markEnodeDirty(e) {
3156
+ this.dirtyEnodes.add(e);
3157
+ }
3158
+ setDirtyComponents(e) {
3159
+ this.dirtyComponents = new Set(e);
3160
+ }
3161
+ setDirtyEnodes(e) {
3162
+ this.dirtyEnodes = new Set(e);
3163
+ }
3164
+ setDirtyWires(e) {
3165
+ this.dirtyWires = new Set(e);
3166
+ }
3167
+ getDirtyElements() {
3168
+ const e = {
3169
+ components: new Set(this.dirtyComponents),
3170
+ wires: new Set(this.dirtyWires),
3171
+ enodes: new Set(this.dirtyEnodes)
3172
+ };
3173
+ return this.clear(), e;
3174
+ }
3175
+ hasDirtyElements() {
3176
+ return this.dirtyComponents.size > 0 || this.dirtyWires.size > 0 || this.dirtyEnodes.size > 0;
3177
+ }
3178
+ clear() {
3179
+ this.dirtyComponents.clear(), this.dirtyWires.clear(), this.dirtyEnodes.clear();
3180
+ }
3181
+ getDirtyComponentCount() {
3182
+ return this.dirtyComponents.size;
3183
+ }
3184
+ getDirtyWireCount() {
3185
+ return this.dirtyWires.size;
3186
+ }
3187
+ getDirtyEnodeCount() {
3188
+ return this.dirtyEnodes.size;
3189
+ }
3190
+ }, ve = class {
3191
+ currentState;
3192
+ history;
3193
+ historyEnabled;
3194
+ historyLimit;
3195
+ historyWriteIndex;
3196
+ constructor(e = !1, t = 1e3) {
3197
+ if (t < 1) throw new RangeError(`historyLimit must be at least 1 (got ${t})`);
3198
+ this.historyEnabled = e, this.historyLimit = t, this.currentState = new J(0), this.history = [], this.historyWriteIndex = 0;
3199
+ }
3200
+ getCurrentState() {
3201
+ return this.currentState;
3202
+ }
3203
+ getCurrentTick() {
3204
+ return this.currentState.tick;
3205
+ }
3206
+ advanceToNextTick() {
3207
+ const e = this.currentState.tick + 1;
3208
+ return this.historyEnabled && this.saveToHistory(this.currentState.clone()), this.currentState.tick = e, this.currentState;
3209
+ }
3210
+ getStateAtTick(e) {
3211
+ if (this.historyEnabled)
3212
+ return this.history.find((t) => t.tick === e);
3213
+ }
3214
+ getHistory() {
3215
+ return this.historyEnabled ? [...this.history].sort((e, t) => e.tick - t.tick) : [];
3216
+ }
3217
+ getOldestTick() {
3218
+ if (!(!this.historyEnabled || this.history.length === 0))
3219
+ return Math.min(...this.history.map((e) => e.tick));
3220
+ }
3221
+ getNewestHistoricalTick() {
3222
+ if (!(!this.historyEnabled || this.history.length === 0))
3223
+ return Math.max(...this.history.map((e) => e.tick));
3224
+ }
3225
+ clearHistory() {
3226
+ this.history = [], this.historyWriteIndex = 0;
3227
+ }
3228
+ reset() {
3229
+ this.currentState = new J(0), this.clearHistory();
3230
+ }
3231
+ isHistoryEnabled() {
3232
+ return this.historyEnabled;
3233
+ }
3234
+ getHistoryLimit() {
3235
+ return this.historyLimit;
3236
+ }
3237
+ getHistorySize() {
3238
+ return this.history.length;
3239
+ }
3240
+ saveToHistory(e) {
3241
+ this.history.length < this.historyLimit ? this.history.push(e) : (this.history[this.historyWriteIndex] = e, this.historyWriteIndex = (this.historyWriteIndex + 1) % this.historyLimit);
3242
+ }
3243
+ }, Pe = class {
3244
+ circuit;
3245
+ stateManager;
3246
+ eventQueue;
3247
+ commands;
3248
+ dirtyTracker;
3249
+ behaviorRegistry;
3250
+ constructor(e, t, n = {}) {
3251
+ this.circuit = e, this.behaviorRegistry = t, this.stateManager = new ve(n.enableHistory ?? !1, n.historyLimit ?? 1e3), this.eventQueue = new fe(), this.commands = /* @__PURE__ */ new Map(), this.dirtyTracker = new ye();
3252
+ try {
3253
+ this.initializeState();
3254
+ } catch (i) {
3255
+ throw console.error("Error during CircuitRunner initialization:", i), i;
3256
+ }
3257
+ }
3258
+ tick() {
3259
+ const e = this.eventQueue.size(), t = this.stateManager.getCurrentTick(), n = this.applyReadyEvents(t + 1), i = this.updateState(t + 1);
3260
+ i.firedEventCount = n.length, i.processedCommandCount = this.processCommands().length, i.scheduledEventCount = this.eventQueue.size() + i.firedEventCount - e;
3261
+ for (const s of n) s.hasChanged && this.dirtyTracker.markComponentDirty(s.componentState.componentId);
3262
+ return i.componentUpdateCount = this.dirtyTracker.getDirtyComponentCount(), this.stateManager.advanceToNextTick(), i.endTick = this.stateManager.getCurrentTick(), i;
3263
+ }
3264
+ tickN(e) {
3265
+ if (e < 1) throw new RangeError(`Tick count must be at least 1 (got ${e})`);
3266
+ const t = [];
3267
+ for (let n = 0; n < e; n++) t.push(this.tick());
3268
+ return t;
3269
+ }
3270
+ reset() {
3271
+ this.stateManager.reset(), this.eventQueue.clear(), this.dirtyTracker.clear(), this.initializeState();
3272
+ }
3273
+ getCurrentTick() {
3274
+ return this.stateManager.getCurrentTick();
3275
+ }
3276
+ getCurrentState() {
3277
+ return this.stateManager.getCurrentState();
3278
+ }
3279
+ getEnodeState(e) {
3280
+ return this.stateManager.getCurrentState().nodeStates.get(e);
3281
+ }
3282
+ getWireState(e) {
3283
+ return this.stateManager.getCurrentState().wireStates.get(e);
3284
+ }
3285
+ getComponentState(e) {
3286
+ return this.stateManager.getCurrentState().componentStates.get(e);
3287
+ }
3288
+ getStateAtTick(e) {
3289
+ return this.stateManager.getStateAtTick(e);
3290
+ }
3291
+ hasBehavior(e) {
3292
+ return this.behaviorRegistry.has(e);
3293
+ }
3294
+ submitCommand(e) {
3295
+ if (!this.circuit.hasComponent(e.targetId)) throw Error(`Cannot submit command for unknown component ID '${e.targetId}'`);
3296
+ return this.commands.has(e.targetId) ? !1 : (e.scheduledAtTick = this.getCurrentTick(), this.commands.set(e.targetId, e), !0);
3297
+ }
3298
+ processCommands() {
3299
+ const e = this.stateManager.getCurrentState(), t = [], n = /* @__PURE__ */ new Set(), i = [];
3300
+ for (const s of this.commands.values()) {
3301
+ const r = this.circuit.getComponent(s.targetId), a = this.behaviorRegistry.get(r.type).onUserCommand(r, e.componentStates.get(r.id), s);
3302
+ a.shouldCancelPending && n.add(r.id);
3303
+ for (const o of a.scheduledEvents) i.push(o);
3304
+ t.push(a), a.hasChanged && this.dirtyTracker.markComponentDirty(r.id);
3305
+ }
3306
+ return this.eventQueue.scheduleMany(i, n), this.commands.clear(), t;
3307
+ }
3308
+ getInitializationOrder(e) {
3309
+ const t = e.get("initializationOrder");
3310
+ if (!t || t === "") return 0;
3311
+ const n = parseInt(t, 10);
3312
+ return isNaN(n) ? 0 : n;
3313
+ }
3314
+ initializeState() {
3315
+ const e = this.stateManager.getCurrentState();
3316
+ for (const c of this.circuit.getAllComponents()) {
3317
+ if (c.pins.length < 1) continue;
3318
+ const p = this.behaviorRegistry.get(c.type);
3319
+ if (!p) continue;
3320
+ const l = p.createInitialState(c);
3321
+ e.componentStates.set(c.id, l), this.dirtyTracker.markComponentDirty(c.id);
3322
+ }
3323
+ for (const c of this.circuit.getAllENodes()) e.nodeStates.set(c.id, {
3324
+ hasVoltage: c.source === g.Voltage,
3325
+ hasCurrent: c.source === g.Current,
3326
+ locked: !!c.source
3327
+ });
3328
+ for (const c of this.circuit.getAllWires()) e.wireStates.set(c.id, {
3329
+ hasVoltage: !1,
3330
+ hasCurrent: !1,
3331
+ locked: !1
3332
+ });
3333
+ const t = this.circuit.getAllComponents(), n = /* @__PURE__ */ new Map();
3334
+ for (const c of t) {
3335
+ const p = this.getInitializationOrder(c.config), l = n.get(p) ?? [];
3336
+ l.push(c), n.set(p, l);
3337
+ }
3338
+ const i = Array.from(n.keys()).sort((c, p) => c - p);
3339
+ for (const c of i) n.get(c).sort((p, l) => p.id.localeCompare(l.id));
3340
+ let s = !0, r = 0;
3341
+ const a = 100;
3342
+ for (; s && r < a; ) {
3343
+ s = !1, r++;
3344
+ for (const c of i) {
3345
+ const p = n.get(c);
3346
+ for (const l of p) {
3347
+ const d = this.behaviorRegistry.get(l.type);
3348
+ if (!d) continue;
3349
+ const y = e.componentStates.get(l.id);
3350
+ if (!y) continue;
3351
+ this.propagateConductivity();
3352
+ const f = d.onStart(l, y);
3353
+ if (f) {
3354
+ e.componentStates.set(l.id, f.componentState), f.shouldCancelPending && this.eventQueue.removeEventsForTarget(l.id);
3355
+ for (const h of f.scheduledEvents) this.eventQueue.schedule(h);
3356
+ continue;
3357
+ }
3358
+ const v = d.onPinsChange(l, y, e.nodeStates, 0);
3359
+ v.hasChanged && (s = !0, e.componentStates.set(l.id, v.componentState));
3360
+ for (const h of v.scheduledEvents) {
3361
+ const S = d.onEventFiring(l, y, h);
3362
+ S.hasChanged && (s = !0, e.componentStates.set(l.id, S.componentState));
3363
+ }
3364
+ }
3365
+ }
3366
+ }
3367
+ const o = this.updateState(0);
3368
+ return this.dirtyTracker.setDirtyComponents(/* @__PURE__ */ new Set([...this.circuit.getAllComponents().map((c) => c.id)])), this.dirtyTracker.setDirtyEnodes(/* @__PURE__ */ new Set([...this.circuit.getAllENodes().map((c) => c.id)])), this.dirtyTracker.setDirtyWires(/* @__PURE__ */ new Set([...this.circuit.getAllWires().map((c) => c.id)])), o;
3369
+ }
3370
+ updateState(e) {
3371
+ const t = this.stateManager.getCurrentState(), { updatedNodes: n, updatedWires: i } = this.propagateConductivity(), s = this.circuit.getComponentsOfPins(n), r = [], a = /* @__PURE__ */ new Set();
3372
+ let o = Array.from(s);
3373
+ e === 0 && (o = o.sort((l, d) => {
3374
+ const y = this.circuit.getComponent(l), f = this.circuit.getComponent(d), v = this.getInitializationOrder(y.config), h = this.getInitializationOrder(f.config);
3375
+ return v !== h ? v - h : l.localeCompare(d);
3376
+ }));
3377
+ const c = /* @__PURE__ */ new Set(), p = [];
3378
+ for (const l of o) {
3379
+ const d = this.circuit.getComponent(l), y = this.behaviorRegistry.get(d.type);
3380
+ if (!y) continue;
3381
+ const f = y.onPinsChange(d, t.componentStates.get(l), t.nodeStates, e);
3382
+ f.shouldCancelPending && c.add(l), f.hasChanged && (a.add(l), r.push(f));
3383
+ for (const v of f.scheduledEvents) p.push(v);
3384
+ }
3385
+ return this.eventQueue.scheduleMany(p, c), this.dirtyTracker.setDirtyComponents(a), this.dirtyTracker.setDirtyEnodes(n), this.dirtyTracker.setDirtyWires(i), {
3386
+ startTick: this.getCurrentTick(),
3387
+ endTick: this.getCurrentTick(),
3388
+ componentUpdateCount: a.size,
3389
+ nodeUpdateCount: n.size,
3390
+ wireUpdateCount: i.size,
3391
+ processedCommandCount: 0,
3392
+ scheduledEventCount: p.length,
3393
+ firedEventCount: 0
3394
+ };
3395
+ }
3396
+ propagateConductivity() {
3397
+ const e = this.stateManager.getCurrentState(), t = (a) => {
3398
+ const o = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set(), p = this.circuit.getAllENodes().filter((h) => h.source == a).map((h) => h.id), l = /* @__PURE__ */ new Set([...this.circuit.getAllENodes().filter((h) => !h.source).map((h) => h.id)]), d = /* @__PURE__ */ new Set([...this.circuit.getAllWires().map((h) => h.id)]), { nodes: y, wires: f } = this.computeReachability(a, p, e.componentStates), v = a == g.Voltage ? "hasVoltage" : "hasCurrent";
3399
+ for (const h of y) {
3400
+ const S = e.nodeStates.get(h);
3401
+ S && !S.locked && (S[v] || (S[v] = !0, o.add(h)), l.delete(h));
3402
+ }
3403
+ for (const h of l) {
3404
+ const S = e.nodeStates.get(h);
3405
+ S && !S.locked && S[v] && (S[v] = !1, o.add(h));
3406
+ }
3407
+ for (const h of f) {
3408
+ const S = e.wireStates.get(h);
3409
+ S && (S[v] || (S[v] = !0, c.add(h)), d.delete(h));
3410
+ }
3411
+ for (const h of d) {
3412
+ const S = e.wireStates.get(h);
3413
+ S && S[v] && (S[v] = !1, c.add(h));
3414
+ }
3415
+ return {
3416
+ updatedNodes: o,
3417
+ updatedWires: c
3418
+ };
3419
+ }, { updatedNodes: n, updatedWires: i } = t(g.Voltage), { updatedNodes: s, updatedWires: r } = t(g.Current);
3420
+ return {
3421
+ updatedNodes: /* @__PURE__ */ new Set([...n, ...s]),
3422
+ updatedWires: /* @__PURE__ */ new Set([...i, ...r])
3423
+ };
3424
+ }
3425
+ computeReachability(e, t, n) {
3426
+ const i = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), r = [];
3427
+ for (const a of t)
3428
+ r.push(a), i.add(a);
3429
+ for (; r.length > 0; ) {
3430
+ const a = r.shift();
3431
+ for (const c of this.circuit.getWiresByNode(a)) {
3432
+ const p = c.node1 === a ? c.node2 : c.node1;
3433
+ i.has(p) || (i.add(p), r.push(p)), s.has(c.id) || s.add(c.id);
3434
+ }
3435
+ const o = this.circuit.getENode(a);
3436
+ if (o.type === P.Pin) {
3437
+ const c = this.circuit.getComponent(o.component), p = this.behaviorRegistry.get(c.type);
3438
+ if (!p) continue;
3439
+ const l = c.getPinMetadata(a);
3440
+ if (l?.subtype === "logicInput" || l?.subtype === "logicOutput") continue;
3441
+ const d = n.get(c.id);
3442
+ for (const y of c.pins)
3443
+ y !== a && (i.has(y) || p.allowConductivity(c, d, e, a, y) && (i.add(y), r.push(y)));
3444
+ }
3445
+ }
3446
+ return {
3447
+ nodes: i,
3448
+ wires: s
3449
+ };
3450
+ }
3451
+ applyReadyEvents(e) {
3452
+ const t = this.stateManager.getCurrentState(), n = this.eventQueue.getReadyEvents(e), i = [], s = /* @__PURE__ */ new Set(), r = [];
3453
+ for (const a of n) {
3454
+ const o = this.circuit.getComponent(a.targetId), c = this.behaviorRegistry.get(o.type);
3455
+ if (!c) continue;
3456
+ const p = t.componentStates.get(o.id), l = c.onEventFiring(o, p, a);
3457
+ l.shouldCancelPending && s.add(o.id);
3458
+ for (const d of l.scheduledEvents) r.push(d);
3459
+ i.push(l);
3460
+ }
3461
+ return this.eventQueue.scheduleMany(r, s), i;
3462
+ }
3463
+ };
3464
+ function xe(e) {
3465
+ return e.register(new Ut()).register(new Xt()).register(new Qt()).register(new Kt()).register(new Yt()).register(new Zt()).register(new jt()).register(new te()), e;
3466
+ }
3467
+ function Ie(e) {
3468
+ return e.register(new ee()).register(new ie()).register(new ne()).register(new se()).register(new re()).register(new ae()).register(new oe()).register(new ce()).register(new ue()).register(new le()), e;
3469
+ }
3470
+ function Te(e) {
3471
+ return e.register(new pe()).register(new de()).register(new he()).register(new ge()), e;
3472
+ }
3473
+ export {
3474
+ Tt as $,
3475
+ x as A,
3476
+ Se as At,
3477
+ Vt as B,
3478
+ jt as C,
3479
+ yt as Ct,
3480
+ Qt as D,
3481
+ Q as Dt,
3482
+ Kt as E,
3483
+ M as Et,
3484
+ zt as F,
3485
+ Mt as G,
3486
+ Gt as H,
3487
+ A as I,
3488
+ At as J,
3489
+ Dt as K,
3490
+ Wt as L,
3491
+ Jt as M,
3492
+ Ft as N,
3493
+ Xt as O,
3494
+ O as Ot,
3495
+ Ht as P,
3496
+ ct as Q,
3497
+ Rt as R,
3498
+ te as S,
3499
+ $ as St,
3500
+ Yt as T,
3501
+ ht as Tt,
3502
+ kt as U,
3503
+ _t as V,
3504
+ Lt as W,
3505
+ Et as X,
3506
+ Nt as Y,
3507
+ Ot as Z,
3508
+ re as _,
3509
+ I as _t,
3510
+ ve as a,
3511
+ at,
3512
+ ie as b,
3513
+ g as bt,
3514
+ ge as c,
3515
+ xt as ct,
3516
+ pe as d,
3517
+ H as dt,
3518
+ It as et,
3519
+ le as f,
3520
+ z as ft,
3521
+ ae as g,
3522
+ Z as gt,
3523
+ oe as h,
3524
+ we as ht,
3525
+ Pe as i,
3526
+ be as it,
3527
+ Ce as j,
3528
+ Ut as k,
3529
+ dt as kt,
3530
+ he as l,
3531
+ bt as lt,
3532
+ ce as m,
3533
+ L as mt,
3534
+ xe as n,
3535
+ J as nt,
3536
+ ye as o,
3537
+ me as ot,
3538
+ ue as p,
3539
+ E as pt,
3540
+ Bt as q,
3541
+ Ie as r,
3542
+ T as rt,
3543
+ fe as s,
3544
+ Pt as st,
3545
+ Te as t,
3546
+ b as tt,
3547
+ de as u,
3548
+ F as ut,
3549
+ se as v,
3550
+ u as vt,
3551
+ Zt as w,
3552
+ V as wt,
3553
+ ee as x,
3554
+ P as xt,
3555
+ ne as y,
3556
+ j as yt,
3557
+ $t as z
3558
+ };
3559
+
3560
+ //# sourceMappingURL=core-b6Q8w2sn.js.map