@tscircuit/pcb-viewer 1.10.16 → 1.10.17
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/README.md +57 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,12 +12,18 @@ If you want to render to an image, check out [circuit-to-png](https://github.com
|
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
|
-
```
|
|
15
|
+
```bash
|
|
16
16
|
npm install @tscircuit/pcb-viewer
|
|
17
17
|
```
|
|
18
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
|
+
|
|
19
25
|
```tsx
|
|
20
|
-
import React
|
|
26
|
+
import React from "react"
|
|
21
27
|
import { PCBViewer } from "@tscircuit/pcb-viewer"
|
|
22
28
|
|
|
23
29
|
export default () => {
|
|
@@ -25,8 +31,57 @@ export default () => {
|
|
|
25
31
|
<div style={{ backgroundColor: "black" }}>
|
|
26
32
|
<PCBViewer>
|
|
27
33
|
<resistor footprint="0805" resistance="10k" />
|
|
34
|
+
<capacitor footprint="0603" capacitance="100nF" />
|
|
28
35
|
</PCBViewer>
|
|
29
36
|
</div>
|
|
30
37
|
)
|
|
31
38
|
}
|
|
32
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
|
package/dist/index.d.ts
CHANGED
|
@@ -56,6 +56,7 @@ type EditEvent = EditComponentLocationEvent | EditTraceHintEvent;
|
|
|
56
56
|
|
|
57
57
|
type Props = {
|
|
58
58
|
children?: any;
|
|
59
|
+
circuitJson?: AnyCircuitElement[];
|
|
59
60
|
soup?: any;
|
|
60
61
|
height?: number;
|
|
61
62
|
allowEditing?: boolean;
|
|
@@ -63,7 +64,7 @@ type Props = {
|
|
|
63
64
|
initialState?: Partial<StateProps>;
|
|
64
65
|
onEditEventsChanged?: (editEvents: EditEvent[]) => void;
|
|
65
66
|
};
|
|
66
|
-
declare const PCBViewer: ({ children, soup, height, initialState, allowEditing, editEvents: editEventsProp, onEditEventsChanged, }: Props) => react_jsx_runtime.JSX.Element;
|
|
67
|
+
declare const PCBViewer: ({ children, soup, circuitJson, height, initialState, allowEditing, editEvents: editEventsProp, onEditEventsChanged, }: Props) => react_jsx_runtime.JSX.Element;
|
|
67
68
|
|
|
68
69
|
declare const applyEditEvents: (soup: AnyCircuitElement[], edit_events: EditEvent[]) => AnyCircuitElement[];
|
|
69
70
|
|
package/dist/index.js
CHANGED
|
@@ -13747,7 +13747,7 @@ var import_css = require("@emotion/css");
|
|
|
13747
13747
|
// package.json
|
|
13748
13748
|
var package_default = {
|
|
13749
13749
|
name: "@tscircuit/pcb-viewer",
|
|
13750
|
-
version: "1.10.
|
|
13750
|
+
version: "1.10.16",
|
|
13751
13751
|
main: "dist/index.js",
|
|
13752
13752
|
repository: "tscircuit/pcb-viewer",
|
|
13753
13753
|
license: "MIT",
|
|
@@ -14955,7 +14955,8 @@ var CanvasElementsRenderer = function(props) {
|
|
|
14955
14955
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
14956
14956
|
var defaultTransform = (0, import_transformation_matrix10.compose)((0, import_transformation_matrix10.translate)(400, 300), (0, import_transformation_matrix10.scale)(40, -40));
|
|
14957
14957
|
var PCBViewer = function(param) {
|
|
14958
|
-
var children = param.children, soup = param.soup, _param_height = param.height, height = _param_height === void 0 ? 600 : _param_height, initialState = param.initialState, _param_allowEditing = param.allowEditing, allowEditing = _param_allowEditing === void 0 ? true : _param_allowEditing, editEventsProp = param.editEvents, onEditEventsChanged = param.onEditEventsChanged;
|
|
14958
|
+
var children = param.children, soup = param.soup, circuitJson = param.circuitJson, _param_height = param.height, height = _param_height === void 0 ? 600 : _param_height, initialState = param.initialState, _param_allowEditing = param.allowEditing, allowEditing = _param_allowEditing === void 0 ? true : _param_allowEditing, editEventsProp = param.editEvents, onEditEventsChanged = param.onEditEventsChanged;
|
|
14959
|
+
soup !== null && soup !== void 0 ? soup : soup = circuitJson;
|
|
14959
14960
|
var _ref = (0, import_core.useRenderedCircuit)(children), circuitJsonFromChildren = _ref.circuitJson, errorFromChildren = _ref.error, isLoading = _ref.isLoading;
|
|
14960
14961
|
var _useMeasure_default = _sliced_to_array(useMeasure_default(), 2), ref = _useMeasure_default[0], refDimensions = _useMeasure_default[1];
|
|
14961
14962
|
var _ref1 = _sliced_to_array((0, import_react20.useState)(defaultTransform), 2), transform = _ref1[0], setTransformInternal = _ref1[1];
|
|
@@ -14997,7 +14998,8 @@ var PCBViewer = function(param) {
|
|
|
14997
14998
|
children,
|
|
14998
14999
|
refDimensions
|
|
14999
15000
|
]);
|
|
15000
|
-
var
|
|
15001
|
+
var _ref5;
|
|
15002
|
+
var pcbElmsPreEdit = ((_ref5 = circuitJson !== null && circuitJson !== void 0 ? circuitJson : soup) !== null && _ref5 !== void 0 ? _ref5 : stateElements).filter(function(e) {
|
|
15001
15003
|
return e.type.startsWith("pcb_") || e.type.startsWith("source_");
|
|
15002
15004
|
});
|
|
15003
15005
|
var elements = (0, import_react20.useMemo)(function() {
|