@tscircuit/pcb-viewer 1.10.15 → 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 +26 -14
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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
|
@@ -11947,6 +11947,16 @@ var scaleOnly = function(mat) {
|
|
|
11947
11947
|
if (Math.abs(mat.a) !== Math.abs(mat.d)) throw new Error("Cannot scale non-uniformly");
|
|
11948
11948
|
return value * Math.abs(mat.a);
|
|
11949
11949
|
};
|
|
11950
|
+
// src/lib/util/z-index-map.ts
|
|
11951
|
+
var zIndexMap = {
|
|
11952
|
+
elementOverlay: 30,
|
|
11953
|
+
dimensionOverlay: 30,
|
|
11954
|
+
editTraceHintOverlay: 30,
|
|
11955
|
+
errorOverlay: 30,
|
|
11956
|
+
ratsNestOverlay: 20,
|
|
11957
|
+
toolbarOverlay: 20,
|
|
11958
|
+
topLayer: 10
|
|
11959
|
+
};
|
|
11950
11960
|
// src/lib/Drawer.ts
|
|
11951
11961
|
var LAYER_NAME_TO_COLOR = _object_spread({
|
|
11952
11962
|
// Standard colors, you shouldn't use these except for testing
|
|
@@ -12246,7 +12256,7 @@ var Drawer = /*#__PURE__*/ function() {
|
|
|
12246
12256
|
order.forEach(function(layer, i) {
|
|
12247
12257
|
var canvas = canvasLayerMap[layer];
|
|
12248
12258
|
if (!canvas) return;
|
|
12249
|
-
canvas.style.zIndex = "".concat(
|
|
12259
|
+
canvas.style.zIndex = "".concat(zIndexMap.topLayer - i);
|
|
12250
12260
|
canvas.style.opacity = opaqueLayers.has(layer) ? "1" : "0.5";
|
|
12251
12261
|
});
|
|
12252
12262
|
}
|
|
@@ -13297,7 +13307,7 @@ var HighlightedPrimitiveBoxWithText = function(param) {
|
|
|
13297
13307
|
var color2 = (_layerColorHightlightMap_primitive__element_layer = layerColorHightlightMap[primitive === null || primitive === void 0 ? void 0 : (_primitive__element = primitive._element) === null || _primitive__element === void 0 ? void 0 : _primitive__element.layer]) !== null && _layerColorHightlightMap_primitive__element_layer !== void 0 ? _layerColorHightlightMap_primitive__element_layer : "red";
|
|
13298
13308
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", {
|
|
13299
13309
|
style: {
|
|
13300
|
-
zIndex:
|
|
13310
|
+
zIndex: zIndexMap.elementOverlay,
|
|
13301
13311
|
position: "absolute",
|
|
13302
13312
|
left: x - w / 2 - 8,
|
|
13303
13313
|
top: y - h / 2 - 8,
|
|
@@ -13612,7 +13622,7 @@ var DimensionOverlay = function(param) {
|
|
|
13612
13622
|
marginTop: arrowScreenBounds.flipY ? 0 : -20,
|
|
13613
13623
|
fontSize: 12,
|
|
13614
13624
|
fontFamily: "sans-serif",
|
|
13615
|
-
zIndex:
|
|
13625
|
+
zIndex: zIndexMap.dimensionOverlay
|
|
13616
13626
|
},
|
|
13617
13627
|
children: Math.abs(dStart.x - dEnd.x).toFixed(2)
|
|
13618
13628
|
}),
|
|
@@ -13630,7 +13640,7 @@ var DimensionOverlay = function(param) {
|
|
|
13630
13640
|
mixBlendMode: "difference",
|
|
13631
13641
|
fontSize: 12,
|
|
13632
13642
|
fontFamily: "sans-serif",
|
|
13633
|
-
zIndex:
|
|
13643
|
+
zIndex: zIndexMap.dimensionOverlay
|
|
13634
13644
|
},
|
|
13635
13645
|
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", {
|
|
13636
13646
|
style: {
|
|
@@ -13647,7 +13657,7 @@ var DimensionOverlay = function(param) {
|
|
|
13647
13657
|
top: 0,
|
|
13648
13658
|
pointerEvents: "none",
|
|
13649
13659
|
mixBlendMode: "difference",
|
|
13650
|
-
zIndex:
|
|
13660
|
+
zIndex: zIndexMap.dimensionOverlay
|
|
13651
13661
|
},
|
|
13652
13662
|
width: containerBounds.width,
|
|
13653
13663
|
height: containerBounds.height,
|
|
@@ -13737,7 +13747,7 @@ var import_css = require("@emotion/css");
|
|
|
13737
13747
|
// package.json
|
|
13738
13748
|
var package_default = {
|
|
13739
13749
|
name: "@tscircuit/pcb-viewer",
|
|
13740
|
-
version: "1.10.
|
|
13750
|
+
version: "1.10.16",
|
|
13741
13751
|
main: "dist/index.js",
|
|
13742
13752
|
repository: "tscircuit/pcb-viewer",
|
|
13743
13753
|
license: "MIT",
|
|
@@ -13752,7 +13762,7 @@ var package_default = {
|
|
|
13752
13762
|
"dist"
|
|
13753
13763
|
],
|
|
13754
13764
|
devDependencies: {
|
|
13755
|
-
"@biomejs/biome": "^1.
|
|
13765
|
+
"@biomejs/biome": "^1.9.4",
|
|
13756
13766
|
"@semantic-release/commit-analyzer": "^9.0.2",
|
|
13757
13767
|
"@semantic-release/git": "^10.0.1",
|
|
13758
13768
|
"@semantic-release/npm": "^9.0.1",
|
|
@@ -13964,7 +13974,7 @@ var ToolbarOverlay = function(param) {
|
|
|
13964
13974
|
top: 16,
|
|
13965
13975
|
left: 16,
|
|
13966
13976
|
transition: isMouseOverContainer ? "opacity 100ms linear" : "opacity 1s linear",
|
|
13967
|
-
zIndex:
|
|
13977
|
+
zIndex: zIndexMap.toolbarOverlay,
|
|
13968
13978
|
color: "red",
|
|
13969
13979
|
display: "flex",
|
|
13970
13980
|
fontSize: 12,
|
|
@@ -14109,7 +14119,7 @@ var ErrorSVG = function(param) {
|
|
|
14109
14119
|
top: 0,
|
|
14110
14120
|
pointerEvents: "none",
|
|
14111
14121
|
mixBlendMode: "difference",
|
|
14112
|
-
zIndex:
|
|
14122
|
+
zIndex: zIndexMap.errorOverlay
|
|
14113
14123
|
},
|
|
14114
14124
|
width: "100%",
|
|
14115
14125
|
height: "100%",
|
|
@@ -14606,7 +14616,7 @@ var EditTraceHintOverlay = function(param) {
|
|
|
14606
14616
|
top: 0,
|
|
14607
14617
|
pointerEvents: "none",
|
|
14608
14618
|
mixBlendMode: "difference",
|
|
14609
|
-
zIndex:
|
|
14619
|
+
zIndex: zIndexMap.editTraceHintOverlay
|
|
14610
14620
|
},
|
|
14611
14621
|
width: containerBounds === null || containerBounds === void 0 ? void 0 : containerBounds.width,
|
|
14612
14622
|
height: containerBounds === null || containerBounds === void 0 ? void 0 : containerBounds.height,
|
|
@@ -14659,7 +14669,7 @@ var EditTraceHintOverlay = function(param) {
|
|
|
14659
14669
|
top: 0,
|
|
14660
14670
|
pointerEvents: "none",
|
|
14661
14671
|
mixBlendMode: "difference",
|
|
14662
|
-
zIndex:
|
|
14672
|
+
zIndex: zIndexMap.editTraceHintOverlay
|
|
14663
14673
|
},
|
|
14664
14674
|
width: containerBounds === null || containerBounds === void 0 ? void 0 : containerBounds.width,
|
|
14665
14675
|
height: containerBounds === null || containerBounds === void 0 ? void 0 : containerBounds.height,
|
|
@@ -14771,7 +14781,7 @@ var RatsNestOverlay = function(param) {
|
|
|
14771
14781
|
height: "100%",
|
|
14772
14782
|
pointerEvents: "none",
|
|
14773
14783
|
opacity: 0.5,
|
|
14774
|
-
zIndex:
|
|
14784
|
+
zIndex: zIndexMap.ratsNestOverlay
|
|
14775
14785
|
},
|
|
14776
14786
|
children: groups.map(function(group, index) {
|
|
14777
14787
|
var points = group.map(function(port) {
|
|
@@ -14945,7 +14955,8 @@ var CanvasElementsRenderer = function(props) {
|
|
|
14945
14955
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
14946
14956
|
var defaultTransform = (0, import_transformation_matrix10.compose)((0, import_transformation_matrix10.translate)(400, 300), (0, import_transformation_matrix10.scale)(40, -40));
|
|
14947
14957
|
var PCBViewer = function(param) {
|
|
14948
|
-
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;
|
|
14949
14960
|
var _ref = (0, import_core.useRenderedCircuit)(children), circuitJsonFromChildren = _ref.circuitJson, errorFromChildren = _ref.error, isLoading = _ref.isLoading;
|
|
14950
14961
|
var _useMeasure_default = _sliced_to_array(useMeasure_default(), 2), ref = _useMeasure_default[0], refDimensions = _useMeasure_default[1];
|
|
14951
14962
|
var _ref1 = _sliced_to_array((0, import_react20.useState)(defaultTransform), 2), transform = _ref1[0], setTransformInternal = _ref1[1];
|
|
@@ -14987,7 +14998,8 @@ var PCBViewer = function(param) {
|
|
|
14987
14998
|
children,
|
|
14988
14999
|
refDimensions
|
|
14989
15000
|
]);
|
|
14990
|
-
var
|
|
15001
|
+
var _ref5;
|
|
15002
|
+
var pcbElmsPreEdit = ((_ref5 = circuitJson !== null && circuitJson !== void 0 ? circuitJson : soup) !== null && _ref5 !== void 0 ? _ref5 : stateElements).filter(function(e) {
|
|
14991
15003
|
return e.type.startsWith("pcb_") || e.type.startsWith("source_");
|
|
14992
15004
|
});
|
|
14993
15005
|
var elements = (0, import_react20.useMemo)(function() {
|