circuit-to-canvas 0.0.3 → 0.0.5

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.
Files changed (44) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.ts +82 -3
  3. package/dist/index.js +357 -4
  4. package/lib/drawer/CircuitToCanvasDrawer.ts +55 -0
  5. package/lib/drawer/elements/index.ts +25 -0
  6. package/lib/drawer/elements/pcb-copper-text.ts +99 -0
  7. package/lib/drawer/elements/pcb-fabrication-note-path.ts +41 -0
  8. package/lib/drawer/elements/pcb-fabrication-note-rect.ts +39 -0
  9. package/lib/drawer/elements/pcb-fabrication-note-text.ts +42 -0
  10. package/lib/drawer/elements/pcb-note-rect.ts +37 -0
  11. package/lib/drawer/shapes/index.ts +9 -0
  12. package/lib/drawer/shapes/rect.ts +28 -3
  13. package/lib/drawer/shapes/text.ts +218 -0
  14. package/lib/drawer/types.ts +8 -0
  15. package/package.json +3 -1
  16. package/tests/elements/__snapshots__/pcb-copper-text-knockout.snap.png +0 -0
  17. package/tests/elements/__snapshots__/pcb-copper-text.snap.png +0 -0
  18. package/tests/elements/__snapshots__/pcb-fabrication-note-path-custom-color.snap.png +0 -0
  19. package/tests/elements/__snapshots__/pcb-fabrication-note-path-thick-stroke.snap.png +0 -0
  20. package/tests/elements/__snapshots__/pcb-fabrication-note-path.snap.png +0 -0
  21. package/tests/elements/__snapshots__/pcb-fabrication-note-rect-all-features.snap.png +0 -0
  22. package/tests/elements/__snapshots__/pcb-fabrication-note-rect-corner-radius.snap.png +0 -0
  23. package/tests/elements/__snapshots__/pcb-fabrication-note-rect-custom-color.snap.png +0 -0
  24. package/tests/elements/__snapshots__/pcb-fabrication-note-rect-dashed.snap.png +0 -0
  25. package/tests/elements/__snapshots__/pcb-fabrication-note-rect-default-color.snap.png +0 -0
  26. package/tests/elements/__snapshots__/pcb-fabrication-note-text-rgba-color.snap.png +0 -0
  27. package/tests/elements/__snapshots__/pcb-fabrication-note-text-small.snap.png +0 -0
  28. package/tests/elements/__snapshots__/pcb-note-rect-all-features.snap.png +0 -0
  29. package/tests/elements/__snapshots__/pcb-note-rect-dashed-stroke.snap.png +0 -0
  30. package/tests/elements/__snapshots__/pcb-note-rect-filled-no-stroke.snap.png +0 -0
  31. package/tests/elements/pcb-copper-text.test.ts +102 -0
  32. package/tests/elements/pcb-fabrication-note-path-custom-color.test.ts +37 -0
  33. package/tests/elements/pcb-fabrication-note-path-thick-stroke.test.ts +37 -0
  34. package/tests/elements/pcb-fabrication-note-path.test.ts +36 -0
  35. package/tests/elements/pcb-fabrication-note-rect-all-features.test.ts +35 -0
  36. package/tests/elements/pcb-fabrication-note-rect-corner-radius.test.ts +33 -0
  37. package/tests/elements/pcb-fabrication-note-rect-custom-color.test.ts +32 -0
  38. package/tests/elements/pcb-fabrication-note-rect-dashed.test.ts +33 -0
  39. package/tests/elements/pcb-fabrication-note-rect-default-color.test.ts +32 -0
  40. package/tests/elements/pcb-fabrication-note-text-rgba-color.test.ts +34 -0
  41. package/tests/elements/pcb-fabrication-note-text-small.test.ts +33 -0
  42. package/tests/elements/pcb-note-rect-all-features.test.ts +38 -0
  43. package/tests/elements/pcb-note-rect-dashed-stroke.test.ts +32 -0
  44. package/tests/elements/pcb-note-rect-filled-no-stroke.test.ts +32 -0
@@ -0,0 +1,102 @@
1
+ import { expect, test } from "bun:test"
2
+ import { createCanvas } from "canvas"
3
+ import type { PcbCopperText } from "circuit-json"
4
+ import { scale } from "transformation-matrix"
5
+ import { CircuitToCanvasDrawer } from "../../lib/drawer"
6
+
7
+ test("draw copper text", async () => {
8
+ const SCALE = 4
9
+ const canvas = createCanvas(100 * SCALE, 100 * SCALE)
10
+ const ctx = canvas.getContext("2d")
11
+ ctx.scale(SCALE, SCALE)
12
+ const drawer = new CircuitToCanvasDrawer(ctx)
13
+
14
+ ctx.fillStyle = "#1a1a1a"
15
+ ctx.fillRect(0, 0, canvas.width / SCALE, canvas.height / SCALE)
16
+
17
+ const text: PcbCopperText[] = [
18
+ {
19
+ type: "pcb_copper_text",
20
+ pcb_copper_text_id: "copper-text-1",
21
+ pcb_component_id: "component1",
22
+ layer: "top",
23
+ text: "T1",
24
+ anchor_position: { x: 40, y: 40 },
25
+ anchor_alignment: "center",
26
+ font: "tscircuit2024",
27
+ font_size: 8,
28
+ },
29
+
30
+ {
31
+ type: "pcb_copper_text",
32
+ pcb_copper_text_id: "copper-text-2",
33
+ pcb_component_id: "component1",
34
+ layer: "bottom",
35
+ text: "T2",
36
+ anchor_position: { x: 60, y: 60 },
37
+ anchor_alignment: "center",
38
+ font: "tscircuit2024",
39
+ font_size: 6,
40
+ is_mirrored: true,
41
+ ccw_rotation: 90,
42
+ },
43
+ ]
44
+
45
+ drawer.drawElements(text)
46
+
47
+ await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
48
+ import.meta.path,
49
+ "pcb-copper-text",
50
+ )
51
+ })
52
+
53
+ test("draw copper text knockout mirrored with padding", async () => {
54
+ const SCALE = 4
55
+ const canvas = createCanvas(100 * SCALE, 60 * SCALE)
56
+ const ctx = canvas.getContext("2d")
57
+ ctx.scale(SCALE, SCALE)
58
+ const drawer = new CircuitToCanvasDrawer(ctx)
59
+
60
+ ctx.fillStyle = "#1a1a1a"
61
+ ctx.fillRect(0, 0, canvas.width / SCALE, canvas.height / SCALE)
62
+
63
+ drawer.realToCanvasMat = scale(2, 2)
64
+
65
+ const text: PcbCopperText[] = [
66
+ {
67
+ type: "pcb_copper_text",
68
+ pcb_copper_text_id: "copper-text-2",
69
+ pcb_component_id: "component1",
70
+ layer: "bottom",
71
+ text: "KO1",
72
+ anchor_position: { x: 25, y: 15 },
73
+ anchor_alignment: "center",
74
+ font: "tscircuit2024",
75
+ font_size: 10,
76
+ is_knockout: true,
77
+ is_mirrored: true,
78
+ },
79
+
80
+ {
81
+ type: "pcb_copper_text",
82
+ pcb_copper_text_id: "copper-text-3",
83
+ pcb_component_id: "component1",
84
+ layer: "top",
85
+ text: "KO2",
86
+ anchor_position: { x: 40, y: 20 },
87
+ anchor_alignment: "center",
88
+ font: "tscircuit2024",
89
+ font_size: 8,
90
+ is_knockout: true,
91
+ is_mirrored: false,
92
+ ccw_rotation: 45,
93
+ },
94
+ ]
95
+
96
+ drawer.drawElements(text)
97
+
98
+ await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
99
+ import.meta.path,
100
+ "pcb-copper-text-knockout",
101
+ )
102
+ })
@@ -0,0 +1,37 @@
1
+ import { expect, test } from "bun:test"
2
+ import { createCanvas } from "canvas"
3
+ import type { PcbFabricationNotePath } from "circuit-json"
4
+ import { CircuitToCanvasDrawer } from "../../lib/drawer"
5
+
6
+ test("draw fabrication note path with custom color", async () => {
7
+ const canvas = createCanvas(100, 100)
8
+ const ctx = canvas.getContext("2d")
9
+ const drawer = new CircuitToCanvasDrawer(ctx)
10
+
11
+ ctx.fillStyle = "#1a1a1a"
12
+ ctx.fillRect(0, 0, 100, 100)
13
+
14
+ const path: PcbFabricationNotePath = {
15
+ type: "pcb_fabrication_note_path",
16
+ pcb_fabrication_note_path_id: "path1",
17
+ pcb_component_id: "component1",
18
+ layer: "top",
19
+ route: [
20
+ { x: 10, y: 50 },
21
+ { x: 30, y: 20 },
22
+ { x: 70, y: 20 },
23
+ { x: 90, y: 50 },
24
+ { x: 70, y: 80 },
25
+ { x: 30, y: 80 },
26
+ { x: 10, y: 50 },
27
+ ],
28
+ stroke_width: 2,
29
+ color: "#FF0000", // Red color
30
+ }
31
+
32
+ drawer.drawElements([path])
33
+
34
+ await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
35
+ import.meta.path,
36
+ )
37
+ })
@@ -0,0 +1,37 @@
1
+ import { expect, test } from "bun:test"
2
+ import { createCanvas } from "canvas"
3
+ import type { PcbFabricationNotePath } from "circuit-json"
4
+ import { CircuitToCanvasDrawer } from "../../lib/drawer"
5
+
6
+ test("draw fabrication note path with thick stroke", async () => {
7
+ const canvas = createCanvas(100, 100)
8
+ const ctx = canvas.getContext("2d")
9
+ const drawer = new CircuitToCanvasDrawer(ctx)
10
+
11
+ ctx.fillStyle = "#1a1a1a"
12
+ ctx.fillRect(0, 0, 100, 100)
13
+
14
+ const path: PcbFabricationNotePath = {
15
+ type: "pcb_fabrication_note_path",
16
+ pcb_fabrication_note_path_id: "path1",
17
+ pcb_component_id: "component1",
18
+ layer: "top",
19
+ route: [
20
+ { x: 10, y: 50 },
21
+ { x: 30, y: 20 },
22
+ { x: 70, y: 20 },
23
+ { x: 90, y: 50 },
24
+ { x: 70, y: 80 },
25
+ { x: 30, y: 80 },
26
+ { x: 10, y: 50 },
27
+ ],
28
+ stroke_width: 5, // Thick stroke
29
+ color: "#00FFFF", // Cyan color
30
+ }
31
+
32
+ drawer.drawElements([path])
33
+
34
+ await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
35
+ import.meta.path,
36
+ )
37
+ })
@@ -0,0 +1,36 @@
1
+ import { expect, test } from "bun:test"
2
+ import { createCanvas } from "canvas"
3
+ import type { PcbFabricationNotePath } from "circuit-json"
4
+ import { CircuitToCanvasDrawer } from "../../lib/drawer"
5
+
6
+ test("draw fabrication note path", async () => {
7
+ const canvas = createCanvas(100, 100)
8
+ const ctx = canvas.getContext("2d")
9
+ const drawer = new CircuitToCanvasDrawer(ctx)
10
+
11
+ ctx.fillStyle = "#1a1a1a"
12
+ ctx.fillRect(0, 0, 100, 100)
13
+
14
+ const path: PcbFabricationNotePath = {
15
+ type: "pcb_fabrication_note_path",
16
+ pcb_fabrication_note_path_id: "path1",
17
+ pcb_component_id: "component1",
18
+ layer: "top",
19
+ route: [
20
+ { x: 10, y: 50 },
21
+ { x: 30, y: 20 },
22
+ { x: 70, y: 20 },
23
+ { x: 90, y: 50 },
24
+ { x: 70, y: 80 },
25
+ { x: 30, y: 80 },
26
+ { x: 10, y: 50 },
27
+ ],
28
+ stroke_width: 2,
29
+ }
30
+
31
+ drawer.drawElements([path])
32
+
33
+ await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
34
+ import.meta.path,
35
+ )
36
+ })
@@ -0,0 +1,35 @@
1
+ import { expect, test } from "bun:test"
2
+ import { createCanvas } from "canvas"
3
+ import type { PcbFabricationNoteRect } from "circuit-json"
4
+ import { CircuitToCanvasDrawer } from "../../lib/drawer"
5
+
6
+ test("draw fabrication note rect with all features", async () => {
7
+ const canvas = createCanvas(100, 100)
8
+ const ctx = canvas.getContext("2d")
9
+ const drawer = new CircuitToCanvasDrawer(ctx)
10
+
11
+ ctx.fillStyle = "#1a1a1a"
12
+ ctx.fillRect(0, 0, 100, 100)
13
+
14
+ const rect: PcbFabricationNoteRect = {
15
+ type: "pcb_fabrication_note_rect",
16
+ pcb_fabrication_note_rect_id: "rect7",
17
+ pcb_component_id: "component1",
18
+ center: { x: 50, y: 50 },
19
+ width: 60,
20
+ height: 40,
21
+ layer: "top",
22
+ stroke_width: 2,
23
+ color: "#00FFFF", // Cyan color
24
+ corner_radius: 5,
25
+ is_filled: true,
26
+ has_stroke: true,
27
+ is_stroke_dashed: true,
28
+ }
29
+
30
+ drawer.drawElements([rect])
31
+
32
+ await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
33
+ import.meta.path,
34
+ )
35
+ })
@@ -0,0 +1,33 @@
1
+ import { expect, test } from "bun:test"
2
+ import { createCanvas } from "canvas"
3
+ import type { PcbFabricationNoteRect } from "circuit-json"
4
+ import { CircuitToCanvasDrawer } from "../../lib/drawer"
5
+
6
+ test("draw fabrication note rect with corner radius", async () => {
7
+ const canvas = createCanvas(100, 100)
8
+ const ctx = canvas.getContext("2d")
9
+ const drawer = new CircuitToCanvasDrawer(ctx)
10
+
11
+ ctx.fillStyle = "#1a1a1a"
12
+ ctx.fillRect(0, 0, 100, 100)
13
+
14
+ const rect: PcbFabricationNoteRect = {
15
+ type: "pcb_fabrication_note_rect",
16
+ pcb_fabrication_note_rect_id: "rect5",
17
+ pcb_component_id: "component1",
18
+ center: { x: 50, y: 50 },
19
+ width: 60,
20
+ height: 40,
21
+ layer: "top",
22
+ stroke_width: 2,
23
+ color: "#FFFF00", // Yellow color
24
+ corner_radius: 5,
25
+ has_stroke: true,
26
+ }
27
+
28
+ drawer.drawElements([rect])
29
+
30
+ await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
31
+ import.meta.path,
32
+ )
33
+ })
@@ -0,0 +1,32 @@
1
+ import { expect, test } from "bun:test"
2
+ import { createCanvas } from "canvas"
3
+ import type { PcbFabricationNoteRect } from "circuit-json"
4
+ import { CircuitToCanvasDrawer } from "../../lib/drawer"
5
+
6
+ test("draw fabrication note rect with custom color", async () => {
7
+ const canvas = createCanvas(100, 100)
8
+ const ctx = canvas.getContext("2d")
9
+ const drawer = new CircuitToCanvasDrawer(ctx)
10
+
11
+ ctx.fillStyle = "#1a1a1a"
12
+ ctx.fillRect(0, 0, 100, 100)
13
+
14
+ const rect: PcbFabricationNoteRect = {
15
+ type: "pcb_fabrication_note_rect",
16
+ pcb_fabrication_note_rect_id: "rect1",
17
+ pcb_component_id: "component1",
18
+ center: { x: 50, y: 50 },
19
+ width: 60,
20
+ height: 40,
21
+ layer: "top",
22
+ stroke_width: 2,
23
+ color: "#FF0000", // Red color
24
+ has_stroke: true,
25
+ }
26
+
27
+ drawer.drawElements([rect])
28
+
29
+ await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
30
+ import.meta.path,
31
+ )
32
+ })
@@ -0,0 +1,33 @@
1
+ import { expect, test } from "bun:test"
2
+ import { createCanvas } from "canvas"
3
+ import type { PcbFabricationNoteRect } from "circuit-json"
4
+ import { CircuitToCanvasDrawer } from "../../lib/drawer"
5
+
6
+ test("draw fabrication note rect with dashed stroke", async () => {
7
+ const canvas = createCanvas(100, 100)
8
+ const ctx = canvas.getContext("2d")
9
+ const drawer = new CircuitToCanvasDrawer(ctx)
10
+
11
+ ctx.fillStyle = "#1a1a1a"
12
+ ctx.fillRect(0, 0, 100, 100)
13
+
14
+ const rect: PcbFabricationNoteRect = {
15
+ type: "pcb_fabrication_note_rect",
16
+ pcb_fabrication_note_rect_id: "rect4",
17
+ pcb_component_id: "component1",
18
+ center: { x: 50, y: 50 },
19
+ width: 60,
20
+ height: 40,
21
+ layer: "top",
22
+ stroke_width: 2,
23
+ color: "#0000FF", // Blue color
24
+ has_stroke: true,
25
+ is_stroke_dashed: true,
26
+ }
27
+
28
+ drawer.drawElements([rect])
29
+
30
+ await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
31
+ import.meta.path,
32
+ )
33
+ })
@@ -0,0 +1,32 @@
1
+ import { expect, test } from "bun:test"
2
+ import { createCanvas } from "canvas"
3
+ import type { PcbFabricationNoteRect } from "circuit-json"
4
+ import { CircuitToCanvasDrawer } from "../../lib/drawer"
5
+
6
+ test("draw fabrication note rect with default color", async () => {
7
+ const canvas = createCanvas(100, 100)
8
+ const ctx = canvas.getContext("2d")
9
+ const drawer = new CircuitToCanvasDrawer(ctx)
10
+
11
+ ctx.fillStyle = "#1a1a1a"
12
+ ctx.fillRect(0, 0, 100, 100)
13
+
14
+ const rect: PcbFabricationNoteRect = {
15
+ type: "pcb_fabrication_note_rect",
16
+ pcb_fabrication_note_rect_id: "rect2",
17
+ pcb_component_id: "component1",
18
+ center: { x: 50, y: 50 },
19
+ width: 60,
20
+ height: 40,
21
+ layer: "top",
22
+ stroke_width: 2,
23
+ // No color specified - should use default
24
+ has_stroke: true,
25
+ }
26
+
27
+ drawer.drawElements([rect])
28
+
29
+ await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
30
+ import.meta.path,
31
+ )
32
+ })
@@ -0,0 +1,34 @@
1
+ import { expect, test } from "bun:test"
2
+ import { createCanvas } from "canvas"
3
+ import type { PcbFabricationNoteText } from "circuit-json"
4
+ import { CircuitToCanvasDrawer } from "../../lib/drawer"
5
+
6
+ test("draw fabrication note text with rgba color", async () => {
7
+ const SCALE = 4
8
+ const canvas = createCanvas(100 * SCALE, 100 * SCALE)
9
+ const ctx = canvas.getContext("2d")
10
+ ctx.scale(SCALE, SCALE)
11
+ const drawer = new CircuitToCanvasDrawer(ctx)
12
+
13
+ ctx.fillStyle = "#1a1a1a"
14
+ ctx.fillRect(0, 0, canvas.width / SCALE, canvas.height / SCALE)
15
+
16
+ const text: PcbFabricationNoteText = {
17
+ type: "pcb_fabrication_note_text",
18
+ pcb_fabrication_note_text_id: "fab-note-rgba",
19
+ pcb_component_id: "component1",
20
+ layer: "top",
21
+ text: "RGBA",
22
+ anchor_position: { x: 50, y: 50 },
23
+ anchor_alignment: "center",
24
+ font: "tscircuit2024",
25
+ font_size: 8,
26
+ color: "rgba(255, 0, 255, 0.8)",
27
+ }
28
+
29
+ drawer.drawElements([text])
30
+
31
+ await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
32
+ import.meta.path,
33
+ )
34
+ })
@@ -0,0 +1,33 @@
1
+ import { expect, test } from "bun:test"
2
+ import { createCanvas } from "canvas"
3
+ import type { PcbFabricationNoteText } from "circuit-json"
4
+ import { CircuitToCanvasDrawer } from "../../lib/drawer"
5
+
6
+ test("draw fabrication note text small size", async () => {
7
+ const SCALE = 4
8
+ const canvas = createCanvas(100 * SCALE, 100 * SCALE)
9
+ const ctx = canvas.getContext("2d")
10
+ ctx.scale(SCALE, SCALE)
11
+ const drawer = new CircuitToCanvasDrawer(ctx)
12
+
13
+ ctx.fillStyle = "#1a1a1a"
14
+ ctx.fillRect(0, 0, canvas.width / SCALE, canvas.height / SCALE)
15
+
16
+ const text: PcbFabricationNoteText = {
17
+ type: "pcb_fabrication_note_text",
18
+ pcb_fabrication_note_text_id: "fab-note-small",
19
+ pcb_component_id: "component1",
20
+ layer: "top",
21
+ text: "SMAL",
22
+ anchor_position: { x: 50, y: 50 },
23
+ anchor_alignment: "center",
24
+ font: "tscircuit2024",
25
+ font_size: 16,
26
+ }
27
+
28
+ drawer.drawElements([text])
29
+
30
+ await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
31
+ import.meta.path,
32
+ )
33
+ })
@@ -0,0 +1,38 @@
1
+ import { expect, test } from "bun:test"
2
+ import { createCanvas } from "canvas"
3
+ import type { PcbNoteRect } from "circuit-json"
4
+ import { CircuitToCanvasDrawer } from "../../lib/drawer"
5
+
6
+ test("draw pcb note rect with all features", async () => {
7
+ const canvas = createCanvas(100, 100)
8
+ const ctx = canvas.getContext("2d")
9
+ const drawer = new CircuitToCanvasDrawer(ctx)
10
+
11
+ ctx.fillStyle = "#1a1a1a"
12
+ ctx.fillRect(0, 0, 100, 100)
13
+
14
+ const rect: PcbNoteRect = {
15
+ type: "pcb_note_rect",
16
+ pcb_note_rect_id: "note_rect1",
17
+ pcb_component_id: "component1",
18
+ pcb_group_id: "group1",
19
+ subcircuit_id: "subcircuit1",
20
+ name: "Test Note",
21
+ text: "This is a test note",
22
+ center: { x: 50, y: 50 },
23
+ width: 60,
24
+ height: 40,
25
+ stroke_width: 2,
26
+ corner_radius: 5,
27
+ is_filled: true,
28
+ has_stroke: true,
29
+ is_stroke_dashed: true,
30
+ color: "#00FFFF", // Cyan color
31
+ }
32
+
33
+ drawer.drawElements([rect])
34
+
35
+ await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
36
+ import.meta.path,
37
+ )
38
+ })
@@ -0,0 +1,32 @@
1
+ import { expect, test } from "bun:test"
2
+ import { createCanvas } from "canvas"
3
+ import type { PcbNoteRect } from "circuit-json"
4
+ import { CircuitToCanvasDrawer } from "../../lib/drawer"
5
+
6
+ test("draw pcb note rect with dashed stroke and no fill", async () => {
7
+ const canvas = createCanvas(100, 100)
8
+ const ctx = canvas.getContext("2d")
9
+ const drawer = new CircuitToCanvasDrawer(ctx)
10
+
11
+ ctx.fillStyle = "#1a1a1a"
12
+ ctx.fillRect(0, 0, 100, 100)
13
+
14
+ const rect: PcbNoteRect = {
15
+ type: "pcb_note_rect",
16
+ pcb_note_rect_id: "note_rect2",
17
+ center: { x: 50, y: 50 },
18
+ width: 60,
19
+ height: 40,
20
+ stroke_width: 2,
21
+ is_filled: false,
22
+ has_stroke: true,
23
+ is_stroke_dashed: true,
24
+ color: "#0000FF", // Blue color
25
+ }
26
+
27
+ drawer.drawElements([rect])
28
+
29
+ await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
30
+ import.meta.path,
31
+ )
32
+ })
@@ -0,0 +1,32 @@
1
+ import { expect, test } from "bun:test"
2
+ import { createCanvas } from "canvas"
3
+ import type { PcbNoteRect } from "circuit-json"
4
+ import { CircuitToCanvasDrawer } from "../../lib/drawer"
5
+
6
+ test("draw pcb note rect with fill and no stroke", async () => {
7
+ const canvas = createCanvas(100, 100)
8
+ const ctx = canvas.getContext("2d")
9
+ const drawer = new CircuitToCanvasDrawer(ctx)
10
+
11
+ ctx.fillStyle = "#1a1a1a"
12
+ ctx.fillRect(0, 0, 100, 100)
13
+
14
+ const rect: PcbNoteRect = {
15
+ type: "pcb_note_rect",
16
+ pcb_note_rect_id: "note_rect3",
17
+ center: { x: 50, y: 50 },
18
+ width: 60,
19
+ height: 40,
20
+ stroke_width: 2,
21
+ corner_radius: 8,
22
+ is_filled: true,
23
+ has_stroke: false,
24
+ is_stroke_dashed: false,
25
+ }
26
+
27
+ drawer.drawElements([rect])
28
+
29
+ await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
30
+ import.meta.path,
31
+ )
32
+ })