@tscircuit/core 0.0.66 → 0.0.67
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/dist/index.js
CHANGED
|
@@ -1629,6 +1629,42 @@ var createNetsFromProps = (component, props) => {
|
|
|
1629
1629
|
}
|
|
1630
1630
|
};
|
|
1631
1631
|
|
|
1632
|
+
// lib/utils/get-bounds-of-pcb-components.ts
|
|
1633
|
+
function getBoundsOfPcbComponents(components) {
|
|
1634
|
+
let minX = Infinity;
|
|
1635
|
+
let minY = Infinity;
|
|
1636
|
+
let maxX = -Infinity;
|
|
1637
|
+
let maxY = -Infinity;
|
|
1638
|
+
for (const child of components) {
|
|
1639
|
+
if (child.isPcbPrimitive) {
|
|
1640
|
+
const { x, y } = child._getGlobalPcbPositionBeforeLayout();
|
|
1641
|
+
const { width: width2, height: height2 } = child.getPcbSize();
|
|
1642
|
+
minX = Math.min(minX, x - width2 / 2);
|
|
1643
|
+
minY = Math.min(minY, y - height2 / 2);
|
|
1644
|
+
maxX = Math.max(maxX, x + width2 / 2);
|
|
1645
|
+
maxY = Math.max(maxY, y + height2 / 2);
|
|
1646
|
+
} else if (child.componentName === "Footprint") {
|
|
1647
|
+
const childBounds = getBoundsOfPcbComponents(child.children);
|
|
1648
|
+
minX = Math.min(minX, childBounds.minX);
|
|
1649
|
+
minY = Math.min(minY, childBounds.minY);
|
|
1650
|
+
maxX = Math.max(maxX, childBounds.maxX);
|
|
1651
|
+
maxY = Math.max(maxY, childBounds.maxY);
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
let width = maxX - minX;
|
|
1655
|
+
let height = maxY - minY;
|
|
1656
|
+
if (width < 0) width = 0;
|
|
1657
|
+
if (height < 0) height = 0;
|
|
1658
|
+
return {
|
|
1659
|
+
minX,
|
|
1660
|
+
minY,
|
|
1661
|
+
maxX,
|
|
1662
|
+
maxY,
|
|
1663
|
+
width,
|
|
1664
|
+
height
|
|
1665
|
+
};
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1632
1668
|
// lib/components/base-components/NormalComponent.ts
|
|
1633
1669
|
var NormalComponent = class extends PrimitiveComponent {
|
|
1634
1670
|
reactSubtrees = [];
|
|
@@ -1788,25 +1824,10 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
1788
1824
|
if (!this.pcb_component_id) return;
|
|
1789
1825
|
const { db } = this.root;
|
|
1790
1826
|
const { _parsedProps: props } = this;
|
|
1791
|
-
|
|
1792
|
-
let minY = Infinity;
|
|
1793
|
-
let maxX = -Infinity;
|
|
1794
|
-
let maxY = -Infinity;
|
|
1795
|
-
for (const child of this.children) {
|
|
1796
|
-
if (child.isPcbPrimitive) {
|
|
1797
|
-
const { x, y } = child._getGlobalPcbPositionBeforeLayout();
|
|
1798
|
-
const { width: width2, height: height2 } = child.getPcbSize();
|
|
1799
|
-
minX = Math.min(minX, x - width2 / 2);
|
|
1800
|
-
minY = Math.min(minY, y - height2 / 2);
|
|
1801
|
-
maxX = Math.max(maxX, x + width2 / 2);
|
|
1802
|
-
maxY = Math.max(maxY, y + height2 / 2);
|
|
1803
|
-
}
|
|
1804
|
-
}
|
|
1805
|
-
const width = maxX - minX;
|
|
1806
|
-
const height = maxY - minY;
|
|
1827
|
+
const bounds = getBoundsOfPcbComponents(this.children);
|
|
1807
1828
|
db.pcb_component.update(this.pcb_component_id, {
|
|
1808
|
-
width,
|
|
1809
|
-
height
|
|
1829
|
+
width: bounds.width,
|
|
1830
|
+
height: bounds.height
|
|
1810
1831
|
});
|
|
1811
1832
|
}
|
|
1812
1833
|
_renderReactSubtree(element) {
|
|
@@ -18,6 +18,7 @@ import { getPortFromHints } from "lib/utils/getPortFromHints"
|
|
|
18
18
|
import { createComponentsFromSoup } from "lib/utils/createComponentsFromSoup"
|
|
19
19
|
import { Net } from "../primitive-components/Net"
|
|
20
20
|
import { createNetsFromProps } from "lib/utils/components/createNetsFromProps"
|
|
21
|
+
import { getBoundsOfPcbComponents } from "lib/utils/get-bounds-of-pcb-components"
|
|
21
22
|
|
|
22
23
|
export type PortMap<T extends string> = {
|
|
23
24
|
[K in T]: Port
|
|
@@ -229,28 +230,11 @@ export class NormalComponent<
|
|
|
229
230
|
const { db } = this.root!
|
|
230
231
|
const { _parsedProps: props } = this
|
|
231
232
|
|
|
232
|
-
|
|
233
|
-
let minY = Infinity
|
|
234
|
-
let maxX = -Infinity
|
|
235
|
-
let maxY = -Infinity
|
|
236
|
-
|
|
237
|
-
for (const child of this.children) {
|
|
238
|
-
if (child.isPcbPrimitive) {
|
|
239
|
-
const { x, y } = child._getGlobalPcbPositionBeforeLayout()
|
|
240
|
-
const { width, height } = child.getPcbSize()
|
|
241
|
-
minX = Math.min(minX, x - width / 2)
|
|
242
|
-
minY = Math.min(minY, y - height / 2)
|
|
243
|
-
maxX = Math.max(maxX, x + width / 2)
|
|
244
|
-
maxY = Math.max(maxY, y + height / 2)
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const width = maxX - minX
|
|
249
|
-
const height = maxY - minY
|
|
233
|
+
const bounds = getBoundsOfPcbComponents(this.children)
|
|
250
234
|
|
|
251
235
|
db.pcb_component.update(this.pcb_component_id!, {
|
|
252
|
-
width,
|
|
253
|
-
height,
|
|
236
|
+
width: bounds.width,
|
|
237
|
+
height: bounds.height,
|
|
254
238
|
})
|
|
255
239
|
}
|
|
256
240
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { PrimitiveComponent } from "lib/components/base-components/PrimitiveComponent"
|
|
2
|
+
|
|
3
|
+
export function getBoundsOfPcbComponents(components: PrimitiveComponent[]) {
|
|
4
|
+
let minX = Infinity
|
|
5
|
+
let minY = Infinity
|
|
6
|
+
let maxX = -Infinity
|
|
7
|
+
let maxY = -Infinity
|
|
8
|
+
|
|
9
|
+
for (const child of components) {
|
|
10
|
+
if (child.isPcbPrimitive) {
|
|
11
|
+
const { x, y } = child._getGlobalPcbPositionBeforeLayout()
|
|
12
|
+
const { width, height } = child.getPcbSize()
|
|
13
|
+
minX = Math.min(minX, x - width / 2)
|
|
14
|
+
minY = Math.min(minY, y - height / 2)
|
|
15
|
+
maxX = Math.max(maxX, x + width / 2)
|
|
16
|
+
maxY = Math.max(maxY, y + height / 2)
|
|
17
|
+
} else if (child.componentName === "Footprint") {
|
|
18
|
+
const childBounds = getBoundsOfPcbComponents(child.children)
|
|
19
|
+
|
|
20
|
+
minX = Math.min(minX, childBounds.minX)
|
|
21
|
+
minY = Math.min(minY, childBounds.minY)
|
|
22
|
+
maxX = Math.max(maxX, childBounds.maxX)
|
|
23
|
+
maxY = Math.max(maxY, childBounds.maxY)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let width = maxX - minX
|
|
28
|
+
let height = maxY - minY
|
|
29
|
+
|
|
30
|
+
if (width < 0) width = 0
|
|
31
|
+
if (height < 0) height = 0
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
minX,
|
|
35
|
+
minY,
|
|
36
|
+
maxX,
|
|
37
|
+
maxY,
|
|
38
|
+
width,
|
|
39
|
+
height,
|
|
40
|
+
}
|
|
41
|
+
}
|