simple-circuit-engine 0.0.11 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/AGENTS.md +11 -7
  2. package/CLAUDE.md +6 -6
  3. package/README.md +5 -2
  4. package/dist/core/index.d.ts +0 -1
  5. package/dist/core/index.js +85 -2115
  6. package/dist/core/setup.d.ts +25 -0
  7. package/dist/core/simulation/CircuitRunner.d.ts +176 -0
  8. package/dist/core/simulation/DirtyTracker.d.ts +87 -0
  9. package/dist/core/simulation/EventQueue.d.ts +68 -0
  10. package/dist/core/simulation/StateManager.d.ts +100 -0
  11. package/dist/core/simulation/behaviors/BehaviorRegistry.d.ts +70 -0
  12. package/dist/core/simulation/behaviors/ComponentBehavior.d.ts +53 -0
  13. package/dist/core/simulation/behaviors/arithmetic/AdderBehavior.d.ts +28 -0
  14. package/dist/core/simulation/behaviors/arithmetic/ArithmeticBehaviorMixin.d.ts +63 -0
  15. package/dist/core/simulation/behaviors/arithmetic/EightBitAdderBehavior.d.ts +51 -0
  16. package/dist/core/simulation/behaviors/arithmetic/EightBitOnesComplementBehavior.d.ts +29 -0
  17. package/dist/core/simulation/behaviors/arithmetic/HalfAdderBehavior.d.ts +22 -0
  18. package/dist/core/simulation/behaviors/arithmetic/index.d.ts +7 -0
  19. package/dist/core/simulation/behaviors/basic/BatteryBehavior.d.ts +14 -0
  20. package/dist/core/simulation/behaviors/basic/ClockBehavior.d.ts +24 -0
  21. package/dist/core/simulation/behaviors/basic/DoubleThrowSwitchBehavior.d.ts +33 -0
  22. package/dist/core/simulation/behaviors/basic/LightbulbBehavior.d.ts +23 -0
  23. package/dist/core/simulation/behaviors/basic/RectangleLEDBehavior.d.ts +24 -0
  24. package/dist/core/simulation/behaviors/basic/RelayBehavior.d.ts +33 -0
  25. package/dist/core/simulation/behaviors/basic/SmallLEDBehavior.d.ts +24 -0
  26. package/dist/core/simulation/behaviors/basic/SwitchBehavior.d.ts +33 -0
  27. package/dist/core/simulation/behaviors/basic/index.d.ts +20 -0
  28. package/dist/core/simulation/behaviors/gates/InverterBehavior.d.ts +29 -0
  29. package/dist/core/simulation/behaviors/gates/Nand4GateBehavior.d.ts +18 -0
  30. package/dist/core/simulation/behaviors/gates/Nand8GateBehavior.d.ts +18 -0
  31. package/dist/core/simulation/behaviors/gates/NandGateBehavior.d.ts +28 -0
  32. package/dist/core/simulation/behaviors/gates/Nor4GateBehavior.d.ts +18 -0
  33. package/dist/core/simulation/behaviors/gates/Nor8GateBehavior.d.ts +18 -0
  34. package/dist/core/simulation/behaviors/gates/NorGateBehavior.d.ts +22 -0
  35. package/dist/core/simulation/behaviors/gates/Xor4GateBehavior.d.ts +18 -0
  36. package/dist/core/simulation/behaviors/gates/Xor8GateBehavior.d.ts +18 -0
  37. package/dist/core/simulation/behaviors/gates/XorGateBehavior.d.ts +22 -0
  38. package/dist/core/simulation/behaviors/gates/index.d.ts +34 -0
  39. package/dist/core/simulation/behaviors/index.d.ts +28 -0
  40. package/dist/core/simulation/behaviors/types.d.ts +101 -0
  41. package/dist/core/simulation/index.d.ts +18 -0
  42. package/dist/core/simulation/states/ComponentState.d.ts +57 -0
  43. package/dist/core/simulation/states/SimulationState.d.ts +46 -0
  44. package/dist/core/simulation/states/arithmetic/AdderState.d.ts +16 -0
  45. package/dist/core/simulation/states/arithmetic/ArithmeticState.d.ts +53 -0
  46. package/dist/core/simulation/states/arithmetic/EightBitAdderState.d.ts +25 -0
  47. package/dist/core/simulation/states/arithmetic/EightBitOnesComplementState.d.ts +18 -0
  48. package/dist/core/simulation/states/arithmetic/HalfAdderState.d.ts +16 -0
  49. package/dist/core/simulation/states/arithmetic/index.d.ts +7 -0
  50. package/dist/core/simulation/states/basic/BatteryState.d.ts +16 -0
  51. package/dist/core/simulation/states/basic/ClockState.d.ts +16 -0
  52. package/dist/core/simulation/states/basic/DoubleThrowSwitchState.d.ts +21 -0
  53. package/dist/core/simulation/states/basic/LightbulbState.d.ts +21 -0
  54. package/dist/core/simulation/states/basic/RectangleLEDState.d.ts +9 -0
  55. package/dist/core/simulation/states/basic/RelayState.d.ts +25 -0
  56. package/dist/core/simulation/states/basic/SmallLEDState.d.ts +21 -0
  57. package/dist/core/simulation/states/basic/SwitchState.d.ts +25 -0
  58. package/dist/core/simulation/states/gates/InverterState.d.ts +17 -0
  59. package/dist/core/simulation/states/gates/Nand4GateState.d.ts +10 -0
  60. package/dist/core/simulation/states/gates/Nand8GateState.d.ts +10 -0
  61. package/dist/core/simulation/states/gates/NandGateState.d.ts +16 -0
  62. package/dist/core/simulation/states/gates/Nor4GateState.d.ts +10 -0
  63. package/dist/core/simulation/states/gates/Nor8GateState.d.ts +10 -0
  64. package/dist/core/simulation/states/gates/NorGateState.d.ts +10 -0
  65. package/dist/core/simulation/states/gates/Xor4GateState.d.ts +10 -0
  66. package/dist/core/simulation/states/gates/Xor8GateState.d.ts +10 -0
  67. package/dist/core/simulation/states/gates/XorGateState.d.ts +10 -0
  68. package/dist/core/simulation/states/gates/index.d.ts +25 -0
  69. package/dist/core/simulation/states/index.d.ts +31 -0
  70. package/dist/core/simulation/states/types.d.ts +32 -0
  71. package/dist/core/simulation/types.d.ts +155 -0
  72. package/dist/core/topology/Circuit.d.ts +420 -0
  73. package/dist/core/topology/CircuitMetadata.d.ts +24 -0
  74. package/dist/core/topology/CircuitOptions.d.ts +14 -0
  75. package/dist/core/topology/Component.d.ts +153 -0
  76. package/dist/core/topology/ENode.d.ts +200 -0
  77. package/dist/core/topology/Wire.d.ts +130 -0
  78. package/dist/core/topology/delays.d.ts +52 -0
  79. package/dist/core/topology/index.d.ts +14 -0
  80. package/dist/core/topology/types.d.ts +189 -0
  81. package/dist/core/utils/CameraOptions.d.ts +83 -0
  82. package/dist/core/utils/MemoizeDecorator.d.ts +9 -0
  83. package/dist/core/utils/Position.d.ts +166 -0
  84. package/dist/core/utils/Position3D.d.ts +77 -0
  85. package/dist/core/utils/Rotation.d.ts +82 -0
  86. package/dist/core/utils/index.d.ts +24 -0
  87. package/dist/core/utils/types.d.ts +35 -0
  88. package/dist/core-b6Q8w2sn.js +3560 -0
  89. package/dist/core-b6Q8w2sn.js.map +1 -0
  90. package/dist/i18n/index.d.ts +882 -0
  91. package/dist/i18n/locales/en.json.d.ts +268 -0
  92. package/dist/i18n/locales/fr.json.d.ts +268 -0
  93. package/dist/index.d.ts +14 -6306
  94. package/dist/index.js +136 -112
  95. package/dist/scene/CircuitEngine.d.ts +283 -0
  96. package/dist/scene/index.d.ts +1 -2
  97. package/dist/scene/index.js +50 -41
  98. package/dist/scene/setup.d.ts +26 -0
  99. package/dist/scene/shared/AbstractCircuitController.d.ts +217 -0
  100. package/dist/scene/shared/BranchingPointVisualFactory.d.ts +70 -0
  101. package/dist/scene/shared/EventEmitter.d.ts +92 -0
  102. package/dist/scene/shared/HoverManager.d.ts +151 -0
  103. package/dist/scene/shared/SelectionManager.d.ts +159 -0
  104. package/dist/scene/shared/WireVisualManager.d.ts +242 -0
  105. package/dist/scene/shared/components/ComponentVisualFactory.d.ts +438 -0
  106. package/dist/scene/shared/components/DefaultVisualFactory.d.ts +51 -0
  107. package/dist/scene/shared/components/FactoryRegistry.d.ts +84 -0
  108. package/dist/scene/shared/components/GroupedFactoryRegistry.d.ts +153 -0
  109. package/dist/scene/shared/components/arithmetic/AdderVisualFactory.d.ts +54 -0
  110. package/dist/scene/shared/components/arithmetic/EightBitAdderVisualFactory.d.ts +45 -0
  111. package/dist/scene/shared/components/arithmetic/EightBitOnesComplementVisualFactory.d.ts +63 -0
  112. package/dist/scene/shared/components/arithmetic/HalfAdderVisualFactory.d.ts +55 -0
  113. package/dist/scene/shared/components/arithmetic/index.d.ts +4 -0
  114. package/dist/scene/shared/components/basic/BatteryVisualFactory.d.ts +13 -0
  115. package/dist/scene/shared/components/basic/ClockVisualFactory.d.ts +79 -0
  116. package/dist/scene/shared/components/basic/DoubleThrowSwitchVisualFactory.d.ts +87 -0
  117. package/dist/scene/shared/components/basic/LabelVisualFactory.d.ts +148 -0
  118. package/dist/scene/shared/components/basic/LightbulbVisualFactory.d.ts +72 -0
  119. package/dist/scene/shared/components/basic/RectangleLEDVisualFactory.d.ts +86 -0
  120. package/dist/scene/shared/components/basic/RelayVisualFactory.d.ts +92 -0
  121. package/dist/scene/shared/components/basic/SmallLEDVisualFactory.d.ts +86 -0
  122. package/dist/scene/shared/components/basic/SwitchVisualFactory.d.ts +85 -0
  123. package/dist/scene/shared/components/gates/InverterVisualFactory.d.ts +104 -0
  124. package/dist/scene/shared/components/gates/Nand4GateVisualFactory.d.ts +27 -0
  125. package/dist/scene/shared/components/gates/Nand8GateVisualFactory.d.ts +27 -0
  126. package/dist/scene/shared/components/gates/NandGateVisualFactory.d.ts +101 -0
  127. package/dist/scene/shared/components/gates/Nor4GateVisualFactory.d.ts +27 -0
  128. package/dist/scene/shared/components/gates/Nor8GateVisualFactory.d.ts +27 -0
  129. package/dist/scene/shared/components/gates/NorGateVisualFactory.d.ts +101 -0
  130. package/dist/scene/shared/components/gates/Xor4GateVisualFactory.d.ts +29 -0
  131. package/dist/scene/shared/components/gates/Xor8GateVisualFactory.d.ts +29 -0
  132. package/dist/scene/shared/components/gates/XorGateVisualFactory.d.ts +103 -0
  133. package/dist/scene/shared/components/index.d.ts +33 -0
  134. package/dist/scene/shared/components/types.d.ts +43 -0
  135. package/dist/scene/shared/types.d.ts +474 -0
  136. package/dist/scene/shared/utils/CameraUtils.d.ts +23 -0
  137. package/dist/scene/shared/utils/ColorUtils.d.ts +26 -0
  138. package/dist/scene/shared/utils/ControlsUtils.d.ts +8 -0
  139. package/dist/scene/shared/utils/GeometryUtils.d.ts +337 -0
  140. package/dist/scene/shared/utils/LayerConstants.d.ts +40 -0
  141. package/dist/scene/shared/utils/LightingUtils.d.ts +31 -0
  142. package/dist/scene/shared/utils/MaterialUtils.d.ts +73 -0
  143. package/dist/scene/shared/utils/Options.d.ts +16 -0
  144. package/dist/scene/simulation/CircuitRunnerController.d.ts +227 -0
  145. package/dist/scene/static/CircuitController.d.ts +228 -0
  146. package/dist/scene/static/CircuitWriter.d.ts +146 -0
  147. package/dist/scene/static/PinTooltipWidget.d.ts +31 -0
  148. package/dist/scene/static/tools/BuildTool.d.ts +290 -0
  149. package/dist/scene/static/tools/ComponentPickerWidget.d.ts +89 -0
  150. package/dist/scene/static/tools/ConfigPanelWidget.d.ts +107 -0
  151. package/dist/scene/static/tools/MultiSelectTool.d.ts +265 -0
  152. package/dist/scene-D4QcWeiq.js +8745 -0
  153. package/dist/scene-D4QcWeiq.js.map +1 -0
  154. package/package.json +29 -25
  155. package/dist/CircuitRunner-BQQlhwjD.js +0 -1981
  156. package/dist/CircuitRunner-BQQlhwjD.js.map +0 -1
  157. package/dist/core/index.js.map +0 -1
  158. package/dist/index.js.map +0 -1
  159. package/dist/scene/index.js.map +0 -1
  160. package/dist/setup-CIq_kgaw.js +0 -10230
  161. package/dist/setup-CIq_kgaw.js.map +0 -1
@@ -0,0 +1,189 @@
1
+ import { ICameraOptions, IPosition, UUID } from '../utils';
2
+ /**
3
+ * canonic version for circuit files produced
4
+ */
5
+ export declare const CIRCUIT_FILE_VERSION = "0.0.11";
6
+ /**
7
+ * Type of electrical pinSources in the circuit.
8
+ *
9
+ * ENodes have a sourceType which can be undefined or one of the following:
10
+ * - **Voltage**: ENode that provides a voltage source to the circuit. All Enodes of this type are considered at the same positive potential.
11
+ * - **Current**: Ground/neutral ENodes that provides a current source to the circuit. All Enodes of this type are considered as points at
12
+ * the same 0V-GROUND potential and are points from where electrons enters the circuit.
13
+ */
14
+ export declare enum ENodeSourceType {
15
+ Voltage = "Voltage",
16
+ Current = "Current"
17
+ }
18
+ /**
19
+ * Type of electrical node (ENode) in the circuit.
20
+ *
21
+ * ENodes represent atomic electrical connection points and come in two variants (immutable after node creation)
22
+ *
23
+ * - **Pin**: Connection point belonging to a Component. Position is derived
24
+ * from the parent component's position, rotation, and pin index. Automatically
25
+ * created when a component is added, deleted when component is removed.
26
+ *
27
+ * - **BranchingPoint**: Junction point where wires split. Has an independent
28
+ * position on the grid. Automatically created when wires are split, deleted
29
+ * when no wires remain connected (orphaned).
30
+ */
31
+ export declare enum ENodeType {
32
+ /**
33
+ * Component pin connection point.
34
+ *
35
+ * Properties:
36
+ * - Has parent component reference
37
+ * - Has pin label within component
38
+ * - Position derived from component
39
+ * - Lifecycle tied to component (cascade deletion)
40
+ */
41
+ Pin = "Pin",
42
+ /**
43
+ * Wire branching point (junction).
44
+ *
45
+ * Properties:
46
+ * - Independent position on grid
47
+ * - Created when wire is split
48
+ * - Deleted when last wire is removed (orphaned cleanup)
49
+ * - No parent component
50
+ */
51
+ BranchingPoint = "BranchingPoint"
52
+ }
53
+ /**
54
+ * Metadata describing a logic pin's interface data.
55
+ *
56
+ * @property interface - name of the pin's interface (one interface combine several pins in the case of numeric inputs/outpus)
57
+ * @property index - index of the pin within the interface (starts at 0 by convention)
58
+ */
59
+ export interface ILogicPinMetadata {
60
+ readonly interface: string;
61
+ readonly index: number;
62
+ }
63
+ /**
64
+ * Metadata describing a component pin's source type and subtype.
65
+ *
66
+ * @property subtype - Pin role classification: 'free', 'vcc', 'logicInput', 'logicOutput'
67
+ * @property logicPinData - only for pins of subtype 'logicInput' and 'logicOutput' (MANDATORY in these cases): their logic pin metadata (interface/index)
68
+ * @property sourceType - Voltage/Current source or undefined for passive pins
69
+ */
70
+ export interface IPinMetadata {
71
+ readonly subtype: string;
72
+ readonly logicPinData?: ILogicPinMetadata;
73
+ readonly sourceType?: ENodeSourceType;
74
+ }
75
+ /**
76
+ * Metadata for a component type.
77
+ *
78
+ * @property id - Unique string identifier matching the enum value
79
+ * @property pins - Array of pin labels (order-significant)
80
+ * @property config - Default configuration parameters (depends on the component, e.g., initialState, activationLogic, color...)
81
+ */
82
+ export interface IComponentTypeMetadata {
83
+ readonly id: string;
84
+ readonly pins: Map<string, IPinMetadata>;
85
+ readonly config: Map<string, string>;
86
+ }
87
+ /**
88
+ * Available logic families
89
+ *
90
+ * - `CMOS1`: CMOS technology, base unit 1 inverter = 1 tick
91
+ * - `TTL1`: TTL technology, base unit 1 NAND2 = 1 tick
92
+ * - `Sandbox`: User-defined delays, no technology constraints
93
+ */
94
+ export type LogicFamily = 'CMOS1' | 'TTL1' | 'Sandbox';
95
+ /** All supported logic families */
96
+ export declare const ALL_LOGIC_FAMILIES: LogicFamily[];
97
+ /** Default logic family applied when none is specified */
98
+ export declare const DEFAULT_LOGIC_FAMILY: LogicFamily;
99
+ /** Interface defining an ElectricalNode **/
100
+ export interface IENode {
101
+ id: UUID;
102
+ type: ENodeType;
103
+ component?: UUID | null;
104
+ pinLabel?: string | null;
105
+ position?: IPosition | null;
106
+ source?: ENodeSourceType | null;
107
+ subtype: string;
108
+ }
109
+ /** Interface defining a Wire (link between 2 ENodes supporting intermediate position to tune its path) **/
110
+ export interface IWire {
111
+ id: UUID;
112
+ node1: UUID;
113
+ node2: UUID;
114
+ intermediatePositions: IPosition[];
115
+ }
116
+ /** Interface defining a Component **/
117
+ export interface IComponent {
118
+ id: UUID;
119
+ type: ComponentType;
120
+ position: IPosition;
121
+ rotation: number;
122
+ pins: UUID[];
123
+ config: {
124
+ [key: string]: string;
125
+ };
126
+ editable: boolean;
127
+ }
128
+ /**
129
+ * User editable options for a Circuit
130
+ */
131
+ export type ICircuitOptions = {
132
+ name: string;
133
+ defaultLogicFamily: LogicFamily;
134
+ };
135
+ /** circuit metadata type — combines user writable options and managed metadata */
136
+ export type ICircuitMetadata = {
137
+ version: string;
138
+ options: ICircuitOptions;
139
+ cameraOptions: ICameraOptions;
140
+ size: number;
141
+ divisions: number;
142
+ };
143
+ /** circuit type */
144
+ export type ICircuit = {
145
+ metadata: ICircuitMetadata;
146
+ components: Iterable<IComponent>;
147
+ enodes: Iterable<IENode>;
148
+ wires: Iterable<IWire>;
149
+ };
150
+ /**
151
+ * Enumeration of ALL available component types.
152
+ *
153
+ * Each component type represents a specific electrical element that can be
154
+ * placed in a circuit (battery, LED, transistor, etc.).
155
+ */
156
+ export declare enum ComponentType {
157
+ Cube = "cube",// no pins component for testing purposes mainly
158
+ Label = "label",// decorative text label with no pins
159
+ Battery = "battery",
160
+ Switch = "switch",
161
+ DoubleThrowSwitch = "doubleThrowSwitch",
162
+ Lightbulb = "lightbulb",
163
+ Relay = "relay",
164
+ SmallLED = "smallLED",
165
+ RectangleLED = "rectangleLED",
166
+ Clock = "clock",
167
+ Inverter = "inverter",
168
+ NandGate = "nandGate",
169
+ Nand4Gate = "nand4Gate",
170
+ Nand8Gate = "nand8Gate",
171
+ NorGate = "norGate",
172
+ Nor4Gate = "nor4Gate",
173
+ Nor8Gate = "nor8Gate",
174
+ XorGate = "xorGate",
175
+ Xor4Gate = "xor4Gate",
176
+ Xor8Gate = "xor8Gate",
177
+ HalfAdder = "halfAdder",
178
+ Adder = "adder",
179
+ EightBitAdder = "eightBitAdder",
180
+ EightBitOnesComplement = "eightBitOnesComplement"
181
+ }
182
+ /**
183
+ * Component type metadata lookup table.
184
+ *
185
+ * Maps each ComponentType enum value to its associated metadata
186
+ * (id, display name, pins, and default configuration arguments).
187
+ *
188
+ */
189
+ export declare const COMPONENT_TYPE_METADATA: Readonly<Record<ComponentType, IComponentTypeMetadata>>;
@@ -0,0 +1,83 @@
1
+ import { ICameraOptions } from './types';
2
+ import { Position3D } from './Position3D';
3
+ /**
4
+ * Camera configuration options.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * // Create with defaults
9
+ * const defaultOpts = new CameraOptions();
10
+ *
11
+ * // Create with custom values
12
+ * const customOpts = new CameraOptions(
13
+ * new Position3D(0, 20, 10),
14
+ * new Position3D(5, 0, 0),
15
+ * 60,
16
+ * 0.5,
17
+ * 2000
18
+ * );
19
+ * ```
20
+ */
21
+ export declare class CameraOptions {
22
+ readonly position: Position3D;
23
+ readonly lookAtPosition: Position3D;
24
+ readonly fov: number;
25
+ readonly near: number;
26
+ readonly far: number;
27
+ /**
28
+ * Create new camera options.
29
+ *
30
+ * @param position - Camera position (default: 0, 15, 15)
31
+ * @param lookAtPosition - Camera look-at target position (default: 0, 0, 0)
32
+ * @param fov - Field of view in degrees (default: 75)
33
+ * @param near - Near clipping plane distance (default: 0.1)
34
+ * @param far - Far clipping plane distance (default: 1000)
35
+ */
36
+ constructor(position?: Position3D, lookAtPosition?: Position3D, fov?: number, near?: number, far?: number);
37
+ /**
38
+ * Serialize camera options to JSON.
39
+ *
40
+ * @returns Plain object with camera configuration
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const opts = new CameraOptions();
45
+ * const json = opts.toJSON();
46
+ * console.log(json);
47
+ * // {
48
+ * // position: { x: 0, y: 15, z: 0 },
49
+ * // lookAtPosition: { x: 0, y: 0, z: 0 },
50
+ * // fov: 75,
51
+ * // near: 0.1,
52
+ * // far: 1000
53
+ * // }
54
+ * ```
55
+ */
56
+ toJSON(): ICameraOptions;
57
+ /**
58
+ * Deserialize camera options from JSON.
59
+ *
60
+ * @param json - Plain object with camera configuration
61
+ * @returns CameraOptions instance
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const json = {
66
+ * position: { x: 0, y: 20, z: 10 },
67
+ * lookAtPosition: { x: 5, y: 0, z: 0 },
68
+ * fov: 60,
69
+ * near: 0.5,
70
+ * far: 2000
71
+ * };
72
+ * const opts = CameraOptions.fromJSON(json);
73
+ * console.log(opts.position.y); // 20
74
+ * ```
75
+ */
76
+ static fromJSON(json: ICameraOptions): CameraOptions;
77
+ /**
78
+ * String representation for debugging.
79
+ *
80
+ * @returns String with camera configuration details
81
+ */
82
+ toString(): string;
83
+ }
@@ -0,0 +1,9 @@
1
+ interface MemoizeArgs {
2
+ expiring?: number;
3
+ hashFunction?: boolean | ((...args: any[]) => any);
4
+ tags?: string[];
5
+ }
6
+ export declare function Memoize(args?: MemoizeArgs | MemoizeArgs['hashFunction']): (_target: Object, _propertyKey: string, descriptor: TypedPropertyDescriptor<any>) => void;
7
+ export declare function MemoizeExpiring(expiring: number, hashFunction?: MemoizeArgs['hashFunction']): (_target: Object, _propertyKey: string, descriptor: TypedPropertyDescriptor<any>) => void;
8
+ export declare function clear(tags: string[]): number;
9
+ export {};
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Position Type for 2D Discrete Grid
3
+ *
4
+ * Represents a position on a 2D discrete (integer) grid. Used for:
5
+ * - Component placement
6
+ * - Branching point ENode positions
7
+ * - Wire intermediate waypoints
8
+ *
9
+ * @module core/utils
10
+ */
11
+ /**
12
+ * Position on a 2D discrete grid with integer coordinates.
13
+ *
14
+ * Enforces integer constraint at construction time to ensure all positions
15
+ * align with the discrete grid model. Positions are immutable once created.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const pos = new Position(10, 20);
20
+ * console.log(pos.x); // 10
21
+ * console.log(pos.y); // 20
22
+ *
23
+ * // Invalid: non-integer coordinates
24
+ * const invalid = new Position(10.5, 20); // TypeError
25
+ * ```
26
+ */
27
+ export declare class Position {
28
+ readonly x: number;
29
+ readonly y: number;
30
+ /**
31
+ * Create a new position on the discrete grid.
32
+ *
33
+ * @param x - X coordinate (must be integer)
34
+ * @param y - Y coordinate (must be integer)
35
+ * @throws {TypeError} If x or y are not integers
36
+ */
37
+ constructor(x: number, y: number);
38
+ /**
39
+ * Check if this position equals another position.
40
+ *
41
+ * @param other - Position to compare with
42
+ * @returns true if both x and y coordinates are equal
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const p1 = new Position(10, 20);
47
+ * const p2 = new Position(10, 20);
48
+ * const p3 = new Position(15, 20);
49
+ *
50
+ * console.log(p1.equals(p2)); // true
51
+ * console.log(p1.equals(p3)); // false
52
+ * ```
53
+ */
54
+ equals(other: Position): boolean;
55
+ /**
56
+ * Serialize position to JSON.
57
+ *
58
+ * @returns Plain object with x and y properties
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const pos = new Position(10, 20);
63
+ * const json = pos.toJSON();
64
+ * console.log(json); // { x: 10, y: 20 }
65
+ * ```
66
+ */
67
+ toJSON(): {
68
+ x: number;
69
+ y: number;
70
+ };
71
+ /**
72
+ * Deserialize position from JSON.
73
+ *
74
+ * @param json - Plain object with x and y properties
75
+ * @returns Position instance
76
+ * @throws {TypeError} If coordinates are not integers
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const json = { x: 10, y: 20 };
81
+ * const pos = Position.fromJSON(json);
82
+ * console.log(pos.x); // 10
83
+ * ```
84
+ */
85
+ static fromJSON(json: {
86
+ x: number;
87
+ y: number;
88
+ }): Position;
89
+ /**
90
+ * String representation for debugging.
91
+ *
92
+ * @returns String in format "Position(x, y)"
93
+ */
94
+ toString(): string;
95
+ }
96
+ /**
97
+ * Given a path defined by an array of 2D positions, find the best index to insert
98
+ * a target position so that the path shape is preserved as much as possible.
99
+ *
100
+ * This is used when splitting a wire at a position: we need to determine which
101
+ * segment of the path the target falls on, and return the insertion index.
102
+ *
103
+ * Algorithm:
104
+ * 1. For each consecutive pair of positions (segment), calculate the perpendicular
105
+ * distance from target to that segment
106
+ * 2. Return the index after the start of the closest segment
107
+ *
108
+ * @param positions - Array of positions defining the path (typically includes
109
+ * start endpoint, intermediate positions, and end endpoint)
110
+ * @param target - Position to insert
111
+ * @param minDistance - Optional maximum distance to consider (default: Infinity)
112
+ * @returns Index where target should be inserted (0 to positions.length)
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * // Path: (0,0) -> (10,0) -> (10,10) -> (20,10)
117
+ * const path = [
118
+ * new Position(0, 0),
119
+ * new Position(10, 0),
120
+ * new Position(10, 10),
121
+ * new Position(20, 10)
122
+ * ];
123
+ * // Target at (5, 0) - on first segment
124
+ * findPositionBestIndex(path, new Position(5, 0)); // Returns 1
125
+ * // Target at (10, 5) - on second segment
126
+ * findPositionBestIndex(path, new Position(10, 5)); // Returns 2
127
+ * ```
128
+ */
129
+ export declare function findPositionBestIndex(positions: Position[], target: Position, minDistance?: number): number;
130
+ /**
131
+ * Simplify a path by removing collinear intermediate positions.
132
+ *
133
+ * Given an ordered array of positions representing a line path, this function
134
+ * removes positions that lie on the same line as their neighbors (collinear points).
135
+ * The resulting path is visually identical but with fewer redundant points.
136
+ *
137
+ * Three points A, B, C are collinear if B lies on the line from A to C.
138
+ * When collinear, B is redundant and can be removed without changing the path shape.
139
+ *
140
+ * @param positions - Ordered array of positions representing the path
141
+ * @param tolerance - Optional tolerance for collinearity check (default: 5)
142
+ * @returns Simplified array with collinear intermediate points removed
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * // Horizontal line with redundant middle points
147
+ * const path = [
148
+ * new Position(0, 0),
149
+ * new Position(5, 0), // collinear - will be removed
150
+ * new Position(10, 0), // collinear - will be removed
151
+ * new Position(15, 0)
152
+ * ];
153
+ * simplifyPositions(path);
154
+ * // Returns: [Position(0, 0), Position(15, 0)]
155
+ *
156
+ * // L-shaped path - corner point is NOT collinear
157
+ * const lPath = [
158
+ * new Position(0, 0),
159
+ * new Position(10, 0), // corner - kept
160
+ * new Position(10, 10)
161
+ * ];
162
+ * simplifyPositions(lPath);
163
+ * // Returns: [Position(0, 0), Position(10, 0), Position(10, 10)]
164
+ * ```
165
+ */
166
+ export declare function simplifyPositions(positions: Position[], tolerance?: number): Position[];
@@ -0,0 +1,77 @@
1
+ import { IPosition3D } from './types';
2
+ /**
3
+ * 3D position.
4
+ * Positions are immutable once created.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * const pos3 = new Position3D(10, 20, 40);
9
+ * console.log(pos.x); // 10
10
+ * console.log(pos.y); // 20
11
+ * console.log(pos.y); // 40
12
+ *
13
+ * ```
14
+ */
15
+ export declare class Position3D {
16
+ readonly x: number;
17
+ readonly y: number;
18
+ readonly z: number;
19
+ /**
20
+ * Create a new 3D position.
21
+ *
22
+ * @param x - X coordinate
23
+ * @param y - Y coordinate
24
+ * @param z - Z coordinate
25
+ */
26
+ constructor(x: number, y: number, z: number);
27
+ /**
28
+ * Check if this position equals another position.
29
+ *
30
+ * @param other - Position to compare with
31
+ * @returns true if x,y and z coordinates are equal
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const p1 = new Position(10, 20, 40);
36
+ * const p2 = new Position(10, 20, 40);
37
+ * const p3 = new Position(15, 20, 40);
38
+ *
39
+ * console.log(p1.equals(p2)); // true
40
+ * console.log(p1.equals(p3)); // false
41
+ * ```
42
+ */
43
+ equals(other: Position3D): boolean;
44
+ /**
45
+ * Serialize position to JSON.
46
+ *
47
+ * @returns Plain object with x, y and z properties
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * const pos = new Position(10, 20, 40);
52
+ * const json = pos.toJSON();
53
+ * console.log(json); // { x: 10, y: 20, z: 40 }
54
+ * ```
55
+ */
56
+ toJSON(): IPosition3D;
57
+ /**
58
+ * Deserialize position from JSON.
59
+ *
60
+ * @param json - Plain object with x, y and z properties
61
+ * @returns Position instance
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const json = { x: 10, y: 20, z: 40 };
66
+ * const pos = Position.fromJSON(json);
67
+ * console.log(pos.x); // 10
68
+ * ```
69
+ */
70
+ static fromJSON(json: IPosition3D): Position3D;
71
+ /**
72
+ * String representation for debugging.
73
+ *
74
+ * @returns String in format "Position(x, y, z)"
75
+ */
76
+ toString(): string;
77
+ }
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Rotation Type for Component Orientation
3
+ * Represents orientation angle for components on the 2D grid.
4
+ * Uses integer degrees for discrete rotation values.
5
+ * @module core/utils
6
+ */
7
+ /**
8
+ * Rotation angle for component orientation.
9
+ *
10
+ * Enforces integer constraint at construction time. Typically used with
11
+ * values like 0, 90, 180, 270 degrees, but any integer is valid.
12
+ * Rotations are immutable once created.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const rotation = new Rotation(90);
17
+ * console.log(rotation.angle); // 90
18
+ *
19
+ * // Invalid: non-integer angle
20
+ * const invalid = new Rotation(45.5); // TypeError
21
+ * ```
22
+ */
23
+ export declare class Rotation {
24
+ readonly angle: number;
25
+ /**
26
+ * Create a new rotation with the specified angle.
27
+ *
28
+ * @param angle - Rotation angle in degrees (must be integer)
29
+ * @throws {TypeError} If angle is not an integer
30
+ */
31
+ constructor(angle: number);
32
+ /**
33
+ * Serialize rotation to JSON.
34
+ *
35
+ * @returns The angle value as a number
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const rotation = new Rotation(90);
40
+ * const json = rotation.toJSON();
41
+ * console.log(json); // 90
42
+ * ```
43
+ */
44
+ toJSON(): number;
45
+ /**
46
+ * Deserialize rotation from JSON.
47
+ *
48
+ * @param angle - Angle value
49
+ * @returns Rotation instance
50
+ * @throws {TypeError} If angle is not an integer
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const rotation = Rotation.fromJSON(90);
55
+ * console.log(rotation.angle); // 90
56
+ * ```
57
+ */
58
+ static fromJSON(angle: number): Rotation;
59
+ /**
60
+ * Check if this rotation equals another rotation.
61
+ *
62
+ * @param other - Rotation to compare with
63
+ * @returns true if angles are equal
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const r1 = new Rotation(90);
68
+ * const r2 = new Rotation(90);
69
+ * const r3 = new Rotation(180);
70
+ *
71
+ * console.log(r1.equals(r2)); // true
72
+ * console.log(r1.equals(r3)); // false
73
+ * ```
74
+ */
75
+ equals(other: Rotation): boolean;
76
+ /**
77
+ * String representation for debugging.
78
+ *
79
+ * @returns String in format "Rotation(angle°)"
80
+ */
81
+ toString(): string;
82
+ }
@@ -0,0 +1,24 @@
1
+ import { UUID } from './types';
2
+ export type { UUID, IPosition, IPosition3D, ICameraOptions } from './types';
3
+ /**
4
+ * Generate a new RFC 4122 UUID v4 identifier.
5
+ *
6
+ * Uses the native `crypto.randomUUID()` API when available (ES2022+ browsers,
7
+ * Node 19+). For older Node.js environments in testing, falls back to a
8
+ * polyfill implementation.
9
+ *
10
+ * @returns A newly generated UUID string
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const componentId = generateUUID();
15
+ * const wireId = generateUUID();
16
+ * console.log(componentId !== wireId); // true (collision probability: ~10^-36)
17
+ * ```
18
+ */
19
+ export declare function generateUUID(): UUID;
20
+ export { Memoize, MemoizeExpiring } from './MemoizeDecorator.js';
21
+ export { CameraOptions } from './CameraOptions';
22
+ export { Position, simplifyPositions, findPositionBestIndex } from './Position';
23
+ export { Position3D } from './Position3D';
24
+ export { Rotation } from './Rotation';
@@ -0,0 +1,35 @@
1
+ /**
2
+ * core utilities types definitions
3
+ * @module core/utils
4
+ */
5
+ /**
6
+ * Universally Unique Identifier (RFC 4122 UUID v4).
7
+ */
8
+ export type UUID = string;
9
+ /**
10
+ * 2D Position Type
11
+ * Represents a 2D position on the circuit grid
12
+ */
13
+ export type IPosition = {
14
+ x: number;
15
+ y: number;
16
+ };
17
+ /**
18
+ * 3D Position Type
19
+ * Represents a 3D position. Used for Camera placement
20
+ */
21
+ export type IPosition3D = {
22
+ x: number;
23
+ y: number;
24
+ z: number;
25
+ };
26
+ /**
27
+ * Circuit camera options (used to position camera at startup)
28
+ */
29
+ export type ICameraOptions = {
30
+ position: IPosition3D;
31
+ lookAtPosition: IPosition3D;
32
+ fov: number;
33
+ near: number;
34
+ far: number;
35
+ };