@tscircuit/schematic-viewer 1.2.14 → 1.4.0

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.
Files changed (54) hide show
  1. package/.github/workflows/chromatic.yml +30 -0
  2. package/.github/workflows/npm-build.yml +26 -0
  3. package/.github/workflows/npm-typecheck.yml +26 -0
  4. package/README.md +1 -1
  5. package/dist/index.d.ts +6 -7
  6. package/dist/index.js +690 -664
  7. package/dist/index.js.map +1 -1
  8. package/package.json +21 -12
  9. package/renovate.json +12 -1
  10. package/src/Schematic.tsx +148 -77
  11. package/src/lib/types/core.ts +14 -49
  12. package/src/lib/types/source-component.ts +6 -0
  13. package/src/lib/utils/collect-element-refs.ts +4 -3
  14. package/src/lib/utils/colors.ts +236 -0
  15. package/src/schematic-components/SVGPathComponent.tsx +84 -144
  16. package/src/schematic-components/SchematicChip.tsx +183 -0
  17. package/src/schematic-components/SchematicComponent.tsx +18 -24
  18. package/src/schematic-components/SchematicComponentFromSymbol.tsx +44 -0
  19. package/src/schematic-components/SchematicElement.tsx +4 -38
  20. package/src/schematic-components/SchematicTrace.tsx +4 -3
  21. package/src/schematic-components/index.tsx +7 -14
  22. package/src/stories/basics/schematic-net-label.stories.tsx +112 -166
  23. package/src/stories/basics/schematic-net-labels-2.stories.tsx +22 -20
  24. package/src/stories/bug-connections.stories.tsx +9 -6
  25. package/src/stories/bug-high-port-numbers.stories.tsx +99 -82
  26. package/src/stories/bug-pin-spacing.stories.tsx +1 -0
  27. package/src/stories/bugs/bug1-y-flip.stories.tsx +3 -2
  28. package/src/stories/bugs/bug3-scaling-trace.stories.tsx +11 -5
  29. package/src/stories/bugs/bug4-schematic-line.stories.tsx +0 -1
  30. package/src/stories/bugs/bug5-diode.stories.tsx +0 -1
  31. package/src/stories/bugs/bug8-autolayout.stories.tsx +22 -31
  32. package/src/stories/circuit-components/diode.stories.tsx +3 -1
  33. package/src/stories/circuit-components/resistor.stories.tsx +3 -1
  34. package/src/stories/component-drawing-example.stories.tsx +2 -2
  35. package/src/stories/led-circuit-react.stories.tsx +40 -45
  36. package/src/stories/net-alias.stories.tsx +1 -1
  37. package/src/stories/off-center-render.stories.tsx +6 -6
  38. package/src/stories/rotated-resistor.stories.tsx +1 -1
  39. package/src/stories/schematic-path.stories.tsx +1 -1
  40. package/src/stories/three-sided-bug.stories.tsx +8 -8
  41. package/src/pages/led-circuit.tsx +0 -96
  42. package/src/schematic-components/ProjectComponent.tsx +0 -70
  43. package/src/schematic-components/SchematicBox.tsx +0 -29
  44. package/src/schematic-components/SchematicBug.tsx +0 -90
  45. package/src/schematic-components/SchematicLine.tsx +0 -48
  46. package/src/schematic-components/SchematicPath.tsx +0 -51
  47. package/src/schematic-components/SchematicPort.tsx +0 -63
  48. package/src/schematic-components/SimpleCapacitor.tsx +0 -29
  49. package/src/schematic-components/SimpleDiode.tsx +0 -42
  50. package/src/schematic-components/SimpleGround.tsx +0 -30
  51. package/src/schematic-components/SimpleInductor.tsx +0 -29
  52. package/src/schematic-components/SimplePowerSource.tsx +0 -43
  53. package/src/schematic-components/SimpleResistor.tsx +0 -28
  54. package/src/stories/led-circuit-builder.stories.tsx +0 -104
@@ -1,79 +1,99 @@
1
+ import { Circuit } from "@tscircuit/core"
1
2
  import { Schematic } from "Schematic"
2
3
 
3
- const FTDIBasic3v3 = () => (
4
- <group>
5
- <bug
6
- name="U1"
7
- port_arrangement={{
8
- left_side: {
9
- pins: [16, 15, 20, 17, 4, 27, 28, 19, 26, 25, 7, 18, 21],
10
- direction: "top-to-bottom",
11
- },
12
- right_side: {
13
- pins: [1, 5, 11, 3, 2, 9, 10, 6, 23, 22, 14, 13, 12],
14
- direction: "top-to-bottom",
15
- },
16
- }}
17
- footprint="ssop28Db"
18
- port_labels={{
19
- "1": "TXD",
20
- "5": "RXD",
21
- "11": "CTS",
22
- "3": "RTS",
23
- "2": "DTR",
24
- "9": "DSR",
25
- "10": "DCD",
26
- "6": "RI",
27
- "23": "TXLED",
28
- "22": "RXLED",
29
- "14": "PWRUN",
30
- "13": "TXDEN",
31
- "12": "SLEEP",
32
- "16": "USBDM",
33
- "15": "USBDP",
34
- "20": "VCC",
35
- "17": "3V3OUT",
36
- "4": "VCCIO",
37
- "27": "OSCI",
38
- "28": "OSCO",
39
- "19": "RESET",
40
- "26": "TEST",
41
- "25": "AGND",
42
- "7": "GND7",
43
- "18": "GND18",
44
- "21": "GND21",
45
- }}
46
- />
47
- <resistor
48
- resistance="1kohm"
49
- name="R1"
50
- footprint="0805"
51
- center={[3, 0]}
52
- rotation="90deg"
53
- />
54
- <resistor
55
- resistance="1kohm"
56
- name="R2"
57
- footprint="0805"
58
- center={[4.5, 0]}
59
- rotation="90deg"
60
- />
61
- <diode name="LED1" footprint="0805" rotation="90deg" center={[3, 2]} />
62
- <diode name="LED2" footprint="0805" rotation="90deg" center={[4.5, 2]} />
63
- <netalias net="5V" center={[3, -2]} />
64
- <netalias net="5V" center={[4.5, -2]} />
65
- <trace path={[".5V", ".R2 > port.left"]} />
66
- <trace path={[".5V", ".R1 > port.left"]} />
67
- <trace path={[".R1 > port.right", ".LED1 > port.left"]} />
68
- <trace path={[".R2 > port.right", ".LED2 > port.left"]} />
69
- <trace path={[".LED1 > port.right", ".U1 > .TXLED"]} />
70
- <trace path={[".LED2 > port.right", ".U1 > .RXLED"]} />
71
- <netalias net="GND" center={[-3, 4]} rotation="180deg" />
72
- <netalias net="GND" center={[-5, 3]} rotation="180deg" />
73
- <netalias net="GND" center={[-6, 3]} rotation="180deg" />
74
- <netalias net="GND" center={[-7, 3]} rotation="180deg" />
75
- <netalias net="GND" center={[-8, 2]} rotation="180deg" />
76
- {/* <component>
4
+ export const BugHighPortNumbers = () => {
5
+ const circuit = new Circuit()
6
+
7
+ circuit.add(
8
+ <group>
9
+ <chip
10
+ name="U1"
11
+ manufacturerPartNumber="part-number"
12
+ schPortArrangement={{
13
+ leftSide: {
14
+ pins: [16, 15, 20, 17, 4, 27, 28, 19, 26, 25, 7, 18, 21],
15
+ direction: "top-to-bottom",
16
+ },
17
+ rightSide: {
18
+ pins: [1, 5, 11, 3, 2, 9, 10, 6, 23, 22, 14, 13, 12],
19
+ direction: "top-to-bottom",
20
+ },
21
+ }}
22
+ schWidth={1}
23
+ footprint="ssop28Db"
24
+ pinLabels={{
25
+ "1": "TXD",
26
+ "5": "RXD",
27
+ "11": "CTS",
28
+ "3": "RTS",
29
+ "2": "DTR",
30
+ "9": "DSR",
31
+ "10": "DCD",
32
+ "6": "RI",
33
+ "23": "TXLED",
34
+ "22": "RXLED",
35
+ "14": "PWRUN",
36
+ "13": "TXDEN",
37
+ "12": "SLEEP",
38
+ "16": "USBDM",
39
+ "15": "USBDP",
40
+ "20": "VCC",
41
+ "17": "3V3OUT",
42
+ "4": "VCCIO",
43
+ "27": "OSCI",
44
+ "28": "OSCO",
45
+ "19": "RESET",
46
+ "26": "TEST",
47
+ "25": "AGND",
48
+ "7": "GND7",
49
+ "18": "GND18",
50
+ "21": "GND21",
51
+ }}
52
+ />
53
+ <resistor
54
+ resistance="1kohm"
55
+ name="R1"
56
+ footprint="0805"
57
+ schX={3}
58
+ schY={0}
59
+ symbolName="boxresistor_vert"
60
+ />
61
+ <resistor
62
+ resistance="1kohm"
63
+ name="R2"
64
+ footprint="0805"
65
+ schX={4.5}
66
+ schY={0}
67
+ symbolName="boxresistor_vert"
68
+ />
69
+ <diode
70
+ name="LED1"
71
+ footprint="0805"
72
+ symbolName="diode_vert"
73
+ schX={3}
74
+ schY={3}
75
+ />
76
+ <diode
77
+ name="LED2"
78
+ footprint="0805"
79
+ symbolName="diode_vert"
80
+ schX={4.5}
81
+ schY={3}
82
+ />
83
+ <netalias net="5V" schX={3} schY={-2} />
84
+ <netalias net="5V" schX={4.5} schY={-2} />
85
+ {/* <trace path={[".5V", ".R2 > port.left"]} />
86
+ <trace path={[".5V", ".R1 > port.left"]} /> */}
87
+ <trace path={[".R1 > port.right", ".LED1 > port.left"]} />
88
+ <trace path={[".R2 > port.right", ".LED2 > port.left"]} />
89
+ <trace path={[".LED1 > port.right", ".U1 > .pin1"]} />
90
+ <trace path={[".LED2 > port.right", ".U1 > .RXLED"]} />
91
+ <netalias net="GND" schX={-3} schY={4} schRotation="180deg" />
92
+ <netalias net="GND" schX={-5} schY={3} schRotation="180deg" />
93
+ <netalias net="GND" schX={-6} schY={3} schRotation="180deg" />
94
+ <netalias net="GND" schX={-7} schY={3} schRotation="180deg" />
95
+ <netalias net="GND" schX={-8} schY={2} schRotation="180deg" />
96
+ {/* <component>
77
97
  <schematicbox
78
98
  name="USB"
79
99
  center={[-9, 0]}
@@ -83,15 +103,12 @@ const FTDIBasic3v3 = () => (
83
103
  height={2}
84
104
  />
85
105
  </component> */}
86
- </group>
87
- )
88
-
89
- export const BugHighPortNumbers = () => {
90
- return (
91
- <Schematic style={{ height: 600 }}>
92
- <FTDIBasic3v3 />
93
- </Schematic>
106
+ </group>,
94
107
  )
108
+
109
+ const circuitJson = circuit.getCircuitJson()
110
+
111
+ return <Schematic soup={circuitJson as any} style={{ height: 600 }} />
95
112
  }
96
113
 
97
114
  export default {
@@ -3,6 +3,7 @@ import { Schematic } from "Schematic"
3
3
  const BugPinSpacingExample = () => (
4
4
  <bug
5
5
  name="U2"
6
+ manufacturerPartNumber="part-number"
6
7
  schPortArrangement={{
7
8
  leftSize: 2,
8
9
  rightSize: 2,
@@ -4,8 +4,9 @@ export const Bug1YFlip = () => {
4
4
  return (
5
5
  <Schematic style={{ height: 600 }}>
6
6
  <bug
7
- port_arrangement={{ top_size: 2 }}
8
- port_labels={{ 1: "foo", 2: "baz" }}
7
+ name="U1"
8
+ schPortArrangement={{ topSize: 2 }}
9
+ pinLabels={{ 1: "foo", 2: "baz" }}
9
10
  />
10
11
  </Schematic>
11
12
  )
@@ -1,13 +1,19 @@
1
- import { useResistor } from "@tscircuit/react-fiber"
2
1
  import { Schematic } from "../../Schematic"
3
2
 
4
3
  export const Bug3ScalingTrace = () => {
5
- const R1 = useResistor("R1", { resistance: "10" })
6
- const R2 = useResistor("R2", { resistance: "1k" })
7
4
  return (
8
5
  <Schematic style={{ height: 500 }}>
9
- <R1 schX={2} schY={1} />
10
- <R2 schRotation="90deg" schX={0} schY={3} left={R1.left} />
6
+ <board width={"10mm"} height={"10mm"} pcbX={0} pcbY={0}>
7
+ <resistor name="R1" resistance="10" schX={2} schY={1} />
8
+ <resistor
9
+ name="R2"
10
+ resistance="1k"
11
+ schX={0}
12
+ schY={3}
13
+ symbolName="boxresistor_vert"
14
+ />
15
+ <trace path={[".R1 > port.right", ".R2 > port.left"]} />
16
+ </board>
11
17
  </Schematic>
12
18
  )
13
19
  }
@@ -1,4 +1,3 @@
1
- import { useResistor } from "@tscircuit/react-fiber"
2
1
  import { Schematic } from "../../Schematic"
3
2
 
4
3
  export const Bug4SchematicLine = () => {
@@ -1,4 +1,3 @@
1
- import { useResistor } from "@tscircuit/react-fiber"
2
1
  import { Schematic } from "../../Schematic"
3
2
 
4
3
  export const Bug5SchematicLine = () => {
@@ -1,45 +1,36 @@
1
- import { Schematic } from "../../Schematic"
2
1
  import { layout } from "@tscircuit/layout"
3
- import { useBug, useResistor, useCapacitor } from "@tscircuit/react-fiber"
2
+ import { Schematic } from "../../Schematic"
4
3
 
5
4
  export const Bug8Autolayout = () => {
6
- const U1 = useBug("U1", {
7
- pinLabels: {
8
- 1: "VCC",
9
- 2: "D0",
10
- 3: "D1",
11
- 4: "GND",
12
- 5: "INP",
13
- 6: "THR",
14
- },
15
- schPortArrangement: {
16
- leftSize: 3,
17
- topSize: 0,
18
- bottomSize: 0,
19
- rightSize: 3,
20
- },
21
- })
22
-
23
- const R1 = useResistor("R1", { resistance: "10k" })
24
- const R2 = useResistor("R2", { resistance: "1k" })
25
- const R3 = useResistor("R3", { resistance: "5k" })
26
- const C1 = useCapacitor("C1", { capacitance: "1uF" })
27
-
28
5
  return (
29
6
  <div>
30
7
  <Schematic style={{ height: 500 }}>
31
8
  <board
32
9
  layout={layout().autoLayoutSchematic()}
33
- pcbCenterX={0}
34
- pcbCenterY={0}
10
+ pcbX={0}
11
+ pcbY={0}
35
12
  width={"10mm"}
36
13
  height={"10mm"}
37
14
  >
38
- <U1 />
39
- <R1 left={U1.D1} right={U1.VCC} />
40
- <R2 left={U1.D0} right={U1.GND} />
41
- <R3 left={U1.INP} right={U1.THR} />
42
- <C1 left={U1.INP} right={U1.THR} />
15
+ <bug
16
+ name="U1"
17
+ schX={0}
18
+ schY={0}
19
+ schPortArrangement={{
20
+ leftSize: 3,
21
+ topSize: 0,
22
+ bottomSize: 0,
23
+ rightSize: 3,
24
+ }}
25
+ />
26
+ <resistor name="R1" resistance="10k" schX={0} schY={1} />
27
+ <resistor name="R2" resistance="1k" schX={0} schY={3} />
28
+ <resistor name="R3" resistance="5k" schX={2} schY={1} />
29
+ <capacitor name="C1" capacitance="1uF" schX={2} schY={3} />
30
+ <trace path={[".R1 > port.right", ".R2 > port.left"]} />
31
+ <trace path={[".R2 > port.right", ".R3 > port.left"]} />
32
+ <trace path={[".R3 > port.right", ".C1 > port.left"]} />
33
+ <trace path={[".C1 > port.right", ".R1 > port.left"]} />
43
34
  </board>
44
35
  </Schematic>
45
36
  </div>
@@ -3,7 +3,9 @@ import { Schematic } from "../../Schematic"
3
3
  export const Diode = () => {
4
4
  return (
5
5
  <Schematic style={{ height: 500 }}>
6
- <diode name="D1" schX={3} schY={1} />
6
+ <board width={10} height={10}>
7
+ <diode name="D1" schX={2} schY={1} />
8
+ </board>
7
9
  </Schematic>
8
10
  )
9
11
  }
@@ -3,7 +3,9 @@ import { Schematic } from "../../Schematic"
3
3
  export const Resistor = () => {
4
4
  return (
5
5
  <Schematic style={{ height: 500 }}>
6
- <resistor name="R1" resistance="10 ohm" schX={2} schY={1} />
6
+ <board width={10} height={10}>
7
+ <resistor name="R1" resistance="10 ohm" schX={2} schY={1} />
8
+ </board>
7
9
  </Schematic>
8
10
  )
9
11
  }
@@ -3,8 +3,8 @@ import { Schematic } from "Schematic"
3
3
  export const ComponentDrawingExample = () => {
4
4
  return (
5
5
  <Schematic style={{ height: 600 }}>
6
- <component>
7
- <schematicbox x={0} y={0} width="6mm" height="6mm" />
6
+ <component name={"C1"}>
7
+ <schematicbox schX={0} schY={0} width="6mm" height="6mm" />
8
8
  <schematicline x1={0} y1={0} x2={1} y2={1} />
9
9
  </component>
10
10
  </Schematic>
@@ -3,51 +3,46 @@ import { Schematic } from "../Schematic"
3
3
  export const LEDCircuitReact = () => {
4
4
  return (
5
5
  <Schematic style={{ height: 500 }}>
6
- <resistor name="R1" resistance="10 ohm" center={[2, 1]} />
7
- <capacitor
8
- name="C1"
9
- capacitance="10 uF"
10
- center={[4, 2]}
11
- rotation="90deg"
12
- />
13
- <resistor
14
- name="R2"
15
- resistance="10 ohm"
16
- center={[6, 1]}
17
- rotation="90deg"
18
- />
19
- <trace
20
- path={[".R1 > port.right", ".C1 > port.left", ".R2 > port.left"]}
21
- />
22
- <powersource voltage="5V" center={[1, 2]} name="main_power" />
23
- <trace path={[".main_power > port.positive", ".R1 > port.left"]} />
24
- <trace
25
- path={["power > port.negative", ".C1 > port.right", ".R2 > port.right"]}
26
- />
27
- <bug
28
- name="B1"
29
- port_arrangement={{ left_size: 3, right_size: 3 }}
30
- center={[8, 3]}
31
- port_labels={{
32
- 1: "PWR",
33
- 2: "NC",
34
- 3: "RG",
35
- 4: "D0",
36
- 5: "D1",
37
- 6: "GND",
38
- }}
39
- />
40
- <trace path={[".B1 > port.PWR", ".R2 > port.left"]} />
41
- <ground name="GND" center={[11, 3]} />
42
- <trace path={[".B1 > port.GND", ".GND > .gnd"]} />
43
- {/* <trace from=".B1 > port.GND" to=".GND > .gnd" /> */}
44
- <diode name="D1" center={[6, 3.5]} rotation="180deg" />
45
- <trace path={[".D1 > port.right", ".C1 > .right"]} />
46
- <trace path={[".D1 > port.left", ".B1 > .RG"]} />
47
- {/* <trace from=".D1 > .left" to=".B1 > .RG" /> */}
48
- {/* <trace from=".D1 > .right" to=".C1> .right" /> */}
49
- <netalias center={["10mm", "1.5mm"]} net="D0BUS" />
50
- <trace path={[".B1 > .D0", ".D0BUS"]} />
6
+ <group>
7
+ <resistor name="R1" resistance="10 ohm" schX={2} schY={1}/>
8
+ <capacitor
9
+ name="C1"
10
+ capacitance="10 uF"
11
+ schX={4}
12
+ schY={2}
13
+ symbolName="capacitor_vert"
14
+ />
15
+ <resistor
16
+ name="R2"
17
+ resistance="10 ohm"
18
+ schX={6}
19
+ schY={1}
20
+ />
21
+ <trace path={[".R1 > port.right", ".C1 > port.left"]} />
22
+ <trace path={[".C1 > port.right", ".R2 > port.left"]} />
23
+ <powersource voltage={5} schX={1} schY={2} name="main_power" />
24
+ <trace path={[".main_power > port.positive", ".R1 > port.left"]} />
25
+ <trace path={[".main_power > port.negative", ".C1 > port.right"]} />
26
+ <trace path={[".C1 > port.right", ".R2 > port.right"]} />
27
+ <bug
28
+ name="B1"
29
+ schPortArrangement={{
30
+ leftSide: { pins: [3, 2, 1], direction: "top-to-bottom" },
31
+ rightSide: { pins: [6, 5, 4], direction: "top-to-bottom" },
32
+ }}
33
+ // schWidth={4}
34
+ schX={8}
35
+ schY={3}
36
+ pinLabels={{
37
+ 1: "PWR",
38
+ 2: "NC",
39
+ 3: "RG",
40
+ 4: "D0",
41
+ 5: "D1",
42
+ 6: "GND",
43
+ }}
44
+ />
45
+ </group>
51
46
  </Schematic>
52
47
  )
53
48
  }
@@ -83,7 +83,7 @@ const soup = [
83
83
  ]
84
84
 
85
85
  export const NetAliasSoup = () => {
86
- return <Schematic style={{ height: 500 }} soup={soup} />
86
+ return <Schematic style={{ height: 500 }} soup={soup as any} />
87
87
  }
88
88
 
89
89
  export default {
@@ -7,13 +7,13 @@ export const OffCenterRendering = () => {
7
7
  <Schematic style={{ height: 600 }}>
8
8
  <bug
9
9
  name="B1"
10
- port_arrangement={{
11
- left_size: 3,
12
- right_size: 2,
10
+ schPortArrangement={{
11
+ leftSide: { pins: [3, 2, 1], direction: "top-to-bottom" },
12
+ rightSide: { pins: [6, 5, 4], direction: "top-to-bottom" },
13
13
  }}
14
- sch_cx={8}
15
- sch_cy={3}
16
- port_labels={{
14
+ schX={8}
15
+ schY={3}
16
+ pinLabels={{
17
17
  "1": "D0",
18
18
  "2": "D1",
19
19
  }}
@@ -9,7 +9,7 @@ export const RotatedResistor = () => {
9
9
  schX={2}
10
10
  schY={1}
11
11
  schRotation="90deg"
12
- rotation="90deg"
12
+ pcbRotation="90deg"
13
13
  />
14
14
  </Schematic>
15
15
  )
@@ -31,7 +31,7 @@ const soup: AnyElement[] = [
31
31
  ]
32
32
 
33
33
  export const SchematicPathSoup = () => {
34
- return <Schematic style={{ height: 500 }} soup={soup} />
34
+ return <Schematic style={{ height: 500 }} soup={soup as any} />
35
35
  }
36
36
 
37
37
  export default {
@@ -5,15 +5,15 @@ export const ThreeSidedBug = () => {
5
5
  <Schematic style={{ height: 600 }}>
6
6
  <bug
7
7
  name="B1"
8
- port_arrangement={{
9
- left_size: 3,
10
- right_size: 3,
11
- top_size: 0,
12
- bottom_size: 5,
8
+ schPortArrangement={{
9
+ leftSize: 3,
10
+ rightSize: 3,
11
+ topSize: 0,
12
+ bottomSize: 5,
13
13
  }}
14
- sch_cx={8}
15
- sch_cy={3}
16
- port_labels={{
14
+ schX={8}
15
+ schY={3}
16
+ pinLabels={{
17
17
  "1": "D0",
18
18
  "2": "D1",
19
19
  }}
@@ -1,96 +0,0 @@
1
- import { createProjectBuilder } from "@tscircuit/builder"
2
- import { useMaybePromise } from "lib/hooks"
3
- import { Schematic } from "../Schematic"
4
-
5
- const pb = createProjectBuilder()
6
- const $elements = pb
7
- .addGroup((gb) =>
8
- gb
9
- .addResistor((rb) =>
10
- rb
11
- .setSourceProperties({
12
- resistance: "10 ohm",
13
- name: "R1",
14
- })
15
- .setSchematicCenter(2, 1)
16
- )
17
- .addCapacitor((cb) =>
18
- cb
19
- .setSourceProperties({
20
- name: "C1",
21
- capacitance: "10 uF",
22
- })
23
- .setSchematicCenter(4, 2)
24
- .setSchematicRotation("90deg")
25
- )
26
- .addResistor((cb) =>
27
- cb
28
- .setSourceProperties({
29
- resistance: "10 ohm",
30
- name: "R2",
31
- })
32
- .setSchematicCenter(6, 1)
33
- .setSchematicRotation("90deg")
34
- )
35
- .addTrace([".R1 > port.right", ".C1 > port.left", ".R2 > port.left"])
36
- .addPowerSource((cb) =>
37
- cb
38
- .setSourceProperties({
39
- voltage: "5V",
40
- name: "main_power",
41
- })
42
- .setSchematicCenter(1, 2)
43
- )
44
- .addTrace(["power > port.positive", ".R1 > port.left"])
45
- .addTrace([
46
- "power > port.negative",
47
- ".C1 > port.right",
48
- ".R2 > port.right",
49
- ])
50
- .addBug((cb) =>
51
- cb
52
- .setSourceProperties({ name: "B1" })
53
- .setSchematicProperties({
54
- port_arrangement: {
55
- left_size: 3,
56
- right_size: 3,
57
- },
58
- })
59
- .labelPort(1, "PWR")
60
- .labelPort(2, "NC")
61
- .labelPort(3, "RG")
62
- .labelPort(4, "D0")
63
- .labelPort(5, "D1")
64
- .labelPort(6, "GND")
65
- .setSchematicCenter(8, 3)
66
- )
67
- .addTrace([".B1 > port.PWR", ".R2 > port.left"])
68
- .addGround((cb) =>
69
- cb
70
- .setSourceProperties({
71
- name: "GND",
72
- })
73
- .setSchematicCenter(11, 3)
74
- )
75
- .addTrace([".B1 > port.GND", ".gnd"])
76
- .addDiode((db) =>
77
- db
78
- .setSourceProperties({ name: "D1" })
79
- .setSchematicCenter(6, 3.5)
80
- .setSchematicRotation("180deg")
81
- )
82
- .addTrace([".D1 > .left", ".B1 > .RG"])
83
- .addTrace([".D1 > .right", ".C1 > .right"])
84
- )
85
- .build(pb.createBuildContext())
86
-
87
- export default () => {
88
- const elements = useMaybePromise($elements)
89
- if (!elements) return null
90
- return (
91
- <>
92
- <Schematic style={{ height: 400 }} elements={elements} />
93
- <pre>{JSON.stringify(elements, null, " ")}</pre>
94
- </>
95
- )
96
- }