Documentation
Learn how to use @skillpet/circuit in your projects.
Installation
npm install @skillpet/circuitQuick Start
import { renderFromJson, mountFromJson } from '@skillpet/circuit'
// Static SVG string
const svg = renderFromJson({
elements: [
{ type: 'SourceV', label: 'V₁' },
{ type: 'Resistor', d: 'right', label: '1kΩ' },
{ type: 'Capacitor', d: 'down', label: '10μF' },
{ type: 'Line', d: 'left' },
]
})
document.getElementById('root').innerHTML = svg
// Interactive mount
const ctrl = mountFromJson(
document.getElementById('root'),
circuitJson,
{ theme: 'auto', interactive: true }
)
ctrl.on('elementClick', (info) => console.log(info))
ctrl.destroy() // cleanupJSON Specification
Colors & Gradients
Set per-element colors and enable gradient transitions between adjacent elements.
{
"drawing": { "colorTransition": true },
"elements": [
{ "type": "SourceV", "color": "#3498db", "label": "V₁" },
{ "type": "Resistor", "d": "right", "color": "#e74c3c", "label": "R₁" },
{ "type": "Capacitor", "d": "down", "color": "#2ecc71", "label": "C₁" },
{ "type": "Inductor", "d": "left", "color": "#9b59b6", "label": "L₁" }
]
}Theme System
Built-in themes: default dark print auto
theme: "auto" to read from CSS variables on the host page. Define these variables on :root:
/* Light mode */
:root {
--circuit-bg: transparent;
--circuit-stroke: #1a1a1a;
--circuit-text: #1a1a1a;
}
/* Dark mode */
.dark {
--circuit-stroke: #c8d6e5;
--circuit-text: #dfe6e9;
}Interactive API
Component Reference (178)
All available component types, organized by category.
Passive (28)
ResistorResistorIECResistorIEEEResistorVarResistorVarIECThermistorPhotoresistorPhotoresistorIECPotentiometerPotentiometerIECCapacitorCapacitor2CapacitorVarCapacitorTrimInductorInductor2InductorVarInductorVar2CrystalFuseFuseUSFuseIECFuseIEEEBreakerMemristorMemristor2JosephsonSparkGap
Sources (14)
SourceVSourceISourceSinSourceSquareSourceTriangleSourcePulseSourceControlledSourceControlledVSourceControlledIBatteryBatteryCellSolarSourceRampSourceNoise
Semiconductors (41)
DiodeDiodeFullDiodeTunnelDiodeShockleyLEDLED2PhotodiodeZenerSchottkyVaractorDiacBjtNpnBjtPnpBjtNpn2BjtPnp2BjtNpnBulkBjtPnpBulkNpnPhotoPnpPhotoNFetPFetNFet2PFet2NMosPMosNFetDPFetDNJFetPJFetAnalogNFetAnalogPFetHemtNHemtPIgbtNIgbtPOpampOpampDiffSCRTriacRectifierOptocoupler
Logic Gates (21)
AndOrNandNorXorXnorNotBufSchmittAndSchmittNandSchmittNotSchmittBufTristateTristateNotTgateTgate2DFlipFlopJKFlipFlopSRFlipFlopMultiplexerDemultiplexer
ICs & Modules (7)
IcIcDIPIc555Ic555DIPSevenSegmentSevenSegmentDigitVoltageRegulator
Connectors (15)
HeaderHeaderLabelBusConnectBusLineCoaxConnectPlugJackAudioJackRCAUSBDB25DB9DE9DE15OldPhone
Switches (13)
SwitchSwitchSpdtSwitchDpstSwitchDpdtSwitchReedSwitchDIPSwitchRotaryButtonButtonNOButtonNCRelayRelaySPDTRelayDPDT
Lines & Labels (16)
LineArrowWireDotArrowheadLabelTagCurrentLabelCurrentLabelInlineLoopArrowLoopCurrentArcNEncircleEncircleBoxGapAnnotate
Meters (6)
MeterVMeterAMeterIMeterOhmOscilloscopeLamp
Miscellaneous (17)
GroundGroundSignalGroundChassisVddVssVccTransformerWheatstoneMotorGeneratorSpeakerMicrophoneAntennaAntennaLoopAntennaLoop2CableCoax