/** * InlineComponentSVGs — simple schematic-style icons for the components * whose SVG isn't pre-rendered into /component-svgs/ (transistors, MOSFETs, * diodes, capacitors, relays, optocouplers, op-amps, logic gates, signal * generators, batteries, regulators, motor drivers, etc.). * * Used by CircuitPreview.tsx to keep the /examples gallery cards visually * representative even for parts that weren't extracted from wokwi-elements. * * Each renderer receives {w, h} (canvas-space size) and fills its box with * a recognizable schematic glyph. Sizes chosen to match the on-canvas size * of the corresponding custom web component, so bounding boxes line up. */ import React from 'react'; interface InlineSVGProps { w: number; h: number; } // ─── Transistors ─────────────────────────────────────────────────────────── const BjtNpn: React.FC = ({ w, h }) => ( NPN ); const BjtPnp: React.FC = ({ w, h }) => ( PNP ); const Mosfet: React.FC = ({ w, h }) => ( MOS ); // ─── Diodes ──────────────────────────────────────────────────────────────── function diodeGlyph(label: string, w: number, h: number): React.ReactElement { return ( {label} ); } const Diode1N4007: React.FC = ({ w, h }) => diodeGlyph('1N4007', w, h); const Diode1N5817: React.FC = ({ w, h }) => diodeGlyph('1N5817', w, h); const DiodeZener: React.FC = ({ w, h }) => diodeGlyph('ZD', w, h); // ─── Passives ────────────────────────────────────────────────────────────── const Capacitor: React.FC = ({ w, h }) => ( C ); // ─── Relay ───────────────────────────────────────────────────────────────── const Relay: React.FC = ({ w, h }) => ( {[24, 34, 44, 54, 64, 74].map(cy => ( ))} RELAY ); // ─── Optocoupler ─────────────────────────────────────────────────────────── function optoGlyph(label: string, w: number, h: number): React.ReactElement { return ( {label} ); } const Opto4N25: React.FC = ({ w, h }) => optoGlyph('4N25', w, h); // ─── DIP IC block (motor driver, etc.) ───────────────────────────────────── function dipGlyph(label: string, w: number, h: number): React.ReactElement { return ( {[12, 20, 28, 36, 44, 52, 60, 68].map(y => ( ))} {label} ); } const MotorDriverL293D: React.FC = ({ w, h }) => dipGlyph('L293D', w, h); // ─── Op-amp ──────────────────────────────────────────────────────────────── function opampGlyph(label: string, w: number, h: number): React.ReactElement { return ( − + {label} ); } const OpampLM358: React.FC = ({ w, h }) => opampGlyph('LM358', w, h); // ─── Logic gates ─────────────────────────────────────────────────────────── function gateShape( shape: 'and' | 'nand' | 'or' | 'nor' | 'xor' | 'xnor' | 'not', w: number, h: number, ): React.ReactElement { const negated = shape === 'nand' || shape === 'nor' || shape === 'xnor' || shape === 'not'; const exclusive = shape === 'xor' || shape === 'xnor'; const isOr = shape === 'or' || shape === 'nor' || shape === 'xor' || shape === 'xnor'; const isNot = shape === 'not'; const body = isNot ? : isOr ? : ; return ( {!isNot && } {body} {exclusive && } {negated && } ); } const GateAnd: React.FC = ({ w, h }) => gateShape('and', w, h); const GateNand: React.FC = ({ w, h }) => gateShape('nand', w, h); const GateOr: React.FC = ({ w, h }) => gateShape('or', w, h); const GateNor: React.FC = ({ w, h }) => gateShape('nor', w, h); const GateXor: React.FC = ({ w, h }) => gateShape('xor', w, h); const GateXnor: React.FC = ({ w, h }) => gateShape('xnor', w, h); const GateNot: React.FC = ({ w, h }) => gateShape('not', w, h); // ─── Power / instruments ─────────────────────────────────────────────────── function reg3pinGlyph(label: string, w: number, h: number): React.ReactElement { return ( {label} ); } const Reg7805: React.FC = ({ w, h }) => reg3pinGlyph('7805', w, h); const RegLM317: React.FC = ({ w, h }) => reg3pinGlyph('LM317', w, h); const Battery9V: React.FC = ({ w, h }) => ( 9V ); const SignalGenerator: React.FC = ({ w, h }) => ( SIG GEN ); function meterGlyph(label: string, w: number, h: number): React.ReactElement { return ( {label} ); } const Voltmeter: React.FC = ({ w, h }) => meterGlyph('V', w, h); const Ammeter: React.FC = ({ w, h }) => meterGlyph('A', w, h); // ─── Registry ────────────────────────────────────────────────────────────── interface InlineEntry { component: React.FC; w: number; h: number; } export const INLINE_SVGS: Record = { // BJTs 'wokwi-bjt-2n2222': { component: BjtNpn, w: 72, h: 72 }, 'wokwi-bjt-2n3904': { component: BjtNpn, w: 72, h: 72 }, 'wokwi-bjt-2n3906': { component: BjtPnp, w: 72, h: 72 }, 'wokwi-bjt-bc547': { component: BjtNpn, w: 72, h: 72 }, // MOSFETs 'wokwi-mosfet-2n7000': { component: Mosfet, w: 72, h: 72 }, 'wokwi-mosfet-irf540n': { component: Mosfet, w: 72, h: 72 }, 'wokwi-mosfet-bs170': { component: Mosfet, w: 72, h: 72 }, // Diodes 'wokwi-diode': { component: Diode1N4007, w: 72, h: 40 }, 'wokwi-diode-1n4007': { component: Diode1N4007, w: 72, h: 40 }, 'wokwi-diode-1n4148': { component: Diode1N4007, w: 72, h: 40 }, 'wokwi-diode-1n5817': { component: Diode1N5817, w: 72, h: 40 }, 'wokwi-diode-1n5819': { component: Diode1N5817, w: 72, h: 40 }, 'wokwi-zener-1n4733': { component: DiodeZener, w: 72, h: 40 }, // Passives 'wokwi-capacitor': { component: Capacitor, w: 56, h: 36 }, 'wokwi-inductor': { component: Capacitor, w: 56, h: 36 }, // Electromechanical 'wokwi-relay': { component: Relay, w: 96, h: 96 }, // Optocouplers 'wokwi-opto-4n25': { component: Opto4N25, w: 80, h: 64 }, 'wokwi-opto-pc817': { component: Opto4N25, w: 80, h: 64 }, // IC 'wokwi-motor-driver-l293d': { component: MotorDriverL293D, w: 100, h: 80 }, 'wokwi-ic-74hc00': { component: MotorDriverL293D, w: 100, h: 80 }, 'wokwi-ic-74hc04': { component: MotorDriverL293D, w: 100, h: 80 }, 'wokwi-ic-74hc08': { component: MotorDriverL293D, w: 100, h: 80 }, 'wokwi-ic-74hc14': { component: MotorDriverL293D, w: 100, h: 80 }, 'wokwi-ic-74hc32': { component: MotorDriverL293D, w: 100, h: 80 }, 'wokwi-ic-74hc86': { component: MotorDriverL293D, w: 100, h: 80 }, // Op-amps 'wokwi-opamp-ideal': { component: OpampLM358, w: 80, h: 72 }, 'wokwi-opamp-lm358': { component: OpampLM358, w: 80, h: 72 }, 'wokwi-opamp-lm741': { component: OpampLM358, w: 80, h: 72 }, 'wokwi-opamp-lm324': { component: OpampLM358, w: 80, h: 72 }, 'wokwi-opamp-tl072': { component: OpampLM358, w: 80, h: 72 }, // Logic gates — examples use both `wokwi-logic-gate-*` and `wokwi-logic-*` naming 'wokwi-logic-gate-and': { component: GateAnd, w: 72, h: 48 }, 'wokwi-logic-gate-or': { component: GateOr, w: 72, h: 48 }, 'wokwi-logic-gate-nand': { component: GateNand, w: 72, h: 48 }, 'wokwi-logic-gate-nor': { component: GateNor, w: 72, h: 48 }, 'wokwi-logic-gate-xor': { component: GateXor, w: 72, h: 48 }, 'wokwi-logic-gate-xnor': { component: GateXnor, w: 72, h: 48 }, 'wokwi-logic-gate-not': { component: GateNot, w: 72, h: 48 }, 'wokwi-logic-and': { component: GateAnd, w: 72, h: 48 }, 'wokwi-logic-or': { component: GateOr, w: 72, h: 48 }, 'wokwi-logic-nand': { component: GateNand, w: 72, h: 48 }, 'wokwi-logic-nor': { component: GateNor, w: 72, h: 48 }, 'wokwi-logic-xor': { component: GateXor, w: 72, h: 48 }, 'wokwi-logic-xnor': { component: GateXnor, w: 72, h: 48 }, 'wokwi-logic-not': { component: GateNot, w: 72, h: 48 }, // Power 'wokwi-reg-7805': { component: Reg7805, w: 72, h: 56 }, 'wokwi-reg-7812': { component: Reg7805, w: 72, h: 56 }, 'wokwi-reg-7905': { component: Reg7805, w: 72, h: 56 }, 'wokwi-reg-lm317': { component: RegLM317, w: 72, h: 56 }, 'wokwi-battery-9v': { component: Battery9V, w: 48, h: 72 }, 'wokwi-battery-aa': { component: Battery9V, w: 48, h: 72 }, 'wokwi-signal-generator': { component: SignalGenerator, w: 80, h: 64 }, // Instruments 'wokwi-instr-voltmeter': { component: Voltmeter, w: 72, h: 56 }, 'wokwi-instr-ammeter': { component: Ammeter, w: 72, h: 56 }, };