simple-circuit-engine 0.0.2 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import * as a from "three";
2
2
  import { Euler as Ce, BoxGeometry as be } from "three";
3
3
  import { MapControls as Me } from "three/addons/controls/MapControls.js";
4
- import { P as z, R as te, E as H, i as De, d as T, a as S, C as de, h as oe, l as F, T as Se, j as X } from "./CircuitRunner-CAeE31M5.js";
4
+ import { P as z, R as te, E as H, i as De, d as T, a as S, C as de, h as oe, l as F, T as Se, j as X } from "./CircuitRunner-FXM_s5ll.js";
5
5
  import { Line2 as ne } from "three/examples/jsm/lines/Line2.js";
6
6
  import { LineGeometry as K } from "three/examples/jsm/lines/LineGeometry.js";
7
7
  import { LineMaterial as Ee } from "three/examples/jsm/lines/LineMaterial.js";
@@ -1495,17 +1495,17 @@ class ke {
1495
1495
  maxX: Math.max(s.x, l.x),
1496
1496
  maxY: Math.max(s.y, l.y)
1497
1497
  }, d = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Map(), p = this.controller.componentObject3Ds;
1498
- for (const [g, w] of p) {
1498
+ for (const [g, y] of p) {
1499
1499
  const v = new a.Vector3();
1500
- if (w.getWorldPosition(v), se(v, i, n, r, h)) {
1500
+ if (y.getWorldPosition(v), se(v, i, n, r, h)) {
1501
1501
  e.components.push(g);
1502
1502
  const _ = t.getComponent(g);
1503
1503
  if (_)
1504
1504
  for (const f of _.pins) {
1505
1505
  d.add(f);
1506
- const y = t.getENode(f);
1507
- if (y)
1508
- for (const D of y.wires) {
1506
+ const w = t.getENode(f);
1507
+ if (w)
1508
+ for (const D of w.wires) {
1509
1509
  const Y = u.get(D) || 0;
1510
1510
  u.set(D, Y + 1);
1511
1511
  }
@@ -1513,21 +1513,21 @@ class ke {
1513
1513
  }
1514
1514
  }
1515
1515
  const m = this.controller.enodeObject3Ds;
1516
- for (const [g, w] of m) {
1517
- if (w.userData.componentId || d.has(g)) continue;
1516
+ for (const [g, y] of m) {
1517
+ if (y.userData.componentId || d.has(g)) continue;
1518
1518
  const v = new a.Vector3();
1519
- if (w.getWorldPosition(v), se(v, i, n, r, h)) {
1519
+ if (y.getWorldPosition(v), se(v, i, n, r, h)) {
1520
1520
  e.enodes.push(g), d.add(g);
1521
1521
  const _ = t.getENode(g);
1522
1522
  if (!_) continue;
1523
1523
  for (const f of _.wires) {
1524
- const y = u.get(f) || 0;
1525
- u.set(f, y + 1);
1524
+ const w = u.get(f) || 0;
1525
+ u.set(f, w + 1);
1526
1526
  }
1527
1527
  }
1528
1528
  }
1529
- for (const [g, w] of u)
1530
- w >= 2 && e.wires.push(g);
1529
+ for (const [g, y] of u)
1530
+ y >= 2 && e.wires.push(g);
1531
1531
  return e;
1532
1532
  }
1533
1533
  /**
@@ -1763,8 +1763,8 @@ class ke {
1763
1763
  const u = e.getComponent(d);
1764
1764
  if (u) {
1765
1765
  const p = u.position, m = u.pins.map((g) => {
1766
- const w = e.getENode(g);
1767
- return w ? w.source : null;
1766
+ const y = e.getENode(g);
1767
+ return y ? y.source : null;
1768
1768
  });
1769
1769
  r.push({
1770
1770
  type: u.type,
@@ -1849,21 +1849,21 @@ class ke {
1849
1849
  const m = new z(
1850
1850
  Math.round(i.x + p.relativePosition.x),
1851
1851
  Math.round(i.y + p.relativePosition.y)
1852
- ), g = P(m), w = U(new te(p.rotation));
1852
+ ), g = P(m), y = U(new te(p.rotation));
1853
1853
  try {
1854
1854
  const v = this.controller.addComponent(
1855
1855
  p.type,
1856
1856
  g,
1857
- w,
1857
+ y,
1858
1858
  p.config,
1859
1859
  p.pinSources
1860
1860
  );
1861
1861
  n.push(v.id), o.set(p.originalId, v.id);
1862
1862
  for (const [_, f] of this.clipboardPinToComponent)
1863
1863
  if (f === p.originalId) {
1864
- const y = this.clipboardPinIndices.get(_);
1865
- if (y !== void 0 && y < v.pins.length) {
1866
- const D = v.pins[y];
1864
+ const w = this.clipboardPinIndices.get(_);
1865
+ if (w !== void 0 && w < v.pins.length) {
1866
+ const D = v.pins[w];
1867
1867
  D && o.set(_, D);
1868
1868
  }
1869
1869
  }
@@ -1878,10 +1878,10 @@ class ke {
1878
1878
  Math.round(i.y + p.relativePosition.y)
1879
1879
  ), g = P(m);
1880
1880
  try {
1881
- const w = this.controller.addBranchingPoint(g, p.source);
1882
- r.push(w.id), o.set(p.originalId, w.id);
1883
- } catch (w) {
1884
- console.error("Failed to paste branching point:", w);
1881
+ const y = this.controller.addBranchingPoint(g, p.source);
1882
+ r.push(y.id), o.set(p.originalId, y.id);
1883
+ } catch (y) {
1884
+ console.error("Failed to paste branching point:", y);
1885
1885
  }
1886
1886
  }
1887
1887
  const s = [];
@@ -1889,20 +1889,20 @@ class ke {
1889
1889
  const m = o.get(p.node1OriginalId), g = o.get(p.node2OriginalId);
1890
1890
  if (m && g)
1891
1891
  try {
1892
- const w = this.controller.addWire(m, g);
1893
- if (s.push(w.id), p.relativeIntermediatePositions.length > 0) {
1892
+ const y = this.controller.addWire(m, g);
1893
+ if (s.push(y.id), p.relativeIntermediatePositions.length > 0) {
1894
1894
  const v = p.relativeIntermediatePositions.map((_) => ({
1895
1895
  x: Math.round(i.x + _.x),
1896
1896
  y: Math.round(i.y + _.y)
1897
1897
  }));
1898
1898
  this.controller.circuitWriter.saveEditWirePositions(
1899
- w.id,
1899
+ y.id,
1900
1900
  v,
1901
1901
  !0
1902
- ), this.controller.wireVisualManager.updateWireById(w.id);
1902
+ ), this.controller.wireVisualManager.updateWireById(y.id);
1903
1903
  }
1904
- } catch (w) {
1905
- console.error("Failed to paste wire:", w);
1904
+ } catch (y) {
1905
+ console.error("Failed to paste wire:", y);
1906
1906
  }
1907
1907
  }
1908
1908
  const l = this.controller.getSelectionManager(), h = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map();
@@ -3400,7 +3400,7 @@ class _e {
3400
3400
  const p = new a.Vector3().subVectors(u, d), m = p.length();
3401
3401
  if (m === 0) continue;
3402
3402
  p.normalize();
3403
- const w = new a.Vector3().subVectors(t, d).dot(p), v = Math.max(0, Math.min(m, w)), _ = d.clone().addScaledVector(p, v), f = t.distanceTo(_);
3403
+ const y = new a.Vector3().subVectors(t, d).dot(p), v = Math.max(0, Math.min(m, y)), _ = d.clone().addScaledVector(p, v), f = t.distanceTo(_);
3404
3404
  f < s && (s = f, l = h);
3405
3405
  }
3406
3406
  return l;
@@ -3533,36 +3533,38 @@ function J(c = void 0) {
3533
3533
  enableDamping: !0,
3534
3534
  dampingFactor: 0.5,
3535
3535
  minDistance: 1,
3536
- maxDistance: 100,
3536
+ maxDistance: 200,
3537
3537
  panSpeed: 1,
3538
3538
  zoomSpeed: 2,
3539
3539
  rotateSpeed: 1
3540
3540
  };
3541
3541
  return c ? { ...e, ...c } : e;
3542
3542
  }
3543
- function L(c = void 0) {
3543
+ function W(c = void 0) {
3544
3544
  const e = {
3545
3545
  backgroundColor: 2236976,
3546
3546
  colorCenterLine: 14540202,
3547
3547
  colorGrid: 7829367,
3548
3548
  defaultTool: "build",
3549
- mapControls: J()
3549
+ mapControls: J(),
3550
+ simulationSpeed: 3,
3551
+ simulationAutoPlay: !1
3550
3552
  };
3551
3553
  return c ? (c.mapControls = J(c.mapControls), { ...e, ...c }) : e;
3552
3554
  }
3553
3555
  function ce(c = void 0) {
3554
3556
  const e = {
3555
3557
  initialMode: "edit",
3556
- controllerOptions: L(),
3558
+ controllerOptions: W(),
3557
3559
  runnerOptions: { enableHistory: !1, historyLimit: 1 }
3558
3560
  };
3559
- return c ? (c.controllerOptions = L(c.controllerOptions), { ...e, ...c }) : e;
3561
+ return c ? (c.controllerOptions = W(c.controllerOptions), { ...e, ...c }) : e;
3560
3562
  }
3561
- function we(c, e, t) {
3563
+ function ye(c, e, t) {
3562
3564
  const i = new Me(c, e);
3563
3565
  return t = J(t), i.enablePan = t.enablePan, i.screenSpacePanning = t.screenSpacePanning, i.enableZoom = t.enableZoom, i.enableRotate = t.enableRotate, i.enableDamping = t.enableDamping, i.dampingFactor = t.dampingFactor, i.minDistance = t.minDistance, i.maxDistance = t.maxDistance, i.panSpeed = t.panSpeed, i.zoomSpeed = t.zoomSpeed, i.rotateSpeed = t.rotateSpeed, i;
3564
3566
  }
3565
- class ye extends ue {
3567
+ class we extends ue {
3566
3568
  // Container and Three.js core objects
3567
3569
  _container = null;
3568
3570
  _scene = null;
@@ -3604,7 +3606,7 @@ class ye extends ue {
3604
3606
  constructor(e, t) {
3605
3607
  if (super(), !e)
3606
3608
  throw new TypeError("FactoryRegistry is required");
3607
- this._options = L(), t ? (this._sharedResources = t, this._useSharedResources = !0, this.factoryRegistry = t.factoryRegistry, this.branchingPointVisualFactory = t.branchingPointVisualFactory, this.wireVisualManager = t.wireVisualManager) : (this._useSharedResources = !1, this.factoryRegistry = e, this.branchingPointVisualFactory = new M(), this.wireVisualManager = new _e(this._componentObject3Ds, this._wireObject3Ds));
3609
+ this._options = W(), t ? (this._sharedResources = t, this._useSharedResources = !0, this.factoryRegistry = t.factoryRegistry, this.branchingPointVisualFactory = t.branchingPointVisualFactory, this.wireVisualManager = t.wireVisualManager) : (this._useSharedResources = !1, this.factoryRegistry = e, this.branchingPointVisualFactory = new M(), this.wireVisualManager = new _e(this._componentObject3Ds, this._wireObject3Ds));
3608
3610
  }
3609
3611
  get componentObject3Ds() {
3610
3612
  return this._componentObject3Ds;
@@ -3638,7 +3640,7 @@ class ye extends ue {
3638
3640
  */
3639
3641
  initialize(e, t) {
3640
3642
  if (!this._initialized) {
3641
- if (t = L(t), this._options = t, !e || !(e instanceof HTMLElement)) {
3643
+ if (t = W(t), this._options = t, !e || !(e instanceof HTMLElement)) {
3642
3644
  const i = new TypeError("Container must be a valid HTMLElement");
3643
3645
  throw this.emitError(i), i;
3644
3646
  }
@@ -3651,7 +3653,7 @@ class ye extends ue {
3651
3653
  else {
3652
3654
  this._scene = new a.Scene(), this._scene.background = new a.Color(t.backgroundColor), this._grid = G(10, 10, t.colorCenterLine, t.colorGrid), this._scene.add(this._grid), fe(this._scene);
3653
3655
  const i = e.clientWidth / e.clientHeight || 1;
3654
- this._camera = pe(i), this._camera.layers.set(0), this._camera.layers.enable(1), this._camera.layers.enable(2), this._mapControls = we(this._camera, this._container, t.mapControls), this.wireVisualManager.setContainer(this._container), this.wireVisualManager.setResolution(
3656
+ this._camera = pe(i), this._camera.layers.set(0), this._camera.layers.enable(1), this._camera.layers.enable(2), this._mapControls = ye(this._camera, this._container, t.mapControls), this.wireVisualManager.setContainer(this._container), this.wireVisualManager.setResolution(
3655
3657
  this._container.clientWidth,
3656
3658
  this._container.clientHeight
3657
3659
  ), this.wireVisualManager.setSceneAndCamera(this._scene, this._camera), this._hoverManager = new ge(this._scene, this._camera), this._initializeHoverManager(), this._setupMouseCallbacks(), this._active = !0;
@@ -3719,7 +3721,7 @@ class ye extends ue {
3719
3721
  this._circuit = null, this.wireVisualManager.setCircuit(null), this.emit("circuitCleared", { name: t });
3720
3722
  }
3721
3723
  if (!this._useSharedResources && this._grid && (this._grid.geometry.dispose(), this._grid.dispose(), this._scene.remove(this._grid), this._grid = null), e !== null) {
3722
- const t = this._options || L();
3724
+ const t = this._options || W();
3723
3725
  if (this._circuit = e, this._scene.name = this._circuit.metadata.name || "Circuit Scene", this.wireVisualManager.setCircuit(e), this._gridHalfSize = Math.ceil(e.metadata.size / 2), !this._useSharedResources && (this._grid = G(
3724
3726
  e.metadata.size,
3725
3727
  e.metadata.divisions,
@@ -4343,8 +4345,8 @@ class Ve extends I {
4343
4345
  let f = parseFloat(this.$input.value);
4344
4346
  isNaN(f) || (this._stepExplicit && (f = this._snap(f)), this.setValue(this._clamp(f)));
4345
4347
  }, i = (f) => {
4346
- const y = parseFloat(this.$input.value);
4347
- isNaN(y) || (this._snapClampSetValue(y + f), this.$input.value = this.getValue());
4348
+ const w = parseFloat(this.$input.value);
4349
+ isNaN(w) || (this._snapClampSetValue(w + f), this.$input.value = this.getValue());
4348
4350
  }, o = (f) => {
4349
4351
  f.key === "Enter" && this.$input.blur(), f.code === "ArrowUp" && (f.preventDefault(), i(this._step * this._arrowKeyMultiplier(f))), f.code === "ArrowDown" && (f.preventDefault(), i(this._step * this._arrowKeyMultiplier(f) * -1));
4350
4352
  }, n = (f) => {
@@ -4352,19 +4354,19 @@ class Ve extends I {
4352
4354
  };
4353
4355
  let r = !1, s, l, h, d, u;
4354
4356
  const p = 5, m = (f) => {
4355
- s = f.clientX, l = h = f.clientY, r = !0, d = this.getValue(), u = 0, window.addEventListener("mousemove", g), window.addEventListener("mouseup", w);
4357
+ s = f.clientX, l = h = f.clientY, r = !0, d = this.getValue(), u = 0, window.addEventListener("mousemove", g), window.addEventListener("mouseup", y);
4356
4358
  }, g = (f) => {
4357
4359
  if (r) {
4358
- const y = f.clientX - s, D = f.clientY - l;
4359
- Math.abs(D) > p ? (f.preventDefault(), this.$input.blur(), r = !1, this._setDraggingStyle(!0, "vertical")) : Math.abs(y) > p && w();
4360
+ const w = f.clientX - s, D = f.clientY - l;
4361
+ Math.abs(D) > p ? (f.preventDefault(), this.$input.blur(), r = !1, this._setDraggingStyle(!0, "vertical")) : Math.abs(w) > p && y();
4360
4362
  }
4361
4363
  if (!r) {
4362
- const y = f.clientY - h;
4363
- u -= y * this._step * this._arrowKeyMultiplier(f), d + u > this._max ? u = this._max - d : d + u < this._min && (u = this._min - d), this._snapClampSetValue(d + u);
4364
+ const w = f.clientY - h;
4365
+ u -= w * this._step * this._arrowKeyMultiplier(f), d + u > this._max ? u = this._max - d : d + u < this._min && (u = this._min - d), this._snapClampSetValue(d + u);
4364
4366
  }
4365
4367
  h = f.clientY;
4366
- }, w = () => {
4367
- this._setDraggingStyle(!1, "vertical"), this._callOnFinishChange(), window.removeEventListener("mousemove", g), window.removeEventListener("mouseup", w);
4368
+ }, y = () => {
4369
+ this._setDraggingStyle(!1, "vertical"), this._callOnFinishChange(), window.removeEventListener("mousemove", g), window.removeEventListener("mouseup", y);
4368
4370
  }, v = () => {
4369
4371
  this._inputFocused = !0;
4370
4372
  }, _ = () => {
@@ -4374,10 +4376,10 @@ class Ve extends I {
4374
4376
  }
4375
4377
  _initSlider() {
4376
4378
  this._hasSlider = !0, this.$slider = document.createElement("div"), this.$slider.classList.add("lil-slider"), this.$fill = document.createElement("div"), this.$fill.classList.add("lil-fill"), this.$slider.appendChild(this.$fill), this.$widget.insertBefore(this.$slider, this.$input), this.domElement.classList.add("lil-has-slider");
4377
- const e = (_, f, y, D, Y) => (_ - f) / (y - f) * (Y - D) + D, t = (_) => {
4379
+ const e = (_, f, w, D, Y) => (_ - f) / (w - f) * (Y - D) + D, t = (_) => {
4378
4380
  const f = this.$slider.getBoundingClientRect();
4379
- let y = e(_, f.left, f.right, this._min, this._max);
4380
- this._snapClampSetValue(y);
4381
+ let w = e(_, f.left, f.right, this._min, this._max);
4382
+ this._snapClampSetValue(w);
4381
4383
  }, i = (_) => {
4382
4384
  this._setDraggingStyle(!0), t(_.clientX), window.addEventListener("mousemove", o), window.addEventListener("mouseup", n);
4383
4385
  }, o = (_) => {
@@ -4392,19 +4394,19 @@ class Ve extends I {
4392
4394
  _.touches.length > 1 || (this._hasScrollBar ? (s = _.touches[0].clientX, l = _.touches[0].clientY, r = !0) : h(_), window.addEventListener("touchmove", u, { passive: !1 }), window.addEventListener("touchend", p));
4393
4395
  }, u = (_) => {
4394
4396
  if (r) {
4395
- const f = _.touches[0].clientX - s, y = _.touches[0].clientY - l;
4396
- Math.abs(f) > Math.abs(y) ? h(_) : (window.removeEventListener("touchmove", u), window.removeEventListener("touchend", p));
4397
+ const f = _.touches[0].clientX - s, w = _.touches[0].clientY - l;
4398
+ Math.abs(f) > Math.abs(w) ? h(_) : (window.removeEventListener("touchmove", u), window.removeEventListener("touchend", p));
4397
4399
  } else
4398
4400
  _.preventDefault(), t(_.touches[0].clientX);
4399
4401
  }, p = () => {
4400
4402
  this._callOnFinishChange(), this._setDraggingStyle(!1), window.removeEventListener("touchmove", u), window.removeEventListener("touchend", p);
4401
4403
  }, m = this._callOnFinishChange.bind(this), g = 400;
4402
- let w;
4404
+ let y;
4403
4405
  const v = (_) => {
4404
4406
  if (Math.abs(_.deltaX) < Math.abs(_.deltaY) && this._hasScrollBar) return;
4405
4407
  _.preventDefault();
4406
- const y = this._normalizeMouseWheel(_) * this._step;
4407
- this._snapClampSetValue(this.getValue() + y), this.$input.value = this.getValue(), clearTimeout(w), w = setTimeout(m, g);
4408
+ const w = this._normalizeMouseWheel(_) * this._step;
4409
+ this._snapClampSetValue(this.getValue() + w), this.$input.value = this.getValue(), clearTimeout(y), y = setTimeout(m, g);
4408
4410
  };
4409
4411
  this.$slider.addEventListener("mousedown", i), this.$slider.addEventListener("touchstart", d, { passive: !1 }), this.$slider.addEventListener("wheel", v, { passive: !1 });
4410
4412
  }
@@ -5376,7 +5378,7 @@ class Xe {
5376
5378
  this.clickOutsideHandler && (document.removeEventListener("pointerdown", this.clickOutsideHandler), this.clickOutsideHandler = null), this.escapeHandler && (document.removeEventListener("keydown", this.escapeHandler), this.escapeHandler = null);
5377
5379
  }
5378
5380
  }
5379
- class Ke extends ye {
5381
+ class Ke extends we {
5380
5382
  // flags
5381
5383
  _editMode = !1;
5382
5384
  // Circuit writer
@@ -5406,7 +5408,7 @@ class Ke extends ye {
5406
5408
  * @private
5407
5409
  */
5408
5410
  onInitialize(e) {
5409
- e = L(e), this._initializeTools(), this._initializeSelectionManager(), this._initializeConfigPanelManager(), e.defaultTool && (this._initialized = !0, this.setEditMode(!0), this.setActiveTool(e.defaultTool));
5411
+ this._initializeTools(), this._initializeSelectionManager(), this._initializeConfigPanelManager(), this._initialized = !0, this._sharedResources || this.setActive(!0);
5410
5412
  }
5411
5413
  emitReady() {
5412
5414
  this.emit("ready", { controllerType: "static" });
@@ -5818,7 +5820,7 @@ class Ke extends ye {
5818
5820
  autoAdjustCircuitGridSize() {
5819
5821
  if (this._checkInitialized(), !!this._circuit && this.circuitWriter.saveAutoAdjustCircuitSize()) {
5820
5822
  this._gridHalfSize = Math.ceil(this._circuit.metadata.size / 2), this.grid && (this._scene.remove(this.grid), this.grid.geometry.dispose());
5821
- const e = this._options || L();
5823
+ const e = this._options || W();
5822
5824
  this.grid = G(
5823
5825
  this._circuit.metadata.size,
5824
5826
  this._circuit.metadata.divisions,
@@ -5852,10 +5854,11 @@ class Ke extends ye {
5852
5854
  this.grid && (this._scene.remove(this.grid), this.grid.dispose(), this._grid = null);
5853
5855
  }
5854
5856
  }
5855
- class Ze extends ye {
5857
+ class Ze extends we {
5856
5858
  _runner = null;
5857
5859
  _behaviorRegistry;
5858
5860
  // Playback control state
5861
+ _autoPlay = !1;
5859
5862
  _isPlaying = !1;
5860
5863
  _tickIntervalMs = F.DEFAULT_INTERVAL_MS;
5861
5864
  _simulationLoopId = null;
@@ -5963,9 +5966,11 @@ class Ze extends ye {
5963
5966
  /**
5964
5967
  * Specific Initialization logic, performed after AbstractCircuitController initialization
5965
5968
  * @private
5969
+ *
5970
+ * @param options - Controller options passed to initialize()
5966
5971
  */
5967
- onInitialize() {
5968
- this._clickHandler = this._handleClick.bind(this), this._container.addEventListener("click", this._clickHandler);
5972
+ onInitialize(e) {
5973
+ e && (e.simulationSpeed && (this.simulationSpeed = e.simulationSpeed), typeof e.simulationAutoPlay == "boolean" && (this._autoPlay = e.simulationAutoPlay)), this._clickHandler = this._handleClick.bind(this), this._container.addEventListener("click", this._clickHandler), this._sharedResources || this.setActive(!0);
5969
5974
  }
5970
5975
  emitReady() {
5971
5976
  this.emit("ready", { controllerType: "simulation" });
@@ -5981,13 +5986,16 @@ class Ze extends ye {
5981
5986
  this.stop(), this._runner = null, this._removeSimulationStateVisuals();
5982
5987
  else {
5983
5988
  if (!this._circuit) return;
5984
- this._runner = new X(this._circuit, this._behaviorRegistry), this._fullUpdate();
5989
+ this._runner = new X(this._circuit, this._behaviorRegistry), this._fullUpdate(), this._autoPlay && this.play();
5985
5990
  }
5986
5991
  }
5987
5992
  setCircuit(e) {
5988
5993
  if (this._checkInitialized(), e !== this._circuit) {
5989
5994
  if (this._isPlaying && this.stop(), this._runner = null, this._useSharedResources) {
5990
- this._circuit = e, this.wireVisualManager.setCircuit(e), e && (this._gridHalfSize = Math.ceil(e.metadata.size / 2), this._runner = new X(e, this._behaviorRegistry));
5995
+ if (this._circuit = e, this.wireVisualManager.setCircuit(e), e) {
5996
+ if (this._gridHalfSize = Math.ceil(e.metadata.size / 2), !this._active) return;
5997
+ this._runner = new X(e, this._behaviorRegistry), this._fullUpdate(), this._autoPlay && this.play();
5998
+ }
5991
5999
  return;
5992
6000
  }
5993
6001
  this._setCircuit(e);
@@ -6367,6 +6375,8 @@ class rt extends ue {
6367
6375
  this._behaviorRegistry,
6368
6376
  this._sharedResources
6369
6377
  ), this._editController.initialize(e, t.controllerOptions), this._simulationController.initialize(e, t.controllerOptions), this._setupEventForwarding(), this._mode = t?.initialMode ?? "edit", this._mode === "edit" ? this._editController.setActive(!0) : this._simulationController.setActive(!0), this._initialized = !0, this.emit("ready", { controllerType: "engine" });
6378
+ const i = this._mode;
6379
+ this.emit("modeChanged", { mode: i });
6370
6380
  }
6371
6381
  /**
6372
6382
  * Create shared resources for both controllers.
@@ -6383,7 +6393,7 @@ class rt extends ue {
6383
6393
  o.add(n), fe(o);
6384
6394
  const r = e.clientWidth / e.clientHeight || 1, s = pe(r);
6385
6395
  s.layers.set(0), s.layers.enable(1), s.layers.enable(2);
6386
- const l = we(s, e, i.mapControls), h = new ge(o, s), d = new M(), u = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), g = new _e(u, m);
6396
+ const l = ye(s, e, i.mapControls), h = new ge(o, s), d = new M(), u = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), g = new _e(u, m);
6387
6397
  return g.setContainer(e), g.setResolution(e.clientWidth, e.clientHeight), g.setSceneAndCamera(o, s), {
6388
6398
  scene: o,
6389
6399
  camera: s,
@@ -7711,8 +7721,8 @@ class O extends b {
7711
7721
  type: "component",
7712
7722
  componentId: e.id
7713
7723
  }, g.rotateY(Math.PI / 2), g.position.set(0.5, 0, 0.9), t.add(g);
7714
- const w = this.createPinGroup(e.id, e.pins[3], "power_out");
7715
- w.position.set(0.6, 0, 1), w.rotateZ(-Math.PI / 2), w.rotateX(Math.PI / 2), t.add(w);
7724
+ const y = this.createPinGroup(e.id, e.pins[3], "power_out");
7725
+ y.position.set(0.6, 0, 1), y.rotateZ(-Math.PI / 2), y.rotateX(Math.PI / 2), t.add(y);
7716
7726
  const v = new a.Mesh(
7717
7727
  new a.BoxGeometry(2, 1, 1),
7718
7728
  //new THREE.MeshStandardMaterial({ color: 0x00ff00, transparent: true, opacity: 0.2 })
@@ -7736,8 +7746,8 @@ class O extends b {
7736
7746
  !1,
7737
7747
  0,
7738
7748
  Math.PI * 2
7739
- ), y = new a.Mesh(f, _);
7740
- return y.rotateX(-Math.PI / 2), y.rotateZ(Math.PI / 2), y.position.set(0.75, 0, 0), v.add(y), t.add(v), v.position.set(0.6, 0, -0.6), v.rotation.copy(O.OPEN_ROTATION), this.updateFromConfiguration(t, e.config), t;
7749
+ ), w = new a.Mesh(f, _);
7750
+ return w.rotateX(-Math.PI / 2), w.rotateZ(Math.PI / 2), w.position.set(0.75, 0, 0), v.add(w), t.add(v), v.position.set(0.6, 0, -0.6), v.rotation.copy(O.OPEN_ROTATION), this.updateFromConfiguration(t, e.config), t;
7741
7751
  }
7742
7752
  /**
7743
7753
  * Get config form definition for Relay (T025)
@@ -8149,7 +8159,7 @@ class k extends b {
8149
8159
  }
8150
8160
  // Uses default hover implementation
8151
8161
  }
8152
- class W extends b {
8162
+ class L extends b {
8153
8163
  /** Transistor lit color (yellow glow) */
8154
8164
  static TRANSISTOR_CLOSED_COLOR = 16777215;
8155
8165
  /** Transistor lit emissive intensity */
@@ -8170,7 +8180,7 @@ class W extends b {
8170
8180
  const i = this.createComponentHitbox(e.id, t.id, 1.3, 2, 1.3);
8171
8181
  t.add(i);
8172
8182
  const o = new a.MeshStandardMaterial({ color: 16777215 });
8173
- o.emissive.setHex(W.TRANSISTOR_CLOSED_COLOR), o.emissiveIntensity = 0;
8183
+ o.emissive.setHex(L.TRANSISTOR_CLOSED_COLOR), o.emissiveIntensity = 0;
8174
8184
  const n = new a.Mesh(this.openGeometry, o);
8175
8185
  n.userData = {
8176
8186
  type: "component",
@@ -8247,11 +8257,11 @@ class W extends b {
8247
8257
  const i = this.findEnvelopeMesh(e);
8248
8258
  if (!i) return;
8249
8259
  if (!t) {
8250
- i.userData.initialState === "closed" ? (i.geometry = this.closedGeometry, i.material.emissiveIntensity = W.TRANSISTOR_CLOSED_INTENSITY) : (i.geometry = this.openGeometry, i.material.emissiveIntensity = 0);
8260
+ i.userData.initialState === "closed" ? (i.geometry = this.closedGeometry, i.material.emissiveIntensity = L.TRANSISTOR_CLOSED_INTENSITY) : (i.geometry = this.openGeometry, i.material.emissiveIntensity = 0);
8251
8261
  return;
8252
8262
  }
8253
8263
  const o = t;
8254
- o.isClosed ? (i.geometry = this.closedGeometry, i.material.emissiveIntensity = W.TRANSISTOR_CLOSED_INTENSITY) : o.isInTransition ? (i.geometry = this.transientGeometry, i.material.emissiveIntensity = 0.5 * W.TRANSISTOR_CLOSED_INTENSITY) : (i.geometry = this.openGeometry, i.material.emissiveIntensity = 0);
8264
+ o.isClosed ? (i.geometry = this.closedGeometry, i.material.emissiveIntensity = L.TRANSISTOR_CLOSED_INTENSITY) : o.isInTransition ? (i.geometry = this.transientGeometry, i.material.emissiveIntensity = 0.5 * L.TRANSISTOR_CLOSED_INTENSITY) : (i.geometry = this.openGeometry, i.material.emissiveIntensity = 0);
8255
8265
  }
8256
8266
  /**
8257
8267
  * Find the envelope mesh within the component group
@@ -8270,7 +8280,7 @@ class W extends b {
8270
8280
  }
8271
8281
  }
8272
8282
  function lt(c) {
8273
- c.register(S.Battery, new Qe()).register(S.Label, new C()).register(S.Lightbulb, new V()).register(S.RectangleLED, new j()).register(S.Relay, new O()).register(S.SmallLED, new B()).register(S.Switch, new k()).register(S.Transistor, new W());
8283
+ return c.register(S.Battery, new Qe()).register(S.Label, new C()).register(S.Lightbulb, new V()).register(S.RectangleLED, new j()).register(S.Relay, new O()).register(S.SmallLED, new B()).register(S.Switch, new k()).register(S.Transistor, new L()), c;
8274
8284
  }
8275
8285
  export {
8276
8286
  Te as A,
@@ -8283,7 +8293,7 @@ export {
8283
8293
  ke as M,
8284
8294
  j as R,
8285
8295
  Ae as S,
8286
- W as T,
8296
+ L as T,
8287
8297
  _e as W,
8288
8298
  Ke as a,
8289
8299
  Ze as b,
@@ -8295,6 +8305,9 @@ export {
8295
8305
  O as h,
8296
8306
  B as i,
8297
8307
  k as j,
8308
+ W as k,
8309
+ ce as l,
8310
+ J as m,
8298
8311
  lt as r
8299
8312
  };
8300
- //# sourceMappingURL=setup-vP_WEVVE.js.map
8313
+ //# sourceMappingURL=setup-YQJVUHFM.js.map