@tscircuit/core 0.0.65 → 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
- let minX = Infinity;
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) {
@@ -2066,7 +2087,8 @@ var Board = class extends Group {
2066
2087
  const pcb_board = db.pcb_board.insert({
2067
2088
  center: { x: props.pcbX, y: props.pcbY },
2068
2089
  width: props.width,
2069
- height: props.height
2090
+ height: props.height,
2091
+ outline: props.outline
2070
2092
  });
2071
2093
  this.pcb_board_id = pcb_board.pcb_board_id;
2072
2094
  }
@@ -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
- let minX = Infinity
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
 
@@ -30,6 +30,7 @@ export class Board extends Group<typeof boardProps> {
30
30
 
31
31
  width: props.width,
32
32
  height: props.height,
33
+ outline: props.outline,
33
34
  })
34
35
 
35
36
  this.pcb_board_id = pcb_board.pcb_board_id!
@@ -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
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tscircuit/core",
3
3
  "module": "index.ts",
4
4
  "type": "module",
5
- "version": "0.0.65",
5
+ "version": "0.0.67",
6
6
  "types": "dist/index.d.ts",
7
7
  "main": "dist/index.js",
8
8
  "files": [
@@ -23,7 +23,7 @@
23
23
  "@types/react": "^18.3.3",
24
24
  "@types/react-reconciler": "^0.28.8",
25
25
  "bun-match-svg": "0.0.2",
26
- "circuit-to-svg": "^0.0.32",
26
+ "circuit-to-svg": "^0.0.33",
27
27
  "debug": "^4.3.6",
28
28
  "howfat": "^0.3.8",
29
29
  "looks-same": "^9.0.1",