Skip to content

Commit d846e43

Browse files
committed
initial implementation
1 parent 6dd693d commit d846e43

File tree

3 files changed

+98
-3
lines changed

3 files changed

+98
-3
lines changed

src/App.tsx

+85-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,90 @@
1-
import { useState } from "react"
1+
import { useState, useCallback } from "react"
2+
import { PCBViewer } from "@tscircuit/pcb-viewer"
3+
import { parseDsnToCircuitJson } from "dsn-converter"
24

35
function App() {
4-
return <h1 className="text-3xl font-bold underline">Hello world!</h1>
6+
const [circuitJson, setCircuitJson] = useState<any>(null)
7+
8+
const handleDrop = useCallback((e: React.DragEvent) => {
9+
e.preventDefault()
10+
const file = e.dataTransfer.files[0]
11+
if (file) {
12+
const reader = new FileReader()
13+
reader.onload = async (e) => {
14+
const dsnContent = e.target?.result as string
15+
try {
16+
const json = parseDsnToCircuitJson(dsnContent)
17+
setCircuitJson(json)
18+
} catch (err) {
19+
console.error("Failed to parse DSN file:", err)
20+
alert("Failed to parse DSN file. Please check the format.")
21+
}
22+
}
23+
reader.readAsText(file)
24+
}
25+
}, [])
26+
27+
const handlePaste = useCallback((e: React.ClipboardEvent) => {
28+
const dsnContent = e.clipboardData.getData("text")
29+
if (dsnContent) {
30+
try {
31+
const json = parseDsnToCircuitJson(dsnContent)
32+
setCircuitJson(json)
33+
} catch (err) {
34+
console.error("Failed to parse DSN content:", err)
35+
alert("Failed to parse DSN content. Please check the format.")
36+
}
37+
}
38+
}, [])
39+
40+
return (
41+
<div
42+
className="min-h-screen bg-gray-900 text-white p-4"
43+
onDrop={handleDrop}
44+
onDragOver={(e) => e.preventDefault()}
45+
onPaste={handlePaste}
46+
tabIndex={0}
47+
>
48+
{circuitJson ? (
49+
<PCBViewer circuitJson={circuitJson} height={800} />
50+
) : (
51+
<div className="flex flex-col items-center justify-center min-h-screen">
52+
<div className="text-center">
53+
<h1 className="text-3xl font-bold mb-4">
54+
Specctra DSN File Viewer
55+
</h1>
56+
<p className="text-gray-400 mb-2">Drag and drop a DSN file here</p>
57+
<p className="text-gray-400">
58+
or paste DSN content with Ctrl/CMD+V
59+
</p>
60+
</div>
61+
<div className="text-gray-400 text-sm mt-16">
62+
Unofficial Specctra DSN Parser/Viewer created by{" "}
63+
<a
64+
className="underline"
65+
href="https://github.com/tscircuit/tscircuit"
66+
>
67+
tscircuit
68+
</a>
69+
, get the{" "}
70+
<a
71+
className="underline"
72+
href="https://github.com/tscircuit/dsn-viewer"
73+
>
74+
source code here
75+
</a>
76+
.
77+
</div>
78+
<a className="mt-4" href="https://github.com/tscircuit/tscircuit">
79+
<img
80+
src="https://img.shields.io/github/stars/tscircuit/tscircuit?style=social"
81+
alt="GitHub stars"
82+
/>
83+
</a>
84+
</div>
85+
)}
86+
</div>
87+
)
588
}
689

790
export default App

src/index.css

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
@tailwind base;
22
@tailwind components;
3-
@tailwind utilities;
3+
@tailwind utilities;
4+
5+
body {
6+
margin: 0;
7+
padding: 0;
8+
}
9+
10+
#root {
11+
min-height: 100vh;
12+
}

vite.config.ts

+3
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ import react from "@vitejs/plugin-react"
44
// https://vite.dev/config/
55
export default defineConfig({
66
plugins: [react()],
7+
define: {
8+
global: "globalThis",
9+
},
710
})

0 commit comments

Comments
 (0)