@tscircuit/pcb-viewer 1.11.439 → 1.11.440

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
@@ -9394,6 +9394,53 @@ var getBoundsOfPcbElements = (elements) => {
9394
9394
  }
9395
9395
  return bounds;
9396
9396
  };
9397
+ var getBoardBounds = (board) => {
9398
+ if (board.width && board.height && board.center) {
9399
+ const halfWidth = board.width / 2;
9400
+ const halfHeight = board.height / 2;
9401
+ return {
9402
+ minX: board.center.x - halfWidth,
9403
+ minY: board.center.y - halfHeight,
9404
+ maxX: board.center.x + halfWidth,
9405
+ maxY: board.center.y + halfHeight,
9406
+ width: board.width,
9407
+ height: board.height,
9408
+ center: {
9409
+ x: board.center.x,
9410
+ y: board.center.y
9411
+ }
9412
+ };
9413
+ }
9414
+ if (!board.outline || board.outline.length === 0) {
9415
+ throw new Error(
9416
+ "Unable to compute board bounds. pcb_board must include width/height/center or a non-empty outline."
9417
+ );
9418
+ }
9419
+ let minX = Number.POSITIVE_INFINITY;
9420
+ let minY = Number.POSITIVE_INFINITY;
9421
+ let maxX = Number.NEGATIVE_INFINITY;
9422
+ let maxY = Number.NEGATIVE_INFINITY;
9423
+ for (const point2 of board.outline) {
9424
+ minX = Math.min(minX, point2.x);
9425
+ minY = Math.min(minY, point2.y);
9426
+ maxX = Math.max(maxX, point2.x);
9427
+ maxY = Math.max(maxY, point2.y);
9428
+ }
9429
+ const width = maxX - minX;
9430
+ const height = maxY - minY;
9431
+ return {
9432
+ minX,
9433
+ minY,
9434
+ maxX,
9435
+ maxY,
9436
+ width,
9437
+ height,
9438
+ center: {
9439
+ x: minX + width / 2,
9440
+ y: minY + height / 2
9441
+ }
9442
+ };
9443
+ };
9397
9444
  function stringHash(str) {
9398
9445
  let hash = 0;
9399
9446
  if (str.length == 0) return hash;
@@ -9717,6 +9764,27 @@ var getPlatedHolePolygon = (pad, componentRotation = 0) => {
9717
9764
  );
9718
9765
  };
9719
9766
 
9767
+ // src/lib/get-pcb-viewport-bounds.ts
9768
+ function getPcbViewportBounds(elements) {
9769
+ const pcbElements = elements.filter(
9770
+ (element) => element.type.startsWith("pcb_")
9771
+ );
9772
+ if (pcbElements.length === 0) {
9773
+ return { center: { x: 0, y: 0 }, width: 1e-3, height: 1e-3 };
9774
+ }
9775
+ const boardsAndPanels = pcbElements.filter(
9776
+ (element) => element.type === "pcb_board" || element.type === "pcb_panel"
9777
+ ).map((element) => {
9778
+ if (element.type !== "pcb_board" || !element.outline?.length)
9779
+ return element;
9780
+ const { center, width, height } = getBoardBounds(element);
9781
+ return { ...element, center, width, height };
9782
+ });
9783
+ return findBoundsAndCenter(
9784
+ boardsAndPanels.length > 0 ? boardsAndPanels : pcbElements
9785
+ );
9786
+ }
9787
+
9720
9788
  // src/lib/apply-edit-events.ts
9721
9789
  import { translate as translate6 } from "transformation-matrix";
9722
9790
  function applyEditEvents({
@@ -9777,13 +9845,19 @@ function applyEditEvents({
9777
9845
  // src/lib/calculate-board-size-key.ts
9778
9846
  var calculateBoardSizeKey = (circuitJson) => {
9779
9847
  if (!circuitJson) return "empty";
9780
- const board = circuitJson.find((e) => e.type === "pcb_board");
9781
- if (!board) return "no-board";
9782
- const round = (n) => Math.round(n * 1e3) / 1e3;
9783
- if (board.outline) {
9784
- return board.outline.map((o) => `${round(o.x)}_${round(o.y)}`).join(",");
9785
- }
9786
- return `${round(board.width)}_${round(board.height)}`;
9848
+ const boardSizeKeys = circuitJson.filter(
9849
+ (element) => element.type === "pcb_board" || element.type === "pcb_panel"
9850
+ ).map(
9851
+ (element) => JSON.stringify([
9852
+ element.type,
9853
+ element.center.x,
9854
+ element.center.y,
9855
+ element.width,
9856
+ element.height,
9857
+ element.type === "pcb_board" ? element.outline?.map(({ x, y }) => [x, y]) : void 0
9858
+ ])
9859
+ ).sort();
9860
+ return boardSizeKeys.length > 0 ? boardSizeKeys.join(";") : "no-board";
9787
9861
  };
9788
9862
 
9789
9863
  // src/lib/calculate-circuit-json-key.ts
@@ -19125,7 +19199,7 @@ import {
19125
19199
  // package.json
19126
19200
  var package_default = {
19127
19201
  name: "@tscircuit/pcb-viewer",
19128
- version: "1.11.438",
19202
+ version: "1.11.439",
19129
19203
  main: "dist/index.js",
19130
19204
  type: "module",
19131
19205
  repository: {
@@ -22106,14 +22180,13 @@ var PCBViewer = ({
22106
22180
  () => calculateCircuitJsonKey(circuitJson),
22107
22181
  [circuitJson]
22108
22182
  );
22109
- const boardSizeKey = calculateBoardSizeKey(circuitJson);
22183
+ const boardSizeKey = useMemo17(
22184
+ () => calculateBoardSizeKey(circuitJson),
22185
+ [circuitJson]
22186
+ );
22110
22187
  const resetTransform = () => {
22111
22188
  const elmBounds = refDimensions?.width > 0 ? refDimensions : { width: 500, height: 500 };
22112
- const { center, width, height: height2 } = elements.some(
22113
- (e) => e.type.startsWith("pcb_")
22114
- ) ? findBoundsAndCenter(
22115
- elements.filter((e) => e.type.startsWith("pcb_"))
22116
- ) : { center: { x: 0, y: 0 }, width: 1e-3, height: 1e-3 };
22189
+ const { center, width, height: height2 } = getPcbViewportBounds(elements);
22117
22190
  const scaleFactor = Math.min(
22118
22191
  (elmBounds.width ?? 0) / width,
22119
22192
  (elmBounds.height ?? 0) / height2,