simple-circuit-engine 0.0.12 → 0.0.14

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 (99) hide show
  1. package/AGENTS.md +9 -6
  2. package/CLAUDE.md +2 -0
  3. package/README.md +8 -8
  4. package/dist/core/index.js +109 -74
  5. package/dist/core/setup.d.ts +18 -0
  6. package/dist/core/simulation/behaviors/arithmetic/AdderBehavior.d.ts +28 -0
  7. package/dist/core/simulation/behaviors/arithmetic/ArithmeticBehaviorMixin.d.ts +63 -0
  8. package/dist/core/simulation/behaviors/arithmetic/EightBitAdderBehavior.d.ts +51 -0
  9. package/dist/core/simulation/behaviors/arithmetic/EightBitOnesComplementBehavior.d.ts +29 -0
  10. package/dist/core/simulation/behaviors/arithmetic/HalfAdderBehavior.d.ts +22 -0
  11. package/dist/core/simulation/behaviors/arithmetic/index.d.ts +7 -0
  12. package/dist/core/simulation/behaviors/index.d.ts +14 -0
  13. package/dist/core/simulation/behaviors/interface/EightInputBehavior.d.ts +9 -0
  14. package/dist/core/simulation/behaviors/interface/EightLightBehavior.d.ts +9 -0
  15. package/dist/core/simulation/behaviors/interface/FourInputBehavior.d.ts +9 -0
  16. package/dist/core/simulation/behaviors/interface/FourLightBehavior.d.ts +9 -0
  17. package/dist/core/simulation/behaviors/interface/InputBehaviorMixin.d.ts +37 -0
  18. package/dist/core/simulation/behaviors/interface/LightBehaviorMixin.d.ts +60 -0
  19. package/dist/core/simulation/behaviors/interface/OneInputBehavior.d.ts +9 -0
  20. package/dist/core/simulation/behaviors/interface/OneLightBehavior.d.ts +9 -0
  21. package/dist/core/simulation/behaviors/interface/TwoInputBehavior.d.ts +9 -0
  22. package/dist/core/simulation/behaviors/interface/TwoLightBehavior.d.ts +9 -0
  23. package/dist/core/simulation/behaviors/interface/index.d.ts +0 -0
  24. package/dist/core/simulation/states/arithmetic/AdderState.d.ts +16 -0
  25. package/dist/core/simulation/states/arithmetic/ArithmeticState.d.ts +53 -0
  26. package/dist/core/simulation/states/arithmetic/EightBitAdderState.d.ts +25 -0
  27. package/dist/core/simulation/states/arithmetic/EightBitOnesComplementState.d.ts +18 -0
  28. package/dist/core/simulation/states/arithmetic/HalfAdderState.d.ts +16 -0
  29. package/dist/core/simulation/states/arithmetic/index.d.ts +7 -0
  30. package/dist/core/simulation/states/index.d.ts +15 -0
  31. package/dist/core/simulation/states/interface/EightInputState.d.ts +6 -0
  32. package/dist/core/simulation/states/interface/EightLightState.d.ts +6 -0
  33. package/dist/core/simulation/states/interface/FourInputState.d.ts +6 -0
  34. package/dist/core/simulation/states/interface/FourLightState.d.ts +6 -0
  35. package/dist/core/simulation/states/interface/InputState.d.ts +45 -0
  36. package/dist/core/simulation/states/interface/LightState.d.ts +54 -0
  37. package/dist/core/simulation/states/interface/OneInputState.d.ts +6 -0
  38. package/dist/core/simulation/states/interface/OneLightState.d.ts +6 -0
  39. package/dist/core/simulation/states/interface/TwoInputState.d.ts +6 -0
  40. package/dist/core/simulation/states/interface/TwoLightState.d.ts +6 -0
  41. package/dist/core/simulation/types.d.ts +10 -2
  42. package/dist/core/topology/Component.d.ts +6 -1
  43. package/dist/core/topology/ENode.d.ts +7 -2
  44. package/dist/core/topology/index.d.ts +2 -0
  45. package/dist/core/topology/networkTraversal.d.ts +50 -0
  46. package/dist/core/topology/types.d.ts +31 -6
  47. package/dist/core-HH6iRWtB.js +4671 -0
  48. package/dist/core-HH6iRWtB.js.map +1 -0
  49. package/dist/i18n/index.d.ts +1158 -0
  50. package/dist/i18n/locales/en.json.d.ts +366 -0
  51. package/dist/i18n/locales/fr.json.d.ts +366 -0
  52. package/dist/index.d.ts +1 -0
  53. package/dist/index.js +172 -118
  54. package/dist/scene/CircuitEngine.d.ts +49 -4
  55. package/dist/scene/index.d.ts +6 -2
  56. package/dist/scene/index.js +62 -45
  57. package/dist/scene/setup.d.ts +18 -0
  58. package/dist/scene/shared/AbstractCircuitController.d.ts +11 -3
  59. package/dist/scene/shared/HoverManager.d.ts +15 -0
  60. package/dist/scene/shared/components/arithmetic/AdderVisualFactory.d.ts +54 -0
  61. package/dist/scene/shared/components/arithmetic/EightBitAdderVisualFactory.d.ts +45 -0
  62. package/dist/scene/shared/components/arithmetic/EightBitOnesComplementVisualFactory.d.ts +63 -0
  63. package/dist/scene/shared/components/arithmetic/HalfAdderVisualFactory.d.ts +55 -0
  64. package/dist/scene/shared/components/arithmetic/index.d.ts +4 -0
  65. package/dist/scene/shared/components/index.d.ts +14 -0
  66. package/dist/scene/shared/components/interface/EightInputVisualFactory.d.ts +15 -0
  67. package/dist/scene/shared/components/interface/EightLightVisualFactory.d.ts +15 -0
  68. package/dist/scene/shared/components/interface/FourInputVisualFactory.d.ts +15 -0
  69. package/dist/scene/shared/components/interface/FourLightVisualFactory.d.ts +15 -0
  70. package/dist/scene/shared/components/interface/InputVisualFactoryBase.d.ts +50 -0
  71. package/dist/scene/shared/components/interface/LightVisualFactoryBase.d.ts +46 -0
  72. package/dist/scene/shared/components/interface/OneInputVisualFactory.d.ts +15 -0
  73. package/dist/scene/shared/components/interface/OneLightVisualFactory.d.ts +15 -0
  74. package/dist/scene/shared/components/interface/TwoInputVisualFactory.d.ts +15 -0
  75. package/dist/scene/shared/components/interface/TwoLightVisualFactory.d.ts +15 -0
  76. package/dist/scene/shared/types.d.ts +34 -4
  77. package/dist/scene/shared/utils/ControlsUtils.d.ts +1 -1
  78. package/dist/scene/shared/utils/GeometryUtils.d.ts +111 -0
  79. package/dist/scene/static/CircuitController.d.ts +13 -1
  80. package/dist/scene/static/tools/BuildTool.d.ts +81 -0
  81. package/dist/scene/static/tools/ComponentPickerWidget.d.ts +7 -0
  82. package/dist/scene/static/tools/ConfigPanelWidget.d.ts +14 -0
  83. package/dist/scene/static/tools/MultiWiringPlacement.d.ts +40 -0
  84. package/dist/scene/widgets/HelpWidget.d.ts +13 -0
  85. package/dist/scene/widgets/ModeWidget.d.ts +16 -0
  86. package/dist/scene/widgets/MultiWiringWidget.d.ts +21 -0
  87. package/dist/scene/{static → widgets}/PinTooltipWidget.d.ts +7 -1
  88. package/dist/scene/widgets/SimulationPlayerWidget.d.ts +62 -0
  89. package/dist/scene/widgets/ToolsWidget.d.ts +18 -0
  90. package/dist/scene/widgets/WidgetsManager.d.ts +65 -0
  91. package/dist/scene/widgets/assets/icons.d.ts +20 -0
  92. package/dist/scene/widgets/index.d.ts +9 -0
  93. package/dist/scene/widgets/styles.d.ts +33 -0
  94. package/dist/{scene-CVsDdySt.js → scene-C1xhdw_B.js} +3993 -772
  95. package/dist/scene-C1xhdw_B.js.map +1 -0
  96. package/package.json +14 -9
  97. package/dist/core-Bjta9Y7_.js +0 -2707
  98. package/dist/core-Bjta9Y7_.js.map +0 -1
  99. package/dist/scene-CVsDdySt.js.map +0 -1
@@ -0,0 +1,4671 @@
1
+ function yt(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 = X(a.value, t, n, i);
5
+ else if (a.get != null) a.get = X(a.get, t, n, i);
6
+ else throw "Only put a Memoize() decorator on a method or get accessor.";
7
+ };
8
+ }
9
+ function _e(e, t) {
10
+ return yt({
11
+ expiring: e,
12
+ hashFunction: t
13
+ });
14
+ }
15
+ var _ = /* @__PURE__ */ new Map();
16
+ function X(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 u of i) _.has(u) ? _.get(u).push(o) : _.set(u, [o]);
28
+ if (t || r.length > 0 || n > 0) {
29
+ let u;
30
+ t === !0 ? u = r.map((d) => d.toString()).join("!") : t ? u = t.apply(this, r) : u = r[0];
31
+ const l = `${u}__timestamp`;
32
+ let p = !1;
33
+ if (n > 0) if (!o.has(l)) p = !0;
34
+ else {
35
+ let d = o.get(l);
36
+ p = Date.now() - d > n;
37
+ }
38
+ o.has(u) && !p ? a = o.get(u) : (a = e.apply(this, r), o.set(u, a), n > 0 && o.set(l, Date.now()));
39
+ } else {
40
+ const u = this;
41
+ o.has(u) ? a = o.get(u) : (a = e.apply(this, r), o.set(u, a));
42
+ }
43
+ return a;
44
+ };
45
+ }
46
+ var D = class j {
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 j(t.x, t.y, t.z);
62
+ }
63
+ toString() {
64
+ return `Position(${this.x}, ${this.y}, ${this.z})`;
65
+ }
66
+ }, tt = class et {
67
+ constructor(t = new D(0, 15, 15), n = new D(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 et(D.fromJSON(t.position), D.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
+ }, H = class it {
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 it(t.x, t.y);
100
+ }
101
+ toString() {
102
+ return `Position(${this.x}, ${this.y})`;
103
+ }
104
+ };
105
+ function vt(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 = St(t, r, a);
111
+ o < n && (n = o, i = s + 1);
112
+ }
113
+ return i;
114
+ }
115
+ function St(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, u = t.y + a * s;
119
+ return Math.sqrt((e.x - o) ** 2 + (e.y - u) ** 2);
120
+ }
121
+ function V(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
+ wt(s, r, a, t) || n.push(r);
127
+ }
128
+ return n.push(e[e.length - 1]), n;
129
+ }
130
+ function wt(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 mt = class nt {
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 nt(t);
143
+ }
144
+ equals(t) {
145
+ return this.angle === t.angle;
146
+ }
147
+ toString() {
148
+ return `Rotation(${this.angle}°)`;
149
+ }
150
+ };
151
+ function J() {
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 st = "0.0.14", h = /* @__PURE__ */ (function(e) {
172
+ return e.Voltage = "Voltage", e.Current = "Current", e;
173
+ })({}), w = /* @__PURE__ */ (function(e) {
174
+ return e.Pin = "Pin", e.BranchingPoint = "BranchingPoint", e;
175
+ })({}), Ve = [
176
+ "CMOS1",
177
+ "TTL1",
178
+ "Sandbox"
179
+ ], rt = "CMOS1", c = /* @__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.OneInput = "oneInput", e.TwoInput = "twoInput", e.FourInput = "fourInput", e.EightInput = "eightInput", e.OneLight = "oneLight", e.TwoLight = "twoLight", e.FourLight = "fourLight", e.EightLight = "eightLight", e;
181
+ })({}), I = {
182
+ [c.Switch]: {
183
+ id: c.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
+ [c.DoubleThrowSwitch]: {
192
+ id: c.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
+ [c.Battery]: {
205
+ id: c.Battery,
206
+ pins: /* @__PURE__ */ new Map([["cathode", {
207
+ subtype: "mainVcc",
208
+ sourceType: h.Voltage
209
+ }], ["anode", {
210
+ subtype: "mainGnd",
211
+ sourceType: h.Current
212
+ }]]),
213
+ config: /* @__PURE__ */ new Map([])
214
+ },
215
+ [c.Lightbulb]: {
216
+ id: c.Lightbulb,
217
+ pins: /* @__PURE__ */ new Map([["pin1", { subtype: "free" }], ["pin2", { subtype: "free" }]]),
218
+ config: /* @__PURE__ */ new Map([["transitionSpan", "1"], ["size", "1"]])
219
+ },
220
+ [c.Relay]: {
221
+ id: c.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
+ [c.SmallLED]: {
235
+ id: c.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
+ [c.RectangleLED]: {
246
+ id: c.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
+ [c.Cube]: {
258
+ id: c.Cube,
259
+ pins: /* @__PURE__ */ new Map([]),
260
+ config: /* @__PURE__ */ new Map([["color", "red"]])
261
+ },
262
+ [c.Label]: {
263
+ id: c.Label,
264
+ pins: /* @__PURE__ */ new Map([]),
265
+ config: /* @__PURE__ */ new Map([["text", "Label"], ["size", "1"]])
266
+ },
267
+ [c.Clock]: {
268
+ id: c.Clock,
269
+ pins: /* @__PURE__ */ new Map([
270
+ ["vcc", {
271
+ subtype: "vcc",
272
+ sourceType: h.Voltage
273
+ }],
274
+ ["output", {
275
+ subtype: "logicOutput",
276
+ logicPinData: {
277
+ interface: "output",
278
+ index: 0,
279
+ size: 1
280
+ }
281
+ }],
282
+ ["gnd", {
283
+ subtype: "gnd",
284
+ sourceType: h.Current
285
+ }]
286
+ ]),
287
+ config: /* @__PURE__ */ new Map([["startHigh", "true"], ["halfPeriod", "2"]])
288
+ },
289
+ [c.Inverter]: {
290
+ id: c.Inverter,
291
+ pins: /* @__PURE__ */ new Map([
292
+ ["vcc", {
293
+ subtype: "vcc",
294
+ sourceType: h.Voltage
295
+ }],
296
+ ["input", {
297
+ subtype: "logicInput",
298
+ logicPinData: {
299
+ interface: "input",
300
+ index: 0,
301
+ size: 1
302
+ }
303
+ }],
304
+ ["output", {
305
+ subtype: "logicOutput",
306
+ logicPinData: {
307
+ interface: "output",
308
+ index: 0,
309
+ size: 1
310
+ }
311
+ }],
312
+ ["gnd", {
313
+ subtype: "gnd",
314
+ sourceType: h.Current
315
+ }]
316
+ ]),
317
+ config: /* @__PURE__ */ new Map([
318
+ ["defaultLogicFamily", "CMOS1"],
319
+ ["activationLogic", "negative"],
320
+ ["transitionSpan", "1"],
321
+ ["initializationOrder", ""]
322
+ ])
323
+ },
324
+ [c.NandGate]: {
325
+ id: c.NandGate,
326
+ pins: /* @__PURE__ */ new Map([
327
+ ["vcc", {
328
+ subtype: "vcc",
329
+ sourceType: h.Voltage
330
+ }],
331
+ ["input-0", {
332
+ subtype: "logicInput",
333
+ logicPinData: {
334
+ interface: "input",
335
+ index: 0,
336
+ size: 2
337
+ }
338
+ }],
339
+ ["input-1", {
340
+ subtype: "logicInput",
341
+ logicPinData: {
342
+ interface: "input",
343
+ index: 1,
344
+ size: 2
345
+ }
346
+ }],
347
+ ["output", {
348
+ subtype: "logicOutput",
349
+ logicPinData: {
350
+ interface: "output",
351
+ index: 0,
352
+ size: 1
353
+ }
354
+ }],
355
+ ["gnd", {
356
+ subtype: "gnd",
357
+ sourceType: h.Current
358
+ }]
359
+ ]),
360
+ config: /* @__PURE__ */ new Map([
361
+ ["defaultLogicFamily", "CMOS1"],
362
+ ["activationLogic", "negative"],
363
+ ["transitionSpan", "1"],
364
+ ["initializationOrder", ""]
365
+ ])
366
+ },
367
+ [c.Nand4Gate]: {
368
+ id: c.Nand4Gate,
369
+ pins: /* @__PURE__ */ new Map([
370
+ ["vcc", {
371
+ subtype: "vcc",
372
+ sourceType: h.Voltage
373
+ }],
374
+ ["input-0", {
375
+ subtype: "logicInput",
376
+ logicPinData: {
377
+ interface: "input",
378
+ index: 0,
379
+ size: 4
380
+ }
381
+ }],
382
+ ["input-1", {
383
+ subtype: "logicInput",
384
+ logicPinData: {
385
+ interface: "input",
386
+ index: 1,
387
+ size: 4
388
+ }
389
+ }],
390
+ ["input-2", {
391
+ subtype: "logicInput",
392
+ logicPinData: {
393
+ interface: "input",
394
+ index: 2,
395
+ size: 4
396
+ }
397
+ }],
398
+ ["input-3", {
399
+ subtype: "logicInput",
400
+ logicPinData: {
401
+ interface: "input",
402
+ index: 3,
403
+ size: 4
404
+ }
405
+ }],
406
+ ["output", {
407
+ subtype: "logicOutput",
408
+ logicPinData: {
409
+ interface: "output",
410
+ index: 0,
411
+ size: 1
412
+ }
413
+ }],
414
+ ["gnd", {
415
+ subtype: "gnd",
416
+ sourceType: h.Current
417
+ }]
418
+ ]),
419
+ config: /* @__PURE__ */ new Map([
420
+ ["defaultLogicFamily", "CMOS1"],
421
+ ["activationLogic", "negative"],
422
+ ["transitionSpan", "2"],
423
+ ["initializationOrder", ""]
424
+ ])
425
+ },
426
+ [c.Nand8Gate]: {
427
+ id: c.Nand8Gate,
428
+ pins: /* @__PURE__ */ new Map([
429
+ ["vcc", {
430
+ subtype: "vcc",
431
+ sourceType: h.Voltage
432
+ }],
433
+ ["input-0", {
434
+ subtype: "logicInput",
435
+ logicPinData: {
436
+ interface: "input",
437
+ index: 0,
438
+ size: 8
439
+ }
440
+ }],
441
+ ["input-1", {
442
+ subtype: "logicInput",
443
+ logicPinData: {
444
+ interface: "input",
445
+ index: 1,
446
+ size: 8
447
+ }
448
+ }],
449
+ ["input-2", {
450
+ subtype: "logicInput",
451
+ logicPinData: {
452
+ interface: "input",
453
+ index: 2,
454
+ size: 8
455
+ }
456
+ }],
457
+ ["input-3", {
458
+ subtype: "logicInput",
459
+ logicPinData: {
460
+ interface: "input",
461
+ index: 3,
462
+ size: 8
463
+ }
464
+ }],
465
+ ["input-4", {
466
+ subtype: "logicInput",
467
+ logicPinData: {
468
+ interface: "input",
469
+ index: 4,
470
+ size: 8
471
+ }
472
+ }],
473
+ ["input-5", {
474
+ subtype: "logicInput",
475
+ logicPinData: {
476
+ interface: "input",
477
+ index: 5,
478
+ size: 8
479
+ }
480
+ }],
481
+ ["input-6", {
482
+ subtype: "logicInput",
483
+ logicPinData: {
484
+ interface: "input",
485
+ index: 6,
486
+ size: 8
487
+ }
488
+ }],
489
+ ["input-7", {
490
+ subtype: "logicInput",
491
+ logicPinData: {
492
+ interface: "input",
493
+ index: 7,
494
+ size: 8
495
+ }
496
+ }],
497
+ ["output", {
498
+ subtype: "logicOutput",
499
+ logicPinData: {
500
+ interface: "output",
501
+ index: 0,
502
+ size: 1
503
+ }
504
+ }],
505
+ ["gnd", {
506
+ subtype: "gnd",
507
+ sourceType: h.Current
508
+ }]
509
+ ]),
510
+ config: /* @__PURE__ */ new Map([
511
+ ["defaultLogicFamily", "CMOS1"],
512
+ ["activationLogic", "negative"],
513
+ ["transitionSpan", "3"],
514
+ ["initializationOrder", ""]
515
+ ])
516
+ },
517
+ [c.NorGate]: {
518
+ id: c.NorGate,
519
+ pins: /* @__PURE__ */ new Map([
520
+ ["vcc", {
521
+ subtype: "vcc",
522
+ sourceType: h.Voltage
523
+ }],
524
+ ["input-0", {
525
+ subtype: "logicInput",
526
+ logicPinData: {
527
+ interface: "input",
528
+ index: 0,
529
+ size: 2
530
+ }
531
+ }],
532
+ ["input-1", {
533
+ subtype: "logicInput",
534
+ logicPinData: {
535
+ interface: "input",
536
+ index: 1,
537
+ size: 2
538
+ }
539
+ }],
540
+ ["output", {
541
+ subtype: "logicOutput",
542
+ logicPinData: {
543
+ interface: "output",
544
+ index: 0,
545
+ size: 1
546
+ }
547
+ }],
548
+ ["gnd", {
549
+ subtype: "gnd",
550
+ sourceType: h.Current
551
+ }]
552
+ ]),
553
+ config: /* @__PURE__ */ new Map([
554
+ ["defaultLogicFamily", "CMOS1"],
555
+ ["activationLogic", "negative"],
556
+ ["transitionSpan", "1"],
557
+ ["initializationOrder", ""]
558
+ ])
559
+ },
560
+ [c.Nor4Gate]: {
561
+ id: c.Nor4Gate,
562
+ pins: /* @__PURE__ */ new Map([
563
+ ["vcc", {
564
+ subtype: "vcc",
565
+ sourceType: h.Voltage
566
+ }],
567
+ ["input-0", {
568
+ subtype: "logicInput",
569
+ logicPinData: {
570
+ interface: "input",
571
+ index: 0,
572
+ size: 4
573
+ }
574
+ }],
575
+ ["input-1", {
576
+ subtype: "logicInput",
577
+ logicPinData: {
578
+ interface: "input",
579
+ index: 1,
580
+ size: 4
581
+ }
582
+ }],
583
+ ["input-2", {
584
+ subtype: "logicInput",
585
+ logicPinData: {
586
+ interface: "input",
587
+ index: 2,
588
+ size: 4
589
+ }
590
+ }],
591
+ ["input-3", {
592
+ subtype: "logicInput",
593
+ logicPinData: {
594
+ interface: "input",
595
+ index: 3,
596
+ size: 4
597
+ }
598
+ }],
599
+ ["output", {
600
+ subtype: "logicOutput",
601
+ logicPinData: {
602
+ interface: "output",
603
+ index: 0,
604
+ size: 1
605
+ }
606
+ }],
607
+ ["gnd", {
608
+ subtype: "gnd",
609
+ sourceType: h.Current
610
+ }]
611
+ ]),
612
+ config: /* @__PURE__ */ new Map([
613
+ ["defaultLogicFamily", "CMOS1"],
614
+ ["activationLogic", "negative"],
615
+ ["transitionSpan", "2"],
616
+ ["initializationOrder", ""]
617
+ ])
618
+ },
619
+ [c.Nor8Gate]: {
620
+ id: c.Nor8Gate,
621
+ pins: /* @__PURE__ */ new Map([
622
+ ["vcc", {
623
+ subtype: "vcc",
624
+ sourceType: h.Voltage
625
+ }],
626
+ ["input-0", {
627
+ subtype: "logicInput",
628
+ logicPinData: {
629
+ interface: "input",
630
+ index: 0,
631
+ size: 8
632
+ }
633
+ }],
634
+ ["input-1", {
635
+ subtype: "logicInput",
636
+ logicPinData: {
637
+ interface: "input",
638
+ index: 1,
639
+ size: 8
640
+ }
641
+ }],
642
+ ["input-2", {
643
+ subtype: "logicInput",
644
+ logicPinData: {
645
+ interface: "input",
646
+ index: 2,
647
+ size: 8
648
+ }
649
+ }],
650
+ ["input-3", {
651
+ subtype: "logicInput",
652
+ logicPinData: {
653
+ interface: "input",
654
+ index: 3,
655
+ size: 8
656
+ }
657
+ }],
658
+ ["input-4", {
659
+ subtype: "logicInput",
660
+ logicPinData: {
661
+ interface: "input",
662
+ index: 4,
663
+ size: 8
664
+ }
665
+ }],
666
+ ["input-5", {
667
+ subtype: "logicInput",
668
+ logicPinData: {
669
+ interface: "input",
670
+ index: 5,
671
+ size: 8
672
+ }
673
+ }],
674
+ ["input-6", {
675
+ subtype: "logicInput",
676
+ logicPinData: {
677
+ interface: "input",
678
+ index: 6,
679
+ size: 8
680
+ }
681
+ }],
682
+ ["input-7", {
683
+ subtype: "logicInput",
684
+ logicPinData: {
685
+ interface: "input",
686
+ index: 7,
687
+ size: 8
688
+ }
689
+ }],
690
+ ["output", {
691
+ subtype: "logicOutput",
692
+ logicPinData: {
693
+ interface: "output",
694
+ index: 0,
695
+ size: 1
696
+ }
697
+ }],
698
+ ["gnd", {
699
+ subtype: "gnd",
700
+ sourceType: h.Current
701
+ }]
702
+ ]),
703
+ config: /* @__PURE__ */ new Map([
704
+ ["defaultLogicFamily", "CMOS1"],
705
+ ["activationLogic", "negative"],
706
+ ["transitionSpan", "3"],
707
+ ["initializationOrder", ""]
708
+ ])
709
+ },
710
+ [c.XorGate]: {
711
+ id: c.XorGate,
712
+ pins: /* @__PURE__ */ new Map([
713
+ ["vcc", {
714
+ subtype: "vcc",
715
+ sourceType: h.Voltage
716
+ }],
717
+ ["input-0", {
718
+ subtype: "logicInput",
719
+ logicPinData: {
720
+ interface: "input",
721
+ index: 0,
722
+ size: 2
723
+ }
724
+ }],
725
+ ["input-1", {
726
+ subtype: "logicInput",
727
+ logicPinData: {
728
+ interface: "input",
729
+ index: 1,
730
+ size: 2
731
+ }
732
+ }],
733
+ ["output", {
734
+ subtype: "logicOutput",
735
+ logicPinData: {
736
+ interface: "output",
737
+ index: 0,
738
+ size: 1
739
+ }
740
+ }],
741
+ ["gnd", {
742
+ subtype: "gnd",
743
+ sourceType: h.Current
744
+ }]
745
+ ]),
746
+ config: /* @__PURE__ */ new Map([
747
+ ["defaultLogicFamily", "CMOS1"],
748
+ ["activationLogic", "positive"],
749
+ ["transitionSpan", "2"],
750
+ ["initializationOrder", ""]
751
+ ])
752
+ },
753
+ [c.Xor4Gate]: {
754
+ id: c.Xor4Gate,
755
+ pins: /* @__PURE__ */ new Map([
756
+ ["vcc", {
757
+ subtype: "vcc",
758
+ sourceType: h.Voltage
759
+ }],
760
+ ["input-0", {
761
+ subtype: "logicInput",
762
+ logicPinData: {
763
+ interface: "input",
764
+ index: 0,
765
+ size: 4
766
+ }
767
+ }],
768
+ ["input-1", {
769
+ subtype: "logicInput",
770
+ logicPinData: {
771
+ interface: "input",
772
+ index: 1,
773
+ size: 4
774
+ }
775
+ }],
776
+ ["input-2", {
777
+ subtype: "logicInput",
778
+ logicPinData: {
779
+ interface: "input",
780
+ index: 2,
781
+ size: 4
782
+ }
783
+ }],
784
+ ["input-3", {
785
+ subtype: "logicInput",
786
+ logicPinData: {
787
+ interface: "input",
788
+ index: 3,
789
+ size: 4
790
+ }
791
+ }],
792
+ ["output", {
793
+ subtype: "logicOutput",
794
+ logicPinData: {
795
+ interface: "output",
796
+ index: 0,
797
+ size: 1
798
+ }
799
+ }],
800
+ ["gnd", {
801
+ subtype: "gnd",
802
+ sourceType: h.Current
803
+ }]
804
+ ]),
805
+ config: /* @__PURE__ */ new Map([
806
+ ["defaultLogicFamily", "CMOS1"],
807
+ ["activationLogic", "positive"],
808
+ ["transitionSpan", "4"],
809
+ ["initializationOrder", ""]
810
+ ])
811
+ },
812
+ [c.Xor8Gate]: {
813
+ id: c.Xor8Gate,
814
+ pins: /* @__PURE__ */ new Map([
815
+ ["vcc", {
816
+ subtype: "vcc",
817
+ sourceType: h.Voltage
818
+ }],
819
+ ["input-0", {
820
+ subtype: "logicInput",
821
+ logicPinData: {
822
+ interface: "input",
823
+ index: 0,
824
+ size: 8
825
+ }
826
+ }],
827
+ ["input-1", {
828
+ subtype: "logicInput",
829
+ logicPinData: {
830
+ interface: "input",
831
+ index: 1,
832
+ size: 8
833
+ }
834
+ }],
835
+ ["input-2", {
836
+ subtype: "logicInput",
837
+ logicPinData: {
838
+ interface: "input",
839
+ index: 2,
840
+ size: 8
841
+ }
842
+ }],
843
+ ["input-3", {
844
+ subtype: "logicInput",
845
+ logicPinData: {
846
+ interface: "input",
847
+ index: 3,
848
+ size: 8
849
+ }
850
+ }],
851
+ ["input-4", {
852
+ subtype: "logicInput",
853
+ logicPinData: {
854
+ interface: "input",
855
+ index: 4,
856
+ size: 8
857
+ }
858
+ }],
859
+ ["input-5", {
860
+ subtype: "logicInput",
861
+ logicPinData: {
862
+ interface: "input",
863
+ index: 5,
864
+ size: 8
865
+ }
866
+ }],
867
+ ["input-6", {
868
+ subtype: "logicInput",
869
+ logicPinData: {
870
+ interface: "input",
871
+ index: 6,
872
+ size: 8
873
+ }
874
+ }],
875
+ ["input-7", {
876
+ subtype: "logicInput",
877
+ logicPinData: {
878
+ interface: "input",
879
+ index: 7,
880
+ size: 8
881
+ }
882
+ }],
883
+ ["output", {
884
+ subtype: "logicOutput",
885
+ logicPinData: {
886
+ interface: "output",
887
+ index: 0,
888
+ size: 1
889
+ }
890
+ }],
891
+ ["gnd", {
892
+ subtype: "gnd",
893
+ sourceType: h.Current
894
+ }]
895
+ ]),
896
+ config: /* @__PURE__ */ new Map([
897
+ ["defaultLogicFamily", "CMOS1"],
898
+ ["activationLogic", "positive"],
899
+ ["transitionSpan", "6"],
900
+ ["initializationOrder", ""]
901
+ ])
902
+ },
903
+ [c.HalfAdder]: {
904
+ id: c.HalfAdder,
905
+ pins: /* @__PURE__ */ new Map([
906
+ ["vcc", {
907
+ subtype: "vcc",
908
+ sourceType: h.Voltage
909
+ }],
910
+ ["inputA", {
911
+ subtype: "logicInput",
912
+ logicPinData: {
913
+ interface: "input",
914
+ index: 0,
915
+ size: 2
916
+ }
917
+ }],
918
+ ["inputB", {
919
+ subtype: "logicInput",
920
+ logicPinData: {
921
+ interface: "input",
922
+ index: 1,
923
+ size: 2
924
+ }
925
+ }],
926
+ ["sum", {
927
+ subtype: "logicOutput",
928
+ logicPinData: {
929
+ interface: "sum",
930
+ index: 0,
931
+ size: 1
932
+ }
933
+ }],
934
+ ["carry", {
935
+ subtype: "logicOutput",
936
+ logicPinData: {
937
+ interface: "carry",
938
+ index: 0,
939
+ size: 1
940
+ }
941
+ }],
942
+ ["gnd", {
943
+ subtype: "gnd",
944
+ sourceType: h.Current
945
+ }]
946
+ ]),
947
+ config: /* @__PURE__ */ new Map([
948
+ ["defaultLogicFamily", "CMOS1"],
949
+ ["transitionSpan", "2"],
950
+ ["initializationOrder", ""]
951
+ ])
952
+ },
953
+ [c.Adder]: {
954
+ id: c.Adder,
955
+ pins: /* @__PURE__ */ new Map([
956
+ ["vcc", {
957
+ subtype: "vcc",
958
+ sourceType: h.Voltage
959
+ }],
960
+ ["carryIn", {
961
+ subtype: "logicInput",
962
+ logicPinData: {
963
+ interface: "carryIn",
964
+ index: 0,
965
+ size: 1
966
+ }
967
+ }],
968
+ ["inputA", {
969
+ subtype: "logicInput",
970
+ logicPinData: {
971
+ interface: "input",
972
+ index: 0,
973
+ size: 2
974
+ }
975
+ }],
976
+ ["inputB", {
977
+ subtype: "logicInput",
978
+ logicPinData: {
979
+ interface: "input",
980
+ index: 1,
981
+ size: 2
982
+ }
983
+ }],
984
+ ["sum", {
985
+ subtype: "logicOutput",
986
+ logicPinData: {
987
+ interface: "sum",
988
+ index: 0,
989
+ size: 1
990
+ }
991
+ }],
992
+ ["carryOut", {
993
+ subtype: "logicOutput",
994
+ logicPinData: {
995
+ interface: "carryOut",
996
+ index: 0,
997
+ size: 1
998
+ }
999
+ }],
1000
+ ["gnd", {
1001
+ subtype: "gnd",
1002
+ sourceType: h.Current
1003
+ }]
1004
+ ]),
1005
+ config: /* @__PURE__ */ new Map([
1006
+ ["defaultLogicFamily", "CMOS1"],
1007
+ ["transitionSpan", "4"],
1008
+ ["initializationOrder", ""]
1009
+ ])
1010
+ },
1011
+ [c.EightBitAdder]: {
1012
+ id: c.EightBitAdder,
1013
+ pins: /* @__PURE__ */ new Map([
1014
+ ["vcc", {
1015
+ subtype: "vcc",
1016
+ sourceType: h.Voltage
1017
+ }],
1018
+ ["carryIn", {
1019
+ subtype: "logicInput",
1020
+ logicPinData: {
1021
+ interface: "carryIn",
1022
+ index: 0,
1023
+ size: 1
1024
+ }
1025
+ }],
1026
+ ["inputA-0", {
1027
+ subtype: "logicInput",
1028
+ logicPinData: {
1029
+ interface: "inputA",
1030
+ index: 0,
1031
+ size: 8
1032
+ }
1033
+ }],
1034
+ ["inputA-1", {
1035
+ subtype: "logicInput",
1036
+ logicPinData: {
1037
+ interface: "inputA",
1038
+ index: 1,
1039
+ size: 8
1040
+ }
1041
+ }],
1042
+ ["inputA-2", {
1043
+ subtype: "logicInput",
1044
+ logicPinData: {
1045
+ interface: "inputA",
1046
+ index: 2,
1047
+ size: 8
1048
+ }
1049
+ }],
1050
+ ["inputA-3", {
1051
+ subtype: "logicInput",
1052
+ logicPinData: {
1053
+ interface: "inputA",
1054
+ index: 3,
1055
+ size: 8
1056
+ }
1057
+ }],
1058
+ ["inputA-4", {
1059
+ subtype: "logicInput",
1060
+ logicPinData: {
1061
+ interface: "inputA",
1062
+ index: 4,
1063
+ size: 8
1064
+ }
1065
+ }],
1066
+ ["inputA-5", {
1067
+ subtype: "logicInput",
1068
+ logicPinData: {
1069
+ interface: "inputA",
1070
+ index: 5,
1071
+ size: 8
1072
+ }
1073
+ }],
1074
+ ["inputA-6", {
1075
+ subtype: "logicInput",
1076
+ logicPinData: {
1077
+ interface: "inputA",
1078
+ index: 6,
1079
+ size: 8
1080
+ }
1081
+ }],
1082
+ ["inputA-7", {
1083
+ subtype: "logicInput",
1084
+ logicPinData: {
1085
+ interface: "inputA",
1086
+ index: 7,
1087
+ size: 8
1088
+ }
1089
+ }],
1090
+ ["inputB-0", {
1091
+ subtype: "logicInput",
1092
+ logicPinData: {
1093
+ interface: "inputB",
1094
+ index: 0,
1095
+ size: 8
1096
+ }
1097
+ }],
1098
+ ["inputB-1", {
1099
+ subtype: "logicInput",
1100
+ logicPinData: {
1101
+ interface: "inputB",
1102
+ index: 1,
1103
+ size: 8
1104
+ }
1105
+ }],
1106
+ ["inputB-2", {
1107
+ subtype: "logicInput",
1108
+ logicPinData: {
1109
+ interface: "inputB",
1110
+ index: 2,
1111
+ size: 8
1112
+ }
1113
+ }],
1114
+ ["inputB-3", {
1115
+ subtype: "logicInput",
1116
+ logicPinData: {
1117
+ interface: "inputB",
1118
+ index: 3,
1119
+ size: 8
1120
+ }
1121
+ }],
1122
+ ["inputB-4", {
1123
+ subtype: "logicInput",
1124
+ logicPinData: {
1125
+ interface: "inputB",
1126
+ index: 4,
1127
+ size: 8
1128
+ }
1129
+ }],
1130
+ ["inputB-5", {
1131
+ subtype: "logicInput",
1132
+ logicPinData: {
1133
+ interface: "inputB",
1134
+ index: 5,
1135
+ size: 8
1136
+ }
1137
+ }],
1138
+ ["inputB-6", {
1139
+ subtype: "logicInput",
1140
+ logicPinData: {
1141
+ interface: "inputB",
1142
+ index: 6,
1143
+ size: 8
1144
+ }
1145
+ }],
1146
+ ["inputB-7", {
1147
+ subtype: "logicInput",
1148
+ logicPinData: {
1149
+ interface: "inputB",
1150
+ index: 7,
1151
+ size: 8
1152
+ }
1153
+ }],
1154
+ ["sum-0", {
1155
+ subtype: "logicOutput",
1156
+ logicPinData: {
1157
+ interface: "sum",
1158
+ index: 0,
1159
+ size: 8
1160
+ }
1161
+ }],
1162
+ ["sum-1", {
1163
+ subtype: "logicOutput",
1164
+ logicPinData: {
1165
+ interface: "sum",
1166
+ index: 1,
1167
+ size: 8
1168
+ }
1169
+ }],
1170
+ ["sum-2", {
1171
+ subtype: "logicOutput",
1172
+ logicPinData: {
1173
+ interface: "sum",
1174
+ index: 2,
1175
+ size: 8
1176
+ }
1177
+ }],
1178
+ ["sum-3", {
1179
+ subtype: "logicOutput",
1180
+ logicPinData: {
1181
+ interface: "sum",
1182
+ index: 3,
1183
+ size: 8
1184
+ }
1185
+ }],
1186
+ ["sum-4", {
1187
+ subtype: "logicOutput",
1188
+ logicPinData: {
1189
+ interface: "sum",
1190
+ index: 4,
1191
+ size: 8
1192
+ }
1193
+ }],
1194
+ ["sum-5", {
1195
+ subtype: "logicOutput",
1196
+ logicPinData: {
1197
+ interface: "sum",
1198
+ index: 5,
1199
+ size: 8
1200
+ }
1201
+ }],
1202
+ ["sum-6", {
1203
+ subtype: "logicOutput",
1204
+ logicPinData: {
1205
+ interface: "sum",
1206
+ index: 6,
1207
+ size: 8
1208
+ }
1209
+ }],
1210
+ ["sum-7", {
1211
+ subtype: "logicOutput",
1212
+ logicPinData: {
1213
+ interface: "sum",
1214
+ index: 7,
1215
+ size: 8
1216
+ }
1217
+ }],
1218
+ ["carryOut", {
1219
+ subtype: "logicOutput",
1220
+ logicPinData: {
1221
+ interface: "carryOut",
1222
+ index: 0,
1223
+ size: 1
1224
+ }
1225
+ }],
1226
+ ["gnd", {
1227
+ subtype: "gnd",
1228
+ sourceType: h.Current
1229
+ }]
1230
+ ]),
1231
+ config: /* @__PURE__ */ new Map([
1232
+ ["defaultLogicFamily", "CMOS1"],
1233
+ ["transitionSpan", "4"],
1234
+ ["initializationOrder", ""]
1235
+ ])
1236
+ },
1237
+ [c.EightBitOnesComplement]: {
1238
+ id: c.EightBitOnesComplement,
1239
+ pins: /* @__PURE__ */ new Map([
1240
+ ["vcc", {
1241
+ subtype: "vcc",
1242
+ sourceType: h.Voltage
1243
+ }],
1244
+ ["invert", {
1245
+ subtype: "logicInput",
1246
+ logicPinData: {
1247
+ interface: "invert",
1248
+ index: 0,
1249
+ size: 1
1250
+ }
1251
+ }],
1252
+ ["input-0", {
1253
+ subtype: "logicInput",
1254
+ logicPinData: {
1255
+ interface: "input",
1256
+ index: 0,
1257
+ size: 8
1258
+ }
1259
+ }],
1260
+ ["input-1", {
1261
+ subtype: "logicInput",
1262
+ logicPinData: {
1263
+ interface: "input",
1264
+ index: 1,
1265
+ size: 8
1266
+ }
1267
+ }],
1268
+ ["input-2", {
1269
+ subtype: "logicInput",
1270
+ logicPinData: {
1271
+ interface: "input",
1272
+ index: 2,
1273
+ size: 8
1274
+ }
1275
+ }],
1276
+ ["input-3", {
1277
+ subtype: "logicInput",
1278
+ logicPinData: {
1279
+ interface: "input",
1280
+ index: 3,
1281
+ size: 8
1282
+ }
1283
+ }],
1284
+ ["input-4", {
1285
+ subtype: "logicInput",
1286
+ logicPinData: {
1287
+ interface: "input",
1288
+ index: 4,
1289
+ size: 8
1290
+ }
1291
+ }],
1292
+ ["input-5", {
1293
+ subtype: "logicInput",
1294
+ logicPinData: {
1295
+ interface: "input",
1296
+ index: 5,
1297
+ size: 8
1298
+ }
1299
+ }],
1300
+ ["input-6", {
1301
+ subtype: "logicInput",
1302
+ logicPinData: {
1303
+ interface: "input",
1304
+ index: 6,
1305
+ size: 8
1306
+ }
1307
+ }],
1308
+ ["input-7", {
1309
+ subtype: "logicInput",
1310
+ logicPinData: {
1311
+ interface: "input",
1312
+ index: 7,
1313
+ size: 8
1314
+ }
1315
+ }],
1316
+ ["output-0", {
1317
+ subtype: "logicOutput",
1318
+ logicPinData: {
1319
+ interface: "output",
1320
+ index: 0,
1321
+ size: 8
1322
+ }
1323
+ }],
1324
+ ["output-1", {
1325
+ subtype: "logicOutput",
1326
+ logicPinData: {
1327
+ interface: "output",
1328
+ index: 1,
1329
+ size: 8
1330
+ }
1331
+ }],
1332
+ ["output-2", {
1333
+ subtype: "logicOutput",
1334
+ logicPinData: {
1335
+ interface: "output",
1336
+ index: 2,
1337
+ size: 8
1338
+ }
1339
+ }],
1340
+ ["output-3", {
1341
+ subtype: "logicOutput",
1342
+ logicPinData: {
1343
+ interface: "output",
1344
+ index: 3,
1345
+ size: 8
1346
+ }
1347
+ }],
1348
+ ["output-4", {
1349
+ subtype: "logicOutput",
1350
+ logicPinData: {
1351
+ interface: "output",
1352
+ index: 4,
1353
+ size: 8
1354
+ }
1355
+ }],
1356
+ ["output-5", {
1357
+ subtype: "logicOutput",
1358
+ logicPinData: {
1359
+ interface: "output",
1360
+ index: 5,
1361
+ size: 8
1362
+ }
1363
+ }],
1364
+ ["output-6", {
1365
+ subtype: "logicOutput",
1366
+ logicPinData: {
1367
+ interface: "output",
1368
+ index: 6,
1369
+ size: 8
1370
+ }
1371
+ }],
1372
+ ["output-7", {
1373
+ subtype: "logicOutput",
1374
+ logicPinData: {
1375
+ interface: "output",
1376
+ index: 7,
1377
+ size: 8
1378
+ }
1379
+ }],
1380
+ ["gnd", {
1381
+ subtype: "gnd",
1382
+ sourceType: h.Current
1383
+ }]
1384
+ ]),
1385
+ config: /* @__PURE__ */ new Map([
1386
+ ["defaultLogicFamily", "CMOS1"],
1387
+ ["transitionSpan", "3"],
1388
+ ["initializationOrder", ""]
1389
+ ])
1390
+ },
1391
+ [c.OneInput]: {
1392
+ id: c.OneInput,
1393
+ pins: /* @__PURE__ */ new Map([
1394
+ ["vcc", {
1395
+ subtype: "vcc",
1396
+ sourceType: h.Voltage
1397
+ }],
1398
+ ["output-0", {
1399
+ subtype: "logicOutput",
1400
+ logicPinData: {
1401
+ interface: "output",
1402
+ index: 0,
1403
+ size: 1
1404
+ }
1405
+ }],
1406
+ ["gnd", {
1407
+ subtype: "gnd",
1408
+ sourceType: h.Current
1409
+ }]
1410
+ ]),
1411
+ config: /* @__PURE__ */ new Map([
1412
+ ["initialState", "0"],
1413
+ ["transitionSpan", "1"],
1414
+ ["size", "1"]
1415
+ ])
1416
+ },
1417
+ [c.TwoInput]: {
1418
+ id: c.TwoInput,
1419
+ pins: /* @__PURE__ */ new Map([
1420
+ ["vcc", {
1421
+ subtype: "vcc",
1422
+ sourceType: h.Voltage
1423
+ }],
1424
+ ["output-0", {
1425
+ subtype: "logicOutput",
1426
+ logicPinData: {
1427
+ interface: "output",
1428
+ index: 0,
1429
+ size: 2
1430
+ }
1431
+ }],
1432
+ ["output-1", {
1433
+ subtype: "logicOutput",
1434
+ logicPinData: {
1435
+ interface: "output",
1436
+ index: 1,
1437
+ size: 2
1438
+ }
1439
+ }],
1440
+ ["gnd", {
1441
+ subtype: "gnd",
1442
+ sourceType: h.Current
1443
+ }]
1444
+ ]),
1445
+ config: /* @__PURE__ */ new Map([
1446
+ ["initialState", "0"],
1447
+ ["transitionSpan", "1"],
1448
+ ["size", "1"]
1449
+ ])
1450
+ },
1451
+ [c.FourInput]: {
1452
+ id: c.FourInput,
1453
+ pins: /* @__PURE__ */ new Map([
1454
+ ["vcc", {
1455
+ subtype: "vcc",
1456
+ sourceType: h.Voltage
1457
+ }],
1458
+ ["output-0", {
1459
+ subtype: "logicOutput",
1460
+ logicPinData: {
1461
+ interface: "output",
1462
+ index: 0,
1463
+ size: 4
1464
+ }
1465
+ }],
1466
+ ["output-1", {
1467
+ subtype: "logicOutput",
1468
+ logicPinData: {
1469
+ interface: "output",
1470
+ index: 1,
1471
+ size: 4
1472
+ }
1473
+ }],
1474
+ ["output-2", {
1475
+ subtype: "logicOutput",
1476
+ logicPinData: {
1477
+ interface: "output",
1478
+ index: 2,
1479
+ size: 4
1480
+ }
1481
+ }],
1482
+ ["output-3", {
1483
+ subtype: "logicOutput",
1484
+ logicPinData: {
1485
+ interface: "output",
1486
+ index: 3,
1487
+ size: 4
1488
+ }
1489
+ }],
1490
+ ["gnd", {
1491
+ subtype: "gnd",
1492
+ sourceType: h.Current
1493
+ }]
1494
+ ]),
1495
+ config: /* @__PURE__ */ new Map([
1496
+ ["initialState", "0"],
1497
+ ["transitionSpan", "1"],
1498
+ ["size", "1"]
1499
+ ])
1500
+ },
1501
+ [c.EightInput]: {
1502
+ id: c.EightInput,
1503
+ pins: /* @__PURE__ */ new Map([
1504
+ ["vcc", {
1505
+ subtype: "vcc",
1506
+ sourceType: h.Voltage
1507
+ }],
1508
+ ["output-0", {
1509
+ subtype: "logicOutput",
1510
+ logicPinData: {
1511
+ interface: "output",
1512
+ index: 0,
1513
+ size: 8
1514
+ }
1515
+ }],
1516
+ ["output-1", {
1517
+ subtype: "logicOutput",
1518
+ logicPinData: {
1519
+ interface: "output",
1520
+ index: 1,
1521
+ size: 8
1522
+ }
1523
+ }],
1524
+ ["output-2", {
1525
+ subtype: "logicOutput",
1526
+ logicPinData: {
1527
+ interface: "output",
1528
+ index: 2,
1529
+ size: 8
1530
+ }
1531
+ }],
1532
+ ["output-3", {
1533
+ subtype: "logicOutput",
1534
+ logicPinData: {
1535
+ interface: "output",
1536
+ index: 3,
1537
+ size: 8
1538
+ }
1539
+ }],
1540
+ ["output-4", {
1541
+ subtype: "logicOutput",
1542
+ logicPinData: {
1543
+ interface: "output",
1544
+ index: 4,
1545
+ size: 8
1546
+ }
1547
+ }],
1548
+ ["output-5", {
1549
+ subtype: "logicOutput",
1550
+ logicPinData: {
1551
+ interface: "output",
1552
+ index: 5,
1553
+ size: 8
1554
+ }
1555
+ }],
1556
+ ["output-6", {
1557
+ subtype: "logicOutput",
1558
+ logicPinData: {
1559
+ interface: "output",
1560
+ index: 6,
1561
+ size: 8
1562
+ }
1563
+ }],
1564
+ ["output-7", {
1565
+ subtype: "logicOutput",
1566
+ logicPinData: {
1567
+ interface: "output",
1568
+ index: 7,
1569
+ size: 8
1570
+ }
1571
+ }],
1572
+ ["gnd", {
1573
+ subtype: "gnd",
1574
+ sourceType: h.Current
1575
+ }]
1576
+ ]),
1577
+ config: /* @__PURE__ */ new Map([
1578
+ ["initialState", "00"],
1579
+ ["transitionSpan", "1"],
1580
+ ["size", "1"]
1581
+ ])
1582
+ },
1583
+ [c.OneLight]: {
1584
+ id: c.OneLight,
1585
+ pins: /* @__PURE__ */ new Map([
1586
+ ["vcc", {
1587
+ subtype: "vcc",
1588
+ sourceType: h.Voltage
1589
+ }],
1590
+ ["input-0", {
1591
+ subtype: "logicInput",
1592
+ logicPinData: {
1593
+ interface: "input",
1594
+ index: 0,
1595
+ size: 1
1596
+ }
1597
+ }],
1598
+ ["output-0", {
1599
+ subtype: "logicOutput",
1600
+ logicPinData: {
1601
+ interface: "output",
1602
+ index: 0,
1603
+ size: 1
1604
+ }
1605
+ }],
1606
+ ["gnd", {
1607
+ subtype: "gnd",
1608
+ sourceType: h.Current
1609
+ }]
1610
+ ]),
1611
+ config: /* @__PURE__ */ new Map([["transitionSpan", "2"], ["size", "1"]])
1612
+ },
1613
+ [c.TwoLight]: {
1614
+ id: c.TwoLight,
1615
+ pins: /* @__PURE__ */ new Map([
1616
+ ["vcc", {
1617
+ subtype: "vcc",
1618
+ sourceType: h.Voltage
1619
+ }],
1620
+ ["input-0", {
1621
+ subtype: "logicInput",
1622
+ logicPinData: {
1623
+ interface: "input",
1624
+ index: 0,
1625
+ size: 2
1626
+ }
1627
+ }],
1628
+ ["input-1", {
1629
+ subtype: "logicInput",
1630
+ logicPinData: {
1631
+ interface: "input",
1632
+ index: 1,
1633
+ size: 2
1634
+ }
1635
+ }],
1636
+ ["output-0", {
1637
+ subtype: "logicOutput",
1638
+ logicPinData: {
1639
+ interface: "output",
1640
+ index: 0,
1641
+ size: 2
1642
+ }
1643
+ }],
1644
+ ["output-1", {
1645
+ subtype: "logicOutput",
1646
+ logicPinData: {
1647
+ interface: "output",
1648
+ index: 1,
1649
+ size: 2
1650
+ }
1651
+ }],
1652
+ ["gnd", {
1653
+ subtype: "gnd",
1654
+ sourceType: h.Current
1655
+ }]
1656
+ ]),
1657
+ config: /* @__PURE__ */ new Map([["transitionSpan", "2"], ["size", "1"]])
1658
+ },
1659
+ [c.FourLight]: {
1660
+ id: c.FourLight,
1661
+ pins: /* @__PURE__ */ new Map([
1662
+ ["vcc", {
1663
+ subtype: "vcc",
1664
+ sourceType: h.Voltage
1665
+ }],
1666
+ ["input-0", {
1667
+ subtype: "logicInput",
1668
+ logicPinData: {
1669
+ interface: "input",
1670
+ index: 0,
1671
+ size: 4
1672
+ }
1673
+ }],
1674
+ ["input-1", {
1675
+ subtype: "logicInput",
1676
+ logicPinData: {
1677
+ interface: "input",
1678
+ index: 1,
1679
+ size: 4
1680
+ }
1681
+ }],
1682
+ ["input-2", {
1683
+ subtype: "logicInput",
1684
+ logicPinData: {
1685
+ interface: "input",
1686
+ index: 2,
1687
+ size: 4
1688
+ }
1689
+ }],
1690
+ ["input-3", {
1691
+ subtype: "logicInput",
1692
+ logicPinData: {
1693
+ interface: "input",
1694
+ index: 3,
1695
+ size: 4
1696
+ }
1697
+ }],
1698
+ ["output-0", {
1699
+ subtype: "logicOutput",
1700
+ logicPinData: {
1701
+ interface: "output",
1702
+ index: 0,
1703
+ size: 4
1704
+ }
1705
+ }],
1706
+ ["output-1", {
1707
+ subtype: "logicOutput",
1708
+ logicPinData: {
1709
+ interface: "output",
1710
+ index: 1,
1711
+ size: 4
1712
+ }
1713
+ }],
1714
+ ["output-2", {
1715
+ subtype: "logicOutput",
1716
+ logicPinData: {
1717
+ interface: "output",
1718
+ index: 2,
1719
+ size: 4
1720
+ }
1721
+ }],
1722
+ ["output-3", {
1723
+ subtype: "logicOutput",
1724
+ logicPinData: {
1725
+ interface: "output",
1726
+ index: 3,
1727
+ size: 4
1728
+ }
1729
+ }],
1730
+ ["gnd", {
1731
+ subtype: "gnd",
1732
+ sourceType: h.Current
1733
+ }]
1734
+ ]),
1735
+ config: /* @__PURE__ */ new Map([["transitionSpan", "2"], ["size", "1"]])
1736
+ },
1737
+ [c.EightLight]: {
1738
+ id: c.EightLight,
1739
+ pins: /* @__PURE__ */ new Map([
1740
+ ["vcc", {
1741
+ subtype: "vcc",
1742
+ sourceType: h.Voltage
1743
+ }],
1744
+ ["input-0", {
1745
+ subtype: "logicInput",
1746
+ logicPinData: {
1747
+ interface: "input",
1748
+ index: 0,
1749
+ size: 8
1750
+ }
1751
+ }],
1752
+ ["input-1", {
1753
+ subtype: "logicInput",
1754
+ logicPinData: {
1755
+ interface: "input",
1756
+ index: 1,
1757
+ size: 8
1758
+ }
1759
+ }],
1760
+ ["input-2", {
1761
+ subtype: "logicInput",
1762
+ logicPinData: {
1763
+ interface: "input",
1764
+ index: 2,
1765
+ size: 8
1766
+ }
1767
+ }],
1768
+ ["input-3", {
1769
+ subtype: "logicInput",
1770
+ logicPinData: {
1771
+ interface: "input",
1772
+ index: 3,
1773
+ size: 8
1774
+ }
1775
+ }],
1776
+ ["input-4", {
1777
+ subtype: "logicInput",
1778
+ logicPinData: {
1779
+ interface: "input",
1780
+ index: 4,
1781
+ size: 8
1782
+ }
1783
+ }],
1784
+ ["input-5", {
1785
+ subtype: "logicInput",
1786
+ logicPinData: {
1787
+ interface: "input",
1788
+ index: 5,
1789
+ size: 8
1790
+ }
1791
+ }],
1792
+ ["input-6", {
1793
+ subtype: "logicInput",
1794
+ logicPinData: {
1795
+ interface: "input",
1796
+ index: 6,
1797
+ size: 8
1798
+ }
1799
+ }],
1800
+ ["input-7", {
1801
+ subtype: "logicInput",
1802
+ logicPinData: {
1803
+ interface: "input",
1804
+ index: 7,
1805
+ size: 8
1806
+ }
1807
+ }],
1808
+ ["output-0", {
1809
+ subtype: "logicOutput",
1810
+ logicPinData: {
1811
+ interface: "output",
1812
+ index: 0,
1813
+ size: 8
1814
+ }
1815
+ }],
1816
+ ["output-1", {
1817
+ subtype: "logicOutput",
1818
+ logicPinData: {
1819
+ interface: "output",
1820
+ index: 1,
1821
+ size: 8
1822
+ }
1823
+ }],
1824
+ ["output-2", {
1825
+ subtype: "logicOutput",
1826
+ logicPinData: {
1827
+ interface: "output",
1828
+ index: 2,
1829
+ size: 8
1830
+ }
1831
+ }],
1832
+ ["output-3", {
1833
+ subtype: "logicOutput",
1834
+ logicPinData: {
1835
+ interface: "output",
1836
+ index: 3,
1837
+ size: 8
1838
+ }
1839
+ }],
1840
+ ["output-4", {
1841
+ subtype: "logicOutput",
1842
+ logicPinData: {
1843
+ interface: "output",
1844
+ index: 4,
1845
+ size: 8
1846
+ }
1847
+ }],
1848
+ ["output-5", {
1849
+ subtype: "logicOutput",
1850
+ logicPinData: {
1851
+ interface: "output",
1852
+ index: 5,
1853
+ size: 8
1854
+ }
1855
+ }],
1856
+ ["output-6", {
1857
+ subtype: "logicOutput",
1858
+ logicPinData: {
1859
+ interface: "output",
1860
+ index: 6,
1861
+ size: 8
1862
+ }
1863
+ }],
1864
+ ["output-7", {
1865
+ subtype: "logicOutput",
1866
+ logicPinData: {
1867
+ interface: "output",
1868
+ index: 7,
1869
+ size: 8
1870
+ }
1871
+ }],
1872
+ ["gnd", {
1873
+ subtype: "gnd",
1874
+ sourceType: h.Current
1875
+ }]
1876
+ ]),
1877
+ config: /* @__PURE__ */ new Map([["transitionSpan", "2"], ["size", "1"]])
1878
+ }
1879
+ }, $ = class at {
1880
+ id;
1881
+ type;
1882
+ component;
1883
+ pinLabel;
1884
+ position;
1885
+ wires;
1886
+ source;
1887
+ subtype;
1888
+ logicMetadata;
1889
+ constructor(t, n, i, s, r = void 0, a = "free", o) {
1890
+ this.id = J(), this.type = t, this.component = n, this.pinLabel = i, this.position = s, this.wires = /* @__PURE__ */ new Set(), this.source = r, this.subtype = a, this.logicMetadata = o;
1891
+ }
1892
+ getPosition(t) {
1893
+ if (this.type === w.Pin) {
1894
+ if (!this.component) throw new Error("Pin node missing component reference");
1895
+ const n = t.getComponent(this.component);
1896
+ if (!n) throw new Error(`Component ${this.component} not found for pin node ${this.id}`);
1897
+ return n.position;
1898
+ }
1899
+ if (!this.position) throw new Error("Branching point node missing position");
1900
+ return this.position;
1901
+ }
1902
+ setPosition(t) {
1903
+ Object.defineProperty(this, "position", {
1904
+ value: t,
1905
+ writable: !1,
1906
+ enumerable: !0,
1907
+ configurable: !0
1908
+ });
1909
+ }
1910
+ setSourceType(t) {
1911
+ Object.defineProperty(this, "source", {
1912
+ value: t,
1913
+ writable: !0,
1914
+ enumerable: !0,
1915
+ configurable: !0
1916
+ });
1917
+ }
1918
+ toJSON() {
1919
+ const t = {
1920
+ id: this.id,
1921
+ type: this.type,
1922
+ source: this.source || null,
1923
+ subtype: this.subtype,
1924
+ logicMetadata: this.logicMetadata || null
1925
+ };
1926
+ return this.type === w.Pin ? (t.component = this.component || null, t.pinLabel = this.pinLabel || null) : t.position = this.position?.toJSON() || null, t;
1927
+ }
1928
+ static fromJSON(t) {
1929
+ const n = t.position ? H.fromJSON(t.position) : void 0, i = new at(t.type, t.component || void 0, t.pinLabel || void 0, n, t.source || void 0, t.subtype ?? "free", t.logicMetadata || void 0);
1930
+ return Object.defineProperty(i, "id", {
1931
+ value: t.id,
1932
+ writable: !1,
1933
+ enumerable: !0,
1934
+ configurable: !1
1935
+ }), i;
1936
+ }
1937
+ }, N = class ot {
1938
+ id;
1939
+ node1;
1940
+ node2;
1941
+ intermediatePositions;
1942
+ constructor(t, n, i = []) {
1943
+ this.id = J(), this.node1 = t, this.node2 = n, this.intermediatePositions = i;
1944
+ }
1945
+ isStraightLine() {
1946
+ return this.intermediatePositions.length === 0;
1947
+ }
1948
+ toJSON() {
1949
+ return {
1950
+ id: this.id,
1951
+ node1: this.node1,
1952
+ node2: this.node2,
1953
+ intermediatePositions: this.intermediatePositions.map((t) => t.toJSON())
1954
+ };
1955
+ }
1956
+ static fromJSON(t) {
1957
+ const n = t.intermediatePositions.map((s) => H.fromJSON(s)), i = new ot(t.node1, t.node2, n);
1958
+ return Object.defineProperty(i, "id", {
1959
+ value: t.id,
1960
+ writable: !1,
1961
+ enumerable: !0,
1962
+ configurable: !1
1963
+ }), i;
1964
+ }
1965
+ }, Q = class ut {
1966
+ id;
1967
+ type;
1968
+ position;
1969
+ rotation;
1970
+ pins;
1971
+ config;
1972
+ editable;
1973
+ constructor(t, n, i, s, r = !0) {
1974
+ if (this.id = J(), this.type = t, this.position = n, this.rotation = i, new Set(s).size !== s.length) {
1975
+ const a = s.filter((o, u) => s.indexOf(o) !== u);
1976
+ throw new Error(`Duplicate pin names are not allowed: ${[...new Set(a)].join(", ")}`);
1977
+ }
1978
+ this.pins = s, this.config = new Map(I[t].config), this.editable = r;
1979
+ }
1980
+ getPinLabel(t) {
1981
+ const n = this.pins.indexOf(t);
1982
+ if (n === -1) return;
1983
+ const i = I[this.type].pins.keys();
1984
+ return Array.from(i)[n] || void 0;
1985
+ }
1986
+ getPinMetadata(t) {
1987
+ const n = this.getPinLabel(t);
1988
+ if (n)
1989
+ return I[this.type].pins.get(n);
1990
+ }
1991
+ getPinIdByInterface(t, n) {
1992
+ let i = 0;
1993
+ for (const s of I[this.type].pins.values()) {
1994
+ const r = s.logicPinData;
1995
+ if (r && r.interface === t && r.index === n) return this.pins[i];
1996
+ i++;
1997
+ }
1998
+ }
1999
+ getInterfaceMaxIndex(t) {
2000
+ let n = -1;
2001
+ for (const i of I[this.type].pins.values()) {
2002
+ const s = i.logicPinData;
2003
+ s?.interface === t && s.index > n && (n = s.index);
2004
+ }
2005
+ return n;
2006
+ }
2007
+ setAllParameters(t) {
2008
+ this.config = new Map(t);
2009
+ }
2010
+ setParameter(t, n) {
2011
+ this.config.set(t, n);
2012
+ }
2013
+ setPosition(t) {
2014
+ Object.defineProperty(this, "position", {
2015
+ value: t,
2016
+ writable: !1,
2017
+ enumerable: !0,
2018
+ configurable: !0
2019
+ });
2020
+ }
2021
+ setRotation(t) {
2022
+ Object.defineProperty(this, "rotation", {
2023
+ value: t,
2024
+ writable: !1,
2025
+ enumerable: !0,
2026
+ configurable: !0
2027
+ });
2028
+ }
2029
+ toJSON() {
2030
+ return {
2031
+ id: this.id,
2032
+ type: this.type,
2033
+ position: this.position.toJSON(),
2034
+ rotation: this.rotation.toJSON(),
2035
+ pins: [...this.pins],
2036
+ config: Object.fromEntries(this.config),
2037
+ editable: this.editable
2038
+ };
2039
+ }
2040
+ static fromJSON(t) {
2041
+ const n = new ut(t.type, H.fromJSON(t.position), mt.fromJSON(t.rotation), t.pins, t.editable);
2042
+ return n.config = new Map(Object.entries(t.config)), Object.defineProperty(n, "id", {
2043
+ value: t.id,
2044
+ writable: !1,
2045
+ enumerable: !0,
2046
+ configurable: !1
2047
+ }), n;
2048
+ }
2049
+ }, q = class ct {
2050
+ constructor(t = "Untitled Circuit", n = rt) {
2051
+ this.name = t, this.defaultLogicFamily = n;
2052
+ }
2053
+ toJSON() {
2054
+ return {
2055
+ name: this.name,
2056
+ defaultLogicFamily: this.defaultLogicFamily
2057
+ };
2058
+ }
2059
+ static fromJSON(t) {
2060
+ return new ct(t.name, t.defaultLogicFamily);
2061
+ }
2062
+ }, K = class pt {
2063
+ constructor(t, n, i, s, r) {
2064
+ 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})`);
2065
+ }
2066
+ toJSON() {
2067
+ return {
2068
+ version: this.version,
2069
+ options: this.options.toJSON(),
2070
+ size: this.size,
2071
+ divisions: this.divisions,
2072
+ cameraOptions: this.cameraOptions.toJSON()
2073
+ };
2074
+ }
2075
+ static fromJSON(t) {
2076
+ t.version !== "0.0.14" && console.warn(`This version of the engine supports v${st} circuit version files.
2077
+ Unexpected behavior may occurs loading v${t.version}.`);
2078
+ const n = t.options ? q.fromJSON(t.options) : new q("Untitled Circuit", rt);
2079
+ return new pt(t.version, n, t.size, t.divisions, tt.fromJSON(t.cameraOptions));
2080
+ }
2081
+ toString() {
2082
+ return `CircuitMetadata(${this.version}, ${this.options.name}, ${this.options.defaultLogicFamily}, ${this.size}, ${this.divisions}, ${this.cameraOptions.toString()})`;
2083
+ }
2084
+ }, bt = {
2085
+ 2: 1,
2086
+ 4: 1,
2087
+ 8: 2,
2088
+ 16: 2
2089
+ }, Ct = {
2090
+ 2: 2,
2091
+ 4: 2,
2092
+ 8: 3,
2093
+ 16: 3
2094
+ }, Pt = {
2095
+ 2: 1,
2096
+ 4: 2,
2097
+ 8: 2,
2098
+ 16: 3
2099
+ }, xt = {
2100
+ 2: 2,
2101
+ 4: 3,
2102
+ 8: 3,
2103
+ 16: 4
2104
+ };
2105
+ function It(e) {
2106
+ const t = e.config.get("defaultLogicFamily");
2107
+ if (!(!t || t === "Sandbox") && Tt(e.type)) {
2108
+ const n = e.config.get("activationLogic") ?? "negative", i = Ot(e.type, n);
2109
+ return i && Et(t, i.gateFamily, i.inputCount) || void 0;
2110
+ }
2111
+ }
2112
+ function Tt(e) {
2113
+ return [
2114
+ c.Inverter,
2115
+ c.NandGate,
2116
+ c.Nand4Gate,
2117
+ c.Nand8Gate,
2118
+ c.NorGate,
2119
+ c.Nor4Gate,
2120
+ c.Nor8Gate,
2121
+ c.XorGate,
2122
+ c.Xor4Gate,
2123
+ c.Xor8Gate
2124
+ ].includes(e);
2125
+ }
2126
+ function Ot(e, t) {
2127
+ switch (e) {
2128
+ case c.Inverter:
2129
+ return {
2130
+ gateFamily: t === "negative" ? "NOT" : "Buffer",
2131
+ inputCount: 1
2132
+ };
2133
+ case c.NandGate:
2134
+ return {
2135
+ gateFamily: t === "negative" ? "NAND" : "AND",
2136
+ inputCount: 2
2137
+ };
2138
+ case c.Nand4Gate:
2139
+ return {
2140
+ gateFamily: t === "negative" ? "NAND" : "AND",
2141
+ inputCount: 4
2142
+ };
2143
+ case c.Nand8Gate:
2144
+ return {
2145
+ gateFamily: t === "negative" ? "NAND" : "AND",
2146
+ inputCount: 8
2147
+ };
2148
+ case c.NorGate:
2149
+ return {
2150
+ gateFamily: t === "negative" ? "NOR" : "OR",
2151
+ inputCount: 2
2152
+ };
2153
+ case c.Nor4Gate:
2154
+ return {
2155
+ gateFamily: t === "negative" ? "NOR" : "OR",
2156
+ inputCount: 4
2157
+ };
2158
+ case c.Nor8Gate:
2159
+ return {
2160
+ gateFamily: t === "negative" ? "NOR" : "OR",
2161
+ inputCount: 8
2162
+ };
2163
+ case c.XorGate:
2164
+ return {
2165
+ gateFamily: t === "negative" ? "XNOR" : "XOR",
2166
+ inputCount: 2
2167
+ };
2168
+ case c.Xor4Gate:
2169
+ return {
2170
+ gateFamily: t === "negative" ? "XNOR" : "XOR",
2171
+ inputCount: 4
2172
+ };
2173
+ case c.Xor8Gate:
2174
+ return {
2175
+ gateFamily: t === "negative" ? "XNOR" : "XOR",
2176
+ inputCount: 8
2177
+ };
2178
+ default:
2179
+ return null;
2180
+ }
2181
+ }
2182
+ function Et(e, t, n) {
2183
+ if (e === "Sandbox") throw new Error("computeGateDelay must not be called for Sandbox family");
2184
+ if (t === "NOT") return 1;
2185
+ if (t === "Buffer") return 2;
2186
+ if (t === "XOR") return Math.log2(n) * 2;
2187
+ if (t === "XNOR") return Math.log2(n) * 2 + 1;
2188
+ if (e === "CMOS1") {
2189
+ const i = Math.log2(n);
2190
+ switch (t) {
2191
+ case "NAND":
2192
+ return i;
2193
+ case "NOR":
2194
+ return i;
2195
+ case "AND":
2196
+ return i + 1;
2197
+ case "OR":
2198
+ return i + 1;
2199
+ }
2200
+ }
2201
+ if (e === "TTL1") {
2202
+ let i;
2203
+ switch (t) {
2204
+ case "NAND":
2205
+ i = bt;
2206
+ break;
2207
+ case "AND":
2208
+ i = Ct;
2209
+ break;
2210
+ case "NOR":
2211
+ i = Pt;
2212
+ break;
2213
+ case "OR":
2214
+ i = xt;
2215
+ break;
2216
+ }
2217
+ const s = i[n];
2218
+ if (s === void 0) throw new Error(`Unsupported input count ${n} for TTL1 ${t}`);
2219
+ return s;
2220
+ }
2221
+ throw new Error(`Unsupported logic family: ${e}`);
2222
+ }
2223
+ var $e = class lt {
2224
+ metadata;
2225
+ components;
2226
+ enodes;
2227
+ wires;
2228
+ constructor(t) {
2229
+ this.metadata = new K(st, t, 10, 10, new tt()), this.components = /* @__PURE__ */ new Map(), this.enodes = /* @__PURE__ */ new Map(), this.wires = /* @__PURE__ */ new Map();
2230
+ }
2231
+ get name() {
2232
+ return this.metadata.options.name;
2233
+ }
2234
+ set name(t) {
2235
+ if (typeof t != "string" || t.trim() === "") throw new TypeError("Circuit name must be a non-empty string");
2236
+ this.metadata.options.name = t;
2237
+ }
2238
+ addComponent(t, n, i, s) {
2239
+ const r = I[t], a = new Q(t, n, i, []);
2240
+ if (s) for (const [u, l] of s) a.config.set(u, l);
2241
+ a.config.has("defaultLogicFamily") && !a.config.get("defaultLogicFamily") && a.config.set("defaultLogicFamily", this.metadata.options.defaultLogicFamily), this.resolveTransitionSpan(a);
2242
+ const o = [];
2243
+ for (const [u, l] of r.pins) {
2244
+ const p = new $(w.Pin, a.id, u, void 0, l.sourceType, l.subtype, l.logicPinData);
2245
+ this.enodes.set(p.id, p), o.push(p.id);
2246
+ }
2247
+ return Object.defineProperty(a, "pins", {
2248
+ value: o,
2249
+ writable: !1,
2250
+ enumerable: !0,
2251
+ configurable: !1
2252
+ }), this.components.set(a.id, a), a;
2253
+ }
2254
+ resolveTransitionSpan(t) {
2255
+ if (!t.config.has("transitionSpan")) return;
2256
+ const n = It(t);
2257
+ n && t.config.set("transitionSpan", String(n));
2258
+ }
2259
+ removeComponent(t) {
2260
+ const n = this.components.get(t);
2261
+ if (!n) throw new Error(`Component ${t} does not exist`);
2262
+ const i = [], s = [];
2263
+ for (const r of n.pins) {
2264
+ const a = this.enodes.get(r);
2265
+ if (a) {
2266
+ const o = Array.from(a.wires);
2267
+ for (const u of o)
2268
+ this.removeWire(u), i.push(u);
2269
+ }
2270
+ this.enodes.delete(r), s.push(r);
2271
+ }
2272
+ return this.components.delete(t), {
2273
+ deletedWires: i,
2274
+ deletedENodes: s
2275
+ };
2276
+ }
2277
+ hasComponent(t) {
2278
+ return this.components.has(t);
2279
+ }
2280
+ getComponent(t) {
2281
+ return this.components.get(t);
2282
+ }
2283
+ getAllComponents() {
2284
+ return Array.from(this.components.values());
2285
+ }
2286
+ getAllComponentsByType(t) {
2287
+ const n = [];
2288
+ for (const i of this.components.values()) i.type === t && n.push(i);
2289
+ return n;
2290
+ }
2291
+ getFirstComponentOfType(t) {
2292
+ for (const n of this.components.values()) if (n.type === t) return n;
2293
+ }
2294
+ getENode(t) {
2295
+ return this.enodes.get(t);
2296
+ }
2297
+ getAllENodes() {
2298
+ return Array.from(this.enodes.values());
2299
+ }
2300
+ addBranchingPoint(t, n) {
2301
+ const i = new $(w.BranchingPoint, void 0, void 0, t, n, void 0, void 0);
2302
+ return this.enodes.set(i.id, i), i;
2303
+ }
2304
+ removeBranchingPoint(t) {
2305
+ const n = this.enodes.get(t);
2306
+ if (!n) throw new Error(`Enode ${t} does not exist`);
2307
+ if (n.type !== w.BranchingPoint) throw new Error(`Enode ${t} is not a branching point, it must be removed with its component.`);
2308
+ const i = {}, s = this.getWiresByNode(t);
2309
+ if (s.length === 1 || s.length > 2) {
2310
+ const r = [];
2311
+ for (const a of s)
2312
+ this.removeWire(a.id), r.push(a.id);
2313
+ Object.assign(i, { deletedWires: r });
2314
+ } else if (s.length === 2) {
2315
+ const r = s[0], a = s[1], o = r.node1 === t ? r.node2 : r.node1, u = a.node1 === t ? a.node2 : a.node1, l = [];
2316
+ o === r.node1 ? l.push(...r.intermediatePositions) : o === r.node2 && l.push(...[...r.intermediatePositions].reverse()), l.push(n.getPosition(this)), u === a.node1 ? l.push(...[...a.intermediatePositions].reverse()) : u === a.node2 && l.push(...a.intermediatePositions), this.removeWire(r.id), this.removeWire(a.id);
2317
+ const p = this.addWire(o, u, l);
2318
+ if (p instanceof Error) throw new Error(`Failed to merge wires at branching point ${t}: ${p.message}`);
2319
+ Object.assign(i, { mergedWires: [r.id, a.id] }), Object.assign(i, { newWire: p });
2320
+ }
2321
+ return this.enodes.delete(t), i;
2322
+ }
2323
+ addWire(t, n, i) {
2324
+ if (t === n) return /* @__PURE__ */ new Error("Cannot create wire connecting node to itself");
2325
+ const s = this.enodes.get(t), r = this.enodes.get(n);
2326
+ if (!s || !r) return /* @__PURE__ */ new Error("Wire requires at least one existing ENode");
2327
+ if (this.hasWireBetween(t, n)) return /* @__PURE__ */ new Error("Duplicate wire between same nodes");
2328
+ const a = new N(t, n, i || []);
2329
+ return this.wires.set(a.id, a), s.wires.add(a.id), r.wires.add(a.id), a;
2330
+ }
2331
+ removeWire(t) {
2332
+ const n = this.wires.get(t);
2333
+ if (!n) throw new Error(`Wire ${t} does not exist`);
2334
+ const i = this.enodes.get(n.node1), s = this.enodes.get(n.node2);
2335
+ i && i.wires.delete(t), s && s.wires.delete(t), this.wires.delete(t);
2336
+ }
2337
+ splitWire(t, n, i = null) {
2338
+ const s = this.wires.get(t);
2339
+ if (!s) throw new Error(`Wire ${t} does not exist`);
2340
+ const r = this.enodes.get(s.node1), a = this.enodes.get(s.node2);
2341
+ if (!r || !a) throw new Error(`Wire ${t} is connected to non-existent ENodes`);
2342
+ const o = [
2343
+ r.getPosition(this),
2344
+ ...s.intermediatePositions,
2345
+ a.getPosition(this)
2346
+ ], u = vt(o, n), l = o.slice(1, u), p = o.slice(u, o.length - 1);
2347
+ this.wires.delete(t), r.wires.delete(t), a.wires.delete(t);
2348
+ let d;
2349
+ if (i) if (this.enodes.get(i)) d = this.enodes.get(i);
2350
+ else throw new Error(`Target ENode ${i} does not exist`);
2351
+ else d = this.addBranchingPoint(n);
2352
+ const g = [];
2353
+ if ((!d.component || r.component !== d.component) && !this.hasWireBetween(r.id, d.id)) {
2354
+ const f = this.addWire(r.id, d.id, l);
2355
+ f instanceof N ? (this.simplifyWireIntermediatePositions(f.id), g.push(f)) : console.warn(`Failure to create wire at split : ${f.message}`);
2356
+ }
2357
+ if ((!d.component || a.component !== d.component) && !this.hasWireBetween(a.id, d.id)) {
2358
+ const f = this.addWire(d.id, a.id, p);
2359
+ f instanceof N ? (this.simplifyWireIntermediatePositions(f.id), g.push(f)) : console.warn(`Failure to create wire at split : ${f.message}`);
2360
+ }
2361
+ return {
2362
+ branchingPoint: d,
2363
+ wires: g
2364
+ };
2365
+ }
2366
+ getWireBetweenNodes(t, n) {
2367
+ const i = this.enodes.get(t);
2368
+ if (i)
2369
+ for (const s of i.wires) {
2370
+ const r = this.wires.get(s);
2371
+ if (r && (r.node2 === n || r.node1 === n)) return r;
2372
+ }
2373
+ }
2374
+ getWire(t) {
2375
+ return this.wires.get(t);
2376
+ }
2377
+ getAllWires() {
2378
+ return Array.from(this.wires.values());
2379
+ }
2380
+ getWiresByNode(t) {
2381
+ const n = this.enodes.get(t);
2382
+ if (!n) return [];
2383
+ const i = [];
2384
+ for (const s of n.wires) {
2385
+ const r = this.wires.get(s);
2386
+ r && i.push(r);
2387
+ }
2388
+ return i;
2389
+ }
2390
+ getWiresByComponent(t) {
2391
+ const n = this.components.get(t);
2392
+ if (!n) return [];
2393
+ const i = [];
2394
+ for (const s of n.pins) i.push(...this.getWiresByNode(s));
2395
+ return i;
2396
+ }
2397
+ getNodesByWire(t) {
2398
+ const n = this.wires.get(t);
2399
+ if (!n) return;
2400
+ const i = this.enodes.get(n.node1), s = this.enodes.get(n.node2);
2401
+ if (!(!i || !s))
2402
+ return [i, s];
2403
+ }
2404
+ hasWireBetween(t, n) {
2405
+ const i = this.enodes.get(t);
2406
+ if (!i) return !1;
2407
+ for (const s of i.wires) {
2408
+ const r = this.wires.get(s);
2409
+ if (r && (r.node2 === n || r.node1 === n)) return !0;
2410
+ }
2411
+ return !1;
2412
+ }
2413
+ getComponentsOfPins(t) {
2414
+ const n = /* @__PURE__ */ new Set();
2415
+ for (const i of t) {
2416
+ const s = this.enodes.get(i);
2417
+ s?.component && n.add(s.component);
2418
+ }
2419
+ return n;
2420
+ }
2421
+ getComponentPinByLabel(t, n) {
2422
+ let i = 0;
2423
+ const s = I[t.type], r = Array.from(s.pins.keys());
2424
+ for (const a of t.pins) {
2425
+ const o = this.enodes.get(a), u = r[i];
2426
+ if (u) {
2427
+ if (o && u === n) return o;
2428
+ i++;
2429
+ }
2430
+ }
2431
+ }
2432
+ updateWireIntermediatePositions(t, n, i = !1) {
2433
+ const s = this.wires.get(t);
2434
+ if (!s) throw new Error(`Wire ${t} does not exist`);
2435
+ if (i) {
2436
+ const r = V([
2437
+ this.enodes.get(s.node1).getPosition(this),
2438
+ ...n,
2439
+ this.enodes.get(s.node2).getPosition(this)
2440
+ ], 10);
2441
+ s.intermediatePositions = r.slice(1, r.length - 1);
2442
+ } else s.intermediatePositions = n;
2443
+ return s;
2444
+ }
2445
+ simplifyWireIntermediatePositions(t) {
2446
+ const n = this.wires.get(t);
2447
+ if (!n) throw new Error(`Wire ${t} does not exist`);
2448
+ const i = V([
2449
+ this.enodes.get(n.node1).getPosition(this),
2450
+ ...n.intermediatePositions,
2451
+ this.enodes.get(n.node2).getPosition(this)
2452
+ ], 5);
2453
+ return n.intermediatePositions = i.slice(1, i.length - 1), n.intermediatePositions = V(n.intermediatePositions), n;
2454
+ }
2455
+ updateENodeSourceType(t, n) {
2456
+ const i = this.enodes.get(t);
2457
+ if (!i) throw new Error(`ENode ${t} does not exist`);
2458
+ i.source = n || void 0;
2459
+ }
2460
+ getEnclosingSize(t = 0) {
2461
+ let n = 0;
2462
+ for (const i of this.components.values()) n = Math.max(n, Math.abs(i.position.x), Math.abs(i.position.y));
2463
+ for (const i of this.enodes.values()) {
2464
+ if (i.type === w.Pin) continue;
2465
+ const s = i.position;
2466
+ s && (n = Math.max(n, Math.abs(s.x), Math.abs(s.y)));
2467
+ }
2468
+ 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));
2469
+ return Math.ceil(n * 2 + Math.max(t, 0));
2470
+ }
2471
+ toJSON() {
2472
+ return {
2473
+ metadata: this.metadata.toJSON(),
2474
+ components: this.getAllComponents().map((t) => t.toJSON()),
2475
+ enodes: this.getAllENodes().map((t) => t.toJSON()),
2476
+ wires: this.getAllWires().map((t) => t.toJSON())
2477
+ };
2478
+ }
2479
+ static fromJSON(t) {
2480
+ const n = K.fromJSON(t.metadata), i = new lt(n.options);
2481
+ i.metadata = n;
2482
+ for (const s of t.components) {
2483
+ const r = Q.fromJSON(s);
2484
+ i.components.set(r.id, r);
2485
+ }
2486
+ for (const s of t.enodes) {
2487
+ const r = $.fromJSON(s);
2488
+ i.enodes.set(r.id, r);
2489
+ }
2490
+ if (t.wires) for (const s of t.wires) {
2491
+ const r = N.fromJSON(s);
2492
+ i.wires.set(r.id, r);
2493
+ const a = i.enodes.get(r.node1), o = i.enodes.get(r.node2);
2494
+ a && a.wires.add(r.id), o && o.wires.add(r.id);
2495
+ }
2496
+ return i;
2497
+ }
2498
+ };
2499
+ function We(e, t) {
2500
+ const n = /* @__PURE__ */ new Map(), i = e.getENode(t);
2501
+ if (!i || i.type !== w.BranchingPoint) return n;
2502
+ const s = /* @__PURE__ */ new Set([t]), r = [{
2503
+ id: t,
2504
+ edges: 0
2505
+ }];
2506
+ for (; r.length > 0; ) {
2507
+ const { id: a, edges: o } = r.shift();
2508
+ for (const u of e.getWiresByNode(a)) {
2509
+ const l = u.node1 === a ? u.node2 : u.node1, p = e.getENode(l);
2510
+ if (!p) continue;
2511
+ const d = o + 1;
2512
+ if (p.type === w.Pin) {
2513
+ const g = d, f = n.get(l);
2514
+ (f === void 0 || g < f) && n.set(l, g);
2515
+ continue;
2516
+ }
2517
+ s.has(l) || (s.add(l), r.push({
2518
+ id: l,
2519
+ edges: d
2520
+ }));
2521
+ }
2522
+ }
2523
+ return n;
2524
+ }
2525
+ function Re(e, t) {
2526
+ const n = /* @__PURE__ */ new Map(), i = e.getENode(t);
2527
+ if (!i || i.type !== w.BranchingPoint) return n;
2528
+ const s = /* @__PURE__ */ new Set([t]), r = [{
2529
+ id: t,
2530
+ edges: 0,
2531
+ parent: t
2532
+ }];
2533
+ for (; r.length > 0; ) {
2534
+ const { id: a, edges: o } = r.shift();
2535
+ for (const u of e.getWiresByNode(a)) {
2536
+ const l = u.node1 === a ? u.node2 : u.node1, p = e.getENode(l);
2537
+ if (!p) continue;
2538
+ const d = o + 1;
2539
+ if (p.type === w.Pin) {
2540
+ const g = d, f = n.get(l);
2541
+ (f === void 0 || g < f.Dl) && n.set(l, {
2542
+ Dl: g,
2543
+ predecessor: a
2544
+ });
2545
+ continue;
2546
+ }
2547
+ s.has(l) || (s.add(l), r.push({
2548
+ id: l,
2549
+ edges: d,
2550
+ parent: a
2551
+ }));
2552
+ }
2553
+ }
2554
+ return n;
2555
+ }
2556
+ function Fe(e, t, n) {
2557
+ if (n <= 0) return [];
2558
+ const i = e.getENode(t);
2559
+ if (!i || i.type !== w.Pin) return [];
2560
+ const s = n, r = [], a = /* @__PURE__ */ new Set([t]), o = [{
2561
+ id: t,
2562
+ edges: 0
2563
+ }];
2564
+ for (; o.length > 0; ) {
2565
+ const { id: u, edges: l } = o.shift();
2566
+ if (!(l > s))
2567
+ for (const p of e.getWiresByNode(u)) {
2568
+ const d = p.node1 === u ? p.node2 : p.node1;
2569
+ if (a.has(d)) continue;
2570
+ const g = e.getENode(d);
2571
+ if (!g) continue;
2572
+ const f = l + 1;
2573
+ if (g.type !== w.Pin) {
2574
+ if (a.add(d), f === s) {
2575
+ r.push(d);
2576
+ continue;
2577
+ }
2578
+ o.push({
2579
+ id: d,
2580
+ edges: f
2581
+ });
2582
+ }
2583
+ }
2584
+ }
2585
+ return r;
2586
+ }
2587
+ function He(e, t, n) {
2588
+ if (n <= 0) return [];
2589
+ const i = e.getENode(t);
2590
+ if (!i || i.type !== w.Pin) return [];
2591
+ const s = n, r = [], a = /* @__PURE__ */ new Set([t]), o = [{
2592
+ id: t,
2593
+ edges: 0,
2594
+ parent: t
2595
+ }];
2596
+ for (; o.length > 0; ) {
2597
+ const { id: u, edges: l } = o.shift();
2598
+ if (!(l > s))
2599
+ for (const p of e.getWiresByNode(u)) {
2600
+ const d = p.node1 === u ? p.node2 : p.node1;
2601
+ if (a.has(d)) continue;
2602
+ const g = e.getENode(d);
2603
+ if (!g) continue;
2604
+ const f = l + 1;
2605
+ if (g.type !== w.Pin) {
2606
+ if (a.add(d), f === s) {
2607
+ r.push({
2608
+ id: d,
2609
+ predecessor: u
2610
+ });
2611
+ continue;
2612
+ }
2613
+ o.push({
2614
+ id: d,
2615
+ edges: f,
2616
+ parent: u
2617
+ });
2618
+ }
2619
+ }
2620
+ }
2621
+ return r;
2622
+ }
2623
+ var Je = {
2624
+ MIN_TPS: 1,
2625
+ MAX_TPS: 100,
2626
+ DEFAULT_TPS: 3,
2627
+ DEFAULT_INTERVAL_MS: 500
2628
+ }, dt = {
2629
+ TRANSITION_SPAN_TICKS: 1,
2630
+ TRANSITION_USER_SPAN_MS: 200
2631
+ };
2632
+ function O(...e) {
2633
+ return {
2634
+ hasVoltage: e.some((t) => t.hasVoltage),
2635
+ hasCurrent: e.some((t) => t.hasCurrent),
2636
+ locked: !1
2637
+ };
2638
+ }
2639
+ var Y = class ht {
2640
+ tick;
2641
+ nodeStates;
2642
+ wireStates;
2643
+ componentStates;
2644
+ constructor(t) {
2645
+ if (t < 0 || !Number.isInteger(t)) throw new RangeError(`Tick must be a non-negative integer (got ${t})`);
2646
+ this.tick = t, this.nodeStates = /* @__PURE__ */ new Map(), this.wireStates = /* @__PURE__ */ new Map(), this.componentStates = /* @__PURE__ */ new Map();
2647
+ }
2648
+ setTick(t) {
2649
+ this.tick = t;
2650
+ }
2651
+ clone() {
2652
+ const t = new ht(this.tick), n = /* @__PURE__ */ new Map();
2653
+ for (const [r, a] of this.nodeStates.entries()) n.set(r, { ...a });
2654
+ const i = /* @__PURE__ */ new Map();
2655
+ for (const [r, a] of this.wireStates.entries()) i.set(r, { ...a });
2656
+ const s = /* @__PURE__ */ new Map();
2657
+ for (const [r, a] of this.componentStates.entries()) s.set(r, Object.assign(Object.create(Object.getPrototypeOf(a)), a));
2658
+ return Object.defineProperty(t, "nodeStates", {
2659
+ value: n,
2660
+ writable: !1,
2661
+ configurable: !1,
2662
+ enumerable: !0
2663
+ }), Object.defineProperty(t, "wireStates", {
2664
+ value: i,
2665
+ writable: !1,
2666
+ configurable: !1,
2667
+ enumerable: !0
2668
+ }), Object.defineProperty(t, "componentStates", {
2669
+ value: s,
2670
+ writable: !1,
2671
+ configurable: !1,
2672
+ enumerable: !0
2673
+ }), t;
2674
+ }
2675
+ }, m = class {
2676
+ componentId;
2677
+ _state;
2678
+ _startTick;
2679
+ _expirationTick;
2680
+ _nextState;
2681
+ parameters = /* @__PURE__ */ new Map();
2682
+ pinStates = /* @__PURE__ */ new Map();
2683
+ constructor(e, t) {
2684
+ this.componentId = e, this._state = t, this._startTick = 0, this._expirationTick = -1, this._nextState = null;
2685
+ }
2686
+ get state() {
2687
+ return this._state;
2688
+ }
2689
+ setState(e, t) {
2690
+ this._state = e, this._startTick = t, this._expirationTick = -1, this._nextState = null;
2691
+ }
2692
+ get startTick() {
2693
+ return this._startTick;
2694
+ }
2695
+ get expirationTick() {
2696
+ return this._expirationTick;
2697
+ }
2698
+ get nextState() {
2699
+ return this._nextState;
2700
+ }
2701
+ get hasExpiration() {
2702
+ return this._expirationTick >= 0 && !!this._nextState && this._nextState !== this.state;
2703
+ }
2704
+ setNextState(e, t) {
2705
+ this._nextState = e, this._expirationTick = t;
2706
+ }
2707
+ }, Dt = class extends m {
2708
+ constructor(e) {
2709
+ super(e, "on");
2710
+ }
2711
+ }, Nt = class extends m {
2712
+ constructor(e, t = "off") {
2713
+ super(e, t);
2714
+ }
2715
+ get isLit() {
2716
+ return this.state === "on" || this.state === "goingOn";
2717
+ }
2718
+ }, gt = class extends m {
2719
+ constructor(e, t = "off") {
2720
+ super(e, t);
2721
+ }
2722
+ get isLit() {
2723
+ return this.state === "on" || this.state === "goingOn";
2724
+ }
2725
+ }, Mt = class extends gt {
2726
+ }, Lt = class extends m {
2727
+ constructor(e, t = "open") {
2728
+ super(e, t);
2729
+ }
2730
+ get isInTransition() {
2731
+ return this.state === "closing" || this.state === "opening";
2732
+ }
2733
+ get isClosed() {
2734
+ return this.state === "closed" || this.state === "closing";
2735
+ }
2736
+ }, zt = class extends m {
2737
+ constructor(e, t = "open") {
2738
+ super(e, t);
2739
+ }
2740
+ get isInTransition() {
2741
+ return this.state === "closing" || this.state === "opening";
2742
+ }
2743
+ get isClosed() {
2744
+ return this.state === "closed" || this.state === "closing";
2745
+ }
2746
+ }, Bt = class extends m {
2747
+ constructor(e, t = "input1") {
2748
+ super(e, t);
2749
+ }
2750
+ get isInTransition() {
2751
+ return this.state === "1to2" || this.state === "2to1";
2752
+ }
2753
+ }, At = class extends m {
2754
+ constructor(e) {
2755
+ super(e, "high");
2756
+ }
2757
+ }, b = class extends m {
2758
+ constructor(e, t = "low") {
2759
+ super(e, t);
2760
+ }
2761
+ get isInTransition() {
2762
+ return this.state === "rising" || this.state === "falling";
2763
+ }
2764
+ get isHigh() {
2765
+ return this.state === "high";
2766
+ }
2767
+ }, kt = class extends b {
2768
+ constructor(e, t = "low") {
2769
+ super(e, t);
2770
+ }
2771
+ }, Gt = class extends b {
2772
+ constructor(e, t = "low") {
2773
+ super(e, t);
2774
+ }
2775
+ }, _t = class extends b {
2776
+ constructor(e, t = "low") {
2777
+ super(e, t);
2778
+ }
2779
+ }, Vt = class extends b {
2780
+ constructor(e, t = "low") {
2781
+ super(e, t);
2782
+ }
2783
+ }, $t = class extends b {
2784
+ constructor(e, t = "low") {
2785
+ super(e, t);
2786
+ }
2787
+ }, Wt = class extends b {
2788
+ constructor(e, t = "low") {
2789
+ super(e, t);
2790
+ }
2791
+ }, Rt = class extends b {
2792
+ constructor(e, t = "low") {
2793
+ super(e, t);
2794
+ }
2795
+ }, Ft = class extends b {
2796
+ constructor(e, t = "low") {
2797
+ super(e, t);
2798
+ }
2799
+ }, Ht = class extends b {
2800
+ constructor(e, t = "low") {
2801
+ super(e, t);
2802
+ }
2803
+ }, Jt = class extends b {
2804
+ constructor(e, t = "low") {
2805
+ super(e, t);
2806
+ }
2807
+ }, L = class extends m {
2808
+ outputCount;
2809
+ hexDigitCount;
2810
+ allLowState;
2811
+ constructor(e, t, n) {
2812
+ super(e, n), this.outputCount = t, this.hexDigitCount = Math.ceil(t / 4), this.allLowState = "0".repeat(this.hexDigitCount);
2813
+ }
2814
+ get isInTransition() {
2815
+ return this.state.startsWith("to");
2816
+ }
2817
+ get effectiveState() {
2818
+ return this.isInTransition ? this.parameters.get("prevState") ?? this.allLowState : this.state;
2819
+ }
2820
+ isOutputHigh(e) {
2821
+ const t = this.effectiveState;
2822
+ return t === "indeterminate" ? !1 : (parseInt(t, 16) >> e & 1) === 1;
2823
+ }
2824
+ }, Ut = class extends L {
2825
+ constructor(e, t = "0") {
2826
+ super(e, 2, t);
2827
+ }
2828
+ get sumHigh() {
2829
+ return this.isOutputHigh(0);
2830
+ }
2831
+ get carryHigh() {
2832
+ return this.isOutputHigh(1);
2833
+ }
2834
+ }, Xt = class extends L {
2835
+ constructor(e, t = "0") {
2836
+ super(e, 2, t);
2837
+ }
2838
+ get sumHigh() {
2839
+ return this.isOutputHigh(0);
2840
+ }
2841
+ get carryOutHigh() {
2842
+ return this.isOutputHigh(1);
2843
+ }
2844
+ }, Qt = class extends L {
2845
+ constructor(e, t = "0000") {
2846
+ super(e, 16, t);
2847
+ }
2848
+ isSumHigh(e) {
2849
+ return this.isOutputHigh(2 * e);
2850
+ }
2851
+ isStageCarryHigh(e) {
2852
+ return this.isOutputHigh(2 * e + 1);
2853
+ }
2854
+ isCarryOutHigh() {
2855
+ return this.isStageCarryHigh(7);
2856
+ }
2857
+ }, qt = class extends L {
2858
+ constructor(e, t = "000") {
2859
+ super(e, 9, t);
2860
+ }
2861
+ isOutputBitHigh(e) {
2862
+ return this.isOutputHigh(e);
2863
+ }
2864
+ isInvertHigh() {
2865
+ return this.isOutputHigh(8);
2866
+ }
2867
+ }, z = class extends m {
2868
+ outputCount;
2869
+ hexDigitCount;
2870
+ allLowState;
2871
+ constructor(e, t, n) {
2872
+ super(e, n), this.outputCount = t, this.hexDigitCount = Math.ceil(t / 4), this.allLowState = "0".repeat(this.hexDigitCount);
2873
+ }
2874
+ get isInTransition() {
2875
+ return this.state === "moving";
2876
+ }
2877
+ get effectiveState() {
2878
+ return this.isInTransition ? this.parameters.get("prevState") ?? this.allLowState : this.state;
2879
+ }
2880
+ isOutputHigh(e) {
2881
+ const t = this.effectiveState;
2882
+ return (parseInt(t, 16) >> e & 1) === 1;
2883
+ }
2884
+ getPendingMove(e) {
2885
+ const t = this.parameters.get(String(e));
2886
+ if (!t) return null;
2887
+ const n = t.split("-");
2888
+ if (n.length !== 3) return null;
2889
+ const i = parseInt(n[0], 10), s = parseInt(n[1], 10), r = parseInt(n[2], 10);
2890
+ return isNaN(i) || isNaN(s) || isNaN(r) ? null : {
2891
+ target: i === 1 ? 1 : 0,
2892
+ startTick: s,
2893
+ endTick: r
2894
+ };
2895
+ }
2896
+ }, Kt = class extends z {
2897
+ constructor(e, t = "0") {
2898
+ super(e, 1, t);
2899
+ }
2900
+ }, Yt = class extends z {
2901
+ constructor(e, t = "0") {
2902
+ super(e, 2, t);
2903
+ }
2904
+ }, Zt = class extends z {
2905
+ constructor(e, t = "0") {
2906
+ super(e, 4, t);
2907
+ }
2908
+ }, jt = class extends z {
2909
+ constructor(e, t = "00") {
2910
+ super(e, 8, t);
2911
+ }
2912
+ }, B = class extends m {
2913
+ lightCount;
2914
+ hexDigitCount;
2915
+ allLowState;
2916
+ constructor(e, t, n) {
2917
+ super(e, n), this.lightCount = t, this.hexDigitCount = Math.ceil(t / 4), this.allLowState = "0".repeat(this.hexDigitCount);
2918
+ }
2919
+ get isInTransition() {
2920
+ return this.state === "moving";
2921
+ }
2922
+ get effectiveState() {
2923
+ return this.isInTransition ? this.parameters.get("prevState") ?? this.allLowState : this.state;
2924
+ }
2925
+ isOutputHigh(e) {
2926
+ const t = this.effectiveState;
2927
+ return t === "indeterminate" ? !1 : (parseInt(t, 16) >> e & 1) === 1;
2928
+ }
2929
+ getPendingMove(e) {
2930
+ const t = this.parameters.get(String(e));
2931
+ if (!t) return null;
2932
+ const n = t.split("-");
2933
+ if (n.length !== 3) return null;
2934
+ const i = parseInt(n[0], 10), s = parseInt(n[1], 10), r = parseInt(n[2], 10);
2935
+ return isNaN(i) || isNaN(s) || isNaN(r) ? null : {
2936
+ target: i === 1 ? 1 : 0,
2937
+ startTick: s,
2938
+ endTick: r
2939
+ };
2940
+ }
2941
+ }, te = class extends B {
2942
+ constructor(e, t = "0") {
2943
+ super(e, 1, t);
2944
+ }
2945
+ }, ee = class extends B {
2946
+ constructor(e, t = "0") {
2947
+ super(e, 2, t);
2948
+ }
2949
+ }, ie = class extends B {
2950
+ constructor(e, t = "0") {
2951
+ super(e, 4, t);
2952
+ }
2953
+ }, ne = class extends B {
2954
+ constructor(e, t = "00") {
2955
+ super(e, 8, t);
2956
+ }
2957
+ }, Ue = class {
2958
+ behaviors;
2959
+ constructor() {
2960
+ this.behaviors = /* @__PURE__ */ new Map();
2961
+ }
2962
+ register(e) {
2963
+ if (!e) throw new TypeError("Behavior cannot be null or undefined");
2964
+ if (!e.componentType || e.componentType.trim() === "") throw new TypeError("Behavior componentType cannot be empty");
2965
+ return this.behaviors.set(e.componentType, e), this;
2966
+ }
2967
+ registerAll(e) {
2968
+ e.forEach((t) => this.register(t));
2969
+ }
2970
+ get(e) {
2971
+ return this.behaviors.get(e);
2972
+ }
2973
+ has(e) {
2974
+ return this.behaviors.has(e);
2975
+ }
2976
+ unregister(e) {
2977
+ return this.behaviors.delete(e);
2978
+ }
2979
+ clear() {
2980
+ this.behaviors.clear();
2981
+ }
2982
+ getRegisteredTypes() {
2983
+ return Array.from(this.behaviors.keys());
2984
+ }
2985
+ size() {
2986
+ return this.behaviors.size;
2987
+ }
2988
+ }, C = class {
2989
+ _componentType;
2990
+ constructor(e) {
2991
+ this._componentType = e;
2992
+ }
2993
+ get componentType() {
2994
+ return this._componentType;
2995
+ }
2996
+ get typeMetadata() {
2997
+ const e = I[this._componentType];
2998
+ if (!e) throw new Error(`Unknown metadata for Component type ${this._componentType}`);
2999
+ return e;
3000
+ }
3001
+ getPinStates(e, t) {
3002
+ const n = /* @__PURE__ */ new Map();
3003
+ for (const i of e.pins) n.set(e.getPinLabel(i), t.get(i));
3004
+ return n;
3005
+ }
3006
+ getChangedPins(e, t) {
3007
+ const n = /* @__PURE__ */ new Set();
3008
+ for (const [i, s] of e) {
3009
+ if (!t.has(i)) continue;
3010
+ const r = t.get(i);
3011
+ (s.hasVoltage !== r?.hasVoltage || s.hasCurrent !== r?.hasCurrent) && n.add(i);
3012
+ }
3013
+ return n;
3014
+ }
3015
+ onStart(e, t) {
3016
+ return null;
3017
+ }
3018
+ onPinsChange(e, t, n, i) {
3019
+ return {
3020
+ componentState: t,
3021
+ hasChanged: !1,
3022
+ shouldCancelPending: !1,
3023
+ scheduledEvents: []
3024
+ };
3025
+ }
3026
+ allowConductivity(e, t, n, i, s) {
3027
+ return !1;
3028
+ }
3029
+ onUserCommand(e, t, n) {
3030
+ return {
3031
+ componentState: t,
3032
+ hasChanged: !1,
3033
+ shouldCancelPending: !1,
3034
+ scheduledEvents: []
3035
+ };
3036
+ }
3037
+ onEventFiring(e, t, n) {
3038
+ return {
3039
+ componentState: t,
3040
+ hasChanged: !1,
3041
+ shouldCancelPending: !1,
3042
+ scheduledEvents: []
3043
+ };
3044
+ }
3045
+ };
3046
+ function x(e) {
3047
+ const t = parseInt(e.get("transitionSpan") || "", 10);
3048
+ return isNaN(t) || t < 1 ? dt.TRANSITION_SPAN_TICKS : t;
3049
+ }
3050
+ var se = class extends C {
3051
+ constructor() {
3052
+ super(c.Battery);
3053
+ }
3054
+ createInitialState(e) {
3055
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for BatteryBehavior: ${e.type}`);
3056
+ return new Dt(e.id);
3057
+ }
3058
+ }, U = class extends C {
3059
+ getBehavior(e, t, n, i) {
3060
+ let s = !1;
3061
+ const r = [], a = x(e.config), o = t.expirationTick < 1 ? a : Math.max(i - t.startTick, 1);
3062
+ return n ? (t.state === "off" || t.state === "goingOff") && (s = !0, t.setState("goingOn", i), t.setNextState("on", i + o), r.push({
3063
+ targetId: e.id,
3064
+ scheduledAtTick: t.startTick,
3065
+ readyAtTick: t.expirationTick,
3066
+ type: "GoingOnEnd",
3067
+ parameters: void 0
3068
+ })) : (t.state === "on" || t.state === "goingOn") && (s = !0, t.setState("goingOff", i), t.setNextState("off", i + o), r.push({
3069
+ targetId: e.id,
3070
+ scheduledAtTick: t.startTick,
3071
+ readyAtTick: t.expirationTick,
3072
+ type: "GoingOffEnd",
3073
+ parameters: void 0
3074
+ })), {
3075
+ componentState: t,
3076
+ hasChanged: s,
3077
+ shouldCancelPending: !0,
3078
+ scheduledEvents: r
3079
+ };
3080
+ }
3081
+ allowConductivity(e, t, n, i, s) {
3082
+ return !0;
3083
+ }
3084
+ onEventFiring(e, t, n) {
3085
+ let i = !1;
3086
+ 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)), {
3087
+ componentState: t,
3088
+ hasChanged: i,
3089
+ shouldCancelPending: !1,
3090
+ scheduledEvents: []
3091
+ };
3092
+ }
3093
+ }, re = class extends U {
3094
+ constructor() {
3095
+ super(c.Lightbulb);
3096
+ }
3097
+ createInitialState(e) {
3098
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for lightbulbBehavior: ${e.type}`);
3099
+ return new Nt(e.id);
3100
+ }
3101
+ onPinsChange(e, t, n, i) {
3102
+ const s = this.getPinStates(e, n);
3103
+ t.pinStates = s;
3104
+ const r = O(s.get("pin1"), s.get("pin2")), a = r.hasVoltage && r.hasCurrent;
3105
+ return this.getBehavior(e, t, a, i);
3106
+ }
3107
+ }, ae = class extends U {
3108
+ constructor() {
3109
+ super(c.RectangleLED);
3110
+ }
3111
+ createInitialState(e) {
3112
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for RectangleLEDBehavior: ${e.type}`);
3113
+ return new Mt(e.id);
3114
+ }
3115
+ onPinsChange(e, t, n, i) {
3116
+ const s = this.getPinStates(e, n);
3117
+ t.pinStates = s;
3118
+ const r = O(s.get("pin1"), s.get("pin2")), a = r.hasVoltage && r.hasCurrent;
3119
+ return this.getBehavior(e, t, a, i);
3120
+ }
3121
+ };
3122
+ function oe(e) {
3123
+ const t = parseInt(e.get("transitionSpan") || "", 10);
3124
+ return isNaN(t) || t < 1 ? dt.TRANSITION_SPAN_TICKS : t;
3125
+ }
3126
+ var ue = class extends C {
3127
+ constructor() {
3128
+ super(c.Relay);
3129
+ }
3130
+ createInitialState(e) {
3131
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for RelayBehavior: ${e.type}`);
3132
+ const t = e.config.get("activationLogic") === "negative" ? "closed" : "open";
3133
+ return new Lt(e.id, t);
3134
+ }
3135
+ allowConductivity(e, t, n, i, s) {
3136
+ if (i === s) return !0;
3137
+ const r = e.getPinLabel(i), a = e.getPinLabel(s);
3138
+ if (!r || !a) return !1;
3139
+ const o = [r, a];
3140
+ 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;
3141
+ }
3142
+ onPinsChange(e, t, n, i) {
3143
+ const s = this.getPinStates(e, n);
3144
+ s.set("cmd_in*cmd_out", O(s.get("cmd_in"), s.get("cmd_out"))), s.set("power_in*power_out", O(s.get("power_in"), s.get("power_out")));
3145
+ const r = t.pinStates;
3146
+ t.pinStates = s;
3147
+ const a = this.getChangedPins(s, r), o = s.get("cmd_in*cmd_out"), u = o.hasVoltage && o.hasCurrent, l = e.config.get("activationLogic") === "negative" ? !u : u;
3148
+ let p = a.size > 0;
3149
+ const d = [], g = oe(e.config);
3150
+ if (l) {
3151
+ if (t.state === "open" || t.state === "opening") {
3152
+ let f = t.state === "open" ? g : Math.max(i - t.startTick, 1);
3153
+ p = !0, t.setState("closing", i), t.setNextState("closed", i + f), d.push({
3154
+ targetId: e.id,
3155
+ scheduledAtTick: t.startTick,
3156
+ readyAtTick: t.expirationTick,
3157
+ type: "ClosingEnd",
3158
+ parameters: /* @__PURE__ */ new Map([["exclusive", "true"]])
3159
+ });
3160
+ }
3161
+ } else if (t.state === "closed" || t.state === "closing") {
3162
+ let f = t.state === "closed" ? g : Math.max(i - t.startTick, 1);
3163
+ p = !0, t.setState("opening", i), t.setNextState("open", i + f), d.push({
3164
+ targetId: e.id,
3165
+ scheduledAtTick: t.startTick,
3166
+ readyAtTick: t.expirationTick,
3167
+ type: "OpeningEnd",
3168
+ parameters: /* @__PURE__ */ new Map([["exclusive", "true"]])
3169
+ });
3170
+ }
3171
+ return {
3172
+ componentState: t,
3173
+ hasChanged: p,
3174
+ shouldCancelPending: p,
3175
+ scheduledEvents: d
3176
+ };
3177
+ }
3178
+ onEventFiring(e, t, n) {
3179
+ let i = !1;
3180
+ 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), {
3181
+ componentState: t,
3182
+ hasChanged: i,
3183
+ shouldCancelPending: !1,
3184
+ scheduledEvents: []
3185
+ };
3186
+ }
3187
+ }, ce = class extends U {
3188
+ constructor() {
3189
+ super(c.SmallLED);
3190
+ }
3191
+ createInitialState(e) {
3192
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for SmallLEDBehavior: ${e.type}`);
3193
+ return new gt(e.id);
3194
+ }
3195
+ onPinsChange(e, t, n, i) {
3196
+ const s = this.getPinStates(e, n);
3197
+ t.pinStates = s;
3198
+ const r = O(s.get("pin1"), s.get("pin2")), a = r.hasVoltage && r.hasCurrent;
3199
+ return this.getBehavior(e, t, a, i);
3200
+ }
3201
+ }, pe = class extends C {
3202
+ constructor() {
3203
+ super(c.Switch);
3204
+ }
3205
+ createInitialState(e) {
3206
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for SwitchBehavior: ${e.type}`);
3207
+ const t = e.config.get("initialState") || "open";
3208
+ return new zt(e.id, t);
3209
+ }
3210
+ allowConductivity(e, t, n, i, s) {
3211
+ return t.state === "closed" || t.state === "opening";
3212
+ }
3213
+ onPinsChange(e, t, n, i) {
3214
+ const s = this.getPinStates(e, n), r = t.pinStates;
3215
+ t.pinStates = s;
3216
+ const a = this.getChangedPins(s, r);
3217
+ return a.size < 1 || !a.has("output") ? {
3218
+ componentState: t,
3219
+ hasChanged: !1,
3220
+ shouldCancelPending: !1,
3221
+ scheduledEvents: []
3222
+ } : {
3223
+ componentState: t,
3224
+ hasChanged: !0,
3225
+ shouldCancelPending: !1,
3226
+ scheduledEvents: []
3227
+ };
3228
+ }
3229
+ onUserCommand(e, t, n) {
3230
+ let i = !1;
3231
+ const s = [], r = x(e.config);
3232
+ 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({
3233
+ targetId: e.id,
3234
+ scheduledAtTick: t.startTick,
3235
+ readyAtTick: t.expirationTick,
3236
+ type: t.state === "closing" ? "ClosingEnd" : "OpeningEnd",
3237
+ parameters: /* @__PURE__ */ new Map([["exclusive", "true"]])
3238
+ })), {
3239
+ componentState: t,
3240
+ hasChanged: i,
3241
+ shouldCancelPending: !0,
3242
+ scheduledEvents: s
3243
+ };
3244
+ }
3245
+ onEventFiring(e, t, n) {
3246
+ let i = !1;
3247
+ 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), {
3248
+ componentState: t,
3249
+ hasChanged: i,
3250
+ shouldCancelPending: !1,
3251
+ scheduledEvents: []
3252
+ };
3253
+ }
3254
+ }, le = class extends C {
3255
+ constructor() {
3256
+ super(c.DoubleThrowSwitch);
3257
+ }
3258
+ createInitialState(e) {
3259
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for DoubleThrowSwitchBehavior: ${e.type}`);
3260
+ const t = e.config.get("initialState") || "input1";
3261
+ return new Bt(e.id, t);
3262
+ }
3263
+ allowConductivity(e, t, n, i, s) {
3264
+ if (i === s) return !0;
3265
+ const r = e.getPinLabel(i), a = e.getPinLabel(s);
3266
+ if (!r || !a) return !1;
3267
+ const o = [r, a];
3268
+ 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;
3269
+ }
3270
+ onPinsChange(e, t, n, i) {
3271
+ const s = this.getPinStates(e, n), r = t.pinStates;
3272
+ t.pinStates = s;
3273
+ const a = this.getChangedPins(s, r);
3274
+ return a.size < 1 || !a.has("output") ? {
3275
+ componentState: t,
3276
+ hasChanged: !1,
3277
+ shouldCancelPending: !1,
3278
+ scheduledEvents: []
3279
+ } : {
3280
+ componentState: t,
3281
+ hasChanged: !0,
3282
+ shouldCancelPending: !1,
3283
+ scheduledEvents: []
3284
+ };
3285
+ }
3286
+ onUserCommand(e, t, n) {
3287
+ let i = !1;
3288
+ const s = [], r = x(e.config);
3289
+ 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({
3290
+ targetId: e.id,
3291
+ scheduledAtTick: t.startTick,
3292
+ readyAtTick: t.expirationTick,
3293
+ type: t.state === "1to2" ? "ContactedInput2" : "ContactedInput1",
3294
+ parameters: /* @__PURE__ */ new Map([["exclusive", "true"]])
3295
+ })), {
3296
+ componentState: t,
3297
+ hasChanged: i,
3298
+ shouldCancelPending: !0,
3299
+ scheduledEvents: s
3300
+ };
3301
+ }
3302
+ onEventFiring(e, t, n) {
3303
+ let i = !1;
3304
+ 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), {
3305
+ componentState: t,
3306
+ hasChanged: i,
3307
+ shouldCancelPending: !1,
3308
+ scheduledEvents: []
3309
+ };
3310
+ }
3311
+ }, de = class extends C {
3312
+ constructor() {
3313
+ super(c.Clock);
3314
+ }
3315
+ createInitialState(e) {
3316
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for ClockBehavior: ${e.type}`);
3317
+ const t = new At(e.id), n = e.config.get("startHigh") == "true";
3318
+ t.setState(n ? "high" : "low", 0);
3319
+ const i = Number(e.config.get("halfPeriod"));
3320
+ return t.setNextState(n ? "low" : "high", i), t;
3321
+ }
3322
+ allowConductivity(e, t, n, i, s) {
3323
+ if (i === s) return !0;
3324
+ const r = e.getPinLabel(i), a = e.getPinLabel(s);
3325
+ if (!r || !a) return !1;
3326
+ const o = [r, a];
3327
+ 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;
3328
+ }
3329
+ onStart(e, t) {
3330
+ const i = Number(e.config.get("halfPeriod"));
3331
+ return t.setNextState(t.state === "high" ? "low" : "high", 0 + i), {
3332
+ componentState: t,
3333
+ hasChanged: !0,
3334
+ shouldCancelPending: !0,
3335
+ scheduledEvents: [{
3336
+ targetId: e.id,
3337
+ scheduledAtTick: t.startTick,
3338
+ readyAtTick: t.expirationTick,
3339
+ type: "tick",
3340
+ parameters: /* @__PURE__ */ new Map([["exclusive", "true"]])
3341
+ }]
3342
+ };
3343
+ }
3344
+ onEventFiring(e, t, n) {
3345
+ if (n.type !== "tick") return {
3346
+ componentState: t,
3347
+ hasChanged: !1,
3348
+ shouldCancelPending: !1,
3349
+ scheduledEvents: []
3350
+ };
3351
+ const i = Number(e.config.get("halfPeriod"));
3352
+ return t.setState(t.state === "high" ? "low" : "high", n.readyAtTick), t.setNextState(t.state === "high" ? "low" : "high", n.readyAtTick + i), {
3353
+ componentState: t,
3354
+ hasChanged: !0,
3355
+ shouldCancelPending: !0,
3356
+ scheduledEvents: [{
3357
+ targetId: e.id,
3358
+ scheduledAtTick: t.startTick,
3359
+ readyAtTick: t.expirationTick,
3360
+ type: "tick",
3361
+ parameters: /* @__PURE__ */ new Map([["exclusive", "true"]])
3362
+ }]
3363
+ };
3364
+ }
3365
+ }, P = class extends C {
3366
+ vccGuardBehavior(e, t, n) {
3367
+ if (t.get("vcc").hasVoltage) return null;
3368
+ let i = !1, s = !1;
3369
+ return e.state !== "low" && (e.setState("low", n), i = !0, s = !0), {
3370
+ componentState: e,
3371
+ hasChanged: i,
3372
+ shouldCancelPending: s,
3373
+ scheduledEvents: []
3374
+ };
3375
+ }
3376
+ nonLogicInputGuardBehavior(e, t, n) {
3377
+ let i = !1;
3378
+ const s = this.typeMetadata.pins;
3379
+ for (const [o, u] of t) {
3380
+ if (!s.has(o)) continue;
3381
+ const l = s.get(o);
3382
+ if (l && l?.subtype === "logicInput") {
3383
+ if (u.hasVoltage && u.hasCurrent) {
3384
+ i = !0;
3385
+ break;
3386
+ }
3387
+ if (!u.hasVoltage && !u.hasCurrent) {
3388
+ i = !0;
3389
+ break;
3390
+ }
3391
+ }
3392
+ }
3393
+ if (!i) return null;
3394
+ let r = !1, a = !1;
3395
+ return e.state !== "indeterminate" && (e.setState("indeterminate", n), r = !0, a = !0), {
3396
+ componentState: e,
3397
+ hasChanged: r,
3398
+ shouldCancelPending: a,
3399
+ scheduledEvents: []
3400
+ };
3401
+ }
3402
+ getBehavior(e, t, n, i) {
3403
+ if (![
3404
+ "low",
3405
+ "rising",
3406
+ "high",
3407
+ "falling",
3408
+ "indeterminate"
3409
+ ].includes(t.state))
3410
+ return t.setState("low", i), {
3411
+ componentState: t,
3412
+ hasChanged: !0,
3413
+ shouldCancelPending: !0,
3414
+ scheduledEvents: []
3415
+ };
3416
+ const s = x(e.config), r = t.expirationTick < 1 ? s : Math.max(i - t.startTick, 1);
3417
+ if (n) {
3418
+ if (t.state === "low" || t.state === "falling" || t.state === "indeterminate")
3419
+ return t.setState("rising", i), t.setNextState("high", i + r), {
3420
+ componentState: t,
3421
+ hasChanged: !0,
3422
+ shouldCancelPending: !0,
3423
+ scheduledEvents: [{
3424
+ targetId: e.id,
3425
+ scheduledAtTick: t.startTick,
3426
+ readyAtTick: t.expirationTick,
3427
+ type: "RisingComplete",
3428
+ parameters: void 0
3429
+ }]
3430
+ };
3431
+ if (t.state === "rising" || t.state === "high") return {
3432
+ componentState: t,
3433
+ hasChanged: !1,
3434
+ shouldCancelPending: !1,
3435
+ scheduledEvents: []
3436
+ };
3437
+ }
3438
+ return t.state === "falling" || t.state === "low" ? {
3439
+ componentState: t,
3440
+ hasChanged: !1,
3441
+ shouldCancelPending: !1,
3442
+ scheduledEvents: []
3443
+ } : t.state === "high" || t.state === "rising" || t.state === "indeterminate" ? (t.setState("falling", i), t.setNextState("low", i + r), {
3444
+ componentState: t,
3445
+ hasChanged: !0,
3446
+ shouldCancelPending: !0,
3447
+ scheduledEvents: [{
3448
+ targetId: e.id,
3449
+ scheduledAtTick: t.startTick,
3450
+ readyAtTick: t.expirationTick,
3451
+ type: "FallingComplete",
3452
+ parameters: void 0
3453
+ }]
3454
+ }) : (t.setState("low", i), {
3455
+ componentState: t,
3456
+ hasChanged: !0,
3457
+ shouldCancelPending: !0,
3458
+ scheduledEvents: []
3459
+ });
3460
+ }
3461
+ allowConductivity(e, t, n, i, s) {
3462
+ if (i === s) return !0;
3463
+ const r = e.getPinLabel(i), a = e.getPinLabel(s);
3464
+ if (!r || !a) return !1;
3465
+ const o = [r, a];
3466
+ 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;
3467
+ }
3468
+ onEventFiring(e, t, n) {
3469
+ let i = !1;
3470
+ 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)), {
3471
+ componentState: t,
3472
+ hasChanged: i,
3473
+ shouldCancelPending: !1,
3474
+ scheduledEvents: []
3475
+ };
3476
+ }
3477
+ }, he = class extends P {
3478
+ constructor() {
3479
+ super(c.Inverter);
3480
+ }
3481
+ createInitialState(e) {
3482
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for InverterBehavior: ${e.type}`);
3483
+ const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
3484
+ return new kt(e.id, t);
3485
+ }
3486
+ onPinsChange(e, t, n, i) {
3487
+ const s = this.getPinStates(e, n);
3488
+ t.pinStates = s;
3489
+ const r = this.vccGuardBehavior(t, s, i);
3490
+ if (r) return r;
3491
+ const a = this.nonLogicInputGuardBehavior(t, s, i);
3492
+ if (a) return a;
3493
+ const o = s.get("input").hasVoltage, u = e.config.get("activationLogic") === "negative" ? !o : o;
3494
+ return this.getBehavior(e, t, u, i);
3495
+ }
3496
+ }, ge = class extends P {
3497
+ constructor() {
3498
+ super(c.NandGate);
3499
+ }
3500
+ createInitialState(e) {
3501
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for NandGateBehavior: ${e.type}`);
3502
+ const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
3503
+ return new Gt(e.id, t);
3504
+ }
3505
+ onPinsChange(e, t, n, i) {
3506
+ const s = this.getPinStates(e, n);
3507
+ t.pinStates = s;
3508
+ const r = this.vccGuardBehavior(t, s, i);
3509
+ if (r) return r;
3510
+ const a = this.nonLogicInputGuardBehavior(t, s, i);
3511
+ if (a) return a;
3512
+ const o = s.get("input-0").hasVoltage && s.get("input-1").hasVoltage, u = e.config.get("activationLogic") === "negative" ? !o : o;
3513
+ return this.getBehavior(e, t, u, i);
3514
+ }
3515
+ }, fe = class extends P {
3516
+ constructor() {
3517
+ super(c.Nand4Gate);
3518
+ }
3519
+ createInitialState(e) {
3520
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for Nand4GateBehavior: ${e.type}`);
3521
+ const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
3522
+ return new _t(e.id, t);
3523
+ }
3524
+ onPinsChange(e, t, n, i) {
3525
+ const s = this.getPinStates(e, n);
3526
+ t.pinStates = s;
3527
+ const r = this.vccGuardBehavior(t, s, i);
3528
+ if (r) return r;
3529
+ const a = this.nonLogicInputGuardBehavior(t, s, i);
3530
+ if (a) return a;
3531
+ const o = s.get("input-0").hasVoltage && s.get("input-1").hasVoltage && s.get("input-2").hasVoltage && s.get("input-3").hasVoltage, u = e.config.get("activationLogic") === "negative" ? !o : o;
3532
+ return this.getBehavior(e, t, u, i);
3533
+ }
3534
+ }, ye = class extends P {
3535
+ constructor() {
3536
+ super(c.Nand8Gate);
3537
+ }
3538
+ createInitialState(e) {
3539
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for Nand8GateBehavior: ${e.type}`);
3540
+ const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
3541
+ return new Vt(e.id, t);
3542
+ }
3543
+ onPinsChange(e, t, n, i) {
3544
+ const s = this.getPinStates(e, n);
3545
+ t.pinStates = s;
3546
+ const r = this.vccGuardBehavior(t, s, i);
3547
+ if (r) return r;
3548
+ const a = this.nonLogicInputGuardBehavior(t, s, i);
3549
+ if (a) return a;
3550
+ const o = s.get("input-0").hasVoltage && s.get("input-1").hasVoltage && s.get("input-2").hasVoltage && s.get("input-3").hasVoltage && s.get("input-4").hasVoltage && s.get("input-5").hasVoltage && s.get("input-6").hasVoltage && s.get("input-7").hasVoltage, u = e.config.get("activationLogic") === "negative" ? !o : o;
3551
+ return this.getBehavior(e, t, u, i);
3552
+ }
3553
+ }, ve = class extends P {
3554
+ constructor() {
3555
+ super(c.NorGate);
3556
+ }
3557
+ createInitialState(e) {
3558
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for NorGateBehavior: ${e.type}`);
3559
+ const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
3560
+ return new $t(e.id, t);
3561
+ }
3562
+ onPinsChange(e, t, n, i) {
3563
+ const s = this.getPinStates(e, n);
3564
+ t.pinStates = s;
3565
+ const r = this.vccGuardBehavior(t, s, i);
3566
+ if (r) return r;
3567
+ const a = this.nonLogicInputGuardBehavior(t, s, i);
3568
+ if (a) return a;
3569
+ const o = s.get("input-0").hasVoltage || s.get("input-1").hasVoltage, u = e.config.get("activationLogic") === "negative" ? !o : o;
3570
+ return this.getBehavior(e, t, u, i);
3571
+ }
3572
+ }, Se = class extends P {
3573
+ constructor() {
3574
+ super(c.Nor4Gate);
3575
+ }
3576
+ createInitialState(e) {
3577
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for Nor4GateBehavior: ${e.type}`);
3578
+ const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
3579
+ return new Wt(e.id, t);
3580
+ }
3581
+ onPinsChange(e, t, n, i) {
3582
+ const s = this.getPinStates(e, n);
3583
+ t.pinStates = s;
3584
+ const r = this.vccGuardBehavior(t, s, i);
3585
+ if (r) return r;
3586
+ const a = this.nonLogicInputGuardBehavior(t, s, i);
3587
+ if (a) return a;
3588
+ const o = s.get("input-0").hasVoltage || s.get("input-1").hasVoltage || s.get("input-2").hasVoltage || s.get("input-3").hasVoltage, u = e.config.get("activationLogic") === "negative" ? !o : o;
3589
+ return this.getBehavior(e, t, u, i);
3590
+ }
3591
+ }, we = class extends P {
3592
+ constructor() {
3593
+ super(c.Nor8Gate);
3594
+ }
3595
+ createInitialState(e) {
3596
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for Nor8GateBehavior: ${e.type}`);
3597
+ const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
3598
+ return new Rt(e.id, t);
3599
+ }
3600
+ onPinsChange(e, t, n, i) {
3601
+ const s = this.getPinStates(e, n);
3602
+ t.pinStates = s;
3603
+ const r = this.vccGuardBehavior(t, s, i);
3604
+ if (r) return r;
3605
+ const a = this.nonLogicInputGuardBehavior(t, s, i);
3606
+ if (a) return a;
3607
+ const o = s.get("input-0").hasVoltage || s.get("input-1").hasVoltage || s.get("input-2").hasVoltage || s.get("input-3").hasVoltage || s.get("input-4").hasVoltage || s.get("input-5").hasVoltage || s.get("input-6").hasVoltage || s.get("input-7").hasVoltage, u = e.config.get("activationLogic") === "negative" ? !o : o;
3608
+ return this.getBehavior(e, t, u, i);
3609
+ }
3610
+ }, me = class extends P {
3611
+ constructor() {
3612
+ super(c.XorGate);
3613
+ }
3614
+ createInitialState(e) {
3615
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for XorGateBehavior: ${e.type}`);
3616
+ const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
3617
+ return new Ft(e.id, t);
3618
+ }
3619
+ onPinsChange(e, t, n, i) {
3620
+ const s = this.getPinStates(e, n);
3621
+ t.pinStates = s;
3622
+ const r = this.vccGuardBehavior(t, s, i);
3623
+ if (r) return r;
3624
+ const a = this.nonLogicInputGuardBehavior(t, s, i);
3625
+ if (a) return a;
3626
+ const o = s.get("input-0").hasVoltage !== s.get("input-1").hasVoltage, u = e.config.get("activationLogic") === "negative" ? !o : o;
3627
+ return this.getBehavior(e, t, u, i);
3628
+ }
3629
+ }, be = class extends P {
3630
+ constructor() {
3631
+ super(c.Xor4Gate);
3632
+ }
3633
+ createInitialState(e) {
3634
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for Xor4GateBehavior: ${e.type}`);
3635
+ const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
3636
+ return new Ht(e.id, t);
3637
+ }
3638
+ onPinsChange(e, t, n, i) {
3639
+ const s = this.getPinStates(e, n);
3640
+ t.pinStates = s;
3641
+ const r = this.vccGuardBehavior(t, s, i);
3642
+ if (r) return r;
3643
+ const a = this.nonLogicInputGuardBehavior(t, s, i);
3644
+ if (a) return a;
3645
+ const o = ((s.get("input-0").hasVoltage ? 1 : 0) + (s.get("input-1").hasVoltage ? 1 : 0) + (s.get("input-2").hasVoltage ? 1 : 0) + (s.get("input-3").hasVoltage ? 1 : 0)) % 2 === 1, u = e.config.get("activationLogic") === "negative" ? !o : o;
3646
+ return this.getBehavior(e, t, u, i);
3647
+ }
3648
+ }, Ce = class extends P {
3649
+ constructor() {
3650
+ super(c.Xor8Gate);
3651
+ }
3652
+ createInitialState(e) {
3653
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for Xor8GateBehavior: ${e.type}`);
3654
+ const t = e.config.get("activationLogic") === "negative" ? "high" : "low";
3655
+ return new Jt(e.id, t);
3656
+ }
3657
+ onPinsChange(e, t, n, i) {
3658
+ const s = this.getPinStates(e, n);
3659
+ t.pinStates = s;
3660
+ const r = this.vccGuardBehavior(t, s, i);
3661
+ if (r) return r;
3662
+ const a = this.nonLogicInputGuardBehavior(t, s, i);
3663
+ if (a) return a;
3664
+ const o = ((s.get("input-0").hasVoltage ? 1 : 0) + (s.get("input-1").hasVoltage ? 1 : 0) + (s.get("input-2").hasVoltage ? 1 : 0) + (s.get("input-3").hasVoltage ? 1 : 0) + (s.get("input-4").hasVoltage ? 1 : 0) + (s.get("input-5").hasVoltage ? 1 : 0) + (s.get("input-6").hasVoltage ? 1 : 0) + (s.get("input-7").hasVoltage ? 1 : 0)) % 2 === 1, u = e.config.get("activationLogic") === "negative" ? !o : o;
3665
+ return this.getBehavior(e, t, u, i);
3666
+ }
3667
+ }, A = class extends C {
3668
+ onPinsChange(e, t, n, i) {
3669
+ const s = this.getPinStates(e, n);
3670
+ t.pinStates = s;
3671
+ const r = t, a = this.vccGuardBehavior(r, s, i);
3672
+ if (a) return a;
3673
+ const o = this.nonLogicInputGuardBehavior(r, s, i);
3674
+ if (o) return o;
3675
+ const u = this.computeTargetStableState(s);
3676
+ return this.scheduleTransition(e, r, u, i);
3677
+ }
3678
+ onEventFiring(e, t, n) {
3679
+ if (!n.type.startsWith("to")) return this.noChange(t);
3680
+ const i = n.type.slice(2);
3681
+ return t.state === i ? this.noChange(t) : (t.setState(i, n.readyAtTick), t.parameters.delete("prevState"), {
3682
+ componentState: t,
3683
+ hasChanged: !0,
3684
+ shouldCancelPending: !1,
3685
+ scheduledEvents: []
3686
+ });
3687
+ }
3688
+ allowConductivity(e, t, n, i, s) {
3689
+ if (i === s) return !0;
3690
+ const r = t.effectiveState;
3691
+ if (r === "indeterminate") return !1;
3692
+ const a = e.getPinMetadata(i), o = e.getPinMetadata(s);
3693
+ if (!a || !o) return !1;
3694
+ let u, l = 0;
3695
+ if (a.subtype === "logicOutput" && (l++, u = a), o.subtype === "logicOutput" && (l++, u = o), l !== 1 || !u?.logicPinData) return !1;
3696
+ let p = 0;
3697
+ if (p += a.subtype === "vcc" ? 1 : a.subtype === "gnd" ? -1 : 0, p += o.subtype === "vcc" ? 1 : o.subtype === "gnd" ? -1 : 0, p !== 1 && p !== -1) return !1;
3698
+ const d = t;
3699
+ return (parseInt(r, 16) >> (u.logicPinData.interface === "sum" ? u.logicPinData.index * 2 : d.outputCount - 1) & 1) === 1 ? p === 1 : p === -1;
3700
+ }
3701
+ vccGuardBehavior(e, t, n) {
3702
+ if (t.get("vcc").hasVoltage) return null;
3703
+ const i = e.allLowState;
3704
+ return e.state === i ? {
3705
+ componentState: e,
3706
+ hasChanged: !1,
3707
+ shouldCancelPending: !1,
3708
+ scheduledEvents: []
3709
+ } : (e.setState(i, n), e.parameters.delete("prevState"), {
3710
+ componentState: e,
3711
+ hasChanged: !0,
3712
+ shouldCancelPending: !0,
3713
+ scheduledEvents: []
3714
+ });
3715
+ }
3716
+ nonLogicInputGuardBehavior(e, t, n) {
3717
+ const i = this.typeMetadata.pins;
3718
+ let s = !1;
3719
+ for (const [r, a] of t) {
3720
+ const o = i.get(r);
3721
+ if (!(!o || o.subtype !== "logicInput") && (a.hasVoltage && a.hasCurrent || !a.hasVoltage && !a.hasCurrent)) {
3722
+ s = !0;
3723
+ break;
3724
+ }
3725
+ }
3726
+ return s ? e.state === "indeterminate" ? {
3727
+ componentState: e,
3728
+ hasChanged: !1,
3729
+ shouldCancelPending: !1,
3730
+ scheduledEvents: []
3731
+ } : (e.setState("indeterminate", n), e.parameters.delete("prevState"), {
3732
+ componentState: e,
3733
+ hasChanged: !0,
3734
+ shouldCancelPending: !0,
3735
+ scheduledEvents: []
3736
+ }) : null;
3737
+ }
3738
+ scheduleTransition(e, t, n, i) {
3739
+ const s = `to${n}`;
3740
+ if (t.state === n || t.state === s) return this.noChange(t);
3741
+ const r = x(e.config), a = t.expirationTick < 1 ? r : Math.max(i - t.startTick, 1), o = t.effectiveState, u = o === "indeterminate" ? t.allLowState : o;
3742
+ return t.setState(s, i), t.setNextState(n, i + a), t.parameters.set("prevState", u), {
3743
+ componentState: t,
3744
+ hasChanged: !0,
3745
+ shouldCancelPending: !0,
3746
+ scheduledEvents: [{
3747
+ targetId: e.id,
3748
+ scheduledAtTick: t.startTick,
3749
+ readyAtTick: t.expirationTick,
3750
+ type: s,
3751
+ parameters: void 0
3752
+ }]
3753
+ };
3754
+ }
3755
+ noChange(e) {
3756
+ return {
3757
+ componentState: e,
3758
+ hasChanged: !1,
3759
+ shouldCancelPending: !1,
3760
+ scheduledEvents: []
3761
+ };
3762
+ }
3763
+ }, Pe = class extends A {
3764
+ constructor() {
3765
+ super(c.HalfAdder);
3766
+ }
3767
+ createInitialState(e) {
3768
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for HalfAdderBehavior: ${e.type}`);
3769
+ return new Ut(e.id, "0");
3770
+ }
3771
+ computeTargetStableState(e) {
3772
+ const t = e.get("inputA").hasVoltage, n = e.get("inputB").hasVoltage;
3773
+ return ((t !== n ? 1 : 0) | (t && n ? 2 : 0)).toString(16);
3774
+ }
3775
+ }, xe = class extends A {
3776
+ constructor() {
3777
+ super(c.Adder);
3778
+ }
3779
+ createInitialState(e) {
3780
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for AdderBehavior: ${e.type}`);
3781
+ return new Xt(e.id, "0");
3782
+ }
3783
+ computeTargetStableState(e) {
3784
+ 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);
3785
+ return ((s % 2 === 1 ? 1 : 0) | (s >= 2 ? 2 : 0)).toString(16);
3786
+ }
3787
+ }, M = 8, Ie = class extends A {
3788
+ constructor() {
3789
+ super(c.EightBitAdder);
3790
+ }
3791
+ createInitialState(e) {
3792
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for EightBitAdderBehavior: ${e.type}`);
3793
+ return new Qt(e.id, "0000");
3794
+ }
3795
+ onPinsChange(e, t, n, i) {
3796
+ const s = this.getPinStates(e, n);
3797
+ t.pinStates = s;
3798
+ const r = t, a = this.vccGuardBehavior(r, s, i);
3799
+ if (a) return a;
3800
+ const o = this.nonLogicInputGuardBehavior(r, s, i);
3801
+ if (o) return o;
3802
+ if (i === 0) {
3803
+ const y = this.computeTargetStableState(s);
3804
+ return this.scheduleTransition(e, r, y, i);
3805
+ }
3806
+ const u = r.effectiveState, l = u === "indeterminate" ? 0 : parseInt(u, 16), p = s.get("carryIn").hasVoltage;
3807
+ let d = 0;
3808
+ for (let y = 0; y < M; y++) {
3809
+ const S = s.get(`inputA-${y}`).hasVoltage, T = s.get(`inputB-${y}`).hasVoltage, { sum: E, carry: ft } = W(S, T, y === 0 ? p : (l >> 2 * (y - 1) + 1 & 1) === 1);
3810
+ d = R(d, y, E, ft);
3811
+ }
3812
+ const g = F(d);
3813
+ if (g === u) return this.noChange(t);
3814
+ const f = x(e.config), v = u === "indeterminate" ? r.allLowState : u;
3815
+ return r.setState(`to${g}`, i), r.setNextState(g, i + f), r.parameters.set("prevState", v), {
3816
+ componentState: r,
3817
+ hasChanged: !0,
3818
+ shouldCancelPending: !0,
3819
+ scheduledEvents: [{
3820
+ targetId: e.id,
3821
+ scheduledAtTick: i,
3822
+ readyAtTick: i + f,
3823
+ type: `to${g}`,
3824
+ parameters: /* @__PURE__ */ new Map([["nextStage", "1"]])
3825
+ }]
3826
+ };
3827
+ }
3828
+ onEventFiring(e, t, n) {
3829
+ if (!n.type.startsWith("to")) return this.noChange(t);
3830
+ const i = n.type.slice(2), s = parseInt(n.parameters?.get("nextStage") ?? `${M}`), r = t;
3831
+ if (r.state === i) return this.noChange(r);
3832
+ if (r.setState(i, n.readyAtTick), r.parameters.delete("prevState"), s >= M) return {
3833
+ componentState: r,
3834
+ hasChanged: !0,
3835
+ shouldCancelPending: !1,
3836
+ scheduledEvents: []
3837
+ };
3838
+ const a = parseInt(i, 16), o = (a >> 2 * (s - 1) + 1 & 1) === 1, u = r.pinStates.get(`inputA-${s}`).hasVoltage, l = r.pinStates.get(`inputB-${s}`).hasVoltage, { sum: p, carry: d } = W(u, l, o), g = (a >> 2 * s & 1) === 1, f = (a >> 2 * s + 1 & 1) === 1;
3839
+ if (p === g && d === f) return {
3840
+ componentState: r,
3841
+ hasChanged: !0,
3842
+ shouldCancelPending: !1,
3843
+ scheduledEvents: []
3844
+ };
3845
+ const v = F(R(a, s, p, d)), y = x(e.config);
3846
+ return r.setState(`to${v}`, n.readyAtTick), r.setNextState(v, n.readyAtTick + y), r.parameters.set("prevState", i), {
3847
+ componentState: r,
3848
+ hasChanged: !0,
3849
+ shouldCancelPending: !1,
3850
+ scheduledEvents: [{
3851
+ targetId: e.id,
3852
+ scheduledAtTick: n.readyAtTick,
3853
+ readyAtTick: n.readyAtTick + y,
3854
+ type: `to${v}`,
3855
+ parameters: /* @__PURE__ */ new Map([["nextStage", `${s + 1}`]])
3856
+ }]
3857
+ };
3858
+ }
3859
+ computeTargetStableState(e) {
3860
+ let t = e.get("carryIn").hasVoltage, n = 0;
3861
+ for (let i = 0; i < M; i++) {
3862
+ const s = e.get(`inputA-${i}`).hasVoltage, r = e.get(`inputB-${i}`).hasVoltage, a = W(s, r, t);
3863
+ n = R(n, i, a.sum, a.carry), t = a.carry;
3864
+ }
3865
+ return F(n);
3866
+ }
3867
+ };
3868
+ function W(e, t, n) {
3869
+ return {
3870
+ sum: e !== t !== n,
3871
+ carry: e && t || e && n || t && n
3872
+ };
3873
+ }
3874
+ function R(e, t, n, i) {
3875
+ const s = 2 * t, r = s + 1;
3876
+ let a = e;
3877
+ return a = a & ~(1 << s) | (n ? 1 : 0) << s, a = a & ~(1 << r) | (i ? 1 : 0) << r, a;
3878
+ }
3879
+ function F(e) {
3880
+ return e.toString(16).padStart(4, "0");
3881
+ }
3882
+ var Z = 8, Te = class extends A {
3883
+ constructor() {
3884
+ super(c.EightBitOnesComplement);
3885
+ }
3886
+ createInitialState(e) {
3887
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for EightBitOnesComplementBehavior: ${e.type}`);
3888
+ return new qt(e.id, "000");
3889
+ }
3890
+ allowConductivity(e, t, n, i, s) {
3891
+ if (i === s) return !0;
3892
+ const r = t.effectiveState;
3893
+ if (r === "indeterminate") return !1;
3894
+ const a = e.getPinMetadata(i), o = e.getPinMetadata(s);
3895
+ if (!a || !o) return !1;
3896
+ let u, l = 0;
3897
+ if (a.subtype === "logicOutput" && (l++, u = a), o.subtype === "logicOutput" && (l++, u = o), l !== 1 || !u?.logicPinData) return !1;
3898
+ let p = 0;
3899
+ return p += a.subtype === "vcc" ? 1 : a.subtype === "gnd" ? -1 : 0, p += o.subtype === "vcc" ? 1 : o.subtype === "gnd" ? -1 : 0, p !== 1 && p !== -1 ? !1 : (parseInt(r, 16) >> u.logicPinData.index & 1) === 1 ? p === 1 : p === -1;
3900
+ }
3901
+ computeTargetStableState(e) {
3902
+ const t = e.get("invert").hasVoltage;
3903
+ let n = 0;
3904
+ for (let i = 0; i < Z; i++) e.get(`input-${i}`).hasVoltage !== t && (n |= 1 << i);
3905
+ return t && (n |= 1 << Z), n.toString(16).padStart(3, "0");
3906
+ }
3907
+ }, k = class extends C {
3908
+ onPinsChange(e, t, n, i) {
3909
+ const s = this.getPinStates(e, n);
3910
+ t.pinStates = s;
3911
+ const r = t;
3912
+ return s.get("vcc").hasVoltage ? this.noChange(t) : r.state === r.allLowState && r.parameters.size === 0 ? this.noChange(t) : (r.parameters.clear(), r.setState(r.allLowState, i), {
3913
+ componentState: r,
3914
+ hasChanged: !0,
3915
+ shouldCancelPending: !0,
3916
+ scheduledEvents: []
3917
+ });
3918
+ }
3919
+ onUserCommand(e, t, n) {
3920
+ if (n.type !== "toggle_switch") return this.noChange(t);
3921
+ const i = t, s = n.parameters?.get("index");
3922
+ if (s === void 0) return this.noChange(t);
3923
+ const r = parseInt(s, 10);
3924
+ if (isNaN(r) || r < 0 || r >= i.outputCount) return this.noChange(t);
3925
+ const a = i.pinStates.get("vcc");
3926
+ if (a && !a.hasVoltage) return this.noChange(t);
3927
+ if (i.parameters.has(String(r))) return this.noChange(t);
3928
+ const o = n.scheduledAtTick, u = o + x(e.config), l = i.effectiveState, p = (parseInt(l, 16) >> r & 1) === 0 ? 1 : 0;
3929
+ return i.isInTransition || (i.parameters.set("prevState", l), i.setState("moving", o)), i.parameters.set(String(r), `${p}-${o}-${u}`), {
3930
+ componentState: i,
3931
+ hasChanged: !0,
3932
+ shouldCancelPending: !1,
3933
+ scheduledEvents: [{
3934
+ targetId: e.id,
3935
+ scheduledAtTick: o,
3936
+ readyAtTick: u,
3937
+ type: "switchChanged",
3938
+ parameters: /* @__PURE__ */ new Map([["index", String(r)], ["target", String(p)]])
3939
+ }]
3940
+ };
3941
+ }
3942
+ onEventFiring(e, t, n) {
3943
+ if (n.type !== "switchChanged") return this.noChange(t);
3944
+ const i = t, s = n.parameters?.get("index"), r = n.parameters?.get("target");
3945
+ if (s === void 0 || r === void 0) return this.noChange(t);
3946
+ const a = parseInt(s, 10);
3947
+ if (isNaN(a) || !i.parameters.has(String(a))) return this.noChange(t);
3948
+ const o = parseInt(r, 10) === 1 ? 1 : 0, u = i.parameters.get("prevState") ?? i.allLowState;
3949
+ let l = parseInt(u, 16);
3950
+ l = l & ~(1 << a) | o << a;
3951
+ const p = l.toString(16).padStart(i.hexDigitCount, "0");
3952
+ return i.parameters.delete(String(a)), Array.from(i.parameters.keys()).some((d) => d !== "prevState") ? (i.parameters.set("prevState", p), {
3953
+ componentState: i,
3954
+ hasChanged: !0,
3955
+ shouldCancelPending: !1,
3956
+ scheduledEvents: []
3957
+ }) : (i.parameters.delete("prevState"), i.setState(p, n.readyAtTick), {
3958
+ componentState: i,
3959
+ hasChanged: !0,
3960
+ shouldCancelPending: !1,
3961
+ scheduledEvents: []
3962
+ });
3963
+ }
3964
+ allowConductivity(e, t, n, i, s) {
3965
+ if (i === s) return !0;
3966
+ const r = t, a = e.getPinMetadata(i), o = e.getPinMetadata(s);
3967
+ if (!a || !o) return !1;
3968
+ let u, l = 0;
3969
+ if (a.subtype === "logicOutput" && (l++, u = a), o.subtype === "logicOutput" && (l++, u = o), l !== 1 || !u?.logicPinData) return !1;
3970
+ let p = 0;
3971
+ return p += a.subtype === "vcc" ? 1 : a.subtype === "gnd" ? -1 : 0, p += o.subtype === "vcc" ? 1 : o.subtype === "gnd" ? -1 : 0, p !== 1 && p !== -1 ? !1 : r.isOutputHigh(u.logicPinData.index) ? p === 1 : p === -1;
3972
+ }
3973
+ noChange(e) {
3974
+ return {
3975
+ componentState: e,
3976
+ hasChanged: !1,
3977
+ shouldCancelPending: !1,
3978
+ scheduledEvents: []
3979
+ };
3980
+ }
3981
+ }, Oe = class extends k {
3982
+ constructor() {
3983
+ super(c.OneInput);
3984
+ }
3985
+ createInitialState(e) {
3986
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for OneInputBehavior: ${e.type}`);
3987
+ const t = e.config.get("initialState") || "0";
3988
+ return new Kt(e.id, t);
3989
+ }
3990
+ }, Ee = class extends k {
3991
+ constructor() {
3992
+ super(c.TwoInput);
3993
+ }
3994
+ createInitialState(e) {
3995
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for TwoInputBehavior: ${e.type}`);
3996
+ const t = e.config.get("initialState") || "0";
3997
+ return new Yt(e.id, t);
3998
+ }
3999
+ }, De = class extends k {
4000
+ constructor() {
4001
+ super(c.FourInput);
4002
+ }
4003
+ createInitialState(e) {
4004
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for FourInputBehavior: ${e.type}`);
4005
+ const t = e.config.get("initialState") || "0";
4006
+ return new Zt(e.id, t);
4007
+ }
4008
+ }, Ne = class extends k {
4009
+ constructor() {
4010
+ super(c.EightInput);
4011
+ }
4012
+ createInitialState(e) {
4013
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for EightInputBehavior: ${e.type}`);
4014
+ const t = e.config.get("initialState") || "00";
4015
+ return new jt(e.id, t);
4016
+ }
4017
+ }, G = class extends C {
4018
+ onPinsChange(e, t, n, i) {
4019
+ const s = this.getPinStates(e, n);
4020
+ t.pinStates = s;
4021
+ const r = t, a = this.vccGuardBehavior(r, s, i);
4022
+ if (a) return a;
4023
+ const o = this.nonLogicInputGuardBehavior(r, s, i);
4024
+ return o || this.scheduleInputTransitions(e, r, s, i);
4025
+ }
4026
+ onEventFiring(e, t, n) {
4027
+ if (n.type !== "lightChanged") return this.noChange(t);
4028
+ const i = t, s = n.parameters?.get("index"), r = n.parameters?.get("target");
4029
+ if (s === void 0 || r === void 0) return this.noChange(t);
4030
+ const a = parseInt(s, 10);
4031
+ if (isNaN(a)) return this.noChange(t);
4032
+ const o = i.getPendingMove(a);
4033
+ if (!o) return this.noChange(t);
4034
+ if (o.endTick !== n.readyAtTick) return this.noChange(t);
4035
+ const u = o.target, l = i.parameters.get("prevState") ?? i.allLowState;
4036
+ let p = parseInt(l, 16);
4037
+ p = p & ~(1 << a) | u << a;
4038
+ const d = p.toString(16).padStart(i.hexDigitCount, "0");
4039
+ return i.parameters.delete(String(a)), Array.from(i.parameters.keys()).some((g) => g !== "prevState") ? (i.parameters.set("prevState", d), {
4040
+ componentState: i,
4041
+ hasChanged: !0,
4042
+ shouldCancelPending: !1,
4043
+ scheduledEvents: []
4044
+ }) : (i.parameters.delete("prevState"), i.setState(d, n.readyAtTick), {
4045
+ componentState: i,
4046
+ hasChanged: !0,
4047
+ shouldCancelPending: !1,
4048
+ scheduledEvents: []
4049
+ });
4050
+ }
4051
+ allowConductivity(e, t, n, i, s) {
4052
+ if (i === s) return !0;
4053
+ const r = t;
4054
+ if (r.effectiveState === "indeterminate") return !1;
4055
+ const a = e.getPinMetadata(i), o = e.getPinMetadata(s);
4056
+ if (!a || !o) return !1;
4057
+ let u, l = 0;
4058
+ if (a.subtype === "logicOutput" && (l++, u = a), o.subtype === "logicOutput" && (l++, u = o), l !== 1 || !u?.logicPinData) return !1;
4059
+ let p = 0;
4060
+ return p += a.subtype === "vcc" ? 1 : a.subtype === "gnd" ? -1 : 0, p += o.subtype === "vcc" ? 1 : o.subtype === "gnd" ? -1 : 0, p !== 1 && p !== -1 ? !1 : r.isOutputHigh(u.logicPinData.index) ? p === 1 : p === -1;
4061
+ }
4062
+ vccGuardBehavior(e, t, n) {
4063
+ return t.get("vcc").hasVoltage ? null : e.state === e.allLowState && e.parameters.size === 0 ? this.noChange(e) : (e.parameters.clear(), e.setState(e.allLowState, n), {
4064
+ componentState: e,
4065
+ hasChanged: !0,
4066
+ shouldCancelPending: !0,
4067
+ scheduledEvents: []
4068
+ });
4069
+ }
4070
+ nonLogicInputGuardBehavior(e, t, n) {
4071
+ const i = this.typeMetadata.pins;
4072
+ let s = !1;
4073
+ for (const [r, a] of t) {
4074
+ const o = i.get(r);
4075
+ if (!(!o || o.subtype !== "logicInput") && (a.hasVoltage && a.hasCurrent || !a.hasVoltage && !a.hasCurrent)) {
4076
+ s = !0;
4077
+ break;
4078
+ }
4079
+ }
4080
+ return s ? e.state === "indeterminate" && e.parameters.size === 0 ? this.noChange(e) : (e.parameters.clear(), e.setState("indeterminate", n), {
4081
+ componentState: e,
4082
+ hasChanged: !0,
4083
+ shouldCancelPending: !0,
4084
+ scheduledEvents: []
4085
+ }) : null;
4086
+ }
4087
+ scheduleInputTransitions(e, t, n, i) {
4088
+ const s = x(e.config), r = t.effectiveState === "indeterminate" ? t.allLowState : t.effectiveState, a = parseInt(r, 16), o = [];
4089
+ let u = !1;
4090
+ for (let l = 0; l < t.lightCount; l++) {
4091
+ const p = n.get(`input-${l}`);
4092
+ if (!p) continue;
4093
+ const d = p.hasVoltage ? 1 : 0, g = t.getPendingMove(l), f = a >> l & 1;
4094
+ if (g) {
4095
+ if (g.target === d) continue;
4096
+ const S = Math.max(g.endTick - g.startTick, 1), T = i, E = T + S;
4097
+ t.parameters.set(String(l), `${d}-${T}-${E}`), o.push({
4098
+ targetId: e.id,
4099
+ scheduledAtTick: T,
4100
+ readyAtTick: E,
4101
+ type: "lightChanged",
4102
+ parameters: /* @__PURE__ */ new Map([["index", String(l)], ["target", String(d)]])
4103
+ }), u = !0;
4104
+ continue;
4105
+ }
4106
+ if (f === d) continue;
4107
+ const v = i, y = v + s;
4108
+ t.isInTransition || (t.parameters.set("prevState", r), t.setState("moving", v)), t.parameters.set(String(l), `${d}-${v}-${y}`), o.push({
4109
+ targetId: e.id,
4110
+ scheduledAtTick: v,
4111
+ readyAtTick: y,
4112
+ type: "lightChanged",
4113
+ parameters: /* @__PURE__ */ new Map([["index", String(l)], ["target", String(d)]])
4114
+ }), u = !0;
4115
+ }
4116
+ return u ? {
4117
+ componentState: t,
4118
+ hasChanged: !0,
4119
+ shouldCancelPending: !1,
4120
+ scheduledEvents: o
4121
+ } : this.noChange(t);
4122
+ }
4123
+ noChange(e) {
4124
+ return {
4125
+ componentState: e,
4126
+ hasChanged: !1,
4127
+ shouldCancelPending: !1,
4128
+ scheduledEvents: []
4129
+ };
4130
+ }
4131
+ }, Me = class extends G {
4132
+ constructor() {
4133
+ super(c.OneLight);
4134
+ }
4135
+ createInitialState(e) {
4136
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for OneLightBehavior: ${e.type}`);
4137
+ return new te(e.id, "0");
4138
+ }
4139
+ }, Le = class extends G {
4140
+ constructor() {
4141
+ super(c.TwoLight);
4142
+ }
4143
+ createInitialState(e) {
4144
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for TwoLightBehavior: ${e.type}`);
4145
+ return new ee(e.id, "0");
4146
+ }
4147
+ }, ze = class extends G {
4148
+ constructor() {
4149
+ super(c.FourLight);
4150
+ }
4151
+ createInitialState(e) {
4152
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for FourLightBehavior: ${e.type}`);
4153
+ return new ie(e.id, "0");
4154
+ }
4155
+ }, Be = class extends G {
4156
+ constructor() {
4157
+ super(c.EightLight);
4158
+ }
4159
+ createInitialState(e) {
4160
+ if (e.type !== this._componentType) throw new Error(`Invalid component type for EightLightBehavior: ${e.type}`);
4161
+ return new ne(e.id, "00");
4162
+ }
4163
+ }, Ae = class {
4164
+ heap;
4165
+ constructor() {
4166
+ this.heap = [];
4167
+ }
4168
+ schedule(e) {
4169
+ if (e.readyAtTick < e.scheduledAtTick) throw new RangeError(`readyAtTick (${e.readyAtTick}) cannot be before scheduledAtTick (${e.scheduledAtTick})`);
4170
+ this.heap.push(e), this.bubbleUp(this.heap.length - 1);
4171
+ }
4172
+ getReadyEvents(e) {
4173
+ const t = [];
4174
+ for (; this.heap.length > 0 && this.heap[0].readyAtTick <= e; ) {
4175
+ const n = this.extractMin();
4176
+ n && t.push(n);
4177
+ }
4178
+ return t.sort((n, i) => n.readyAtTick === i.readyAtTick ? n.scheduledAtTick - i.scheduledAtTick : n.readyAtTick - i.readyAtTick), t;
4179
+ }
4180
+ hasEvents() {
4181
+ return this.heap.length > 0;
4182
+ }
4183
+ clear() {
4184
+ this.heap = [];
4185
+ }
4186
+ scheduleMany(e, t) {
4187
+ for (const n of e) if (n.readyAtTick < n.scheduledAtTick) throw new RangeError(`readyAtTick (${n.readyAtTick}) cannot be before scheduledAtTick (${n.scheduledAtTick})`);
4188
+ t && t.size > 0 && (this.heap = this.heap.filter((n) => !t.has(n.targetId)));
4189
+ for (const n of e) this.heap.push(n);
4190
+ (e.length > 0 || t && t.size > 0) && this.rebuildHeap();
4191
+ }
4192
+ removeEventsForTarget(e) {
4193
+ const t = this.heap.length;
4194
+ return this.heap = this.heap.filter((n) => n.targetId !== e), this.heap.length !== t && this.rebuildHeap(), t - this.heap.length;
4195
+ }
4196
+ size() {
4197
+ return this.heap.length;
4198
+ }
4199
+ rebuildHeap() {
4200
+ for (let e = Math.floor(this.heap.length / 2) - 1; e >= 0; e--) this.bubbleDown(e);
4201
+ }
4202
+ bubbleUp(e) {
4203
+ for (; e > 0; ) {
4204
+ const t = Math.floor((e - 1) / 2);
4205
+ if (this.heap[e].readyAtTick < this.heap[t].readyAtTick)
4206
+ [this.heap[e], this.heap[t]] = [this.heap[t], this.heap[e]], e = t;
4207
+ else break;
4208
+ }
4209
+ }
4210
+ bubbleDown(e) {
4211
+ const t = this.heap.length;
4212
+ for (; ; ) {
4213
+ const n = 2 * e + 1, i = 2 * e + 2;
4214
+ let s = e;
4215
+ 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)
4216
+ [this.heap[e], this.heap[s]] = [this.heap[s], this.heap[e]], e = s;
4217
+ else break;
4218
+ }
4219
+ }
4220
+ extractMin() {
4221
+ if (this.heap.length === 0) return;
4222
+ const e = this.heap[0], t = this.heap.pop();
4223
+ return this.heap.length > 0 && t && (this.heap[0] = t, this.bubbleDown(0)), e;
4224
+ }
4225
+ }, ke = class {
4226
+ dirtyComponents;
4227
+ dirtyWires;
4228
+ dirtyEnodes;
4229
+ constructor() {
4230
+ this.dirtyComponents = /* @__PURE__ */ new Set(), this.dirtyWires = /* @__PURE__ */ new Set(), this.dirtyEnodes = /* @__PURE__ */ new Set();
4231
+ }
4232
+ markComponentDirty(e) {
4233
+ this.dirtyComponents.add(e);
4234
+ }
4235
+ markWireDirty(e) {
4236
+ this.dirtyWires.add(e);
4237
+ }
4238
+ markEnodeDirty(e) {
4239
+ this.dirtyEnodes.add(e);
4240
+ }
4241
+ setDirtyComponents(e) {
4242
+ this.dirtyComponents = new Set(e);
4243
+ }
4244
+ setDirtyEnodes(e) {
4245
+ this.dirtyEnodes = new Set(e);
4246
+ }
4247
+ setDirtyWires(e) {
4248
+ this.dirtyWires = new Set(e);
4249
+ }
4250
+ getDirtyElements() {
4251
+ const e = {
4252
+ components: new Set(this.dirtyComponents),
4253
+ wires: new Set(this.dirtyWires),
4254
+ enodes: new Set(this.dirtyEnodes)
4255
+ };
4256
+ return this.clear(), e;
4257
+ }
4258
+ hasDirtyElements() {
4259
+ return this.dirtyComponents.size > 0 || this.dirtyWires.size > 0 || this.dirtyEnodes.size > 0;
4260
+ }
4261
+ clear() {
4262
+ this.dirtyComponents.clear(), this.dirtyWires.clear(), this.dirtyEnodes.clear();
4263
+ }
4264
+ getDirtyComponentCount() {
4265
+ return this.dirtyComponents.size;
4266
+ }
4267
+ getDirtyWireCount() {
4268
+ return this.dirtyWires.size;
4269
+ }
4270
+ getDirtyEnodeCount() {
4271
+ return this.dirtyEnodes.size;
4272
+ }
4273
+ }, Ge = class {
4274
+ currentState;
4275
+ history;
4276
+ historyEnabled;
4277
+ historyLimit;
4278
+ historyWriteIndex;
4279
+ constructor(e = !1, t = 1e3) {
4280
+ if (t < 1) throw new RangeError(`historyLimit must be at least 1 (got ${t})`);
4281
+ this.historyEnabled = e, this.historyLimit = t, this.currentState = new Y(0), this.history = [], this.historyWriteIndex = 0;
4282
+ }
4283
+ getCurrentState() {
4284
+ return this.currentState;
4285
+ }
4286
+ getCurrentTick() {
4287
+ return this.currentState.tick;
4288
+ }
4289
+ advanceToNextTick() {
4290
+ const e = this.currentState.tick + 1;
4291
+ return this.historyEnabled && this.saveToHistory(this.currentState.clone()), this.currentState.tick = e, this.currentState;
4292
+ }
4293
+ getStateAtTick(e) {
4294
+ if (this.historyEnabled)
4295
+ return this.history.find((t) => t.tick === e);
4296
+ }
4297
+ getHistory() {
4298
+ return this.historyEnabled ? [...this.history].sort((e, t) => e.tick - t.tick) : [];
4299
+ }
4300
+ getOldestTick() {
4301
+ if (!(!this.historyEnabled || this.history.length === 0))
4302
+ return Math.min(...this.history.map((e) => e.tick));
4303
+ }
4304
+ getNewestHistoricalTick() {
4305
+ if (!(!this.historyEnabled || this.history.length === 0))
4306
+ return Math.max(...this.history.map((e) => e.tick));
4307
+ }
4308
+ clearHistory() {
4309
+ this.history = [], this.historyWriteIndex = 0;
4310
+ }
4311
+ reset() {
4312
+ this.currentState = new Y(0), this.clearHistory();
4313
+ }
4314
+ isHistoryEnabled() {
4315
+ return this.historyEnabled;
4316
+ }
4317
+ getHistoryLimit() {
4318
+ return this.historyLimit;
4319
+ }
4320
+ getHistorySize() {
4321
+ return this.history.length;
4322
+ }
4323
+ saveToHistory(e) {
4324
+ this.history.length < this.historyLimit ? this.history.push(e) : (this.history[this.historyWriteIndex] = e, this.historyWriteIndex = (this.historyWriteIndex + 1) % this.historyLimit);
4325
+ }
4326
+ }, Xe = class {
4327
+ circuit;
4328
+ stateManager;
4329
+ eventQueue;
4330
+ commands;
4331
+ dirtyTracker;
4332
+ behaviorRegistry;
4333
+ constructor(e, t, n = {}) {
4334
+ this.circuit = e, this.behaviorRegistry = t, this.stateManager = new Ge(n.enableHistory ?? !1, n.historyLimit ?? 1e3), this.eventQueue = new Ae(), this.commands = /* @__PURE__ */ new Map(), this.dirtyTracker = new ke();
4335
+ try {
4336
+ this.initializeState();
4337
+ } catch (i) {
4338
+ throw console.error("Error during CircuitRunner initialization:", i), i;
4339
+ }
4340
+ }
4341
+ tick() {
4342
+ const e = this.eventQueue.size(), t = this.stateManager.getCurrentTick(), n = this.applyReadyEvents(t + 1), i = this.updateState(t + 1);
4343
+ i.firedEventCount = n.length, i.processedCommandCount = this.processCommands().length, i.scheduledEventCount = this.eventQueue.size() + i.firedEventCount - e;
4344
+ for (const s of n) s.hasChanged && this.dirtyTracker.markComponentDirty(s.componentState.componentId);
4345
+ return i.componentUpdateCount = this.dirtyTracker.getDirtyComponentCount(), this.stateManager.advanceToNextTick(), i.endTick = this.stateManager.getCurrentTick(), i;
4346
+ }
4347
+ tickN(e) {
4348
+ if (e < 1) throw new RangeError(`Tick count must be at least 1 (got ${e})`);
4349
+ const t = [];
4350
+ for (let n = 0; n < e; n++) t.push(this.tick());
4351
+ return t;
4352
+ }
4353
+ reset() {
4354
+ this.stateManager.reset(), this.eventQueue.clear(), this.dirtyTracker.clear(), this.initializeState();
4355
+ }
4356
+ getCurrentTick() {
4357
+ return this.stateManager.getCurrentTick();
4358
+ }
4359
+ getCurrentState() {
4360
+ return this.stateManager.getCurrentState();
4361
+ }
4362
+ getEnodeState(e) {
4363
+ return this.stateManager.getCurrentState().nodeStates.get(e);
4364
+ }
4365
+ getWireState(e) {
4366
+ return this.stateManager.getCurrentState().wireStates.get(e);
4367
+ }
4368
+ getComponentState(e) {
4369
+ return this.stateManager.getCurrentState().componentStates.get(e);
4370
+ }
4371
+ getStateAtTick(e) {
4372
+ return this.stateManager.getStateAtTick(e);
4373
+ }
4374
+ hasBehavior(e) {
4375
+ return this.behaviorRegistry.has(e);
4376
+ }
4377
+ submitCommand(e) {
4378
+ if (!this.circuit.hasComponent(e.targetId)) throw Error(`Cannot submit command for unknown component ID '${e.targetId}'`);
4379
+ return this.commands.has(e.targetId) ? !1 : (e.scheduledAtTick = this.getCurrentTick(), this.commands.set(e.targetId, e), !0);
4380
+ }
4381
+ processCommands() {
4382
+ const e = this.stateManager.getCurrentState(), t = [], n = /* @__PURE__ */ new Set(), i = [];
4383
+ for (const s of this.commands.values()) {
4384
+ const r = this.circuit.getComponent(s.targetId), a = this.behaviorRegistry.get(r.type).onUserCommand(r, e.componentStates.get(r.id), s);
4385
+ a.shouldCancelPending && n.add(r.id);
4386
+ for (const o of a.scheduledEvents) i.push(o);
4387
+ t.push(a), a.hasChanged && this.dirtyTracker.markComponentDirty(r.id);
4388
+ }
4389
+ return this.eventQueue.scheduleMany(i, n), this.commands.clear(), t;
4390
+ }
4391
+ getInitializationOrder(e) {
4392
+ const t = e.get("initializationOrder");
4393
+ if (!t || t === "") return 0;
4394
+ const n = parseInt(t, 10);
4395
+ return isNaN(n) ? 0 : n;
4396
+ }
4397
+ initializeState() {
4398
+ const e = this.stateManager.getCurrentState();
4399
+ for (const u of this.circuit.getAllComponents()) {
4400
+ if (u.pins.length < 1) continue;
4401
+ const l = this.behaviorRegistry.get(u.type);
4402
+ if (!l) continue;
4403
+ const p = l.createInitialState(u);
4404
+ e.componentStates.set(u.id, p), this.dirtyTracker.markComponentDirty(u.id);
4405
+ }
4406
+ for (const u of this.circuit.getAllENodes()) e.nodeStates.set(u.id, {
4407
+ hasVoltage: u.source === h.Voltage,
4408
+ hasCurrent: u.source === h.Current,
4409
+ locked: !!u.source
4410
+ });
4411
+ for (const u of this.circuit.getAllWires()) e.wireStates.set(u.id, {
4412
+ hasVoltage: !1,
4413
+ hasCurrent: !1,
4414
+ locked: !1
4415
+ });
4416
+ const t = this.circuit.getAllComponents(), n = /* @__PURE__ */ new Map();
4417
+ for (const u of t) {
4418
+ const l = this.getInitializationOrder(u.config), p = n.get(l) ?? [];
4419
+ p.push(u), n.set(l, p);
4420
+ }
4421
+ const i = Array.from(n.keys()).sort((u, l) => u - l);
4422
+ for (const u of i) n.get(u).sort((l, p) => l.id.localeCompare(p.id));
4423
+ let s = !0, r = 0;
4424
+ const a = 100;
4425
+ for (; s && r < a; ) {
4426
+ s = !1, r++;
4427
+ for (const u of i) {
4428
+ const l = n.get(u);
4429
+ for (const p of l) {
4430
+ const d = this.behaviorRegistry.get(p.type);
4431
+ if (!d) continue;
4432
+ const g = e.componentStates.get(p.id);
4433
+ if (!g) continue;
4434
+ this.propagateConductivity();
4435
+ const f = d.onStart(p, g);
4436
+ if (f) {
4437
+ e.componentStates.set(p.id, f.componentState), f.shouldCancelPending && this.eventQueue.removeEventsForTarget(p.id);
4438
+ for (const y of f.scheduledEvents) this.eventQueue.schedule(y);
4439
+ continue;
4440
+ }
4441
+ const v = d.onPinsChange(p, g, e.nodeStates, 0);
4442
+ v.hasChanged && (s = !0, e.componentStates.set(p.id, v.componentState));
4443
+ for (const y of v.scheduledEvents) {
4444
+ const S = d.onEventFiring(p, g, y);
4445
+ S.hasChanged && (s = !0, e.componentStates.set(p.id, S.componentState));
4446
+ }
4447
+ }
4448
+ }
4449
+ }
4450
+ const o = this.updateState(0);
4451
+ return this.dirtyTracker.setDirtyComponents(/* @__PURE__ */ new Set([...this.circuit.getAllComponents().map((u) => u.id)])), this.dirtyTracker.setDirtyEnodes(/* @__PURE__ */ new Set([...this.circuit.getAllENodes().map((u) => u.id)])), this.dirtyTracker.setDirtyWires(/* @__PURE__ */ new Set([...this.circuit.getAllWires().map((u) => u.id)])), o;
4452
+ }
4453
+ updateState(e) {
4454
+ const t = this.stateManager.getCurrentState(), { updatedNodes: n, updatedWires: i } = this.propagateConductivity(), s = this.circuit.getComponentsOfPins(n), r = [], a = /* @__PURE__ */ new Set();
4455
+ let o = Array.from(s);
4456
+ e === 0 && (o = o.sort((p, d) => {
4457
+ const g = this.circuit.getComponent(p), f = this.circuit.getComponent(d), v = this.getInitializationOrder(g.config), y = this.getInitializationOrder(f.config);
4458
+ return v !== y ? v - y : p.localeCompare(d);
4459
+ }));
4460
+ const u = /* @__PURE__ */ new Set(), l = [];
4461
+ for (const p of o) {
4462
+ const d = this.circuit.getComponent(p), g = this.behaviorRegistry.get(d.type);
4463
+ if (!g) continue;
4464
+ const f = g.onPinsChange(d, t.componentStates.get(p), t.nodeStates, e);
4465
+ f.shouldCancelPending && u.add(p), f.hasChanged && (a.add(p), r.push(f));
4466
+ for (const v of f.scheduledEvents) l.push(v);
4467
+ }
4468
+ return this.eventQueue.scheduleMany(l, u), this.dirtyTracker.setDirtyComponents(a), this.dirtyTracker.setDirtyEnodes(n), this.dirtyTracker.setDirtyWires(i), {
4469
+ startTick: this.getCurrentTick(),
4470
+ endTick: this.getCurrentTick(),
4471
+ componentUpdateCount: a.size,
4472
+ nodeUpdateCount: n.size,
4473
+ wireUpdateCount: i.size,
4474
+ processedCommandCount: 0,
4475
+ scheduledEventCount: l.length,
4476
+ firedEventCount: 0
4477
+ };
4478
+ }
4479
+ propagateConductivity() {
4480
+ const e = this.stateManager.getCurrentState(), t = (a) => {
4481
+ const o = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set(), l = this.circuit.getAllENodes().filter((y) => y.source == a).map((y) => y.id), p = /* @__PURE__ */ new Set([...this.circuit.getAllENodes().filter((y) => !y.source).map((y) => y.id)]), d = /* @__PURE__ */ new Set([...this.circuit.getAllWires().map((y) => y.id)]), { nodes: g, wires: f } = this.computeReachability(a, l, e.componentStates), v = a == h.Voltage ? "hasVoltage" : "hasCurrent";
4482
+ for (const y of g) {
4483
+ const S = e.nodeStates.get(y);
4484
+ S && !S.locked && (S[v] || (S[v] = !0, o.add(y)), p.delete(y));
4485
+ }
4486
+ for (const y of p) {
4487
+ const S = e.nodeStates.get(y);
4488
+ S && !S.locked && S[v] && (S[v] = !1, o.add(y));
4489
+ }
4490
+ for (const y of f) {
4491
+ const S = e.wireStates.get(y);
4492
+ S && (S[v] || (S[v] = !0, u.add(y)), d.delete(y));
4493
+ }
4494
+ for (const y of d) {
4495
+ const S = e.wireStates.get(y);
4496
+ S && S[v] && (S[v] = !1, u.add(y));
4497
+ }
4498
+ return {
4499
+ updatedNodes: o,
4500
+ updatedWires: u
4501
+ };
4502
+ }, { updatedNodes: n, updatedWires: i } = t(h.Voltage), { updatedNodes: s, updatedWires: r } = t(h.Current);
4503
+ return {
4504
+ updatedNodes: /* @__PURE__ */ new Set([...n, ...s]),
4505
+ updatedWires: /* @__PURE__ */ new Set([...i, ...r])
4506
+ };
4507
+ }
4508
+ computeReachability(e, t, n) {
4509
+ const i = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), r = [];
4510
+ for (const a of t)
4511
+ r.push(a), i.add(a);
4512
+ for (; r.length > 0; ) {
4513
+ const a = r.shift();
4514
+ for (const u of this.circuit.getWiresByNode(a)) {
4515
+ const l = u.node1 === a ? u.node2 : u.node1;
4516
+ i.has(l) || (i.add(l), r.push(l)), s.has(u.id) || s.add(u.id);
4517
+ }
4518
+ const o = this.circuit.getENode(a);
4519
+ if (o.type === w.Pin) {
4520
+ const u = this.circuit.getComponent(o.component), l = this.behaviorRegistry.get(u.type);
4521
+ if (!l) continue;
4522
+ const p = u.getPinMetadata(a);
4523
+ if (p?.subtype === "logicInput" || p?.subtype === "logicOutput") continue;
4524
+ const d = n.get(u.id);
4525
+ for (const g of u.pins)
4526
+ g !== a && (i.has(g) || l.allowConductivity(u, d, e, a, g) && (i.add(g), r.push(g)));
4527
+ }
4528
+ }
4529
+ return {
4530
+ nodes: i,
4531
+ wires: s
4532
+ };
4533
+ }
4534
+ applyReadyEvents(e) {
4535
+ const t = this.stateManager.getCurrentState(), n = this.eventQueue.getReadyEvents(e), i = [], s = /* @__PURE__ */ new Set(), r = [];
4536
+ for (const a of n) {
4537
+ const o = this.circuit.getComponent(a.targetId), u = this.behaviorRegistry.get(o.type);
4538
+ if (!u) continue;
4539
+ const l = t.componentStates.get(o.id), p = u.onEventFiring(o, l, a);
4540
+ p.shouldCancelPending && s.add(o.id);
4541
+ for (const d of p.scheduledEvents) r.push(d);
4542
+ i.push(p);
4543
+ }
4544
+ return this.eventQueue.scheduleMany(r, s), i;
4545
+ }
4546
+ };
4547
+ function Qe(e) {
4548
+ return e.register(new se()).register(new re()).register(new ae()).register(new ue()).register(new ce()).register(new pe()).register(new le()).register(new de()), e;
4549
+ }
4550
+ function qe(e) {
4551
+ return e.register(new he()).register(new ge()).register(new fe()).register(new ye()).register(new ve()).register(new Se()).register(new we()).register(new me()).register(new be()).register(new Ce()), e;
4552
+ }
4553
+ function Ke(e) {
4554
+ return e.register(new Pe()).register(new xe()).register(new Ie()).register(new Te()), e;
4555
+ }
4556
+ function Ye(e) {
4557
+ return e.register(new Oe()).register(new Ee()).register(new De()).register(new Ne()).register(new Me()).register(new Le()).register(new ze()).register(new Be()), e;
4558
+ }
4559
+ export {
4560
+ qt as $,
4561
+ D as $t,
4562
+ fe as A,
4563
+ Re as At,
4564
+ se as B,
4565
+ Ve as Bt,
4566
+ Ce as C,
4567
+ Y as Ct,
4568
+ Se as D,
4569
+ Fe as Dt,
4570
+ we as E,
4571
+ dt as Et,
4572
+ pe as F,
4573
+ K as Ft,
4574
+ ee as G,
4575
+ h as Gt,
4576
+ Ue as H,
4577
+ I as Ht,
4578
+ ce as I,
4579
+ q as It,
4580
+ jt as J,
4581
+ mt as Jt,
4582
+ te as K,
4583
+ w as Kt,
4584
+ ue as L,
4585
+ Q as Lt,
4586
+ he as M,
4587
+ Ot as Mt,
4588
+ de as N,
4589
+ Et as Nt,
4590
+ ve as O,
4591
+ He as Ot,
4592
+ le as P,
4593
+ It as Pt,
4594
+ z as Q,
4595
+ tt as Qt,
4596
+ ae as R,
4597
+ N as Rt,
4598
+ Pe as S,
4599
+ m as St,
4600
+ me as T,
4601
+ Je as Tt,
4602
+ ne as U,
4603
+ c as Ut,
4604
+ x as V,
4605
+ st as Vt,
4606
+ ie as W,
4607
+ rt as Wt,
4608
+ Yt as X,
4609
+ vt as Xt,
4610
+ Zt as Y,
4611
+ H as Yt,
4612
+ Kt as Z,
4613
+ V as Zt,
4614
+ Oe as _,
4615
+ Lt as _t,
4616
+ Xe as a,
4617
+ Ht as at,
4618
+ Ie as b,
4619
+ Nt as bt,
4620
+ Ae as c,
4621
+ Wt as ct,
4622
+ Le as d,
4623
+ _t as dt,
4624
+ yt as en,
4625
+ Qt as et,
4626
+ Me as f,
4627
+ Gt as ft,
4628
+ Ee as g,
4629
+ zt as gt,
4630
+ De as h,
4631
+ Bt as ht,
4632
+ Ye as i,
4633
+ Jt as it,
4634
+ ge as j,
4635
+ $e as jt,
4636
+ ye as k,
4637
+ We as kt,
4638
+ Be as l,
4639
+ $t as lt,
4640
+ Ne as m,
4641
+ At as mt,
4642
+ Qe as n,
4643
+ Ut as nt,
4644
+ Ge as o,
4645
+ Ft as ot,
4646
+ G as p,
4647
+ kt as pt,
4648
+ B as q,
4649
+ J as qt,
4650
+ qe as r,
4651
+ L as rt,
4652
+ ke as s,
4653
+ Rt as st,
4654
+ Ke as t,
4655
+ _e as tn,
4656
+ Xt as tt,
4657
+ ze as u,
4658
+ Vt as ut,
4659
+ k as v,
4660
+ Mt as vt,
4661
+ be as w,
4662
+ O as wt,
4663
+ xe as x,
4664
+ Dt as xt,
4665
+ Te as y,
4666
+ gt as yt,
4667
+ re as z,
4668
+ $ as zt
4669
+ };
4670
+
4671
+ //# sourceMappingURL=core-HH6iRWtB.js.map