velxio/frontend/src/components/velxio-components/OpAmpElements.ts

84 lines
3.2 KiB
TypeScript
Raw Normal View History

feat: expand SPICE component catalog (fases 9 + 10) Adds 44 SPICE mappers, 58 custom metadata entries, and 12 visual Web Components covering logic gates, transistors, op-amps, regulators, sources, electromechanical parts and integrated-circuit packaging. Fase 9 — component catalog expansion ------------------------------------ - 7 logic gates (AND/OR/NAND/NOR/XOR/XNOR + NOT) as SPICE B-sources - 8 multi-input gates (AND/OR/NAND/NOR with 3 and 4 inputs) - 9 transistors: 5 BJTs (incl. PNP 2N3906/BC557) + 4 MOSFETs (incl. P-channel IRF9540/FQP27P06). NMOS refactored from Level=3 W=0.1 (hangs ngspice) to Level=1 with sane W/L - 5 op-amps: LM358, LM741, TL072, LM324 with per-chip saturation rails + opamp-ideal - 4 linear regulators (7805, 7812, 7905, LM317) with dropout - 3 batteries (9V, AA, coin-cell) with realistic ESR - Signal generator (sine / square / DC) - 2 Schottky diodes (1N5817, 1N5819) + photodiode (lux-driven current source) Fase 10 — electromechanical + ICs --------------------------------- - Relay (SPDT): coil + L + S-switch with native hysteresis + flyback diode, inverted-control trick for the NC contact - Optocouplers 4N25 and PC817 (LED + CCCS with CTR=0.5 / 1.0) - 7 74HC ICs as DIP-14 packages emitting 4 or 6 B-sources per component (first mapper pattern emitting multiple device cards) - 3 flip-flops (D, T, JK) — digital-sim only (edge detection is not representable in ngspice .op) - L293D dual H-bridge motor driver Infrastructure -------------- - scripts/component-overrides.json gains a _customComponents[] array that lets new Velxio-only parts survive metadata regeneration (previously applyOverrides() could only patch wokwi-elements components that had already been scanned) - scripts/generate-component-metadata.ts injects custom entries before the patch loop - New ComponentCategory values: 'logic', 'analog', 'electromech' - frontend/src/components/DynamicComponent.tsx PASSIVE tracing extended from just ['resistor','resistor-us'] to 9 two-terminal passives with per-part pin name maps - New CI workflow test-circuit.yml runs the sandbox on push/PR - frontend-tests.yml regenerates metadata and fails if committed JSON is stale - Documented 2 new ngspice gotchas in circuit-emulation-gotchas.md: unicode in netlist titles silently hangs the parser, and MOSFET Level=3 + W=0.1m causes .op to hang - 164/164 sandbox tests passing in ~9 s (was 88 pre-fase-9) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 06:44:18 +07:00
/**
* OpAmpElements.ts Custom Web Components for operational amplifier packages.
*
* Each op-amp is drawn as the classic triangle schematic symbol with:
* - IN+ (non-inverting input) on the left upper
* - IN- (inverting input) on the left lower
* - OUT on the right tip
*
* Tags defined:
* wokwi-opamp-ideal generic ideal op-amp (already used by Velxio)
* wokwi-opamp-lm358 dual rail-to-rail, single supply
* wokwi-opamp-lm741 single, conventional
* wokwi-opamp-tl072 dual, JFET input (audio)
* wokwi-opamp-lm324 quad, rail-to-rail output
*
* Pin layout (CSS pixels, 80 × 64):
* IN+ (0, 12) IN- (0, 52) OUT (80, 32)
*/
const FILL = '#eef3fa';
const STROKE = '#2a2a2a';
const LEAD = '#555555';
const LABEL = '#333333';
const STYLE = ':host{display:inline-block;line-height:0}';
function opampPinInfo() {
return [
{ name: 'IN+', x: 0, y: 12, number: 1, signals: [] as string[] },
{ name: 'IN-', x: 0, y: 52, number: 2, signals: [] as string[] },
{ name: 'OUT', x: 80, y: 32, number: 3, signals: [] as string[] },
];
}
function opampSvg(label: string): string {
return `
<style>${STYLE}</style>
<svg width="80" height="72" xmlns="http://www.w3.org/2000/svg">
<!-- Input leads -->
<line x1="0" y1="12" x2="18" y2="12" stroke="${LEAD}" stroke-width="2"/>
<line x1="0" y1="52" x2="18" y2="52" stroke="${LEAD}" stroke-width="2"/>
<!-- Output lead -->
<line x1="62" y1="32" x2="80" y2="32" stroke="${LEAD}" stroke-width="2"/>
<!-- Triangle body -->
<polygon points="18,4 18,60 62,32" fill="${FILL}" stroke="${STROKE}" stroke-width="1.5"/>
<!-- + and signs inside -->
<text x="24" y="16" font-family="sans-serif" font-size="10" fill="${STROKE}" font-weight="bold">+</text>
<text x="24" y="56" font-family="sans-serif" font-size="12" fill="${STROKE}" font-weight="bold"></text>
<!-- Pin labels -->
<text x="2" y="10" font-family="sans-serif" font-size="6" fill="${LABEL}">IN+</text>
<text x="2" y="50" font-family="sans-serif" font-size="6" fill="${LABEL}">IN-</text>
<text x="64" y="28" font-family="sans-serif" font-size="6" fill="${LABEL}">OUT</text>
<!-- Part number -->
<text x="40" y="70" text-anchor="middle" font-family="sans-serif" font-size="7" fill="${LABEL}" font-weight="bold">${label}</text>
</svg>`;
}
function makeOpampClass(label: string) {
return class extends HTMLElement {
readonly pinInfo = opampPinInfo();
constructor() {
super();
this.attachShadow({ mode: 'open' }).innerHTML = opampSvg(label);
}
};
}
const OpAmpIdeal = makeOpampClass('IDEAL');
const OpAmpLM358 = makeOpampClass('LM358');
const OpAmpLM741 = makeOpampClass('LM741');
const OpAmpTL072 = makeOpampClass('TL072');
const OpAmpLM324 = makeOpampClass('LM324');
function def(tag: string, cls: CustomElementConstructor) {
if (!customElements.get(tag)) customElements.define(tag, cls);
}
def('wokwi-opamp-ideal', OpAmpIdeal);
def('wokwi-opamp-lm358', OpAmpLM358);
def('wokwi-opamp-lm741', OpAmpLM741);
def('wokwi-opamp-tl072', OpAmpTL072);
def('wokwi-opamp-lm324', OpAmpLM324);
export {};