@skillpet/circuit
v0.6.5
Published
Circuit diagram library — render electrical schematics from JSON, with interactive SVG, themes, and Vue/React components
Downloads
1,194
Readme
@skillpet/circuit
Website & Demos: circuit.skill.pet
Examples: github.com/skillpet/circuit
Features
- 200+ built-in electrical components (resistors, capacitors, diodes, transistors, ICs, logic gates, etc.)
- Vue 3 & React components out of the box
- Interactive SVG: hover highlights, tooltips, click events
- 3 built-in themes (light, dark, print) + custom themes
- Smooth color transitions between elements
- Render circuit diagrams from a simple JSON description
- Browser bundle (script tag) & ESM / CJS support
- KaTeX math label rendering
- Flow charts, DSP blocks, pictorial breadboard components
- Zero runtime dependencies (except optional KaTeX)
Installation
npm install @skillpet/circuitQuick Start
React
import { CircuitDiagram } from "@skillpet/circuit/react";
function App() {
const circuit = {
elements: [
{ type: "SourceV", d: "up", label: "12V" },
{ type: "ResistorIEEE", d: "right", label: "R1 10kΩ", id: "R1", tooltip: "100kΩ Carbon Film" },
{ type: "Capacitor", d: "down", label: "C1 100nF", id: "C1", tooltip: "Ceramic 100nF" },
{ type: "Line", d: "left" },
{ type: "Ground" },
],
};
return (
<CircuitDiagram
circuit={circuit}
interactive
theme="light"
onElementClick={(info) => console.log("Clicked:", info.id)}
onElementHover={(info) => console.log("Hover:", info.tooltip)}
/>
);
}Vue 3
<script setup>
import { CircuitDiagram } from "@skillpet/circuit/vue";
const circuit = {
elements: [
{ type: "SourceV", d: "up", label: "12V" },
{ type: "ResistorIEEE", d: "right", label: "R1 10kΩ", id: "R1", tooltip: "100kΩ Carbon Film" },
{ type: "Capacitor", d: "down", label: "C1 100nF", id: "C1", tooltip: "Ceramic 100nF" },
{ type: "Line", d: "left" },
{ type: "Ground" },
],
};
const onElementClick = (info) => console.log("Clicked:", info.id);
</script>
<template>
<CircuitDiagram
:circuit="circuit"
interactive
theme="light"
@element-click="onElementClick"
/>
</template>ESM / TypeScript
import { renderFromJson, mountFromJson } from "@skillpet/circuit";
// Static rendering — returns an SVG string
const svg = renderFromJson({
elements: [
{ type: "SourceV", d: "up", label: "12V" },
{ type: "ResistorIEEE", d: "right", label: "R1 10kΩ" },
{ type: "Capacitor", d: "down", label: "C1 100nF" },
{ type: "Line", d: "left" },
{ type: "Ground" },
],
});
// Interactive mode — mount into DOM with hover, tooltips, click events
const ctrl = mountFromJson(document.getElementById("container")!, {
elements: [
{ type: "ResistorIEEE", id: "R1", tooltip: "100kΩ Carbon Film" },
{ type: "Capacitor", d: "down", id: "C1", tooltip: "0.1μF Ceramic" },
],
}, { interactive: true });
ctrl.on("element:click", (info) => console.log("Clicked:", info.id));Browser (CDN)
<div id="output"></div>
<script src="https://unpkg.com/@skillpet/circuit/dist/circuit.bundle.min.js"></script>
<script>
document.getElementById("output").innerHTML = Circuit.renderFromJson({
elements: [
{ type: "SourceV", d: "up", label: "12V" },
{ type: "ResistorIEEE", d: "right", label: "R1 10kΩ" },
{ type: "Capacitor", d: "down", label: "C1 100nF" },
{ type: "Line", d: "left" },
{ type: "Ground" },
],
});
</script>Themes
Three built-in themes: light (default), dark, and print.
const svg = renderFromJson(circuit, { theme: "dark" });Color Transitions
Smooth gradient transitions between differently colored elements:
const svg = renderFromJson({
drawing: { colorTransition: true },
elements: [
{ type: "SourceV", d: "up", color: "#2ecc71" },
{ type: "ResistorIEEE", d: "right", color: "#e74c3c" },
{ type: "Capacitor", d: "down", color: "#3498db" },
{ type: "Line", d: "left" },
{ type: "Ground" },
],
}, { colorTransition: true });License
Free for personal and educational use. Commercial use requires a separate license.
See the LICENSE file included in this package for full terms.
For commercial licensing, contact [email protected] or visit circuit.skill.pet/license.
