circuit-to-canvas 0.0.63 → 0.0.65

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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AnyCircuitElement, PcbRenderLayer, NinePointAnchor, PcbPlatedHole, PCBVia, PcbHole, PcbSmtPad, PcbTrace, PcbBoard, PcbPanel, PcbSilkscreenText, PcbSilkscreenRect, PcbSilkscreenCircle, PcbSilkscreenLine, PcbSilkscreenPath, PcbSilkscreenPill, PcbSilkscreenOval, PcbCutout, PCBKeepout, PcbCopperPour, PcbCopperText, PcbFabricationNoteText, PcbFabricationNoteRect, PcbNoteRect, PcbFabricationNotePath, PcbNotePath, PcbNoteText, PcbNoteDimension, PcbFabricationNoteDimension } from 'circuit-json';
1
+ import { AnyCircuitElement, PcbRenderLayer, NinePointAnchor, PcbPlatedHole, PCBVia, PcbHole, PcbSmtPad, PcbTrace, PcbBoard, PcbPanel, PcbSilkscreenText, PcbSilkscreenRect, PcbSilkscreenCircle, PcbSilkscreenLine, PcbSilkscreenPath, PcbSilkscreenPill, PcbSilkscreenOval, PcbCutout, PCBKeepout, PcbCopperPour, PcbCopperText, PcbFabricationNoteText, PcbFabricationNoteRect, PcbNoteRect, PcbFabricationNotePath, PcbNotePath, PcbNoteText, PcbNoteDimension, PcbFabricationNoteDimension, PcbCourtyardCircle } from 'circuit-json';
2
2
  import { Matrix } from 'transformation-matrix';
3
3
 
4
4
  /**
@@ -550,4 +550,12 @@ interface DrawPcbFabricationNoteDimensionParams {
550
550
  }
551
551
  declare function drawPcbFabricationNoteDimension(params: DrawPcbFabricationNoteDimensionParams): void;
552
552
 
553
- export { type AlphabetLayout, type AnchorAlignment, type CameraBounds, type CanvasContext, CircuitToCanvasDrawer, type CopperColorMap, type CopperLayerName, DEFAULT_PCB_COLOR_MAP, type DrawArrowParams, type DrawCircleParams, type DrawContext, type DrawDimensionLineParams, type DrawElementsOptions, type DrawLineParams, type DrawOvalParams, type DrawPathParams, type DrawPcbBoardParams, type DrawPcbCopperPourParams, type DrawPcbCopperTextParams, type DrawPcbCutoutParams, type DrawPcbFabricationNoteDimensionParams, type DrawPcbFabricationNotePathParams, type DrawPcbFabricationNoteRectParams, type DrawPcbFabricationNoteTextParams, type DrawPcbHoleParams, type DrawPcbKeepoutParams, type DrawPcbNoteDimensionParams, type DrawPcbNotePathParams, type DrawPcbNoteRectParams, type DrawPcbNoteTextParams, type DrawPcbPanelParams, type DrawPcbPlatedHoleParams, type DrawPcbSilkscreenCircleParams, type DrawPcbSilkscreenLineParams, type DrawPcbSilkscreenOvalParams, type DrawPcbSilkscreenPathParams, type DrawPcbSilkscreenPillParams, type DrawPcbSilkscreenRectParams, type DrawPcbSilkscreenTextParams, type DrawPcbSmtPadParams, type DrawPcbTraceParams, type DrawPcbViaParams, type DrawPillParams, type DrawPolygonParams, type DrawRectParams, type DrawTextParams, type DrawerConfig, type PcbColorMap, drawArrow, drawCircle, drawDimensionLine, drawLine, drawOval, drawPath, drawPcbBoard, drawPcbCopperPour, drawPcbCopperText, drawPcbCutout, drawPcbFabricationNoteDimension, drawPcbFabricationNotePath, drawPcbFabricationNoteRect, drawPcbFabricationNoteText, drawPcbHole, drawPcbKeepout, drawPcbNoteDimension, drawPcbNotePath, drawPcbNoteRect, drawPcbNoteText, drawPcbPanelElement, drawPcbPlatedHole, drawPcbSilkscreenCircle, drawPcbSilkscreenLine, drawPcbSilkscreenOval, drawPcbSilkscreenPath, drawPcbSilkscreenPill, drawPcbSilkscreenRect, drawPcbSilkscreenText, drawPcbSmtPad, drawPcbTrace, drawPcbVia, drawPill, drawPolygon, drawRect, drawSoldermaskRingForCircle, drawSoldermaskRingForOval, drawSoldermaskRingForPill, drawSoldermaskRingForRect, drawText, getAlphabetLayout, getTextStartPosition, strokeAlphabetText };
553
+ interface DrawPcbCourtyardCircleParams {
554
+ ctx: CanvasContext;
555
+ circle: PcbCourtyardCircle;
556
+ realToCanvasMat: Matrix;
557
+ colorMap: PcbColorMap;
558
+ }
559
+ declare function drawPcbCourtyardCircle(params: DrawPcbCourtyardCircleParams): void;
560
+
561
+ export { type AlphabetLayout, type AnchorAlignment, type CameraBounds, type CanvasContext, CircuitToCanvasDrawer, type CopperColorMap, type CopperLayerName, DEFAULT_PCB_COLOR_MAP, type DrawArrowParams, type DrawCircleParams, type DrawContext, type DrawDimensionLineParams, type DrawElementsOptions, type DrawLineParams, type DrawOvalParams, type DrawPathParams, type DrawPcbBoardParams, type DrawPcbCopperPourParams, type DrawPcbCopperTextParams, type DrawPcbCourtyardCircleParams, type DrawPcbCutoutParams, type DrawPcbFabricationNoteDimensionParams, type DrawPcbFabricationNotePathParams, type DrawPcbFabricationNoteRectParams, type DrawPcbFabricationNoteTextParams, type DrawPcbHoleParams, type DrawPcbKeepoutParams, type DrawPcbNoteDimensionParams, type DrawPcbNotePathParams, type DrawPcbNoteRectParams, type DrawPcbNoteTextParams, type DrawPcbPanelParams, type DrawPcbPlatedHoleParams, type DrawPcbSilkscreenCircleParams, type DrawPcbSilkscreenLineParams, type DrawPcbSilkscreenOvalParams, type DrawPcbSilkscreenPathParams, type DrawPcbSilkscreenPillParams, type DrawPcbSilkscreenRectParams, type DrawPcbSilkscreenTextParams, type DrawPcbSmtPadParams, type DrawPcbTraceParams, type DrawPcbViaParams, type DrawPillParams, type DrawPolygonParams, type DrawRectParams, type DrawTextParams, type DrawerConfig, type PcbColorMap, drawArrow, drawCircle, drawDimensionLine, drawLine, drawOval, drawPath, drawPcbBoard, drawPcbCopperPour, drawPcbCopperText, drawPcbCourtyardCircle, drawPcbCutout, drawPcbFabricationNoteDimension, drawPcbFabricationNotePath, drawPcbFabricationNoteRect, drawPcbFabricationNoteText, drawPcbHole, drawPcbKeepout, drawPcbNoteDimension, drawPcbNotePath, drawPcbNoteRect, drawPcbNoteText, drawPcbPanelElement, drawPcbPlatedHole, drawPcbSilkscreenCircle, drawPcbSilkscreenLine, drawPcbSilkscreenOval, drawPcbSilkscreenPath, drawPcbSilkscreenPill, drawPcbSilkscreenRect, drawPcbSilkscreenText, drawPcbSmtPad, drawPcbTrace, drawPcbVia, drawPill, drawPolygon, drawRect, drawSoldermaskRingForCircle, drawSoldermaskRingForOval, drawSoldermaskRingForPill, drawSoldermaskRingForRect, drawText, getAlphabetLayout, getTextStartPosition, strokeAlphabetText };
package/dist/index.js CHANGED
@@ -673,6 +673,35 @@ function drawCircle(params) {
673
673
  }
674
674
  }
675
675
 
676
+ // lib/drawer/elements/pcb-courtyard-circle.ts
677
+ function drawPcbCourtyardCircle(params) {
678
+ const { ctx, circle, realToCanvasMat, colorMap } = params;
679
+ drawCircle({
680
+ ctx,
681
+ center: circle.center,
682
+ radius: circle.radius,
683
+ stroke: colorMap.courtyard,
684
+ strokeWidth: 0.05,
685
+ // Default thin line for courtyard info
686
+ realToCanvasMat
687
+ });
688
+ }
689
+
690
+ // lib/drawer/elements/pcb-courtyard-rect.ts
691
+ function drawPcbCourtyardRect(params) {
692
+ const { ctx, rect, realToCanvasMat, colorMap } = params;
693
+ drawRect({
694
+ ctx,
695
+ center: rect.center,
696
+ width: rect.width,
697
+ height: rect.height,
698
+ stroke: colorMap.courtyard,
699
+ strokeWidth: 0.05,
700
+ // Default thin line for courtyard info
701
+ realToCanvasMat
702
+ });
703
+ }
704
+
676
705
  // lib/drawer/elements/pcb-cutout.ts
677
706
  function drawPcbCutout(params) {
678
707
  const { ctx, cutout, realToCanvasMat, colorMap } = params;
@@ -3657,6 +3686,22 @@ var CircuitToCanvasDrawer = class {
3657
3686
  colorMap: this.colorMap
3658
3687
  });
3659
3688
  }
3689
+ if (element.type === "pcb_courtyard_circle") {
3690
+ drawPcbCourtyardCircle({
3691
+ ctx: this.ctx,
3692
+ circle: element,
3693
+ realToCanvasMat: this.realToCanvasMat,
3694
+ colorMap: this.colorMap
3695
+ });
3696
+ }
3697
+ if (element.type === "pcb_courtyard_rect") {
3698
+ drawPcbCourtyardRect({
3699
+ ctx: this.ctx,
3700
+ rect: element,
3701
+ realToCanvasMat: this.realToCanvasMat,
3702
+ colorMap: this.colorMap
3703
+ });
3704
+ }
3660
3705
  }
3661
3706
  }
3662
3707
  };
@@ -3688,6 +3733,7 @@ export {
3688
3733
  drawPcbBoard,
3689
3734
  drawPcbCopperPour,
3690
3735
  drawPcbCopperText,
3736
+ drawPcbCourtyardCircle,
3691
3737
  drawPcbCutout,
3692
3738
  drawPcbFabricationNoteDimension,
3693
3739
  drawPcbFabricationNotePath,
@@ -4,6 +4,8 @@ import type {
4
4
  PcbBoard,
5
5
  PcbCopperPour,
6
6
  PcbCopperText,
7
+ PcbCourtyardCircle,
8
+ PcbCourtyardRect,
7
9
  PcbCutout,
8
10
  PcbFabricationNoteDimension,
9
11
  PcbFabricationNotePath,
@@ -40,6 +42,8 @@ import {
40
42
  import { drawPcbBoard } from "./elements/pcb-board"
41
43
  import { drawPcbCopperPour } from "./elements/pcb-copper-pour"
42
44
  import { drawPcbCopperText } from "./elements/pcb-copper-text"
45
+ import { drawPcbCourtyardCircle } from "./elements/pcb-courtyard-circle"
46
+ import { drawPcbCourtyardRect } from "./elements/pcb-courtyard-rect"
43
47
  import { drawPcbCutout } from "./elements/pcb-cutout"
44
48
  import { drawPcbFabricationNoteDimension } from "./elements/pcb-fabrication-note-dimension"
45
49
  import { drawPcbFabricationNotePath } from "./elements/pcb-fabrication-note-path"
@@ -490,6 +494,24 @@ export class CircuitToCanvasDrawer {
490
494
  colorMap: this.colorMap,
491
495
  })
492
496
  }
497
+
498
+ if (element.type === "pcb_courtyard_circle") {
499
+ drawPcbCourtyardCircle({
500
+ ctx: this.ctx,
501
+ circle: element as PcbCourtyardCircle,
502
+ realToCanvasMat: this.realToCanvasMat,
503
+ colorMap: this.colorMap,
504
+ })
505
+ }
506
+
507
+ if (element.type === "pcb_courtyard_rect") {
508
+ drawPcbCourtyardRect({
509
+ ctx: this.ctx,
510
+ rect: element as PcbCourtyardRect,
511
+ realToCanvasMat: this.realToCanvasMat,
512
+ colorMap: this.colorMap,
513
+ })
514
+ }
493
515
  }
494
516
  }
495
517
  }
@@ -109,3 +109,8 @@ export {
109
109
  drawPcbFabricationNoteDimension,
110
110
  type DrawPcbFabricationNoteDimensionParams,
111
111
  } from "./pcb-fabrication-note-dimension"
112
+
113
+ export {
114
+ drawPcbCourtyardCircle,
115
+ type DrawPcbCourtyardCircleParams,
116
+ } from "./pcb-courtyard-circle"
@@ -0,0 +1,26 @@
1
+ import type { PcbCourtyardCircle } from "circuit-json"
2
+ import type { Matrix } from "transformation-matrix"
3
+ import type { PcbColorMap, CanvasContext } from "../types"
4
+ import { drawCircle } from "../shapes/circle"
5
+
6
+ export interface DrawPcbCourtyardCircleParams {
7
+ ctx: CanvasContext
8
+ circle: PcbCourtyardCircle
9
+ realToCanvasMat: Matrix
10
+ colorMap: PcbColorMap
11
+ }
12
+
13
+ export function drawPcbCourtyardCircle(
14
+ params: DrawPcbCourtyardCircleParams,
15
+ ): void {
16
+ const { ctx, circle, realToCanvasMat, colorMap } = params
17
+
18
+ drawCircle({
19
+ ctx,
20
+ center: circle.center,
21
+ radius: circle.radius,
22
+ stroke: colorMap.courtyard,
23
+ strokeWidth: 0.05, // Default thin line for courtyard info
24
+ realToCanvasMat,
25
+ })
26
+ }
@@ -0,0 +1,25 @@
1
+ import type { PcbCourtyardRect } from "circuit-json"
2
+ import type { Matrix } from "transformation-matrix"
3
+ import type { PcbColorMap, CanvasContext } from "../types"
4
+ import { drawRect } from "../shapes/rect"
5
+
6
+ export interface DrawPcbCourtyardRectParams {
7
+ ctx: CanvasContext
8
+ rect: PcbCourtyardRect
9
+ realToCanvasMat: Matrix
10
+ colorMap: PcbColorMap
11
+ }
12
+
13
+ export function drawPcbCourtyardRect(params: DrawPcbCourtyardRectParams): void {
14
+ const { ctx, rect, realToCanvasMat, colorMap } = params
15
+
16
+ drawRect({
17
+ ctx,
18
+ center: rect.center,
19
+ width: rect.width,
20
+ height: rect.height,
21
+ stroke: colorMap.courtyard,
22
+ strokeWidth: 0.05, // Default thin line for courtyard info
23
+ realToCanvasMat,
24
+ })
25
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "circuit-to-canvas",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.63",
4
+ "version": "0.0.65",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "tsup-node ./lib/index.ts --format esm --dts",
@@ -17,9 +17,9 @@
17
17
  "@tscircuit/math-utils": "^0.0.29",
18
18
  "@types/bun": "latest",
19
19
  "bun-match-svg": "^0.0.14",
20
- "circuit-json": "^0.0.356",
20
+ "circuit-json": "^0.0.374",
21
21
  "circuit-json-to-connectivity-map": "^0.0.23",
22
- "circuit-to-svg": "^0.0.303",
22
+ "circuit-to-svg": "^0.0.323",
23
23
  "looks-same": "^10.0.1",
24
24
  "schematic-symbols": "^0.0.202",
25
25
  "tsup": "^8.5.1"
@@ -0,0 +1,44 @@
1
+ import { expect, test } from "bun:test"
2
+ import { createCanvas } from "@napi-rs/canvas"
3
+ import type { PcbCourtyardCircle } from "circuit-json"
4
+ import { CircuitToCanvasDrawer } from "../../lib/drawer"
5
+
6
+ test("draw courtyard circle", async () => {
7
+ const canvas = createCanvas(1000, 1000)
8
+ const ctx = canvas.getContext("2d")
9
+ const drawer = new CircuitToCanvasDrawer(ctx)
10
+
11
+ ctx.fillStyle = "#1a1a1a"
12
+ ctx.fillRect(0, 0, 1000, 1000)
13
+
14
+ const circle: PcbCourtyardCircle = {
15
+ type: "pcb_courtyard_circle",
16
+ pcb_courtyard_circle_id: "courtyard_circle1",
17
+ pcb_component_id: "component1",
18
+ layer: "top",
19
+ center: { x: 0, y: 0 },
20
+ radius: 2,
21
+ }
22
+
23
+ const circle2: PcbCourtyardCircle = {
24
+ type: "pcb_courtyard_circle",
25
+ pcb_courtyard_circle_id: "courtyard_circle2",
26
+ pcb_component_id: "component2",
27
+ layer: "bottom",
28
+ center: { x: 3, y: 3 },
29
+ radius: 1,
30
+ }
31
+
32
+ drawer.setCameraBounds({
33
+ minX: -5,
34
+ maxX: 5,
35
+ minY: -5,
36
+ maxY: 5,
37
+ })
38
+
39
+ drawer.drawElements([circle, circle2])
40
+
41
+ await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
42
+ import.meta.path,
43
+ )
44
+ })
@@ -0,0 +1,46 @@
1
+ import { expect, test } from "bun:test"
2
+ import { createCanvas } from "@napi-rs/canvas"
3
+ import type { PcbCourtyardRect } from "circuit-json"
4
+ import { CircuitToCanvasDrawer } from "../../lib/drawer"
5
+
6
+ test("draw courtyard rect", async () => {
7
+ const canvas = createCanvas(1000, 1000)
8
+ const ctx = canvas.getContext("2d")
9
+ const drawer = new CircuitToCanvasDrawer(ctx)
10
+
11
+ ctx.fillStyle = "#1a1a1a"
12
+ ctx.fillRect(0, 0, 1000, 1000)
13
+
14
+ const rect1: PcbCourtyardRect = {
15
+ type: "pcb_courtyard_rect",
16
+ pcb_courtyard_rect_id: "courtyard_rect1",
17
+ pcb_component_id: "component1",
18
+ layer: "top",
19
+ center: { x: 0, y: 0 },
20
+ width: 4,
21
+ height: 2,
22
+ }
23
+
24
+ const rect2: PcbCourtyardRect = {
25
+ type: "pcb_courtyard_rect",
26
+ pcb_courtyard_rect_id: "courtyard_rect2",
27
+ pcb_component_id: "component2",
28
+ layer: "bottom",
29
+ center: { x: 3, y: 3 },
30
+ width: 2,
31
+ height: 4,
32
+ }
33
+
34
+ drawer.setCameraBounds({
35
+ minX: -5,
36
+ maxX: 5,
37
+ minY: -5,
38
+ maxY: 5,
39
+ })
40
+
41
+ drawer.drawElements([rect1, rect2])
42
+
43
+ await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
44
+ import.meta.path,
45
+ )
46
+ })