@tscircuit/pcb-viewer 1.11.352 → 1.11.353

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
@@ -5572,6 +5572,34 @@ var cju = (circuitJsonInput, options = {}) => {
5572
5572
  if (prop === "subtree") {
5573
5573
  return (opts) => cju(buildSubtree(circuitJson, opts), options);
5574
5574
  }
5575
+ if (prop === "insert") {
5576
+ return (elm) => {
5577
+ const component_type2 = elm.type;
5578
+ if (!component_type2) {
5579
+ throw new Error("insert requires an element with a type");
5580
+ }
5581
+ internalStore.counts[component_type2] ??= -1;
5582
+ internalStore.counts[component_type2]++;
5583
+ const index = internalStore.counts[component_type2];
5584
+ const newElm = {
5585
+ ...elm,
5586
+ type: component_type2,
5587
+ [`${component_type2}_id`]: `${component_type2}_${index}`
5588
+ };
5589
+ if (options.validateInserts) {
5590
+ const parser = Soup[component_type2] ?? Soup.any_soup_element;
5591
+ parser.parse(newElm);
5592
+ }
5593
+ circuitJson.push(newElm);
5594
+ internalStore.editCount++;
5595
+ return newElm;
5596
+ };
5597
+ }
5598
+ if (prop === "insertAll") {
5599
+ return (elms) => {
5600
+ return elms.map((elm) => su2.insert(elm));
5601
+ };
5602
+ }
5575
5603
  const component_type = prop;
5576
5604
  return {
5577
5605
  get: (id) => circuitJson.find(
@@ -6199,6 +6227,43 @@ var getElementId = (elm) => {
6199
6227
  const id = elm[`${type}_id`];
6200
6228
  return id;
6201
6229
  };
6230
+ var mergeBounds = (currentBounds, nextBounds) => ({
6231
+ minX: Math.min(currentBounds.minX, nextBounds.minX),
6232
+ minY: Math.min(currentBounds.minY, nextBounds.minY),
6233
+ maxX: Math.max(currentBounds.maxX, nextBounds.maxX),
6234
+ maxY: Math.max(currentBounds.maxY, nextBounds.maxY)
6235
+ });
6236
+ var getCircleBounds = (x, y, diameter) => {
6237
+ const radius = diameter / 2;
6238
+ return {
6239
+ minX: x - radius,
6240
+ minY: y - radius,
6241
+ maxX: x + radius,
6242
+ maxY: y + radius
6243
+ };
6244
+ };
6245
+ var getRotatedRectBounds = (x, y, width, height, rotationDegrees) => {
6246
+ const halfWidth = width / 2;
6247
+ const halfHeight = height / 2;
6248
+ const theta = rotationDegrees * Math.PI / 180;
6249
+ const cosTheta = Math.cos(theta);
6250
+ const sinTheta = Math.sin(theta);
6251
+ const corners = [
6252
+ { x: -halfWidth, y: -halfHeight },
6253
+ { x: halfWidth, y: -halfHeight },
6254
+ { x: halfWidth, y: halfHeight },
6255
+ { x: -halfWidth, y: halfHeight }
6256
+ ].map((corner) => ({
6257
+ x: x + corner.x * cosTheta - corner.y * sinTheta,
6258
+ y: y + corner.x * sinTheta + corner.y * cosTheta
6259
+ }));
6260
+ return {
6261
+ minX: Math.min(...corners.map((corner) => corner.x)),
6262
+ minY: Math.min(...corners.map((corner) => corner.y)),
6263
+ maxX: Math.max(...corners.map((corner) => corner.x)),
6264
+ maxY: Math.max(...corners.map((corner) => corner.y))
6265
+ };
6266
+ };
6202
6267
  var getBoundsOfPcbElements = (elements) => {
6203
6268
  let minX = Number.POSITIVE_INFINITY;
6204
6269
  let minY = Number.POSITIVE_INFINITY;
@@ -6215,6 +6280,47 @@ var getBoundsOfPcbElements = (elements) => {
6215
6280
  }
6216
6281
  continue;
6217
6282
  }
6283
+ if (elm.type === "pcb_hole" && elm.hole_shape === "circle") {
6284
+ const holeBounds = getCircleBounds(elm.x, elm.y, elm.hole_diameter);
6285
+ minX = Math.min(minX, holeBounds.minX);
6286
+ minY = Math.min(minY, holeBounds.minY);
6287
+ maxX = Math.max(maxX, holeBounds.maxX);
6288
+ maxY = Math.max(maxY, holeBounds.maxY);
6289
+ continue;
6290
+ }
6291
+ if (elm.type === "pcb_plated_hole") {
6292
+ let platedHoleBounds;
6293
+ if ("outer_diameter" in elm && typeof elm.outer_diameter === "number") {
6294
+ platedHoleBounds = getCircleBounds(elm.x, elm.y, elm.outer_diameter);
6295
+ } else if ("hole_diameter" in elm && typeof elm.hole_diameter === "number") {
6296
+ platedHoleBounds = getCircleBounds(elm.x, elm.y, elm.hole_diameter);
6297
+ }
6298
+ if ("rect_pad_width" in elm && typeof elm.rect_pad_width === "number" && "rect_pad_height" in elm && typeof elm.rect_pad_height === "number") {
6299
+ const rectBounds = getRotatedRectBounds(
6300
+ elm.x,
6301
+ elm.y,
6302
+ elm.rect_pad_width,
6303
+ elm.rect_pad_height,
6304
+ "rect_ccw_rotation" in elm ? elm.rect_ccw_rotation ?? 0 : 0
6305
+ );
6306
+ platedHoleBounds = platedHoleBounds ? mergeBounds(platedHoleBounds, rectBounds) : rectBounds;
6307
+ }
6308
+ if ("hole_diameter" in elm && typeof elm.hole_diameter === "number") {
6309
+ const drillBounds = getCircleBounds(
6310
+ elm.x + ("hole_offset_x" in elm ? elm.hole_offset_x ?? 0 : 0),
6311
+ elm.y + ("hole_offset_y" in elm ? elm.hole_offset_y ?? 0 : 0),
6312
+ elm.hole_diameter
6313
+ );
6314
+ platedHoleBounds = platedHoleBounds ? mergeBounds(platedHoleBounds, drillBounds) : drillBounds;
6315
+ }
6316
+ if (platedHoleBounds) {
6317
+ minX = Math.min(minX, platedHoleBounds.minX);
6318
+ minY = Math.min(minY, platedHoleBounds.minY);
6319
+ maxX = Math.max(maxX, platedHoleBounds.maxX);
6320
+ maxY = Math.max(maxY, platedHoleBounds.maxY);
6321
+ continue;
6322
+ }
6323
+ }
6218
6324
  let centerX;
6219
6325
  let centerY;
6220
6326
  let width;
@@ -6261,6 +6367,20 @@ var getBoundsOfPcbElements = (elements) => {
6261
6367
  maxX = Math.max(maxX, point.x);
6262
6368
  maxY = Math.max(maxY, point.y);
6263
6369
  }
6370
+ } else if (elm.type === "pcb_courtyard_outline") {
6371
+ for (const point of elm.outline) {
6372
+ minX = Math.min(minX, point.x);
6373
+ minY = Math.min(minY, point.y);
6374
+ maxX = Math.max(maxX, point.x);
6375
+ maxY = Math.max(maxY, point.y);
6376
+ }
6377
+ } else if (elm.type === "pcb_courtyard_polygon") {
6378
+ for (const point of elm.points) {
6379
+ minX = Math.min(minX, point.x);
6380
+ minY = Math.min(minY, point.y);
6381
+ maxX = Math.max(maxX, point.x);
6382
+ maxY = Math.max(maxY, point.y);
6383
+ }
6264
6384
  }
6265
6385
  }
6266
6386
  return { minX, minY, maxX, maxY };
@@ -14241,7 +14361,7 @@ import { css as css3 } from "@emotion/css";
14241
14361
  // package.json
14242
14362
  var package_default = {
14243
14363
  name: "@tscircuit/pcb-viewer",
14244
- version: "1.11.351",
14364
+ version: "1.11.352",
14245
14365
  main: "dist/index.js",
14246
14366
  type: "module",
14247
14367
  repository: "tscircuit/pcb-viewer",
@@ -14265,7 +14385,7 @@ var package_default = {
14265
14385
  "@semantic-release/npm": "^9.0.1",
14266
14386
  "@semantic-release/release-notes-generator": "^10.0.3",
14267
14387
  "@swc/core": "^1.4.12",
14268
- "@tscircuit/circuit-json-util": "^0.0.78",
14388
+ "@tscircuit/circuit-json-util": "^0.0.90",
14269
14389
  "@tscircuit/eagle-xml-converter": "^1.0.0",
14270
14390
  "@types/bun": "latest",
14271
14391
  "@types/color": "^3.0.6",
@@ -14278,7 +14398,7 @@ var package_default = {
14278
14398
  "react-cosmos-plugin-vite": "7.0.0-beta.0",
14279
14399
  "react-dom": "19.1.0",
14280
14400
  "react-use": "^17.4.0",
14281
- tscircuit: "^0.0.1421",
14401
+ tscircuit: "^0.0.1517",
14282
14402
  tsup: "^8.0.2",
14283
14403
  "type-fest": "^3.0.0",
14284
14404
  typescript: "^5.4.4",
@@ -14294,9 +14414,9 @@ var package_default = {
14294
14414
  "@tscircuit/alphabet": "^0.0.22",
14295
14415
  "@tscircuit/math-utils": "^0.0.29",
14296
14416
  "@vitejs/plugin-react": "^5.0.2",
14297
- "circuit-json": "^0.0.387",
14298
- "circuit-to-canvas": "^0.0.92",
14299
- "circuit-to-svg": "^0.0.323",
14417
+ "circuit-json": "^0.0.403",
14418
+ "circuit-to-canvas": "^0.0.93",
14419
+ "circuit-to-svg": "^0.0.337",
14300
14420
  color: "^4.2.3",
14301
14421
  "react-supergrid": "^1.0.10",
14302
14422
  "react-toastify": "^10.0.5",