@tscircuit/schematic-viewer 2.0.55 → 2.0.57
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.
- package/dist/index.js +7 -3
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
- package/.github/workflows/bun-formatcheck.yml +0 -26
- package/.github/workflows/bun-pver-release.yml +0 -59
- package/.github/workflows/bun-typecheck.yml +0 -26
- package/.github/workflows/on-merge-inform-release-tracker.yml +0 -24
- package/CLAUDE.md +0 -1
- package/biome.json +0 -56
- package/bun.lockb +0 -0
- package/cosmos.config.json +0 -3
- package/cosmos.decorator.tsx +0 -3
- package/docs/circuit-to-svg-metadata.md +0 -151
- package/docs/dragndrop-spec.md +0 -39
- package/examples/example1-resistor-and-capacitor.fixture.tsx +0 -16
- package/examples/example10-groups-view-schematic-groups.fixture.tsx +0 -76
- package/examples/example11-automatic-grouping-view-schematic-groups.fixture.tsx +0 -109
- package/examples/example12-spice-boost-converter.fixture.tsx +0 -78
- package/examples/example13-disablegroups.fixture.tsx +0 -30
- package/examples/example14-schematic-component-click.fixture.tsx +0 -46
- package/examples/example15-analog-simulation-viewer.fixture.tsx +0 -145
- package/examples/example16-no-analog-simulation.fixture.tsx +0 -13
- package/examples/example17-schematic-ports.fixture.tsx +0 -49
- package/examples/example2-small-circuit.fixture.tsx +0 -48
- package/examples/example3-small-circuit-without-debug-grid.fixture.tsx +0 -44
- package/examples/example4-reset-edit-events.fixture.tsx +0 -57
- package/examples/example5-circuit-json-rerender.fixture.tsx +0 -110
- package/examples/example6-click-to-interact.fixture.tsx +0 -36
- package/examples/example7-schematic-viewer-fix-snapping.fixture.tsx +0 -123
- package/examples/example8-color-overrides.fixture.tsx +0 -52
- package/examples/example9-spice-rc-charging-voltage-divider.fixture.tsx +0 -77
- package/index.html +0 -12
- package/lib/components/AnalogSimulationViewer.tsx +0 -300
- package/lib/components/ControlledSchematicViewer.tsx +0 -40
- package/lib/components/EditIcon.tsx +0 -46
- package/lib/components/GridIcon.tsx +0 -45
- package/lib/components/MouseTracker.tsx +0 -257
- package/lib/components/SchematicComponentMouseTarget.tsx +0 -189
- package/lib/components/SchematicPortMouseTarget.tsx +0 -224
- package/lib/components/SchematicViewer.tsx +0 -582
- package/lib/components/SpiceIcon.tsx +0 -14
- package/lib/components/SpicePlot.tsx +0 -221
- package/lib/components/SpiceSimulationIcon.tsx +0 -32
- package/lib/components/SpiceSimulationOverlay.tsx +0 -250
- package/lib/components/ViewMenu.tsx +0 -218
- package/lib/components/ViewMenuIcon.tsx +0 -47
- package/lib/dev/render-to-circuit-json.ts +0 -8
- package/lib/hooks/use-resize-handling.ts +0 -35
- package/lib/hooks/useChangeSchematicComponentLocationsInSvg.ts +0 -117
- package/lib/hooks/useChangeSchematicTracesForMovedComponents.ts +0 -121
- package/lib/hooks/useComponentDragging.ts +0 -251
- package/lib/hooks/useLocalStorage.ts +0 -63
- package/lib/hooks/useMouseEventsOverBoundingBox.ts +0 -74
- package/lib/hooks/useSchematicGroupsOverlay.ts +0 -364
- package/lib/hooks/useSpiceSimulation.ts +0 -149
- package/lib/index.ts +0 -4
- package/lib/types/edit-events.ts +0 -16
- package/lib/types/eecircuit-engine.d.ts +0 -147
- package/lib/utils/debug.ts +0 -9
- package/lib/utils/get-component-offset-due-to-events.ts +0 -43
- package/lib/utils/spice-utils.ts +0 -128
- package/lib/utils/z-index-map.ts +0 -11
- package/lib/workers/spice-simulation.worker.ts +0 -51
- package/scripts/build-worker-blob-url.ts +0 -55
- package/src/main.tsx +0 -21
- package/tsconfig.json +0 -33
- package/tsup-webworker.config.ts +0 -13
- package/vite.config.js +0 -15
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { renderToCircuitJson } from "lib/dev/render-to-circuit-json"
|
|
2
|
-
import { SchematicViewer } from "lib/index"
|
|
3
|
-
import type { CircuitJson } from "circuit-json"
|
|
4
|
-
import { sel } from "tscircuit"
|
|
5
|
-
|
|
6
|
-
const circuit = (
|
|
7
|
-
<board width={30} height={30}>
|
|
8
|
-
<voltagesource
|
|
9
|
-
name="V1"
|
|
10
|
-
voltage={"5V"}
|
|
11
|
-
schY={2}
|
|
12
|
-
schX={-5}
|
|
13
|
-
schRotation={270}
|
|
14
|
-
/>
|
|
15
|
-
<trace from={".V1 > .pin1"} to={".L1 > .pin1"} />
|
|
16
|
-
<trace from={".L1 > .pin2"} to={".D1 > .anode"} />
|
|
17
|
-
<trace from={".D1 > .cathode"} to={".C1 > .pin1"} />
|
|
18
|
-
<trace from={".D1 > .cathode"} to={".R1 > .pin1"} />
|
|
19
|
-
<trace from={".C1 > .pin2"} to={".R1 > .pin2"} />
|
|
20
|
-
<trace from={".R1 > .pin2"} to={".V1 > .pin2"} />
|
|
21
|
-
<trace from={".L1 > .pin2"} to={".M1 > .drain"} />
|
|
22
|
-
<trace from={".M1 > .source"} to={".V1 > .pin2"} />
|
|
23
|
-
<trace from={".M1 > .source"} to={"net.GND"} />
|
|
24
|
-
<trace from={".M1 > .gate"} to={".V2 > .pin1"} />
|
|
25
|
-
<trace from={".V2 > .pin2"} to={".V1 > .pin2"} />
|
|
26
|
-
<inductor name="L1" inductance={"1H"} schY={3} pcbY={3} />
|
|
27
|
-
<diode name="D1" footprint={"0603"} schY={3} schX={3} pcbY={6} pcbX={3} />
|
|
28
|
-
<capacitor
|
|
29
|
-
polarized
|
|
30
|
-
schRotation={270}
|
|
31
|
-
name="C1"
|
|
32
|
-
capacitance={"10uF"}
|
|
33
|
-
footprint={"0603"}
|
|
34
|
-
schX={3}
|
|
35
|
-
pcbX={3}
|
|
36
|
-
/>
|
|
37
|
-
<resistor
|
|
38
|
-
schRotation={270}
|
|
39
|
-
name="R1"
|
|
40
|
-
resistance={"1k"}
|
|
41
|
-
footprint={"0603"}
|
|
42
|
-
schX={6}
|
|
43
|
-
pcbX={9}
|
|
44
|
-
/>
|
|
45
|
-
<voltagesource
|
|
46
|
-
name="V2"
|
|
47
|
-
schRotation={270}
|
|
48
|
-
voltage={"10V"}
|
|
49
|
-
waveShape="square"
|
|
50
|
-
dutyCycle={0.68}
|
|
51
|
-
frequency={"1kHz"}
|
|
52
|
-
schX={-3}
|
|
53
|
-
/>
|
|
54
|
-
<mosfet
|
|
55
|
-
channelType="n"
|
|
56
|
-
footprint={"sot23"}
|
|
57
|
-
name="M1"
|
|
58
|
-
mosfetMode="enhancement"
|
|
59
|
-
pcbX={-4}
|
|
60
|
-
/>
|
|
61
|
-
</board>
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
export default () => {
|
|
65
|
-
const circuitJson = renderToCircuitJson(circuit) as CircuitJson
|
|
66
|
-
|
|
67
|
-
return (
|
|
68
|
-
<div style={{ position: "relative", height: "100%" }}>
|
|
69
|
-
<SchematicViewer
|
|
70
|
-
circuitJson={circuitJson}
|
|
71
|
-
containerStyle={{ height: "100%" }}
|
|
72
|
-
debugGrid
|
|
73
|
-
editingEnabled
|
|
74
|
-
spiceSimulationEnabled
|
|
75
|
-
/>
|
|
76
|
-
</div>
|
|
77
|
-
)
|
|
78
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { SchematicViewer } from "lib/components/SchematicViewer"
|
|
2
|
-
import { renderToCircuitJson } from "lib/dev/render-to-circuit-json"
|
|
3
|
-
|
|
4
|
-
const circuitJson = renderToCircuitJson(
|
|
5
|
-
<board>
|
|
6
|
-
<group name="Alpha Node">
|
|
7
|
-
<resistor resistance="1k" footprint="0402" name="R1" schX={3} />
|
|
8
|
-
<capacitor capacitance="1000pF" footprint="0402" name="C1" schX={-3} />
|
|
9
|
-
<trace from=".R1 > .pin1" to=".C1 > .pin1" />
|
|
10
|
-
</group>
|
|
11
|
-
</board>,
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
export default () => {
|
|
15
|
-
return (
|
|
16
|
-
<div style={{ position: "relative", height: "100%" }}>
|
|
17
|
-
<SchematicViewer
|
|
18
|
-
circuitJson={circuitJson}
|
|
19
|
-
containerStyle={{
|
|
20
|
-
width: "100vw",
|
|
21
|
-
height: "100vh",
|
|
22
|
-
backgroundColor: "#f8f9fa",
|
|
23
|
-
}}
|
|
24
|
-
debugGrid={false}
|
|
25
|
-
editingEnabled={false}
|
|
26
|
-
disableGroups
|
|
27
|
-
/>
|
|
28
|
-
</div>
|
|
29
|
-
)
|
|
30
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { useState } from "react"
|
|
2
|
-
import { ControlledSchematicViewer } from "lib/components/ControlledSchematicViewer"
|
|
3
|
-
import { renderToCircuitJson } from "lib/dev/render-to-circuit-json"
|
|
4
|
-
|
|
5
|
-
const circuitJson = renderToCircuitJson(
|
|
6
|
-
<board width="12mm" height="12mm">
|
|
7
|
-
<resistor name="R1" resistance={1000} schX={-2} schY={0} />
|
|
8
|
-
<capacitor name="C1" capacitance="1uF" schX={2} schY={0} />
|
|
9
|
-
<trace from=".R1 .pin2" to=".C1 .pin1" />
|
|
10
|
-
<trace from=".R1 .pin1" to=".C1 .pin2" />
|
|
11
|
-
</board>,
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
export default function Example() {
|
|
15
|
-
const [clickedComponentId, setClickedComponentId] = useState<string | null>(
|
|
16
|
-
null,
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
return (
|
|
20
|
-
<div
|
|
21
|
-
style={{
|
|
22
|
-
display: "flex",
|
|
23
|
-
flexDirection: "column",
|
|
24
|
-
gap: "12px",
|
|
25
|
-
padding: "16px",
|
|
26
|
-
height: "100%",
|
|
27
|
-
boxSizing: "border-box",
|
|
28
|
-
}}
|
|
29
|
-
>
|
|
30
|
-
<div style={{ fontFamily: "sans-serif" }}>
|
|
31
|
-
{clickedComponentId
|
|
32
|
-
? `Last clicked component: ${clickedComponentId}`
|
|
33
|
-
: "Click a component to highlight it"}
|
|
34
|
-
</div>
|
|
35
|
-
<div style={{ flex: 1, minHeight: 320 }}>
|
|
36
|
-
<ControlledSchematicViewer
|
|
37
|
-
circuitJson={circuitJson}
|
|
38
|
-
containerStyle={{ height: "100%" }}
|
|
39
|
-
onSchematicComponentClicked={({ schematicComponentId }) => {
|
|
40
|
-
setClickedComponentId(schematicComponentId)
|
|
41
|
-
}}
|
|
42
|
-
/>
|
|
43
|
-
</div>
|
|
44
|
-
</div>
|
|
45
|
-
)
|
|
46
|
-
}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import React from "react"
|
|
2
|
-
import { AnalogSimulationViewer } from "../lib/components/AnalogSimulationViewer"
|
|
3
|
-
import * as Core from "@tscircuit/core"
|
|
4
|
-
import createNgspiceSpiceEngine from "@tscircuit/ngspice-spice-engine"
|
|
5
|
-
|
|
6
|
-
// TSX circuit definition
|
|
7
|
-
const SwitchCircuitElement = (
|
|
8
|
-
<board schMaxTraceDistance={10} routingDisabled>
|
|
9
|
-
<voltagesource name="V1" voltage="5V" />
|
|
10
|
-
<resistor name="R_base" resistance="10k" schY={2} />
|
|
11
|
-
<switch name="SW1" simSwitchFrequency="1kHz" schX={1.5} schY={2} />
|
|
12
|
-
<transistor
|
|
13
|
-
name="Q1"
|
|
14
|
-
type="npn"
|
|
15
|
-
footprint="sot23"
|
|
16
|
-
schX={2}
|
|
17
|
-
schY={0.3}
|
|
18
|
-
schRotation={180}
|
|
19
|
-
/>
|
|
20
|
-
<resistor name="R_collector" resistance="10k" schY={-2} />
|
|
21
|
-
|
|
22
|
-
<trace from=".V1 > .pin1" to=".R_base > .pin1" />
|
|
23
|
-
<trace from=".R_base > .pin2" to=".SW1 > .pin1" />
|
|
24
|
-
<trace from=".SW1 > .pin2" to=".Q1 > .base" />
|
|
25
|
-
|
|
26
|
-
<trace from=".V1 > .pin1" to=".R_collector > .pin1" />
|
|
27
|
-
<trace from=".R_collector > .pin2" to=".Q1 > .collector" />
|
|
28
|
-
|
|
29
|
-
<trace from=".Q1 > .emitter" to=".V1 > .pin2" />
|
|
30
|
-
|
|
31
|
-
<voltageprobe name="VP_COLLECTOR" connectsTo=".R_collector > .pin2" />
|
|
32
|
-
|
|
33
|
-
<analogsimulation duration="4ms" timePerStep="1us" spiceEngine="ngspice" />
|
|
34
|
-
</board>
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
// Convert TSX to CircuitJSON and add simulation data
|
|
38
|
-
const createSimulatedCircuitJson = async () => {
|
|
39
|
-
try {
|
|
40
|
-
// Step 1: Create circuit with platform configuration
|
|
41
|
-
const circuit = new Core.Circuit()
|
|
42
|
-
|
|
43
|
-
const ngspiceEngine = await createNgspiceSpiceEngine()
|
|
44
|
-
circuit.setPlatform({
|
|
45
|
-
spiceEngineMap: {
|
|
46
|
-
ngspice: ngspiceEngine,
|
|
47
|
-
},
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
// Step 2: Add the circuit element
|
|
51
|
-
circuit.add(SwitchCircuitElement)
|
|
52
|
-
await circuit.renderUntilSettled()
|
|
53
|
-
|
|
54
|
-
// Step 3: Get CircuitJSON (includes simulation data if produced by the platform)
|
|
55
|
-
return circuit.getCircuitJson()
|
|
56
|
-
} catch (error) {
|
|
57
|
-
console.error("Simulation failed:", error)
|
|
58
|
-
// Return basic CircuitJSON if simulation fails
|
|
59
|
-
const fallbackCircuit = new Core.Circuit()
|
|
60
|
-
fallbackCircuit.add(SwitchCircuitElement)
|
|
61
|
-
await fallbackCircuit.renderUntilSettled()
|
|
62
|
-
return fallbackCircuit.getCircuitJson()
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export default () => {
|
|
67
|
-
const [simulatedCircuitJson, setSimulatedCircuitJson] = React.useState<
|
|
68
|
-
any[] | null
|
|
69
|
-
>(null)
|
|
70
|
-
const [isLoading, setIsLoading] = React.useState(true)
|
|
71
|
-
const [error, setError] = React.useState<string | null>(null)
|
|
72
|
-
|
|
73
|
-
React.useEffect(() => {
|
|
74
|
-
const loadAndSimulateCircuit = async () => {
|
|
75
|
-
try {
|
|
76
|
-
setIsLoading(true)
|
|
77
|
-
setError(null)
|
|
78
|
-
|
|
79
|
-
const result = await createSimulatedCircuitJson()
|
|
80
|
-
setSimulatedCircuitJson(result)
|
|
81
|
-
} catch (err) {
|
|
82
|
-
setError(err instanceof Error ? err.message : "Failed to load circuit")
|
|
83
|
-
console.error("Error loading circuit:", err)
|
|
84
|
-
} finally {
|
|
85
|
-
setIsLoading(false)
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
loadAndSimulateCircuit()
|
|
90
|
-
}, [])
|
|
91
|
-
|
|
92
|
-
if (isLoading) {
|
|
93
|
-
return (
|
|
94
|
-
<div style={{ padding: "20px", textAlign: "center" }}>
|
|
95
|
-
<h2>Analog Simulation Viewer Example</h2>
|
|
96
|
-
<p>Converting TSX to CircuitJSON and running SPICE simulation...</p>
|
|
97
|
-
<div
|
|
98
|
-
style={{
|
|
99
|
-
display: "inline-block",
|
|
100
|
-
padding: "20px",
|
|
101
|
-
backgroundColor: "#f5f5f5",
|
|
102
|
-
borderRadius: "8px",
|
|
103
|
-
marginTop: "20px",
|
|
104
|
-
}}
|
|
105
|
-
>
|
|
106
|
-
Loading and simulating circuit...
|
|
107
|
-
</div>
|
|
108
|
-
</div>
|
|
109
|
-
)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (error) {
|
|
113
|
-
return (
|
|
114
|
-
<div style={{ padding: "20px", textAlign: "center" }}>
|
|
115
|
-
<h2>Analog Simulation Viewer Example</h2>
|
|
116
|
-
<div
|
|
117
|
-
style={{
|
|
118
|
-
display: "inline-block",
|
|
119
|
-
padding: "20px",
|
|
120
|
-
backgroundColor: "#fef2f2",
|
|
121
|
-
borderRadius: "8px",
|
|
122
|
-
border: "1px solid #fecaca",
|
|
123
|
-
color: "#dc2626",
|
|
124
|
-
marginTop: "20px",
|
|
125
|
-
}}
|
|
126
|
-
>
|
|
127
|
-
<h4>Error:</h4>
|
|
128
|
-
<p>{error}</p>
|
|
129
|
-
</div>
|
|
130
|
-
</div>
|
|
131
|
-
)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return (
|
|
135
|
-
simulatedCircuitJson && (
|
|
136
|
-
<AnalogSimulationViewer
|
|
137
|
-
circuitJson={simulatedCircuitJson}
|
|
138
|
-
containerStyle={{
|
|
139
|
-
width: "100vw",
|
|
140
|
-
height: "100vh",
|
|
141
|
-
}}
|
|
142
|
-
/>
|
|
143
|
-
)
|
|
144
|
-
)
|
|
145
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { AnalogSimulationViewer } from "lib/components/AnalogSimulationViewer"
|
|
2
|
-
import { renderToCircuitJson } from "lib/dev/render-to-circuit-json"
|
|
3
|
-
|
|
4
|
-
const circuitJson = renderToCircuitJson(
|
|
5
|
-
<board width="10mm" height="10mm" routingDisabled></board>,
|
|
6
|
-
)
|
|
7
|
-
|
|
8
|
-
export default () => (
|
|
9
|
-
<AnalogSimulationViewer
|
|
10
|
-
circuitJson={circuitJson}
|
|
11
|
-
containerStyle={{ height: "100%" }}
|
|
12
|
-
/>
|
|
13
|
-
)
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { SchematicViewer } from "lib/components/SchematicViewer"
|
|
2
|
-
import { renderToCircuitJson } from "lib/dev/render-to-circuit-json"
|
|
3
|
-
|
|
4
|
-
const circuitJson = renderToCircuitJson(
|
|
5
|
-
<board width="10mm" height="10mm" routingDisabled>
|
|
6
|
-
<resistor name="R1" resistance={1000} schX={-2} />
|
|
7
|
-
<capacitor name="C1" capacitance="1uF" schX={2} schY={2} />
|
|
8
|
-
<capacitor
|
|
9
|
-
name="C2"
|
|
10
|
-
schRotation={90}
|
|
11
|
-
capacitance="1uF"
|
|
12
|
-
schX={0}
|
|
13
|
-
schY={-4}
|
|
14
|
-
/>
|
|
15
|
-
<chip
|
|
16
|
-
name="U1"
|
|
17
|
-
pinLabels={{
|
|
18
|
-
pin1: "D0",
|
|
19
|
-
pin2: "D1",
|
|
20
|
-
pin3: "D2",
|
|
21
|
-
pin4: "GND",
|
|
22
|
-
pin5: "D3",
|
|
23
|
-
pin6: "EN",
|
|
24
|
-
pin7: "D4",
|
|
25
|
-
pin8: "VCC",
|
|
26
|
-
}}
|
|
27
|
-
footprint="soic8"
|
|
28
|
-
schX={0}
|
|
29
|
-
schY={-1.5}
|
|
30
|
-
/>
|
|
31
|
-
|
|
32
|
-
<trace from=".R1 .pin2" to=".C1 .pin1" />
|
|
33
|
-
<trace from=".C1 .pin2" to=".U1 .pin4" />
|
|
34
|
-
<trace from=".U1 .pin8" to=".C2 .pin1" />
|
|
35
|
-
<trace from=".C2 .pin2" to=".R1 .pin1" />
|
|
36
|
-
<trace from=".U1 .pin1" to=".U1 .pin5" />
|
|
37
|
-
</board>,
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
export default () => (
|
|
41
|
-
<SchematicViewer
|
|
42
|
-
circuitJson={circuitJson}
|
|
43
|
-
containerStyle={{ height: "100%" }}
|
|
44
|
-
showSchematicPorts
|
|
45
|
-
onSchematicPortClicked={({ schematicPortId }) => {
|
|
46
|
-
console.log("Port clicked:", schematicPortId)
|
|
47
|
-
}}
|
|
48
|
-
/>
|
|
49
|
-
)
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { ControlledSchematicViewer } from "lib/components/ControlledSchematicViewer"
|
|
2
|
-
import { renderToCircuitJson } from "lib/dev/render-to-circuit-json"
|
|
3
|
-
|
|
4
|
-
const circuitJson = renderToCircuitJson(
|
|
5
|
-
<board width="10mm" height="10mm" routingDisabled>
|
|
6
|
-
<resistor name="R1" resistance={1000} schX={-2} />
|
|
7
|
-
<capacitor name="C1" capacitance="1uF" schX={2} schY={2} />
|
|
8
|
-
<capacitor
|
|
9
|
-
name="C2"
|
|
10
|
-
schRotation={90}
|
|
11
|
-
capacitance="1uF"
|
|
12
|
-
schX={0}
|
|
13
|
-
schY={-4}
|
|
14
|
-
/>
|
|
15
|
-
<chip
|
|
16
|
-
name="U1"
|
|
17
|
-
pinLabels={{
|
|
18
|
-
pin1: "D0",
|
|
19
|
-
pin2: "D1",
|
|
20
|
-
pin3: "D2",
|
|
21
|
-
pin4: "GND",
|
|
22
|
-
pin5: "D3",
|
|
23
|
-
pin6: "EN",
|
|
24
|
-
pin7: "D4",
|
|
25
|
-
pin8: "VCC",
|
|
26
|
-
}}
|
|
27
|
-
footprint="soic8"
|
|
28
|
-
schX={0}
|
|
29
|
-
schY={-1.5}
|
|
30
|
-
/>
|
|
31
|
-
|
|
32
|
-
<trace from=".R1 .pin2" to=".C1 .pin1" />
|
|
33
|
-
<trace from=".C1 .pin2" to=".U1 .pin4" />
|
|
34
|
-
<trace from=".U1 .pin8" to=".C2 .pin1" />
|
|
35
|
-
<trace from=".C2 .pin2" to=".R1 .pin1" />
|
|
36
|
-
<trace from=".U1 .pin1" to=".U1 .pin5" />
|
|
37
|
-
</board>,
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
export default () => (
|
|
41
|
-
<ControlledSchematicViewer
|
|
42
|
-
circuitJson={circuitJson}
|
|
43
|
-
editingEnabled
|
|
44
|
-
containerStyle={{ height: "100%" }}
|
|
45
|
-
debugGrid
|
|
46
|
-
debug
|
|
47
|
-
/>
|
|
48
|
-
)
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { ControlledSchematicViewer } from "lib/components/ControlledSchematicViewer"
|
|
2
|
-
import { renderToCircuitJson } from "lib/dev/render-to-circuit-json"
|
|
3
|
-
|
|
4
|
-
export default () => (
|
|
5
|
-
<ControlledSchematicViewer
|
|
6
|
-
circuitJson={renderToCircuitJson(
|
|
7
|
-
<board width="10mm" height="10mm">
|
|
8
|
-
<resistor name="R1" resistance={1000} schX={-2} />
|
|
9
|
-
<capacitor name="C1" capacitance="1uF" schX={2} schY={2} />
|
|
10
|
-
<capacitor
|
|
11
|
-
name="C2"
|
|
12
|
-
schRotation={90}
|
|
13
|
-
capacitance="1uF"
|
|
14
|
-
schX={0}
|
|
15
|
-
schY={-4}
|
|
16
|
-
/>
|
|
17
|
-
<chip
|
|
18
|
-
name="U1"
|
|
19
|
-
pinLabels={{
|
|
20
|
-
pin1: "D0",
|
|
21
|
-
pin2: "D1",
|
|
22
|
-
pin3: "D2",
|
|
23
|
-
pin4: "GND",
|
|
24
|
-
pin5: "D3",
|
|
25
|
-
pin6: "EN",
|
|
26
|
-
pin7: "D4",
|
|
27
|
-
pin8: "VCC",
|
|
28
|
-
}}
|
|
29
|
-
footprint="soic8"
|
|
30
|
-
schX={0}
|
|
31
|
-
schY={-1.5}
|
|
32
|
-
/>
|
|
33
|
-
|
|
34
|
-
<trace from=".R1 .pin2" to=".C1 .pin1" />
|
|
35
|
-
<trace from=".C1 .pin2" to=".U1 .pin4" />
|
|
36
|
-
<trace from=".U1 .pin8" to=".C2 .pin1" />
|
|
37
|
-
<trace from=".C2 .pin2" to=".R1 .pin1" />
|
|
38
|
-
<trace from=".U1 .pin1" to=".U1 .pin5" />
|
|
39
|
-
</board>,
|
|
40
|
-
)}
|
|
41
|
-
editingEnabled
|
|
42
|
-
containerStyle={{ height: "100%" }}
|
|
43
|
-
/>
|
|
44
|
-
)
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { useState } from "react"
|
|
2
|
-
import { ControlledSchematicViewer } from "lib/components/ControlledSchematicViewer"
|
|
3
|
-
import { renderToCircuitJson } from "lib/dev/render-to-circuit-json"
|
|
4
|
-
import type { ManualEditEvent } from "lib/types/edit-events"
|
|
5
|
-
import { SchematicViewer } from "lib/index"
|
|
6
|
-
|
|
7
|
-
export default () => {
|
|
8
|
-
const [editEvents, setEditEvents] = useState<ManualEditEvent[]>([])
|
|
9
|
-
|
|
10
|
-
return (
|
|
11
|
-
<div style={{ position: "relative", height: "100%" }}>
|
|
12
|
-
<button
|
|
13
|
-
type="button"
|
|
14
|
-
onClick={() => setEditEvents([])}
|
|
15
|
-
style={{
|
|
16
|
-
position: "absolute",
|
|
17
|
-
top: "16px",
|
|
18
|
-
right: "64px",
|
|
19
|
-
zIndex: 1001,
|
|
20
|
-
backgroundColor: "#f44336",
|
|
21
|
-
color: "#fff",
|
|
22
|
-
padding: "8px",
|
|
23
|
-
borderRadius: "4px",
|
|
24
|
-
cursor: "pointer",
|
|
25
|
-
border: "none",
|
|
26
|
-
boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
|
|
27
|
-
}}
|
|
28
|
-
>
|
|
29
|
-
Reset Edits
|
|
30
|
-
</button>
|
|
31
|
-
<SchematicViewer
|
|
32
|
-
editEvents={editEvents}
|
|
33
|
-
onEditEvent={(event) => setEditEvents([...editEvents, event])}
|
|
34
|
-
circuitJson={
|
|
35
|
-
renderToCircuitJson(
|
|
36
|
-
<board width="10mm" height="10mm">
|
|
37
|
-
<resistor name="R1" resistance={1000} schX={-2} />
|
|
38
|
-
<capacitor name="C1" capacitance="1uF" schX={2} schY={2} />
|
|
39
|
-
<capacitor
|
|
40
|
-
name="C2"
|
|
41
|
-
schRotation={90}
|
|
42
|
-
capacitance="1uF"
|
|
43
|
-
schX={0}
|
|
44
|
-
schY={-4}
|
|
45
|
-
/>
|
|
46
|
-
<trace from=".R1 .pin2" to=".C1 .pin1" />
|
|
47
|
-
<trace from=".C1 .pin2" to=".C2 .pin1" />
|
|
48
|
-
</board>,
|
|
49
|
-
) as any
|
|
50
|
-
}
|
|
51
|
-
containerStyle={{ height: "100%" }}
|
|
52
|
-
debugGrid
|
|
53
|
-
editingEnabled
|
|
54
|
-
/>
|
|
55
|
-
</div>
|
|
56
|
-
)
|
|
57
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from "react"
|
|
2
|
-
import { ControlledSchematicViewer } from "lib/components/ControlledSchematicViewer"
|
|
3
|
-
import { renderToCircuitJson } from "lib/dev/render-to-circuit-json"
|
|
4
|
-
import type { ManualEditEvent } from "lib/types/edit-events"
|
|
5
|
-
import { SchematicViewer } from "lib/index"
|
|
6
|
-
import type { CircuitJson } from "circuit-json"
|
|
7
|
-
|
|
8
|
-
export default () => {
|
|
9
|
-
const [editEvents, setEditEvents] = useState<ManualEditEvent[]>([])
|
|
10
|
-
const [circuitJson, setCircuitJson] = useState<CircuitJson | null>(null)
|
|
11
|
-
|
|
12
|
-
const rerenderCircuitJson = useCallback(() => {
|
|
13
|
-
setCircuitJson(
|
|
14
|
-
renderToCircuitJson(
|
|
15
|
-
<board width="10mm" height="10mm">
|
|
16
|
-
<resistor name="R1" resistance={1000} schX={Math.random() * 8 - 4} />
|
|
17
|
-
<capacitor
|
|
18
|
-
name="C1"
|
|
19
|
-
capacitance="1uF"
|
|
20
|
-
schX={Math.random() * 8 - 4}
|
|
21
|
-
schY={Math.random() * 8 - 4}
|
|
22
|
-
/>
|
|
23
|
-
<capacitor
|
|
24
|
-
name="C2"
|
|
25
|
-
schRotation={90}
|
|
26
|
-
capacitance="1uF"
|
|
27
|
-
schX={Math.random() * 8 - 4}
|
|
28
|
-
schY={Math.random() * 8 - 4}
|
|
29
|
-
/>
|
|
30
|
-
<trace from=".R1 .pin2" to=".C1 .pin1" />
|
|
31
|
-
<trace from=".C1 .pin2" to=".C2 .pin1" />
|
|
32
|
-
</board>,
|
|
33
|
-
) as any,
|
|
34
|
-
)
|
|
35
|
-
}, [])
|
|
36
|
-
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
rerenderCircuitJson()
|
|
39
|
-
}, [])
|
|
40
|
-
|
|
41
|
-
return (
|
|
42
|
-
<div style={{ position: "relative", height: "100%" }}>
|
|
43
|
-
<button
|
|
44
|
-
type="button"
|
|
45
|
-
onClick={rerenderCircuitJson}
|
|
46
|
-
style={{
|
|
47
|
-
position: "absolute",
|
|
48
|
-
top: "16px",
|
|
49
|
-
right: "64px",
|
|
50
|
-
zIndex: 1001,
|
|
51
|
-
backgroundColor: "#f44336",
|
|
52
|
-
color: "#fff",
|
|
53
|
-
padding: "8px",
|
|
54
|
-
borderRadius: "4px",
|
|
55
|
-
cursor: "pointer",
|
|
56
|
-
border: "none",
|
|
57
|
-
boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
|
|
58
|
-
}}
|
|
59
|
-
>
|
|
60
|
-
Rerender Circuit JSON
|
|
61
|
-
</button>
|
|
62
|
-
<button
|
|
63
|
-
type="button"
|
|
64
|
-
onClick={() => setEditEvents([])}
|
|
65
|
-
style={{
|
|
66
|
-
position: "absolute",
|
|
67
|
-
top: "16px",
|
|
68
|
-
right: "220px",
|
|
69
|
-
zIndex: 1001,
|
|
70
|
-
backgroundColor: "#2196f3",
|
|
71
|
-
color: "#fff",
|
|
72
|
-
padding: "8px",
|
|
73
|
-
borderRadius: "4px",
|
|
74
|
-
cursor: "pointer",
|
|
75
|
-
border: "none",
|
|
76
|
-
boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
|
|
77
|
-
}}
|
|
78
|
-
>
|
|
79
|
-
Reset Edits
|
|
80
|
-
</button>
|
|
81
|
-
<pre
|
|
82
|
-
style={{
|
|
83
|
-
position: "absolute",
|
|
84
|
-
top: "64px",
|
|
85
|
-
right: "64px",
|
|
86
|
-
zIndex: 1001,
|
|
87
|
-
backgroundColor: "#fff",
|
|
88
|
-
padding: "12px",
|
|
89
|
-
borderRadius: "4px",
|
|
90
|
-
border: "1px solid #ccc",
|
|
91
|
-
boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
|
|
92
|
-
maxHeight: "300px",
|
|
93
|
-
overflowY: "auto",
|
|
94
|
-
fontSize: "12px",
|
|
95
|
-
fontFamily: "monospace",
|
|
96
|
-
}}
|
|
97
|
-
>
|
|
98
|
-
{JSON.stringify(editEvents, null, 2)}
|
|
99
|
-
</pre>
|
|
100
|
-
<SchematicViewer
|
|
101
|
-
editEvents={editEvents}
|
|
102
|
-
onEditEvent={(event) => setEditEvents([...editEvents, event])}
|
|
103
|
-
circuitJson={circuitJson ?? []}
|
|
104
|
-
containerStyle={{ height: "100%" }}
|
|
105
|
-
debugGrid
|
|
106
|
-
editingEnabled
|
|
107
|
-
/>
|
|
108
|
-
</div>
|
|
109
|
-
)
|
|
110
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { ControlledSchematicViewer } from "lib/components/ControlledSchematicViewer"
|
|
2
|
-
import { renderToCircuitJson } from "lib/dev/render-to-circuit-json"
|
|
3
|
-
|
|
4
|
-
export default () => (
|
|
5
|
-
<div style={{ position: "relative", height: "100%" }}>
|
|
6
|
-
<div
|
|
7
|
-
style={{
|
|
8
|
-
position: "absolute",
|
|
9
|
-
top: "16px",
|
|
10
|
-
right: "64px",
|
|
11
|
-
zIndex: 1001,
|
|
12
|
-
backgroundColor: "#fff",
|
|
13
|
-
padding: "12px",
|
|
14
|
-
borderRadius: "4px",
|
|
15
|
-
border: "1px solid #ccc",
|
|
16
|
-
boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
|
|
17
|
-
fontSize: "14px",
|
|
18
|
-
fontFamily: "sans-serif",
|
|
19
|
-
}}
|
|
20
|
-
>
|
|
21
|
-
This example demonstrates the clickToInteractEnabled feature
|
|
22
|
-
</div>
|
|
23
|
-
<ControlledSchematicViewer
|
|
24
|
-
circuitJson={renderToCircuitJson(
|
|
25
|
-
<board width="10mm" height="10mm">
|
|
26
|
-
<resistor name="R1" resistance={1000} schX={-2} />
|
|
27
|
-
<capacitor name="C1" capacitance="1uF" schX={2} />
|
|
28
|
-
<trace from=".R1 .pin2" to=".C1 .pin1" />
|
|
29
|
-
</board>,
|
|
30
|
-
)}
|
|
31
|
-
containerStyle={{ height: "100%" }}
|
|
32
|
-
debugGrid
|
|
33
|
-
clickToInteractEnabled={true}
|
|
34
|
-
/>
|
|
35
|
-
</div>
|
|
36
|
-
)
|