@tscircuit/pcb-viewer 1.11.233 → 1.11.235

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
@@ -7043,8 +7043,13 @@ function getExpandedStroke(strokeInput, defaultWidth) {
7043
7043
  }
7044
7044
 
7045
7045
  // src/lib/convert-element-to-primitive.ts
7046
+ import { distance as distance2 } from "circuit-json";
7046
7047
  var globalPcbDrawingObjectCount = 0;
7047
7048
  var getNewPcbDrawingObjectId = (prefix) => `${prefix}_${globalPcbDrawingObjectCount++}`;
7049
+ var normalizePolygonPoints = (points) => (points ?? []).map((point) => ({
7050
+ x: distance2.parse(point.x),
7051
+ y: distance2.parse(point.y)
7052
+ }));
7048
7053
  var convertElementToPrimitives = (element, allElements) => {
7049
7054
  const _parent_pcb_component = "pcb_component_id" in element ? allElements.find(
7050
7055
  (elm) => elm.type === "pcb_component" && elm.pcb_component_id === element.pcb_component_id
@@ -7174,7 +7179,7 @@ var convertElementToPrimitives = (element, allElements) => {
7174
7179
  {
7175
7180
  _pcb_drawing_object_id: `polygon_${globalPcbDrawingObjectCount++}`,
7176
7181
  pcb_drawing_type: "polygon",
7177
- points,
7182
+ points: normalizePolygonPoints(points),
7178
7183
  layer: layer || "top",
7179
7184
  _element: element,
7180
7185
  _parent_pcb_component,
@@ -7724,7 +7729,7 @@ var convertElementToPrimitives = (element, allElements) => {
7724
7729
  "pcb_copper_pour_polygon"
7725
7730
  ),
7726
7731
  pcb_drawing_type: "polygon",
7727
- points,
7732
+ points: normalizePolygonPoints(points),
7728
7733
  layer,
7729
7734
  _element: element
7730
7735
  }
@@ -7925,7 +7930,7 @@ var convertElementToPrimitives = (element, allElements) => {
7925
7930
  {
7926
7931
  _pcb_drawing_object_id: getNewPcbDrawingObjectId("pcb_cutout_polygon"),
7927
7932
  pcb_drawing_type: "polygon",
7928
- points: cutoutElement.points,
7933
+ points: normalizePolygonPoints(cutoutElement.points),
7929
7934
  layer: "drill",
7930
7935
  _element: element,
7931
7936
  _parent_pcb_component,
@@ -8692,8 +8697,10 @@ var Drawer = class {
8692
8697
  ctx.closePath();
8693
8698
  ctx.fill("evenodd");
8694
8699
  const lineWidth = scaleOnly(this.transform, this.aperture.size);
8695
- ctx.lineWidth = lineWidth;
8696
- ctx.stroke();
8700
+ if (lineWidth > 0) {
8701
+ ctx.lineWidth = lineWidth;
8702
+ ctx.stroke();
8703
+ }
8697
8704
  }
8698
8705
  /* NOTE: This is not gerber compatible */
8699
8706
  debugText(text, x, y) {
@@ -10282,10 +10289,10 @@ var isInsideOfSmtpad = (elm, point, padding = 0) => {
10282
10289
  };
10283
10290
  var isInsideOfPlatedHole = (hole, point, padding = 0) => {
10284
10291
  if (hole.shape === "circle") {
10285
- const distance3 = Math.sqrt(
10292
+ const distance5 = Math.sqrt(
10286
10293
  (point.x - hole.x) ** 2 + (point.y - hole.y) ** 2
10287
10294
  );
10288
- return distance3 <= hole.outer_diameter / 2 + padding;
10295
+ return distance5 <= hole.outer_diameter / 2 + padding;
10289
10296
  } else if (hole.shape === "circular_hole_with_rect_pad") {
10290
10297
  const dx = Math.abs(point.x - hole.x);
10291
10298
  const dy = Math.abs(point.y - hole.y);
@@ -11198,22 +11205,27 @@ var getTextForHighlightedPrimitive = (prim) => {
11198
11205
  }
11199
11206
  case "pcb_smtpad":
11200
11207
  case "pcb_plated_hole": {
11201
- let s = "";
11208
+ const selectors = [];
11202
11209
  const port_hints = Array.from(
11203
11210
  new Set(
11204
11211
  (element.port_hints ?? []).concat(
11205
11212
  _source_port?.port_hints ?? []
11206
11213
  )
11207
11214
  )
11208
- ).filter((ph) => !/^[0-9]+$/.test(ph)).sort((a, b) => b.localeCompare(a));
11209
- if (_parent_source_component && "name" in _parent_source_component && _parent_source_component.name) {
11210
- s += `.${_parent_source_component.name}`;
11211
- if (port_hints.length > 0) s += " > ";
11212
- }
11215
+ ).filter((ph) => !/^[0-9]+$/.test(ph)).filter((ph) => !ph.includes("unnamed_")).sort((a, b) => b.localeCompare(a));
11216
+ const parentName = _parent_source_component && "name" in _parent_source_component && _parent_source_component.name && !_parent_source_component.name.includes("unnamed_") ? _parent_source_component.name : null;
11213
11217
  if (port_hints.length > 0) {
11214
- s += port_hints.map((ph) => `.${ph}`).join(", ");
11218
+ if (parentName) {
11219
+ selectors.push(
11220
+ ...port_hints.map((ph) => `${parentName}.${ph}`)
11221
+ );
11222
+ } else {
11223
+ selectors.push(...port_hints);
11224
+ }
11225
+ } else if (parentName) {
11226
+ selectors.push(parentName);
11215
11227
  }
11216
- return s;
11228
+ return selectors.join(", ");
11217
11229
  }
11218
11230
  default: {
11219
11231
  return "";
@@ -11381,6 +11393,9 @@ var ElementOverlayBox = ({
11381
11393
  )) });
11382
11394
  };
11383
11395
 
11396
+ // src/components/MouseElementTracker.tsx
11397
+ import { distance as distance4 } from "circuit-json";
11398
+
11384
11399
  // src/lib/util/if-sets-match-exactly.ts
11385
11400
  function ifSetsMatchExactly(set1, set2) {
11386
11401
  if (set1.size !== set2.size) return false;
@@ -11390,16 +11405,16 @@ function ifSetsMatchExactly(set1, set2) {
11390
11405
  // node_modules/@tscircuit/math-utils/dist/chunk-EFLPMB4J.js
11391
11406
  function pointToSegmentDistance2(p, v, w) {
11392
11407
  const l2 = (w.x - v.x) ** 2 + (w.y - v.y) ** 2;
11393
- if (l2 === 0) return distance2(p, v);
11408
+ if (l2 === 0) return distance3(p, v);
11394
11409
  let t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2;
11395
11410
  t = Math.max(0, Math.min(1, t));
11396
11411
  const projection = {
11397
11412
  x: v.x + t * (w.x - v.x),
11398
11413
  y: v.y + t * (w.y - v.y)
11399
11414
  };
11400
- return distance2(p, projection);
11415
+ return distance3(p, projection);
11401
11416
  }
11402
- function distance2(p1, p2) {
11417
+ function distance3(p1, p2) {
11403
11418
  const dx = p1.x - p2.x;
11404
11419
  const dy = p1.y - p2.y;
11405
11420
  return Math.sqrt(dx * dx + dy * dy);
@@ -11407,19 +11422,85 @@ function distance2(p1, p2) {
11407
11422
 
11408
11423
  // src/components/MouseElementTracker.tsx
11409
11424
  import { jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
11425
+ var getPolygonBoundingBox = (points) => {
11426
+ if (points.length === 0) return null;
11427
+ let minX = points[0].x;
11428
+ let minY = points[0].y;
11429
+ let maxX = points[0].x;
11430
+ let maxY = points[0].y;
11431
+ for (const point of points) {
11432
+ if (point.x < minX) minX = point.x;
11433
+ if (point.y < minY) minY = point.y;
11434
+ if (point.x > maxX) maxX = point.x;
11435
+ if (point.y > maxY) maxY = point.y;
11436
+ }
11437
+ return {
11438
+ center: {
11439
+ x: (minX + maxX) / 2,
11440
+ y: (minY + maxY) / 2
11441
+ },
11442
+ width: maxX - minX,
11443
+ height: maxY - minY
11444
+ };
11445
+ };
11446
+ var isPointInsidePolygon = (point, polygon) => {
11447
+ if (polygon.length < 3) return false;
11448
+ let isInside = false;
11449
+ for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
11450
+ const xi = polygon[i].x;
11451
+ const yi = polygon[i].y;
11452
+ const xj = polygon[j].x;
11453
+ const yj = polygon[j].y;
11454
+ const intersects = yi > point.y !== yj > point.y && point.x < (xj - xi) * (point.y - yi) / (yj - yi || Number.EPSILON) + xi;
11455
+ if (intersects) {
11456
+ isInside = !isInside;
11457
+ }
11458
+ }
11459
+ return isInside;
11460
+ };
11410
11461
  var getPrimitivesUnderPoint = (primitives, rwPoint, transform) => {
11411
11462
  const newMousedPrimitives = [];
11412
11463
  for (const primitive of primitives) {
11413
11464
  if (!primitive._element) continue;
11414
11465
  if ("x1" in primitive && primitive._element?.type === "pcb_trace") {
11415
- const distance3 = pointToSegmentDistance2(
11466
+ const distance5 = pointToSegmentDistance2(
11416
11467
  { x: rwPoint.x, y: rwPoint.y },
11417
11468
  { x: primitive.x1, y: primitive.y1 },
11418
11469
  { x: primitive.x2, y: primitive.y2 }
11419
11470
  );
11420
11471
  const lineWidth = primitive.width || 0.5;
11421
11472
  const detectionThreshold = Math.max(lineWidth * 25, 2) / transform.a;
11422
- if (distance3 < detectionThreshold) {
11473
+ if (distance5 < detectionThreshold) {
11474
+ newMousedPrimitives.push(primitive);
11475
+ }
11476
+ continue;
11477
+ }
11478
+ if (primitive.pcb_drawing_type === "polygon") {
11479
+ const points = primitive.points.map((point) => ({
11480
+ x: distance4.parse(point.x),
11481
+ y: distance4.parse(point.y)
11482
+ }));
11483
+ const boundingBox = getPolygonBoundingBox(points);
11484
+ if (!boundingBox) continue;
11485
+ if (rwPoint.x < boundingBox.center.x - boundingBox.width / 2 || rwPoint.x > boundingBox.center.x + boundingBox.width / 2 || rwPoint.y < boundingBox.center.y - boundingBox.height / 2 || rwPoint.y > boundingBox.center.y + boundingBox.height / 2) {
11486
+ continue;
11487
+ }
11488
+ if (isPointInsidePolygon(rwPoint, points)) {
11489
+ newMousedPrimitives.push(primitive);
11490
+ }
11491
+ continue;
11492
+ }
11493
+ if (primitive.pcb_drawing_type === "polygon_with_arcs") {
11494
+ const points = primitive.brep_shape.outer_ring.vertices.map((v) => ({
11495
+ x: distance4.parse(v.x),
11496
+ y: distance4.parse(v.y)
11497
+ }));
11498
+ const boundingBox = getPolygonBoundingBox(points);
11499
+ if (!boundingBox) continue;
11500
+ if (rwPoint.x < boundingBox.center.x - boundingBox.width / 2 || rwPoint.x > boundingBox.center.x + boundingBox.width / 2 || rwPoint.y < boundingBox.center.y - boundingBox.height / 2 || rwPoint.y > boundingBox.center.y + boundingBox.height / 2) {
11501
+ continue;
11502
+ }
11503
+ if (isPointInsidePolygon(rwPoint, points)) {
11423
11504
  newMousedPrimitives.push(primitive);
11424
11505
  }
11425
11506
  continue;
@@ -11457,12 +11538,32 @@ var MouseElementTracker = ({
11457
11538
  if (primitive._element?.type === "pcb_via") continue;
11458
11539
  if (primitive._element?.type === "pcb_component") continue;
11459
11540
  if (primitive?.layer === "drill") continue;
11460
- const screenPos = applyToPoint12(
11461
- transform,
11462
- primitive
11463
- );
11464
- const w = "w" in primitive ? primitive.w : "r" in primitive ? primitive.r * 2 : 0;
11465
- const h = "h" in primitive ? primitive.h : "r" in primitive ? primitive.r * 2 : 0;
11541
+ let basePoint = null;
11542
+ let w = 0;
11543
+ let h = 0;
11544
+ if (primitive.pcb_drawing_type === "polygon") {
11545
+ const boundingBox = getPolygonBoundingBox(primitive.points);
11546
+ if (!boundingBox) continue;
11547
+ basePoint = boundingBox.center;
11548
+ w = boundingBox.width;
11549
+ h = boundingBox.height;
11550
+ } else if (primitive.pcb_drawing_type === "polygon_with_arcs") {
11551
+ const points = primitive.brep_shape.outer_ring.vertices.map((v) => ({
11552
+ x: v.x,
11553
+ y: v.y
11554
+ }));
11555
+ const boundingBox = getPolygonBoundingBox(points);
11556
+ if (!boundingBox) continue;
11557
+ basePoint = boundingBox.center;
11558
+ w = boundingBox.width;
11559
+ h = boundingBox.height;
11560
+ } else if ("x" in primitive && "y" in primitive) {
11561
+ basePoint = { x: primitive.x, y: primitive.y };
11562
+ w = "w" in primitive ? primitive.w : "r" in primitive ? primitive.r * 2 : 0;
11563
+ h = "h" in primitive ? primitive.h : "r" in primitive ? primitive.r * 2 : 0;
11564
+ }
11565
+ if (!basePoint) continue;
11566
+ const screenPos = applyToPoint12(transform, basePoint);
11466
11567
  const screenSize = {
11467
11568
  w: w * transform.a,
11468
11569
  h: h * transform.a
@@ -11472,6 +11573,10 @@ var MouseElementTracker = ({
11472
11573
  ).length;
11473
11574
  highlightedPrimitives2.push({
11474
11575
  ...primitive,
11576
+ x: basePoint.x,
11577
+ y: basePoint.y,
11578
+ w,
11579
+ h,
11475
11580
  screen_x: screenPos.x,
11476
11581
  screen_y: screenPos.y,
11477
11582
  screen_w: screenSize.w,
@@ -11815,11 +11920,11 @@ var RatsNestOverlay = ({ transform, soup, children }) => {
11815
11920
  connectedIds.forEach((id) => {
11816
11921
  const pos = getElementPosition(id);
11817
11922
  if (pos) {
11818
- const distance3 = Math.sqrt(
11923
+ const distance5 = Math.sqrt(
11819
11924
  (sourcePoint.x - pos.x) ** 2 + (sourcePoint.y - pos.y) ** 2
11820
11925
  );
11821
- if (distance3 < minDistance && distance3 > 0) {
11822
- minDistance = distance3;
11926
+ if (distance5 < minDistance && distance5 > 0) {
11927
+ minDistance = distance5;
11823
11928
  nearestPoint = pos;
11824
11929
  }
11825
11930
  }
@@ -11904,7 +12009,7 @@ import { css as css3 } from "@emotion/css";
11904
12009
  // package.json
11905
12010
  var package_default = {
11906
12011
  name: "@tscircuit/pcb-viewer",
11907
- version: "1.11.232",
12012
+ version: "1.11.234",
11908
12013
  main: "dist/index.js",
11909
12014
  type: "module",
11910
12015
  repository: "tscircuit/pcb-viewer",