simple-circuit-engine 0.0.1 → 0.0.8

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.
package/dist/index.d.ts CHANGED
@@ -1733,6 +1733,7 @@ declare class CircuitMetadata {
1733
1733
  export declare class CircuitRunnerController extends AbstractCircuitController {
1734
1734
  private _runner;
1735
1735
  private _behaviorRegistry;
1736
+ private _autoPlay;
1736
1737
  private _isPlaying;
1737
1738
  private _tickIntervalMs;
1738
1739
  private _simulationLoopId;
@@ -1808,8 +1809,10 @@ export declare class CircuitRunnerController extends AbstractCircuitController {
1808
1809
  /**
1809
1810
  * Specific Initialization logic, performed after AbstractCircuitController initialization
1810
1811
  * @private
1812
+ *
1813
+ * @param options - Controller options passed to initialize()
1811
1814
  */
1812
- protected onInitialize(): void;
1815
+ protected onInitialize(options?: ControllerOptions): void;
1813
1816
  protected emitReady(): void;
1814
1817
  /**
1815
1818
  * specific disposal prepended at the beginning of dispose process
@@ -2740,8 +2743,18 @@ export declare interface ControllerOptions {
2740
2743
  defaultTool?: ToolType | null;
2741
2744
  /** MapControls configuration options */
2742
2745
  mapControls?: MapControlsOptions;
2746
+ /** Startup CircuitRunnerController simulation speed */
2747
+ simulationSpeed?: number;
2748
+ /** If CircuitRunnerController plays automatically at activation */
2749
+ simulationAutoPlay?: boolean;
2743
2750
  }
2744
2751
 
2752
+ /**
2753
+ * returns default complete controllerOptions or an autocompleted partial controllerOptions
2754
+ * @param options
2755
+ */
2756
+ export declare function controllerOptions(options?: ControllerOptions | undefined): ControllerOptions;
2757
+
2745
2758
  /**
2746
2759
  * Cursor types for tool operations
2747
2760
  */
@@ -2822,6 +2835,12 @@ export declare interface EngineOptions {
2822
2835
  runnerOptions?: RunnerOptions;
2823
2836
  }
2824
2837
 
2838
+ /**
2839
+ * returns default complete engineOptions or and autoCompleted partial engineOptions
2840
+ * @param options
2841
+ */
2842
+ export declare function engineOptions(options?: EngineOptions | undefined): EngineOptions;
2843
+
2825
2844
  /**
2826
2845
  * Electrical connection point (component pin or wire branching point).
2827
2846
  *
@@ -4084,6 +4103,12 @@ export declare interface MapControlsOptions {
4084
4103
  rotateSpeed?: number;
4085
4104
  }
4086
4105
 
4106
+ /**
4107
+ * returns default complete mapControlsOptions or an autocompleted partial mapControlOptions
4108
+ * @param options
4109
+ */
4110
+ export declare function mapControlsOptions(options?: MapControlsOptions | undefined): MapControlsOptions;
4111
+
4087
4112
  /**
4088
4113
  * Event emitted when controller mode changes
4089
4114
  */
@@ -4091,7 +4116,7 @@ export declare interface ModeChangedEvent {
4091
4116
  /** New active mode */
4092
4117
  mode: EngineMode;
4093
4118
  /** Previous mode before transition */
4094
- previousMode: EngineMode;
4119
+ previousMode?: EngineMode;
4095
4120
  }
4096
4121
 
4097
4122
  export declare type ModelEditAction = 'edit' | 'add' | 'delete';
@@ -4547,8 +4572,9 @@ export declare class RectangleLEDVisualFactory extends ComponentVisualFactoryBas
4547
4572
  * Basic components are : Battery, Lightbulb, RectangleLED, Relay, SmallLED, Switch, Transistor
4548
4573
  * @public
4549
4574
  * @param registry
4575
+ * @return the input factory registry for chaining
4550
4576
  */
4551
- export declare function registerBasicComponentsFactories(registry: IFactoryRegistry): void;
4577
+ export declare function registerBasicComponentsFactories(registry: IFactoryRegistry): IFactoryRegistry;
4552
4578
 
4553
4579
  /**
4554
4580
  * Visual factory for Relay components
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { b as e, C as s, j as i, i as o, a as r, D as n, E as l, d as c, m as u, P as y, h as S, R as T, l as g, S as C, k as h, T as m, f as p, e as B, g as E, c as D, s as F } from "./CircuitRunner-CAeE31M5.js";
2
- import { BatteryBehavior as R, BatteryState as d, BehaviorRegistry as v, Circuit as M, CircuitMetadata as V, ComponentState as b, ENode as A, LightbulbBehavior as P, LightbulbState as f, RectangleLEDBehavior as N, RectangleLEDState as I, RelayBehavior as x, RelayState as O, SmallLEDBehavior as U, SmallLEDState as W, SwitchBehavior as _, SwitchState as w, TransistorBehavior as H, TransistorState as j, Wire as k, registerBasicComponentsBehaviors as Q } from "./core/index.js";
3
- import { A as q, f as z, d as G, B as J, a as K, C as X, b as Z, c as $, D as aa, F as ta, e as ea, H as sa, L as ia, g as oa, M as ra, R as na, h as la, S as ca, i as ua, j as ya, T as Sa, W as Ta, r as ga } from "./setup-FtJmrLda.js";
1
+ import { b as e, C as s, j as o, i, a as r, D as n, E as l, d as c, m as u, P as y, h as S, R as g, l as p, S as C, k as T, T as m, f as h, e as B, g as E, c as D, s as F } from "./CircuitRunner-FXM_s5ll.js";
2
+ import { BatteryBehavior as R, BatteryState as d, BehaviorRegistry as v, Circuit as M, CircuitMetadata as V, ComponentState as b, ENode as A, LightbulbBehavior as P, LightbulbState as f, RectangleLEDBehavior as N, RectangleLEDState as O, RelayBehavior as I, RelayState as x, SmallLEDBehavior as U, SmallLEDState as W, SwitchBehavior as _, SwitchState as k, TransistorBehavior as w, TransistorState as H, Wire as j, registerBasicComponentsBehaviors as Q } from "./core/index.js";
3
+ import { A as q, f as z, d as G, B as J, a as K, C as X, b as Z, c as $, D as aa, F as ta, e as ea, H as sa, L as oa, g as ia, M as ra, R as na, h as la, S as ca, i as ua, j as ya, T as Sa, W as ga, k as pa, l as Ca, m as Ta, r as ma } from "./setup-aoI3UTB5.js";
4
4
  export {
5
5
  q as AddComponentTool,
6
6
  R as BatteryBehavior,
@@ -15,10 +15,10 @@ export {
15
15
  K as CircuitController,
16
16
  X as CircuitEngine,
17
17
  V as CircuitMetadata,
18
- i as CircuitRunner,
18
+ o as CircuitRunner,
19
19
  Z as CircuitRunnerController,
20
20
  $ as CircuitWriter,
21
- o as Component,
21
+ i as Component,
22
22
  b as ComponentState,
23
23
  r as ComponentType,
24
24
  aa as DefaultVisualFactory,
@@ -30,42 +30,45 @@ export {
30
30
  ta as FactoryRegistry,
31
31
  ea as HitboxLayers,
32
32
  sa as HoverManager,
33
- ia as LabelVisualFactory,
33
+ oa as LabelVisualFactory,
34
34
  P as LightbulbBehavior,
35
35
  f as LightbulbState,
36
- oa as LightbulbVisualFactory,
36
+ ia as LightbulbVisualFactory,
37
37
  ra as MultiSelectTool,
38
38
  y as Position,
39
39
  S as Position3D,
40
40
  N as RectangleLEDBehavior,
41
- I as RectangleLEDState,
41
+ O as RectangleLEDState,
42
42
  na as RectangleLEDVisualFactory,
43
- x as RelayBehavior,
44
- O as RelayState,
43
+ I as RelayBehavior,
44
+ x as RelayState,
45
45
  la as RelayVisualFactory,
46
- T as Rotation,
47
- g as SIMULATION_SPEED,
46
+ g as Rotation,
47
+ p as SIMULATION_SPEED,
48
48
  ca as SelectionManager,
49
49
  C as SimulationState,
50
50
  U as SmallLEDBehavior,
51
51
  W as SmallLEDState,
52
52
  ua as SmallLEDVisualFactory,
53
- h as StateManager,
53
+ T as StateManager,
54
54
  _ as SwitchBehavior,
55
- w as SwitchState,
55
+ k as SwitchState,
56
56
  ya as SwitchVisualFactory,
57
57
  m as TRANSITION_DEFAULTS,
58
- H as TransistorBehavior,
59
- j as TransistorState,
58
+ w as TransistorBehavior,
59
+ H as TransistorState,
60
60
  Sa as TransistorVisualFactory,
61
- k as Wire,
62
- Ta as WireVisualManager,
63
- p as findPositionBestIndex,
61
+ j as Wire,
62
+ ga as WireVisualManager,
63
+ pa as controllerOptions,
64
+ Ca as engineOptions,
65
+ h as findPositionBestIndex,
64
66
  B as generateUUID,
65
67
  E as getAllComponentTypes,
66
68
  D as getComponentTypeMetadata,
69
+ Ta as mapControlsOptions,
67
70
  Q as registerBasicComponentsBehaviors,
68
- ga as registerBasicComponentsFactories,
71
+ ma as registerBasicComponentsFactories,
69
72
  F as simplifyPositions
70
73
  };
71
74
  //# sourceMappingURL=index.js.map
@@ -38,5 +38,6 @@ export type * from './shared/types';
38
38
  export * from './shared/types';
39
39
  export { HitboxLayers } from './shared/utils/LayerConstants';
40
40
  export type { HitboxLayerValue } from './shared/utils/LayerConstants';
41
+ export * from './shared/utils/Options';
41
42
  export { registerBasicComponentsFactories } from './setup';
42
43
  //# sourceMappingURL=index.d.ts.map
@@ -1,27 +1,30 @@
1
- import { A as r, f as i, d as t, B as o, a as e, C as l, b as c, c as u, D as n, F as y, e as F, H as V, L as g, g as C, M as L, R as b, h as B, S as M, i as R, j as S, T, W as d, r as h } from "../setup-FtJmrLda.js";
1
+ import { A as r, f as t, d as i, B as o, a as l, C as e, b as n, c, D as u, F as y, e as F, H as g, L as V, g as C, M as p, R as m, h as L, S as b, i as B, j as M, T as R, W as S, k as T, l as d, m as h, r as D } from "../setup-aoI3UTB5.js";
2
2
  export {
3
3
  r as AddComponentTool,
4
- i as BatteryVisualFactory,
5
- t as BranchingPointVisualFactory,
4
+ t as BatteryVisualFactory,
5
+ i as BranchingPointVisualFactory,
6
6
  o as BuildTool,
7
- e as CircuitController,
8
- l as CircuitEngine,
9
- c as CircuitRunnerController,
10
- u as CircuitWriter,
11
- n as DefaultVisualFactory,
7
+ l as CircuitController,
8
+ e as CircuitEngine,
9
+ n as CircuitRunnerController,
10
+ c as CircuitWriter,
11
+ u as DefaultVisualFactory,
12
12
  y as FactoryRegistry,
13
13
  F as HitboxLayers,
14
- V as HoverManager,
15
- g as LabelVisualFactory,
14
+ g as HoverManager,
15
+ V as LabelVisualFactory,
16
16
  C as LightbulbVisualFactory,
17
- L as MultiSelectTool,
18
- b as RectangleLEDVisualFactory,
19
- B as RelayVisualFactory,
20
- M as SelectionManager,
21
- R as SmallLEDVisualFactory,
22
- S as SwitchVisualFactory,
23
- T as TransistorVisualFactory,
24
- d as WireVisualManager,
25
- h as registerBasicComponentsFactories
17
+ p as MultiSelectTool,
18
+ m as RectangleLEDVisualFactory,
19
+ L as RelayVisualFactory,
20
+ b as SelectionManager,
21
+ B as SmallLEDVisualFactory,
22
+ M as SwitchVisualFactory,
23
+ R as TransistorVisualFactory,
24
+ S as WireVisualManager,
25
+ T as controllerOptions,
26
+ d as engineOptions,
27
+ h as mapControlsOptions,
28
+ D as registerBasicComponentsFactories
26
29
  };
27
30
  //# sourceMappingURL=index.js.map
@@ -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,7 +3533,7 @@ 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
@@ -3546,7 +3546,9 @@ function L(c = void 0) {
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
  }
@@ -3558,11 +3560,11 @@ function ce(c = void 0) {
3558
3560
  };
3559
3561
  return c ? (c.controllerOptions = L(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;
@@ -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;
@@ -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
@@ -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);
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,
@@ -6720,9 +6730,7 @@ class st {
6720
6730
  if (!t)
6721
6731
  throw new TypeError(`Factory cannot be null or undefined for type: ${e}`);
6722
6732
  if (typeof t != "object" || typeof t.createVisual != "function")
6723
- throw new TypeError(
6724
- `Factory must be a an object with createVisual method for type: ${e}`
6725
- );
6733
+ throw new TypeError(`Factory must be a an object with createVisual method for type: ${e}`);
6726
6734
  return this.factories.set(e, t), this;
6727
6735
  }
6728
6736
  /**
@@ -7713,8 +7721,8 @@ class O extends b {
7713
7721
  type: "component",
7714
7722
  componentId: e.id
7715
7723
  }, g.rotateY(Math.PI / 2), g.position.set(0.5, 0, 0.9), t.add(g);
7716
- const w = this.createPinGroup(e.id, e.pins[3], "power_out");
7717
- 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);
7718
7726
  const v = new a.Mesh(
7719
7727
  new a.BoxGeometry(2, 1, 1),
7720
7728
  //new THREE.MeshStandardMaterial({ color: 0x00ff00, transparent: true, opacity: 0.2 })
@@ -7738,8 +7746,8 @@ class O extends b {
7738
7746
  !1,
7739
7747
  0,
7740
7748
  Math.PI * 2
7741
- ), y = new a.Mesh(f, _);
7742
- 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;
7743
7751
  }
7744
7752
  /**
7745
7753
  * Get config form definition for Relay (T025)
@@ -8272,7 +8280,7 @@ class W extends b {
8272
8280
  }
8273
8281
  }
8274
8282
  function lt(c) {
8275
- 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 W()), c;
8276
8284
  }
8277
8285
  export {
8278
8286
  Te as A,
@@ -8297,6 +8305,9 @@ export {
8297
8305
  O as h,
8298
8306
  B as i,
8299
8307
  k as j,
8308
+ L as k,
8309
+ ce as l,
8310
+ J as m,
8300
8311
  lt as r
8301
8312
  };
8302
- //# sourceMappingURL=setup-FtJmrLda.js.map
8313
+ //# sourceMappingURL=setup-aoI3UTB5.js.map