circuit-to-canvas 0.0.50 → 0.0.52
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 +10 -4
- package/dist/index.js +2911 -2719
- package/lib/drawer/CircuitToCanvasDrawer.ts +317 -366
- package/lib/drawer/elements/helper-functions/draw-pill.ts +39 -0
- package/lib/drawer/elements/helper-functions/draw-polygon.ts +25 -0
- package/lib/drawer/elements/helper-functions/draw-rounded-rect.ts +34 -0
- package/lib/drawer/elements/helper-functions/index.ts +3 -0
- package/lib/drawer/elements/pcb-board.ts +28 -13
- package/lib/drawer/elements/pcb-hole.ts +56 -338
- package/lib/drawer/elements/pcb-plated-hole.ts +154 -442
- package/lib/drawer/elements/pcb-smtpad.ts +3 -292
- package/lib/drawer/elements/pcb-soldermask/board.ts +44 -0
- package/lib/drawer/elements/pcb-soldermask/cutout.ts +74 -0
- package/lib/drawer/elements/pcb-soldermask/hole.ts +288 -0
- package/lib/drawer/elements/pcb-soldermask/index.ts +140 -0
- package/lib/drawer/elements/pcb-soldermask/plated-hole.ts +365 -0
- package/lib/drawer/elements/pcb-soldermask/smt-pad.ts +354 -0
- package/lib/drawer/elements/pcb-soldermask/via.ts +27 -0
- package/package.json +1 -1
- package/tests/board-snapshot/__snapshots__/usb-c-flashlight-board.snap.png +0 -0
- package/tests/board-snapshot/usb-c-flashlight-board.test.ts +1 -0
- package/tests/elements/__snapshots__/board-with-elements.snap.png +0 -0
- package/tests/elements/__snapshots__/brep-copper-pours.snap.png +0 -0
- package/tests/elements/__snapshots__/custom-outline-board.snap.png +0 -0
- package/tests/elements/__snapshots__/oval-plated-hole.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-board.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-comprehensive-soldermask-margin.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-fabrication-note-dimension.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-hole-soldermask-margin.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-keepout-layer-filter.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-keepout-multiple-layers.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-keepout-rect-and-circle.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-keepout-with-group-id.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-no-soldermask.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-plated-hole-soldermask-margin.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-plated-hole.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-silkscreen-on-component.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-silkscreen-oval.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-smtpad-asymmetric-soldermask-margin.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-smtpad-soldermask-coverage.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-smtpad-soldermask-margin.snap.png +0 -0
- package/tests/elements/__snapshots__/pill-plated-hole.snap.png +0 -0
- package/tests/elements/pcb-board.test.ts +2 -2
- package/tests/elements/pcb-comprehensive-soldermask-margin.test.ts +2 -2
- package/tests/elements/pcb-hole-soldermask-margin.test.ts +155 -2
- package/tests/elements/pcb-keepout-with-group-id.test.ts +1 -1
- package/tests/elements/pcb-no-soldermask.test.ts +1281 -0
- package/tests/elements/pcb-plated-hole-soldermask-margin.test.ts +1 -1
- package/tests/elements/pcb-plated-hole.test.ts +40 -4
- package/tests/elements/pcb-smtpad-asymmetric-soldermask-margin.test.ts +1 -1
- package/tests/elements/pcb-smtpad-soldermask-coverage.test.ts +1 -1
- package/tests/elements/pcb-smtpad-soldermask-margin.test.ts +1 -1
- package/tests/fixtures/getStackedPngSvgComparison.ts +10 -4
|
@@ -217,7 +217,7 @@ test("draw plated holes with positive and negative soldermask margins", async ()
|
|
|
217
217
|
]
|
|
218
218
|
|
|
219
219
|
drawer.setCameraBounds({ minX: -8, maxX: 8, minY: -6.5, maxY: 6.5 })
|
|
220
|
-
drawer.drawElements(circuit)
|
|
220
|
+
drawer.drawElements(circuit, { drawSoldermask: true })
|
|
221
221
|
|
|
222
222
|
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
223
223
|
import.meta.path,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { expect, test } from "bun:test"
|
|
2
2
|
import { createCanvas } from "@napi-rs/canvas"
|
|
3
|
-
import type { PcbPlatedHole } from "circuit-json"
|
|
3
|
+
import type { PcbBoard, PcbPlatedHole } from "circuit-json"
|
|
4
4
|
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
5
5
|
|
|
6
6
|
test("draw circular plated hole", async () => {
|
|
@@ -22,7 +22,19 @@ test("draw circular plated hole", async () => {
|
|
|
22
22
|
layers: ["top", "bottom"],
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
const board: PcbBoard = {
|
|
26
|
+
type: "pcb_board",
|
|
27
|
+
pcb_board_id: "board1",
|
|
28
|
+
center: { x: 50, y: 50 },
|
|
29
|
+
width: 100,
|
|
30
|
+
height: 100,
|
|
31
|
+
thickness: 1.6,
|
|
32
|
+
num_layers: 2,
|
|
33
|
+
material: "fr4",
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
drawer.setCameraBounds({ minX: 0, maxX: 100, minY: 0, maxY: 100 })
|
|
37
|
+
drawer.drawElements([board, hole], { drawBoardMaterial: true })
|
|
26
38
|
|
|
27
39
|
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
28
40
|
import.meta.path,
|
|
@@ -51,7 +63,19 @@ test("draw oval plated hole", async () => {
|
|
|
51
63
|
ccw_rotation: 0,
|
|
52
64
|
}
|
|
53
65
|
|
|
54
|
-
|
|
66
|
+
const board: PcbBoard = {
|
|
67
|
+
type: "pcb_board",
|
|
68
|
+
pcb_board_id: "board1",
|
|
69
|
+
center: { x: 50, y: 50 },
|
|
70
|
+
width: 100,
|
|
71
|
+
height: 100,
|
|
72
|
+
thickness: 1.6,
|
|
73
|
+
num_layers: 2,
|
|
74
|
+
material: "fr4",
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
drawer.setCameraBounds({ minX: 0, maxX: 100, minY: 0, maxY: 100 })
|
|
78
|
+
drawer.drawElements([board, hole], { drawBoardMaterial: true })
|
|
55
79
|
|
|
56
80
|
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
57
81
|
import.meta.path,
|
|
@@ -81,7 +105,19 @@ test("draw pill plated hole", async () => {
|
|
|
81
105
|
ccw_rotation: 0,
|
|
82
106
|
}
|
|
83
107
|
|
|
84
|
-
|
|
108
|
+
const board: PcbBoard = {
|
|
109
|
+
type: "pcb_board",
|
|
110
|
+
pcb_board_id: "board1",
|
|
111
|
+
center: { x: 50, y: 50 },
|
|
112
|
+
width: 100,
|
|
113
|
+
height: 100,
|
|
114
|
+
thickness: 1.6,
|
|
115
|
+
num_layers: 2,
|
|
116
|
+
material: "fr4",
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
drawer.setCameraBounds({ minX: 0, maxX: 100, minY: 0, maxY: 100 })
|
|
120
|
+
drawer.drawElements([board, hole], { drawBoardMaterial: true })
|
|
85
121
|
|
|
86
122
|
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
87
123
|
import.meta.path,
|
|
@@ -132,7 +132,7 @@ test("draw smt pads with asymmetric soldermask margins", async () => {
|
|
|
132
132
|
]
|
|
133
133
|
|
|
134
134
|
drawer.setCameraBounds({ minX: -7, maxX: 7, minY: -5, maxY: 5 })
|
|
135
|
-
drawer.drawElements(circuit)
|
|
135
|
+
drawer.drawElements(circuit, { drawSoldermask: true })
|
|
136
136
|
|
|
137
137
|
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
138
138
|
import.meta.path,
|
|
@@ -154,7 +154,7 @@ test("draw smt pads fully covered with soldermask and board with soldermask", as
|
|
|
154
154
|
]
|
|
155
155
|
|
|
156
156
|
drawer.setCameraBounds({ minX: -7, maxX: 7, minY: -5, maxY: 5 })
|
|
157
|
-
drawer.drawElements(circuit)
|
|
157
|
+
drawer.drawElements(circuit, { drawSoldermask: true })
|
|
158
158
|
|
|
159
159
|
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
160
160
|
import.meta.path,
|
|
@@ -165,7 +165,7 @@ test("draw smt pads with positive and negative soldermask margins", async () =>
|
|
|
165
165
|
]
|
|
166
166
|
|
|
167
167
|
drawer.setCameraBounds({ minX: -7, maxX: 7, minY: -5, maxY: 5 })
|
|
168
|
-
drawer.drawElements(circuit)
|
|
168
|
+
drawer.drawElements(circuit, { drawSoldermask: true })
|
|
169
169
|
|
|
170
170
|
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
171
171
|
import.meta.path,
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { createCanvas } from "@napi-rs/canvas"
|
|
2
|
+
import { getBoundsOfPcbElements } from "@tscircuit/circuit-json-util"
|
|
3
|
+
import type { Bounds } from "@tscircuit/math-utils"
|
|
2
4
|
import type { AnyCircuitElement } from "circuit-json"
|
|
3
5
|
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
|
|
4
|
-
import type { Bounds } from "@tscircuit/math-utils"
|
|
5
6
|
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
6
7
|
import { stackPngsVertically, svgToPng } from "./stackPngsVertically"
|
|
7
|
-
import { getBoundsOfPcbElements } from "@tscircuit/circuit-json-util"
|
|
8
8
|
|
|
9
9
|
export interface StackedPngSvgComparisonOptions {
|
|
10
10
|
width?: number
|
|
11
11
|
height?: number
|
|
12
12
|
padding?: number
|
|
13
|
+
drawSoldermask?: boolean
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -23,7 +24,12 @@ export async function getStackedPngSvgComparison(
|
|
|
23
24
|
circuitJson: AnyCircuitElement[],
|
|
24
25
|
options: StackedPngSvgComparisonOptions = {},
|
|
25
26
|
): Promise<Buffer> {
|
|
26
|
-
const {
|
|
27
|
+
const {
|
|
28
|
+
width = 400,
|
|
29
|
+
height = 800,
|
|
30
|
+
padding = 4,
|
|
31
|
+
drawSoldermask = false,
|
|
32
|
+
} = options
|
|
27
33
|
|
|
28
34
|
const bounds = getBoundsOfPcbElements(circuitJson)
|
|
29
35
|
|
|
@@ -41,7 +47,7 @@ export async function getStackedPngSvgComparison(
|
|
|
41
47
|
minY: bounds.minY,
|
|
42
48
|
maxY: bounds.maxY,
|
|
43
49
|
})
|
|
44
|
-
drawer.drawElements(circuitJson)
|
|
50
|
+
drawer.drawElements(circuitJson, { drawSoldermask })
|
|
45
51
|
|
|
46
52
|
const canvasPng = canvas.toBuffer("image/png")
|
|
47
53
|
|