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,153 @@
1
+ import { ComponentType } from '../../../core/index.ts';
2
+ import { AnimationContext } from '../types.js';
3
+ import { IComponentVisualFactory, IFactoryRegistry } from './ComponentVisualFactory.js';
4
+ /**
5
+ * Describes a named group of component types
6
+ */
7
+ export interface ComponentGroup {
8
+ readonly id: string;
9
+ readonly label: string;
10
+ }
11
+ /**
12
+ * Builder interface for adding components to a group.
13
+ * Used as the callback parameter type in addGroup().
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * registry.addGroup('basic', 'Basic Components', (group: IComponentGroupBuilder) => {
18
+ * group
19
+ * .add(ComponentType.Battery, new BatteryVisualFactory())
20
+ * .add(ComponentType.Switch, new SwitchVisualFactory());
21
+ * });
22
+ * ```
23
+ */
24
+ export interface IComponentGroupBuilder {
25
+ add(type: ComponentType, factory: IComponentVisualFactory): IComponentGroupBuilder;
26
+ }
27
+ /**
28
+ * Extended registry interface with grouping support.
29
+ *
30
+ * Adds group management on top of the basic factory retrieval,
31
+ * allowing client UIs to build organized component palettes.
32
+ */
33
+ export interface IGroupedFactoryRegistry {
34
+ addGroup(id: string, label: string, builderCallback: (group: IComponentGroupBuilder) => void): IGroupedFactoryRegistry;
35
+ get(type: ComponentType): IComponentVisualFactory;
36
+ has(type: ComponentType): boolean;
37
+ getFallbackFactory(): IComponentVisualFactory;
38
+ getGroups(): ComponentGroup[];
39
+ getGroupOf(type: ComponentType): ComponentGroup | undefined;
40
+ getRegisteredTypes(groupId?: string): ComponentType[];
41
+ unregister(type: ComponentType): boolean;
42
+ }
43
+ /**
44
+ * Factory registry with named group support.
45
+ *
46
+ * Implements both IFactoryRegistry (backward compat) and IGroupedFactoryRegistry.
47
+ * Components may only be registered inside a group context via addGroup().
48
+ *
49
+ * Group insertion order is preserved (Map maintains insertion order).
50
+ * Duplicate group ids merge their components; the label from the first
51
+ * registration is preserved.
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * const registry = new GroupedFactoryRegistry(new DefaultVisualFactory())
56
+ * .addGroup('basic', 'Basic Components', group => group
57
+ * .add(ComponentType.Battery, new BatteryVisualFactory())
58
+ * .add(ComponentType.Switch, new SwitchVisualFactory())
59
+ * )
60
+ * .addGroup('outputs', 'Output Components', group => group
61
+ * .add(ComponentType.Lightbulb, new LightbulbVisualFactory())
62
+ * );
63
+ *
64
+ * registry.getGroups(); // [{ id: 'basic', ... }, { id: 'outputs', ... }]
65
+ * registry.getGroupOf(ComponentType.Battery); // { id: 'basic', label: 'Basic Components' }
66
+ * registry.getRegisteredTypes('basic'); // [ComponentType.Battery, ComponentType.Switch]
67
+ * registry.get(ComponentType.Battery); // BatteryVisualFactory instance
68
+ * ```
69
+ */
70
+ export declare class GroupedFactoryRegistry implements IFactoryRegistry, IGroupedFactoryRegistry {
71
+ private readonly _factories;
72
+ private readonly _fallbackFactory;
73
+ private readonly _groups;
74
+ private readonly _typeToGroupId;
75
+ /**
76
+ * Create a new grouped factory registry.
77
+ *
78
+ * @param fallbackFactory - Factory to use for unregistered component types
79
+ * @throws {TypeError} If fallbackFactory is null or undefined
80
+ */
81
+ constructor(fallbackFactory: IComponentVisualFactory);
82
+ /**
83
+ * Add a named group and register component factories within it.
84
+ *
85
+ * If a group with the same id already exists, the new components are merged
86
+ * into it and the original label is preserved.
87
+ *
88
+ * @param id - Unique group identifier
89
+ * @param label - Human-readable group display name
90
+ * @param builderCallback - Callback receiving a builder for adding components
91
+ * @throws {TypeError} If id or label is empty/whitespace
92
+ * @returns this (for chaining)
93
+ */
94
+ addGroup(id: string, label: string, builderCallback: (group: IComponentGroupBuilder) => void): this;
95
+ /**
96
+ * Retrieve the factory for a component type.
97
+ *
98
+ * @returns Factory, or the fallback factory if type not registered.
99
+ * Never returns null or undefined.
100
+ */
101
+ get(type: ComponentType): IComponentVisualFactory;
102
+ /**
103
+ * Check if a factory is registered for a component type.
104
+ *
105
+ * @returns true if explicitly registered, false if would use fallback
106
+ */
107
+ has(type: ComponentType): boolean;
108
+ /**
109
+ * Get the fallback factory used for unregistered types.
110
+ */
111
+ getFallbackFactory(): IComponentVisualFactory;
112
+ /**
113
+ * Get all defined groups in insertion order.
114
+ *
115
+ * @returns New array of ComponentGroup objects (safe to mutate)
116
+ */
117
+ getGroups(): ComponentGroup[];
118
+ /**
119
+ * Get the group a component type belongs to.
120
+ *
121
+ * @param type - Component type to look up
122
+ * @returns ComponentGroup, or undefined if type is not registered
123
+ */
124
+ getGroupOf(type: ComponentType): ComponentGroup | undefined;
125
+ /**
126
+ * Get registered component types, optionally filtered by group.
127
+ *
128
+ * @param groupId - If provided, returns only types in that group
129
+ * @returns New array of ComponentType values (safe to mutate).
130
+ * Returns empty array if groupId is unknown.
131
+ */
132
+ getRegisteredTypes(groupId?: string): ComponentType[];
133
+ /**
134
+ * Unregister a factory for a component type.
135
+ *
136
+ * The type is removed from its group's list and from the reverse lookup.
137
+ * The group record itself is preserved even if it becomes empty.
138
+ *
139
+ * @param type - Component type to remove
140
+ * @returns true if factory was registered and removed, false otherwise
141
+ */
142
+ unregister(type: ComponentType): boolean;
143
+ /**
144
+ * Fan out animation context to all registered factories and the fallback.
145
+ */
146
+ setAnimationContext(ctx: AnimationContext | null): void;
147
+ /**
148
+ * Not supported. Use addGroup() to register components within a named group.
149
+ *
150
+ * @throws {Error} Always throws
151
+ */
152
+ register(_type: ComponentType, _factory: IComponentVisualFactory): IFactoryRegistry;
153
+ }
@@ -0,0 +1,54 @@
1
+ import { ComponentVisualFactoryBase } from '../ComponentVisualFactory';
2
+ import { Component, ComponentState } from '../../../../core/index.ts';
3
+ import { ConfigFormDefinition, VisualContext } from '../../types';
4
+ import * as THREE from 'three';
5
+ /**
6
+ * Visual factory for Adder components.
7
+ *
8
+ * Creates:
9
+ * - An `envelope` rectangular frame (EmptyRectangleGeometry)
10
+ * - A horizontal `separator` box dividing upper/lower chambers
11
+ * - A `sumFiller` (RectangleWithNailGeometry) in the upper chamber;
12
+ * its material is animated blue↔red following the sum output state
13
+ * - A `plus` box inside the sumFiller (visual cue)
14
+ * - A `carryFiller` (RectangleWithNailGeometry) box in the lower chamber; its material is animated
15
+ * blue↔red following the carry output state
16
+ * - pin groups for vcc, inputA, inputB, sum, carry, gnd
17
+ *
18
+ * Animation:
19
+ * - sumFiller ↔ blue/red based on sum output (current/next state)
20
+ * - carryFiller ↔ blue/red based on carry output (current/next state)
21
+ */
22
+ export declare class AdderVisualFactory extends ComponentVisualFactoryBase {
23
+ private readonly ENVELOPE_GEOM;
24
+ /** Horizontal separator splitting upper/lower chambers at Z=0 */
25
+ private readonly SEPARATOR_GEOM;
26
+ private readonly SEPARATOR_SIDE_GEOM;
27
+ private readonly CELL_FILLER_GEOM;
28
+ /** Small box inside sumFiller (visual cue for the XOR "+") */
29
+ private readonly PLUS_GEOM;
30
+ protected readonly FILLER_COLOR_HIGH: THREE.Color;
31
+ protected readonly FILLER_COLOR_LOW: THREE.Color;
32
+ protected readonly FILLER_EMISSIVE_HIGH_INTENSITY = 0.5;
33
+ protected readonly FILLER_EMISSIVE_LOW_INTENSITY = 0.2;
34
+ constructor();
35
+ createVisual(component: Component, context: VisualContext): THREE.Object3D;
36
+ protected createPinsVisual(component: Component, context: VisualContext, group: THREE.Group): void;
37
+ getConfigFormDefinition(config?: Map<string, string>): ConfigFormDefinition | null;
38
+ mapCoreConfigToForm(config: Map<string, string>): Map<string, any>;
39
+ mapFormToCoreConfig(formData: Map<string, any>): Map<string, string>;
40
+ updateAnimation(object3D: THREE.Object3D, state: ComponentState | null): void;
41
+ private _setFillerColor;
42
+ private _ensureClonedFillerMaterial;
43
+ private _restoreSharedFillerMaterial;
44
+ private _cleanupMixer;
45
+ /**
46
+ * Animate sumFiller and carryFiller fill colors over the transition span.
47
+ * Builds a single AnimationClip with up to two target tracks per filler
48
+ * (color, emissive, emissiveIntensity) — only for fillers whose value changes.
49
+ */
50
+ private _animateFillers;
51
+ private _pushFillerTracks;
52
+ /** Find a child mesh by its userData.part name */
53
+ protected findPartMesh(object3D: THREE.Object3D, part: string): THREE.Mesh | null;
54
+ }
@@ -0,0 +1,45 @@
1
+ import { ComponentVisualFactoryBase } from '../ComponentVisualFactory';
2
+ import { Component, ComponentState } from '../../../../core/index.ts';
3
+ import { ConfigFormDefinition, VisualContext } from '../../types';
4
+ import * as THREE from 'three';
5
+ /**
6
+ * Visual factory for EightBitAdder components.
7
+ *
8
+ * Creates:
9
+ * - An `envelope` frame (KuKoGeometry)
10
+ * - A vertical `separator` dividing carry/sum cells
11
+ * - 7 horizontal separators dividing ith cells
12
+ * - 16 cells carry i / sum i representing state
13
+ * cells materials are animated blue↔red following the component state
14
+ * - pin groups for vcc, 2*8 inputs, 8*sums, carryIn, carryOut and gnd
15
+ *
16
+ */
17
+ export declare class EightBitAdderVisualFactory extends ComponentVisualFactoryBase {
18
+ private readonly ENVELOPE_GEOM;
19
+ private readonly VERTICAL_SEPARATOR_GEOM;
20
+ private readonly HORIZONTAL_SEPARATOR_GEOM;
21
+ private readonly CELL_FILLER_GEOM;
22
+ protected readonly FILLER_COLOR_HIGH: THREE.Color;
23
+ protected readonly FILLER_COLOR_LOW: THREE.Color;
24
+ protected readonly FILLER_EMISSIVE_HIGH_INTENSITY = 0.5;
25
+ protected readonly FILLER_EMISSIVE_LOW_INTENSITY = 0.2;
26
+ constructor();
27
+ createVisual(component: Component, context: VisualContext): THREE.Object3D;
28
+ protected createPinsVisual(component: Component, context: VisualContext, group: THREE.Group): void;
29
+ getConfigFormDefinition(config?: Map<string, string>): ConfigFormDefinition | null;
30
+ mapCoreConfigToForm(config: Map<string, string>): Map<string, any>;
31
+ mapFormToCoreConfig(formData: Map<string, any>): Map<string, string>;
32
+ updateAnimation(object3D: THREE.Object3D, state: ComponentState | null): void;
33
+ private _setCellColor;
34
+ private _ensureClonedMaterial;
35
+ private _restoreSharedMaterial;
36
+ private _cleanupMixer;
37
+ /** Collect all 16 cell meshes with their state bit position. */
38
+ private _findCellMeshes;
39
+ /**
40
+ * Animate the 16 cells over the transition span.
41
+ * Builds a single AnimationClip with tracks only for cells whose bit changes.
42
+ */
43
+ private _animateCells;
44
+ private _pushCellTracks;
45
+ }
@@ -0,0 +1,63 @@
1
+ import { ComponentVisualFactoryBase } from '../ComponentVisualFactory';
2
+ import { Component, ComponentState } from '../../../../core/index.ts';
3
+ import { ConfigFormDefinition, VisualContext } from '../../types';
4
+ import * as THREE from 'three';
5
+ /**
6
+ * Visual factory for EightBitOnesComplement components.
7
+ *
8
+ * Creates:
9
+ * - An `envelope` frame (EmptyRectangleGeometry)
10
+ * - A vertical `separator` dividing flag area / outputs cells
11
+ * - 7 horizontal separators dividing ith cells
12
+ * - 2 rectangles with nail filler, 3 animated box geometry and 2 filler boxes for flag area
13
+ * - 8 cells outputs i representing output state
14
+ * cells materials are animated blue↔red following the component state
15
+ * - pin groups for vcc, 8 inputs, 8*outputs and gnd
16
+ *
17
+ */
18
+ export declare class EightBitOnesComplementVisualFactory extends ComponentVisualFactoryBase {
19
+ private readonly ENVELOPE_GEOM;
20
+ private readonly VERTICAL_SEPARATOR_GEOM;
21
+ private readonly HORIZONTAL_SEPARATOR_GEOM;
22
+ private readonly CELL_FILLER_GEOM;
23
+ private readonly INDICATOR_MINUS_GEOM;
24
+ private readonly INDICATOR_PLUS_GEOM;
25
+ private readonly INDICATOR_FILLER_GEOM;
26
+ protected readonly FILLER_COLOR_HIGH: THREE.Color;
27
+ protected readonly FILLER_COLOR_LOW: THREE.Color;
28
+ protected readonly FILLER_COLOR_NEUTRAL: THREE.Color;
29
+ protected readonly FILLER_EMISSIVE_BLACK: THREE.Color;
30
+ protected readonly FILLER_EMISSIVE_HIGH_INTENSITY = 0.5;
31
+ protected readonly FILLER_EMISSIVE_LOW_INTENSITY = 0.2;
32
+ protected readonly FILLER_EMISSIVE_NEUTRAL_INTENSITY = 0;
33
+ constructor();
34
+ createVisual(component: Component, context: VisualContext): THREE.Object3D;
35
+ protected createPinsVisual(component: Component, context: VisualContext, group: THREE.Group): void;
36
+ getConfigFormDefinition(config?: Map<string, string>): ConfigFormDefinition | null;
37
+ mapCoreConfigToForm(config: Map<string, string>): Map<string, any>;
38
+ mapFormToCoreConfig(formData: Map<string, any>): Map<string, string>;
39
+ updateAnimation(object3D: THREE.Object3D, state: ComponentState | null): void;
40
+ /**
41
+ * Resolve the target color state for a cell given its kind and the bit value:
42
+ * - `output`: high→red, low→blue
43
+ * - `minus`: high→blue, low→red (inverted vs output — blue minus = complement active)
44
+ * - `plus`: high→white (blends with envelope, hiding the +), low→red
45
+ */
46
+ private _cellTarget;
47
+ private _setCellColor;
48
+ private _ensureClonedMaterial;
49
+ private _restoreSharedMaterial;
50
+ private _cleanupMixer;
51
+ /**
52
+ * Collect all animated cells (8 outputs + minus + 2 plus parts).
53
+ * Output cells read bits 0–7; the three indicator cells all read bit 8
54
+ * (the invert flag) but render it with different color rules.
55
+ */
56
+ private _findCellMeshes;
57
+ /**
58
+ * Animate all cells over the transition span.
59
+ * Builds a single AnimationClip with tracks only for cells whose bit changes.
60
+ */
61
+ private _animateCells;
62
+ private _pushCellTracks;
63
+ }
@@ -0,0 +1,55 @@
1
+ import { ComponentVisualFactoryBase } from '../ComponentVisualFactory';
2
+ import { Component, ComponentState } from '../../../../core/index.ts';
3
+ import { ConfigFormDefinition, VisualContext } from '../../types';
4
+ import * as THREE from 'three';
5
+ /**
6
+ * Visual factory for Half Adder components.
7
+ *
8
+ * Creates:
9
+ * - An `envelope` rectangular frame (EmptyRectangleGeometry)
10
+ * - A horizontal `separator` box dividing upper/lower chambers
11
+ * - A `sumFiller` (RectangleWithNailGeometry) in the upper chamber;
12
+ * its material is animated blue↔red following the sum output state
13
+ * - A `halfPlus` small box inside the sumFiller (visual cue)
14
+ * - A `carryFiller` box in the lower chamber; its material is animated
15
+ * blue↔red following the carry output state
16
+ * - pin groups for vcc, inputA, inputB, sum, carry, gnd
17
+ *
18
+ * Animation:
19
+ * - sumFiller ↔ blue/red based on sum output (current/next state)
20
+ * - carryFiller ↔ blue/red based on carry output (current/next state)
21
+ */
22
+ export declare class HalfAdderVisualFactory extends ComponentVisualFactoryBase {
23
+ private readonly ENVELOPE_GEOM;
24
+ /** Horizontal separator splitting upper/lower chambers at Z=0 */
25
+ private readonly SEPARATOR_GEOM;
26
+ private readonly SEPARATOR_SIDE_GEOM;
27
+ private readonly SUM_FILLER_GEOM;
28
+ /** Small box inside sumFiller (visual cue for the XOR "+") */
29
+ private readonly HALF_PLUS_GEOM;
30
+ private readonly CARRY_FILLER_GEOM;
31
+ protected readonly FILLER_COLOR_HIGH: THREE.Color;
32
+ protected readonly FILLER_COLOR_LOW: THREE.Color;
33
+ protected readonly FILLER_EMISSIVE_HIGH_INTENSITY = 0.5;
34
+ protected readonly FILLER_EMISSIVE_LOW_INTENSITY = 0.2;
35
+ constructor();
36
+ createVisual(component: Component, context: VisualContext): THREE.Object3D;
37
+ protected createPinsVisual(component: Component, context: VisualContext, group: THREE.Group): void;
38
+ getConfigFormDefinition(config?: Map<string, string>): ConfigFormDefinition | null;
39
+ mapCoreConfigToForm(config: Map<string, string>): Map<string, any>;
40
+ mapFormToCoreConfig(formData: Map<string, any>): Map<string, string>;
41
+ updateAnimation(object3D: THREE.Object3D, state: ComponentState | null): void;
42
+ private _setFillerColor;
43
+ private _ensureClonedFillerMaterial;
44
+ private _restoreSharedFillerMaterial;
45
+ private _cleanupMixer;
46
+ /**
47
+ * Animate sumFiller and carryFiller fill colors over the transition span.
48
+ * Builds a single AnimationClip with up to two target tracks per filler
49
+ * (color, emissive, emissiveIntensity) — only for fillers whose value changes.
50
+ */
51
+ private _animateFillers;
52
+ private _pushFillerTracks;
53
+ /** Find a child mesh by its userData.part name */
54
+ protected findPartMesh(object3D: THREE.Object3D, part: string): THREE.Mesh | null;
55
+ }
@@ -0,0 +1,4 @@
1
+ export { AdderVisualFactory } from './AdderVisualFactory';
2
+ export { HalfAdderVisualFactory } from './HalfAdderVisualFactory';
3
+ export { EightBitAdderVisualFactory } from './EightBitAdderVisualFactory';
4
+ export { EightBitOnesComplementVisualFactory } from './EightBitOnesComplementVisualFactory';
@@ -0,0 +1,13 @@
1
+ import { ComponentVisualFactoryBase } from '../ComponentVisualFactory';
2
+ import { Component } from '../../../../core/index.ts';
3
+ import { VisualContext } from '../../types';
4
+ import * as THREE from 'three';
5
+ /**
6
+ * Visual factory for Battery components
7
+ */
8
+ export declare class BatteryVisualFactory extends ComponentVisualFactoryBase {
9
+ private readonly BATTERY_GEOMETRY;
10
+ constructor();
11
+ createVisual(component: Component, context: VisualContext): THREE.Object3D;
12
+ private createPinsVisual;
13
+ }
@@ -0,0 +1,79 @@
1
+ import { ComponentVisualFactoryBase } from '../ComponentVisualFactory';
2
+ import { Component, ComponentState } from '../../../../core/index.ts';
3
+ import { ConfigFormDefinition, VisualContext } from '../../types';
4
+ import * as THREE from 'three';
5
+ /**
6
+ * Visual factory for Clock
7
+ */
8
+ export declare class ClockVisualFactory extends ComponentVisualFactoryBase {
9
+ /** Shared Clock envelope geometry */
10
+ private readonly ENVELOPE_GEOMETRY;
11
+ /** Shared Clock hand geometry */
12
+ private readonly HAND_GEOMETRY;
13
+ /** Shared Clock area geometry */
14
+ private readonly AREA_GEOMETRY;
15
+ private readonly RED_AREA_MAT;
16
+ private readonly BLUE_AREA_MAT;
17
+ private readonly HIGH_TICK_ROTATION;
18
+ private readonly LOW_TICK_ROTATION;
19
+ constructor();
20
+ createVisual(component: Component, context: VisualContext): THREE.Object3D;
21
+ private createPinsVisual;
22
+ private createHandGroup;
23
+ /**
24
+ * Get config form definition for Clock
25
+ *
26
+ * @param config - config
27
+ * @returns Form definition
28
+ */
29
+ getConfigFormDefinition(_config?: Map<string, string>): ConfigFormDefinition | null;
30
+ /**
31
+ * Map core config to form data
32
+ *
33
+ * @param config - Core component config
34
+ * @returns Form data
35
+ */
36
+ mapCoreConfigToForm(config: Map<string, string>): Map<string, any>;
37
+ /**
38
+ * Map form data to core config
39
+ *
40
+ * @param formData - Form data
41
+ * @returns Core config
42
+ */
43
+ mapFormToCoreConfig(formData: Map<string, any>): Map<string, string>;
44
+ updateFromConfiguration(object3D: THREE.Object3D, config: Map<string, string>): void;
45
+ /**
46
+ * Update Clock animation based on simulation state.
47
+ *
48
+ * When state is non-null: animates hand rotation toward the current state's target.
49
+ * If the state has a planned transition (hasExpiration), creates a smooth animation
50
+ * from the current visual rotation to the target using Three.js AnimationMixer.
51
+ * Otherwise snaps to the target position.
52
+ *
53
+ * When state is null (leaving simulation): stops all animations, cleans up mixer,
54
+ * and resets hand to config-based default rotation.
55
+ *
56
+ * @param object3D - The Object3D created by createVisual()
57
+ * @param state - The Clock's current simulation state, or null to reset
58
+ */
59
+ updateAnimation(object3D: THREE.Object3D, state: ComponentState | null): void;
60
+ /**
61
+ * Create a smooth animation from current hand rotation to targetRotation
62
+ */
63
+ private _animateHand;
64
+ /**
65
+ * Stop all animations, clean up mixer, and reset hand to config-based default rotation.
66
+ */
67
+ private _cleanupMixer;
68
+ private getStateRotation;
69
+ /**
70
+ * Find the hand group mesh within the component group
71
+ *
72
+ * @param object3D - The Object3D group created by createVisual()
73
+ * @returns The hand mesh if found, null otherwise
74
+ *
75
+ * @remarks
76
+ * Searches for a mesh with userData.part === 'hand'
77
+ */
78
+ private findHandGroup;
79
+ }
@@ -0,0 +1,87 @@
1
+ import { ComponentVisualFactoryBase } from '../ComponentVisualFactory';
2
+ import { Component, ComponentState } from '../../../../core/index.ts';
3
+ import { ConfigFormDefinition, VisualContext } from '../../types';
4
+ import * as THREE from 'three';
5
+ /**
6
+ * Visual factory for DoubleThrowSwitch (SPDT) components
7
+ *
8
+ * Creates:
9
+ * - Input1 pin group
10
+ * - Input2 pin group
11
+ * - Output pin group
12
+ * - Contactor (box, rotatable for animation)
13
+ * - Component hitbox for raycasting
14
+ *
15
+ * Animation:
16
+ * - Smooth rotation of contactor between input1/input2 via AnimationMixer
17
+ * - Contactor material color reflects output pin state (voltage/current)
18
+ * - Supports mid-transition interruption (re-toggle during transition)
19
+ */
20
+ export declare class DoubleThrowSwitchVisualFactory extends ComponentVisualFactoryBase {
21
+ /** Rotation for switch connected to input1 */
22
+ private readonly INPUT1_ROTATION;
23
+ /** Rotation for switch connected to input2 */
24
+ private readonly INPUT2_ROTATION;
25
+ private readonly CONTACTOR_GEOMETRY;
26
+ /** Contactor color when output has both voltage and current */
27
+ private readonly COLOR_VOLTAGE_CURRENT;
28
+ /** Contactor color when output has current only */
29
+ private readonly COLOR_CURRENT;
30
+ /** Contactor color when output has voltage only */
31
+ private readonly COLOR_VOLTAGE;
32
+ /** Contactor color when output has neither */
33
+ private readonly COLOR_NONE;
34
+ constructor();
35
+ createVisual(component: Component, context: VisualContext): THREE.Object3D;
36
+ private createPinsVisual;
37
+ /**
38
+ * Get config form definition for DoubleThrowSwitch
39
+ *
40
+ * @returns Form definition with initialState, transitionSpan and size
41
+ */
42
+ getConfigFormDefinition(): ConfigFormDefinition | null;
43
+ /**
44
+ * Map core config to form data
45
+ * Converts "input1"/"input2" strings to boolean
46
+ */
47
+ mapCoreConfigToForm(config: Map<string, string>): Map<string, any>;
48
+ /**
49
+ * Map form data to core config
50
+ * Converts boolean to "input1"/"input2" strings
51
+ */
52
+ mapFormToCoreConfig(formData: Map<string, any>): Map<string, string>;
53
+ updateFromConfiguration(object3D: THREE.Object3D, config: Map<string, string>): void;
54
+ /**
55
+ * Update switch animation based on simulation state.
56
+ *
57
+ * - null state / no context: cleanup mixer, reset to config default
58
+ * - paused/initial + transitional: snap to start rotation
59
+ * - paused/initial + stable: snap to state rotation
60
+ * - playing + transitional: smooth rotation animation
61
+ * - playing + stable: snap to final rotation, cleanup mixer
62
+ */
63
+ updateAnimation(object3D: THREE.Object3D, state: ComponentState | null): void;
64
+ /** Maps stable state → target rotation */
65
+ private _getStateRotation;
66
+ /** Maps transitional state → the rotation it came FROM */
67
+ private _getStartRotation;
68
+ /**
69
+ * Create smooth rotation + color animations for transitional states.
70
+ * Rotation clip: current → target state rotation (persists across updateAnimation calls)
71
+ * Color clip: current contactor color → white (stopped on next updateAnimation so pin state takes over)
72
+ */
73
+ private _animateContactor;
74
+ /**
75
+ * Stop the color fade animation so _updateContactorColor can set color from pin state.
76
+ */
77
+ private _stopColorAnimation;
78
+ /**
79
+ * Stop all animations, clean up mixer, reset to config default rotation.
80
+ */
81
+ private _cleanupMixer;
82
+ private _ensureClonedMaterial;
83
+ private _restoreSharedMaterial;
84
+ private _updateContactorColor;
85
+ private findContactorGroup;
86
+ private _findContactorMesh;
87
+ }