@tscircuit/pcb-viewer 1.0.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.
@@ -0,0 +1,20 @@
1
+ import React, { useEffect, useRef } from "react"
2
+ import attinyEagle from "../assets/attiny-eagle"
3
+ import { drawEagle } from "../lib/draw-eagle"
4
+ import { Drawer } from "../lib/Drawer"
5
+
6
+ export default () => {
7
+ const ref = useRef()
8
+ let [width, height] = [500, 500]
9
+ useEffect(() => {
10
+ const drawer = new Drawer(ref.current)
11
+ drawer.clear()
12
+ drawEagle(drawer, attinyEagle as any)
13
+ }, [])
14
+
15
+ return (
16
+ <div style={{ backgroundColor: "black" }}>
17
+ <canvas ref={ref} width={width} height={height}></canvas>
18
+ </div>
19
+ )
20
+ }
@@ -0,0 +1,23 @@
1
+ import React, { useEffect, useRef } from "react"
2
+ import { Drawer } from "../lib/Drawer"
3
+
4
+ export default () => {
5
+ const ref = useRef()
6
+ let [width, height] = [500, 500]
7
+ useEffect(() => {
8
+ const drawer = new Drawer(ref.current)
9
+ drawer.clear()
10
+ drawer.equip({ size: 30, shape: "square", mode: "add" })
11
+ drawer.moveTo(50, 50)
12
+ drawer.lineTo(300, 50)
13
+ drawer.equip({ size: 30, shape: "square", mode: "subtract" })
14
+ drawer.moveTo(250, 0)
15
+ drawer.lineTo(250, 300)
16
+ }, [])
17
+
18
+ return (
19
+ <div style={{ backgroundColor: "black" }}>
20
+ <canvas ref={ref} width={width} height={height}></canvas>
21
+ </div>
22
+ )
23
+ }
@@ -0,0 +1,64 @@
1
+ import React, { useEffect, useRef } from "react"
2
+ import attinyEagle from "../assets/attiny-eagle"
3
+ import { drawEagle } from "../lib/draw-eagle"
4
+ import { drawPrimitives } from "../lib/draw-primitives"
5
+ import { Drawer } from "../lib/Drawer"
6
+
7
+ export default () => {
8
+ const ref = useRef()
9
+ let [width, height] = [500, 500]
10
+ useEffect(() => {
11
+ const drawer = new Drawer(ref.current)
12
+ drawer.clear()
13
+ drawPrimitives(drawer, [
14
+ {
15
+ pcb_drawing_type: "circle",
16
+ x: 100,
17
+ y: 100,
18
+ r: 50,
19
+ layer: { name: "top" },
20
+ },
21
+ {
22
+ pcb_drawing_type: "rect",
23
+ x: 100,
24
+ y: 270,
25
+ w: 100,
26
+ h: 100,
27
+ layer: { name: "top" },
28
+ },
29
+ {
30
+ pcb_drawing_type: "text",
31
+ x: 50,
32
+ y: 210,
33
+ size: 45,
34
+ text: "Hello World1",
35
+ layer: { name: "top" },
36
+ },
37
+ {
38
+ pcb_drawing_type: "line",
39
+ x1: 0,
40
+ y1: 500,
41
+ x2: 100,
42
+ y2: 400,
43
+ width: 10,
44
+ layer: { name: "top" },
45
+ },
46
+ {
47
+ pcb_drawing_type: "line",
48
+ x1: 0,
49
+ y1: 400,
50
+ x2: 100,
51
+ y2: 450,
52
+ width: 10,
53
+ squareCap: true,
54
+ layer: { name: "top" },
55
+ },
56
+ ])
57
+ }, [])
58
+
59
+ return (
60
+ <div style={{ backgroundColor: "black" }}>
61
+ <canvas ref={ref} width={width} height={height}></canvas>
62
+ </div>
63
+ )
64
+ }
@@ -0,0 +1,43 @@
1
+ import { GroupBuilder } from "@tscircuit/builder"
2
+ import React, { useEffect, useRef } from "react"
3
+ import { PCBViewer } from "../PCBViewer"
4
+
5
+ declare global {
6
+ namespace JSX {
7
+ interface IntrinsicElements {
8
+ custom: {
9
+ onRender: (gb: GroupBuilder) => any
10
+ }
11
+ }
12
+ }
13
+ }
14
+
15
+ export default () => {
16
+ return (
17
+ <div style={{ backgroundColor: "black" }}>
18
+ <PCBViewer>
19
+ <custom
20
+ onRender={(gb) => {
21
+ // gb.addResistor((rb) => {})
22
+ gb.addComponent((cb) => {
23
+ cb.footprint.addPad((pb) =>
24
+ pb
25
+ .setShape("rect")
26
+ .setLayer("top")
27
+ .setPosition(100, 100)
28
+ .setSize(20, 20)
29
+ )
30
+ cb.footprint.addPad((pb) =>
31
+ pb
32
+ .setShape("rect")
33
+ .setLayer("top")
34
+ .setPosition(140, 100)
35
+ .setSize(20, 20)
36
+ )
37
+ })
38
+ }}
39
+ />
40
+ </PCBViewer>
41
+ </div>
42
+ )
43
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es5",
4
+ "lib": ["dom", "dom.iterable", "esnext"],
5
+ "allowJs": true,
6
+ "skipLibCheck": true,
7
+ "strict": false,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "noEmit": true,
10
+ "incremental": false,
11
+ "esModuleInterop": true,
12
+ "module": "esnext",
13
+ "moduleResolution": "node",
14
+ "resolveJsonModule": true,
15
+ "isolatedModules": true,
16
+ "baseUrl": "./src",
17
+ "jsx": "preserve"
18
+ },
19
+ "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
20
+ "exclude": ["node_modules"]
21
+ }