circuit-to-canvas 0.0.31 → 0.0.33
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 +50 -5
- package/dist/index.js +237 -115
- package/lib/drawer/CircuitToCanvasDrawer.ts +22 -0
- package/lib/drawer/elements/index.ts +10 -0
- package/lib/drawer/elements/pcb-fabrication-note-dimension.ts +42 -0
- package/lib/drawer/elements/pcb-hole.ts +2 -2
- package/lib/drawer/elements/pcb-note-dimension.ts +16 -179
- package/lib/drawer/elements/pcb-plated-hole.ts +6 -6
- package/lib/drawer/elements/pcb-silkscreen-oval.ts +35 -0
- package/lib/drawer/shapes/dimension-line.ts +228 -0
- package/lib/drawer/shapes/index.ts +4 -0
- package/lib/drawer/shapes/oval.ts +25 -10
- package/package.json +3 -3
- package/tests/elements/__snapshots__/pcb-fabrication-note-dimension.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-note-dimension-angled-and-vertical.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-note-dimension-basic.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-note-dimension-vertical.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-note-dimension-with-offset.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-silkscreen-oval.snap.png +0 -0
- package/tests/elements/pcb-fabrication-note-dimension.test.ts +40 -0
- package/tests/elements/pcb-silkscreen-oval.test.ts +37 -0
- package/tests/shapes/__snapshots__/dimension-line.snap.png +0 -0
- package/tests/shapes/__snapshots__/oval.snap.png +0 -0
- package/tests/shapes/dimension-line.test.ts +46 -0
- package/tests/shapes/oval.test.ts +3 -2
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import type {
|
|
3
|
+
AnyCircuitElement,
|
|
4
|
+
PcbFabricationNoteDimension,
|
|
5
|
+
} from "circuit-json"
|
|
6
|
+
import { getStackedPngSvgComparison } from "../fixtures/getStackedPngSvgComparison"
|
|
7
|
+
|
|
8
|
+
test("draw pcb fabrication note dimension - basic", async () => {
|
|
9
|
+
const circuitJson: AnyCircuitElement[] = [
|
|
10
|
+
{
|
|
11
|
+
type: "pcb_board",
|
|
12
|
+
pcb_board_id: "board1",
|
|
13
|
+
center: { x: 10, y: 5 },
|
|
14
|
+
width: 25,
|
|
15
|
+
height: 15,
|
|
16
|
+
thickness: 1.6,
|
|
17
|
+
num_layers: 2,
|
|
18
|
+
material: "fr4",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
type: "pcb_fabrication_note_dimension",
|
|
22
|
+
pcb_fabrication_note_dimension_id: "fab_dim_1",
|
|
23
|
+
from: { x: 2, y: 5 },
|
|
24
|
+
to: { x: 18, y: 5 },
|
|
25
|
+
arrow_size: 0.4,
|
|
26
|
+
font_size: 0.6,
|
|
27
|
+
text: "16mm",
|
|
28
|
+
layer: "top",
|
|
29
|
+
pcb_component_id: "comp_1",
|
|
30
|
+
font: "tscircuit2024",
|
|
31
|
+
},
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
const stackedPng = await getStackedPngSvgComparison(circuitJson, {
|
|
35
|
+
width: 400,
|
|
36
|
+
height: 800,
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
await expect(stackedPng).toMatchPngSnapshot(import.meta.path)
|
|
40
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import type { AnyCircuitElement, PcbSilkscreenOval } from "circuit-json"
|
|
3
|
+
import { getStackedPngSvgComparison } from "../fixtures/getStackedPngSvgComparison"
|
|
4
|
+
|
|
5
|
+
test("draw silkscreen oval", async () => {
|
|
6
|
+
const oval: PcbSilkscreenOval = {
|
|
7
|
+
type: "pcb_silkscreen_oval",
|
|
8
|
+
layer: "top" as const,
|
|
9
|
+
pcb_component_id: "pcb_component_1",
|
|
10
|
+
pcb_silkscreen_oval_id: "oval_1",
|
|
11
|
+
center: { x: 0, y: 0 },
|
|
12
|
+
radius_x: 2,
|
|
13
|
+
radius_y: 1,
|
|
14
|
+
ccw_rotation: 45,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const circuitJson: AnyCircuitElement[] = [
|
|
18
|
+
{
|
|
19
|
+
type: "pcb_board",
|
|
20
|
+
pcb_board_id: "board1",
|
|
21
|
+
center: { x: 0, y: 0 },
|
|
22
|
+
width: 10,
|
|
23
|
+
height: 10,
|
|
24
|
+
thickness: 1.6,
|
|
25
|
+
num_layers: 2,
|
|
26
|
+
material: "fr4",
|
|
27
|
+
},
|
|
28
|
+
oval,
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
const stackedPng = await getStackedPngSvgComparison(circuitJson, {
|
|
32
|
+
width: 400,
|
|
33
|
+
height: 800,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
await expect(stackedPng).toMatchPngSnapshot(import.meta.path)
|
|
37
|
+
})
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { createCanvas } from "@napi-rs/canvas"
|
|
3
|
+
import { identity } from "transformation-matrix"
|
|
4
|
+
import { drawDimensionLine } from "../../lib/drawer/shapes/dimension-line"
|
|
5
|
+
|
|
6
|
+
test("drawDimensionLine shape", async () => {
|
|
7
|
+
const width = 400
|
|
8
|
+
const height = 200
|
|
9
|
+
const canvas = createCanvas(width, height)
|
|
10
|
+
const ctx = canvas.getContext("2d")
|
|
11
|
+
|
|
12
|
+
ctx.fillStyle = "#1a1a1a"
|
|
13
|
+
ctx.fillRect(0, 0, width, height)
|
|
14
|
+
|
|
15
|
+
// Basic horizontal dimension
|
|
16
|
+
drawDimensionLine({
|
|
17
|
+
ctx,
|
|
18
|
+
from: { x: 50, y: 50 },
|
|
19
|
+
to: { x: 350, y: 50 },
|
|
20
|
+
realToCanvasMat: identity(),
|
|
21
|
+
color: "white",
|
|
22
|
+
fontSize: 12,
|
|
23
|
+
arrowSize: 8,
|
|
24
|
+
text: "300mm",
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
// Vertical dimension with offset and extension lines
|
|
28
|
+
drawDimensionLine({
|
|
29
|
+
ctx,
|
|
30
|
+
from: { x: 50, y: 80 },
|
|
31
|
+
to: { x: 50, y: 180 },
|
|
32
|
+
realToCanvasMat: identity(),
|
|
33
|
+
color: "cyan",
|
|
34
|
+
fontSize: 10,
|
|
35
|
+
arrowSize: 6,
|
|
36
|
+
text: "100mm",
|
|
37
|
+
offset: {
|
|
38
|
+
distance: 30,
|
|
39
|
+
direction: { x: 1, y: 0 },
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
44
|
+
import.meta.path,
|
|
45
|
+
)
|
|
46
|
+
})
|
|
@@ -13,10 +13,11 @@ test("draw oval", async () => {
|
|
|
13
13
|
drawOval({
|
|
14
14
|
ctx,
|
|
15
15
|
center: { x: 50, y: 50 },
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
radius_x: 50,
|
|
17
|
+
radius_y: 25,
|
|
18
18
|
fill: "#0000ff",
|
|
19
19
|
realToCanvasMat: identity(),
|
|
20
|
+
rotation: 45,
|
|
20
21
|
})
|
|
21
22
|
|
|
22
23
|
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|