Skip to content

Commit 4bdf835

Browse files
committed
init
0 parents  commit 4bdf835

21 files changed

+646
-0
lines changed

.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

README.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# React + TypeScript + Vite
2+
3+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4+
5+
Currently, two official plugins are available:
6+
7+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9+
10+
## Expanding the ESLint configuration
11+
12+
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
13+
14+
- Configure the top-level `parserOptions` property like this:
15+
16+
```js
17+
export default tseslint.config({
18+
languageOptions: {
19+
// other options...
20+
parserOptions: {
21+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
22+
tsconfigRootDir: import.meta.dirname,
23+
},
24+
},
25+
})
26+
```
27+
28+
- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
29+
- Optionally add `...tseslint.configs.stylisticTypeChecked`
30+
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:
31+
32+
```js
33+
// eslint.config.js
34+
import react from 'eslint-plugin-react'
35+
36+
export default tseslint.config({
37+
// Set the react version
38+
settings: { react: { version: '18.3' } },
39+
plugins: {
40+
// Add the react plugin
41+
react,
42+
},
43+
rules: {
44+
// other rules...
45+
// Enable its recommended rules
46+
...react.configs.recommended.rules,
47+
...react.configs['jsx-runtime'].rules,
48+
},
49+
})
50+
```

biome.json

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.9.3/schema.json",
3+
"organizeImports": {
4+
"enabled": true
5+
},
6+
"formatter": {
7+
"enabled": true,
8+
"indentStyle": "space"
9+
},
10+
"files": {
11+
"ignore": ["cosmos-export", "dist", "package.json", "tsconfig.*"]
12+
},
13+
"javascript": {
14+
"formatter": {
15+
"jsxQuoteStyle": "double",
16+
"quoteProperties": "asNeeded",
17+
"trailingCommas": "all",
18+
"semicolons": "asNeeded",
19+
"arrowParentheses": "always",
20+
"bracketSpacing": true,
21+
"bracketSameLine": false
22+
}
23+
},
24+
"linter": {
25+
"enabled": true,
26+
"rules": {
27+
"recommended": true,
28+
"suspicious": {
29+
"noExplicitAny": "off"
30+
},
31+
"complexity": {
32+
"noForEach": "info"
33+
},
34+
"style": {
35+
"noUselessElse": "off",
36+
"noNonNullAssertion": "off",
37+
"useNumberNamespace": "off",
38+
"useFilenamingConvention": {
39+
"level": "error",
40+
"options": {
41+
"strictCase": true,
42+
"requireAscii": true,
43+
"filenameCases": ["kebab-case", "export"]
44+
}
45+
}
46+
}
47+
}
48+
}
49+
}

bun.lockb

110 KB
Binary file not shown.

docs/dsn-converter-readme.md

+176
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# dsn-converter
2+
3+
A TypeScript library for converting between DSN files and Circuit JSON format.
4+
5+
## Overview
6+
7+
dsn-converter is a powerful tool that enables bidirectional conversion between Specctr DSN format and Circuit JSON. This makes it possible to:
8+
9+
- Parse Specctra DSN files into a workable JSON format
10+
- Convert Circuit JSON back into KiCad-compatible DSN files
11+
- Visualize PCB designs using SVG rendering
12+
13+
## Installation
14+
15+
```bash
16+
# Using bun
17+
bun add dsn-converter
18+
19+
# Using npm
20+
npm install dsn-converter
21+
```
22+
23+
## Usage
24+
25+
### Basic Usage
26+
27+
#### Converting DSN to Circuit JSON
28+
29+
```typescript
30+
import { parseDsnToCircuitJson } from "dsn-converter"
31+
32+
// Read DSN file
33+
const dsnContent = await Bun.file("your-design.dsn").text()
34+
35+
// Convert to Circuit JSON
36+
const circuitJson = parseDsnToCircuitJson(dsnContent)
37+
38+
// Save the output
39+
await Bun.write("output.circuit.json", JSON.stringify(circuitJson, null, 2))
40+
```
41+
42+
#### Converting Circuit JSON to DSN
43+
44+
```typescript
45+
import { circuitJsonToDsnString } from "dsn-converter"
46+
47+
// Convert Circuit JSON to DSN format
48+
const dsnString = circuitJsonToDsnString(circuitJson)
49+
50+
// Save the DSN file
51+
await Bun.write("output.dsn", dsnString)
52+
```
53+
54+
### Advanced Usage
55+
56+
#### Working with DSN JSON Directly
57+
58+
```typescript
59+
import {
60+
parseDsnToDsnJson,
61+
convertDsnJsonToCircuitJson,
62+
stringifyDsnJson
63+
} from "dsn-converter"
64+
65+
// Parse DSN to intermediate JSON format
66+
const dsnJson = parseDsnToDsnJson(dsnString)
67+
68+
// Modify the DSN JSON structure
69+
dsnJson.placement.components.push({
70+
name: "NewComponent",
71+
place: {
72+
refdes: "U1",
73+
x: 1000,
74+
y: 1000,
75+
side: "front",
76+
rotation: 0
77+
}
78+
})
79+
80+
// Convert to Circuit JSON
81+
const circuitJson = convertDsnJsonToCircuitJson(dsnJson)
82+
83+
// Or convert back to DSN string
84+
const modifiedDsnString = stringifyDsnJson(dsnJson)
85+
```
86+
87+
#### Custom Component Processing
88+
89+
```typescript
90+
import { convertCircuitJsonToDsnJson } from "dsn-converter"
91+
92+
// Create Circuit JSON elements
93+
const elements = [
94+
{
95+
type: "pcb_smtpad",
96+
pcb_smtpad_id: "pad1",
97+
pcb_component_id: "R1",
98+
shape: "rect",
99+
x: 0,
100+
y: 0,
101+
width: 0.5,
102+
height: 0.6,
103+
layer: "top"
104+
},
105+
// Add more elements...
106+
]
107+
108+
// Convert to DSN format
109+
const dsnJson = convertCircuitJsonToDsnJson(elements)
110+
```
111+
112+
### Type Support
113+
114+
The library provides comprehensive TypeScript types:
115+
116+
```typescript
117+
import type {
118+
DsnPcb,
119+
Component,
120+
Padstack,
121+
Network,
122+
Wire
123+
} from "dsn-converter"
124+
125+
// Use types for type-safe DSN manipulation
126+
const component: Component = {
127+
name: "R1",
128+
place: {
129+
refdes: "R1",
130+
x: 1000,
131+
y: 1000,
132+
side: "front",
133+
rotation: 0
134+
}
135+
}
136+
```
137+
138+
## Features
139+
140+
- **Complete DSN Support**: Handles all major DSN file components including:
141+
142+
- Component placement
143+
- PCB layers
144+
- Traces and wiring
145+
- Padstacks and SMT pads
146+
- Net definitions
147+
- Board boundaries
148+
149+
- **Accurate Conversions**: Maintains precise measurements and positions during conversion
150+
151+
- **Type Safety**: Full TypeScript support with comprehensive type definitions
152+
153+
## Data Structure
154+
155+
### DSN Format
156+
157+
The DSN format is represented as a structured JSON with the following main sections:
158+
159+
- `parser`: Contains file metadata
160+
- `resolution`: Defines measurement units
161+
- `structure`: Describes board layers and rules
162+
- `placement`: Component positions
163+
- `library`: Component and padstack definitions
164+
- `network`: Net connections
165+
- `wiring`: Trace routing
166+
167+
### Circuit JSON
168+
169+
The Circuit JSON format includes:
170+
171+
- PCB traces
172+
- SMT pads
173+
- Component definitions
174+
- Layer information
175+
- Routing data
176+

docs/pcb-viewer-readme.md

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# @tscircuit/pcb-viewer
2+
3+
[![npm version](https://badge.fury.io/js/@tscircuit%2Fpcb-viewer.svg)](https://badge.fury.io/js/@tscircuit%2Fpcb-viewer)
4+
5+
[Examples](https://pcb-viewer.vercel.app/) · [TSCircuit](https://tscircuit.com) · [Open in CodeSandbox](https://codesandbox.io/p/github/tscircuit/pcb-viewer)
6+
7+
Render Printed Circuit Boards w/ React
8+
9+
If you want to render to an image, check out [circuit-to-png](https://github.com/tscircuit/circuit-to-png)
10+
11+
![image](https://github.com/tscircuit/pcb-viewer/assets/1910070/e010f44e-b8c0-4e1d-9d59-1ea66716427f)
12+
13+
## Usage
14+
15+
```bash
16+
npm install @tscircuit/pcb-viewer
17+
```
18+
19+
There are two main ways to use the PCBViewer:
20+
21+
### 1. Using Circuit Components
22+
23+
This approach allows you to declaratively define your circuit using React components:
24+
25+
```tsx
26+
import React from "react"
27+
import { PCBViewer } from "@tscircuit/pcb-viewer"
28+
29+
export default () => {
30+
return (
31+
<div style={{ backgroundColor: "black" }}>
32+
<PCBViewer>
33+
<resistor footprint="0805" resistance="10k" />
34+
<capacitor footprint="0603" capacitance="100nF" />
35+
</PCBViewer>
36+
</div>
37+
)
38+
}
39+
```
40+
41+
### 2. Using Circuit JSON
42+
43+
If you already have circuit JSON data, you can pass it directly:
44+
45+
```tsx
46+
import React from "react"
47+
import { PCBViewer } from "@tscircuit/pcb-viewer"
48+
49+
const circuitJson = [
50+
{
51+
type: "pcb_component",
52+
pcb_component_id: "R1",
53+
center: { x: 0, y: 0 },
54+
// ... other component properties
55+
},
56+
// ... more elements
57+
]
58+
59+
export default () => {
60+
return (
61+
<div style={{ backgroundColor: "black" }}>
62+
<PCBViewer circuitJson={circuitJson} />
63+
</div>
64+
)
65+
}
66+
```
67+
68+
### Props
69+
70+
The PCBViewer component accepts these props:
71+
72+
- `children`: Circuit components to render
73+
- `circuitJson`: Circuit JSON elements array (alternative to children)
74+
- `height`: Height of viewer in pixels (default: 600)
75+
- `allowEditing`: Enable/disable editing capabilities (default: true)
76+
- `editEvents`: Array of edit events to apply
77+
- `onEditEventsChanged`: Callback when edit events change
78+
- `initialState`: Initial state for the viewer
79+
80+
### Features
81+
82+
- Interactive PCB viewing with pan and zoom
83+
- Multiple layer support (top, bottom, inner layers)
84+
- Component placement editing
85+
- Trace routing
86+
- DRC (Design Rule Check) visualization
87+
- Measurement tools

0 commit comments

Comments
 (0)