@tscircuit/pcb-viewer 1.11.307 → 1.11.308

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
@@ -8586,23 +8586,23 @@ var Drawer = class {
8586
8586
  }
8587
8587
  applyAperture() {
8588
8588
  const { transform, aperture } = this;
8589
- let { size, mode, color: color4, fontSize, layer } = aperture;
8589
+ let { size, mode, color: color5, fontSize, layer } = aperture;
8590
8590
  if (!(layer in this.ctxLayerMap)) this.aperture.layer = "other";
8591
8591
  const ctx = this.getLayerCtx();
8592
8592
  if (!ctx) {
8593
8593
  throw new Error(`No context for layer "${this.foregroundLayer}"`);
8594
8594
  }
8595
- if (!color4) color4 = "undefined";
8595
+ if (!color5) color5 = "undefined";
8596
8596
  ctx.lineWidth = scaleOnly(transform, size);
8597
8597
  ctx.lineCap = "round";
8598
8598
  if (mode === "add") {
8599
8599
  ctx.globalCompositeOperation = "source-over";
8600
- let colorString = LAYER_NAME_TO_COLOR[color4.toLowerCase()];
8600
+ let colorString = LAYER_NAME_TO_COLOR[color5.toLowerCase()];
8601
8601
  if (!colorString)
8602
8602
  try {
8603
- colorString = colorParser(color4).rgb().toString();
8603
+ colorString = colorParser(color5).rgb().toString();
8604
8604
  } catch (error) {
8605
- console.warn(`Invalid color format: '${color4}'`);
8605
+ console.warn(`Invalid color format: '${color5}'`);
8606
8606
  colorString = "white";
8607
8607
  }
8608
8608
  ctx.fillStyle = colorString;
@@ -9318,6 +9318,61 @@ function drawPcbSmtPadElementsForLayer({
9318
9318
  }
9319
9319
  }
9320
9320
 
9321
+ // src/lib/draw-via.ts
9322
+ import {
9323
+ DEFAULT_PCB_COLOR_MAP as DEFAULT_PCB_COLOR_MAP6,
9324
+ CircuitToCanvasDrawer as CircuitToCanvasDrawer9
9325
+ } from "circuit-to-canvas";
9326
+ import color4 from "color";
9327
+ var HOVER_COLOR_MAP3 = {
9328
+ ...DEFAULT_PCB_COLOR_MAP6,
9329
+ copper: {
9330
+ ...DEFAULT_PCB_COLOR_MAP6.copper,
9331
+ top: color4(colors_default.board.pad_front).lighten(0.5).toString(),
9332
+ bottom: color4(colors_default.board.pad_back).lighten(0.5).toString()
9333
+ }
9334
+ };
9335
+ function isPcbVia(element) {
9336
+ return element.type === "pcb_via";
9337
+ }
9338
+ function drawPcbViaElementsForLayer({
9339
+ canvas,
9340
+ elements,
9341
+ layers,
9342
+ realToCanvasMat,
9343
+ primitives
9344
+ }) {
9345
+ const viaElements = elements.filter(isPcbVia).filter((element) => {
9346
+ return layers.some((layer) => layer.includes("copper"));
9347
+ });
9348
+ if (viaElements.length === 0) return;
9349
+ const highlightedElementIds = /* @__PURE__ */ new Set();
9350
+ if (primitives) {
9351
+ for (const primitive of primitives) {
9352
+ if ((primitive.is_mouse_over || primitive.is_in_highlighted_net) && primitive._element?.type === "pcb_via") {
9353
+ highlightedElementIds.add(primitive._element.pcb_via_id);
9354
+ }
9355
+ }
9356
+ }
9357
+ const highlightedElements = viaElements.filter(
9358
+ (element) => highlightedElementIds.has(element.pcb_via_id)
9359
+ );
9360
+ const nonHighlightedElements = viaElements.filter(
9361
+ (element) => !highlightedElementIds.has(element.pcb_via_id)
9362
+ );
9363
+ if (nonHighlightedElements.length > 0) {
9364
+ const drawer = new CircuitToCanvasDrawer9(canvas);
9365
+ drawer.realToCanvasMat = realToCanvasMat;
9366
+ drawer.drawElements(nonHighlightedElements, { layers });
9367
+ }
9368
+ if (highlightedElements.length > 0) {
9369
+ const highlightDrawer = new CircuitToCanvasDrawer9(canvas);
9370
+ highlightDrawer.configure({ colorOverrides: HOVER_COLOR_MAP3 });
9371
+ highlightDrawer.realToCanvasMat = realToCanvasMat;
9372
+ highlightDrawer.drawElements(highlightedElements, { layers });
9373
+ }
9374
+ }
9375
+
9321
9376
  // src/components/CanvasPrimitiveRenderer.tsx
9322
9377
  import { jsx as jsx3, jsxs } from "react/jsx-runtime";
9323
9378
  var orderedLayers = [
@@ -9372,7 +9427,7 @@ var CanvasPrimitiveRenderer = ({
9372
9427
  if (transform) drawer.transform = transform;
9373
9428
  drawer.clear();
9374
9429
  drawer.foregroundLayer = selectedLayer;
9375
- const filteredPrimitives = primitives.filter((p) => isShowingSolderMask || !p.layer?.includes("soldermask")).filter((p) => p.layer !== "board").filter((p) => p._element?.type !== "pcb_smtpad").filter((p) => p._element?.type !== "pcb_plated_hole");
9430
+ const filteredPrimitives = primitives.filter((p) => isShowingSolderMask || !p.layer?.includes("soldermask")).filter((p) => p.layer !== "board").filter((p) => p._element?.type !== "pcb_smtpad").filter((p) => p._element?.type !== "pcb_plated_hole").filter((p) => p._element?.type !== "pcb_via");
9376
9431
  drawPrimitives(drawer, filteredPrimitives);
9377
9432
  if (transform) {
9378
9433
  const topCanvas = canvasRefs.current.top;
@@ -9413,6 +9468,24 @@ var CanvasPrimitiveRenderer = ({
9413
9468
  primitives
9414
9469
  });
9415
9470
  }
9471
+ if (topCanvas) {
9472
+ drawPcbViaElementsForLayer({
9473
+ canvas: topCanvas,
9474
+ elements,
9475
+ layers: ["top_copper"],
9476
+ realToCanvasMat: transform,
9477
+ primitives
9478
+ });
9479
+ }
9480
+ if (bottomCanvas) {
9481
+ drawPcbViaElementsForLayer({
9482
+ canvas: bottomCanvas,
9483
+ elements,
9484
+ layers: ["bottom_copper"],
9485
+ realToCanvasMat: transform,
9486
+ primitives
9487
+ });
9488
+ }
9416
9489
  const topSilkscreenCanvas = canvasRefs.current.top_silkscreen;
9417
9490
  if (topSilkscreenCanvas) {
9418
9491
  drawSilkscreenElementsForLayer(
@@ -12084,7 +12157,7 @@ var HighlightedPrimitiveBoxWithText = ({
12084
12157
  ];
12085
12158
  const si = primitive.same_space_index ?? 0;
12086
12159
  const sip = 26;
12087
- const color4 = layerColorHightlightMap[primitive?._element?.layer] ?? "red";
12160
+ const color5 = layerColorHightlightMap[primitive?._element?.layer] ?? "red";
12088
12161
  let rotation = 0;
12089
12162
  if (primitiveElement.type === "pcb_smtpad" && primitiveElement?.shape === "rotated_rect") {
12090
12163
  rotation = primitiveElement?.ccw_rotation ?? 0;
@@ -12106,7 +12179,7 @@ var HighlightedPrimitiveBoxWithText = ({
12106
12179
  position: "absolute",
12107
12180
  left: mousePos.x,
12108
12181
  top: yOffset,
12109
- color: color4,
12182
+ color: color5,
12110
12183
  pointerEvents: "none",
12111
12184
  transform: "translateX(-50%)"
12112
12185
  },
@@ -12146,7 +12219,7 @@ var HighlightedPrimitiveBoxWithText = ({
12146
12219
  top: y - h / 2 - 8,
12147
12220
  width: w + 16,
12148
12221
  height: h + 16,
12149
- color: color4,
12222
+ color: color5,
12150
12223
  transform: `rotate(${-rotation}deg)`,
12151
12224
  transformOrigin: "center center"
12152
12225
  },
@@ -12162,7 +12235,7 @@ var HighlightedPrimitiveBoxWithText = ({
12162
12235
  height: finalState ? `calc(100% + ${sip * 2 * si}px)` : "100%",
12163
12236
  marginLeft: finalState ? `${-sip * si}px` : 0,
12164
12237
  marginTop: finalState ? `${-sip * si}px` : 0,
12165
- border: `1px solid ${color4}`,
12238
+ border: `1px solid ${color5}`,
12166
12239
  opacity: finalState ? 1 : si === 0 ? 1 : 0,
12167
12240
  transition: "width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"
12168
12241
  },
@@ -13521,7 +13594,7 @@ import { css as css3 } from "@emotion/css";
13521
13594
  // package.json
13522
13595
  var package_default = {
13523
13596
  name: "@tscircuit/pcb-viewer",
13524
- version: "1.11.306",
13597
+ version: "1.11.307",
13525
13598
  main: "dist/index.js",
13526
13599
  type: "module",
13527
13600
  repository: "tscircuit/pcb-viewer",