circuit-to-canvas 0.0.13 → 0.0.15

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 (40) hide show
  1. package/dist/index.d.ts +29 -29
  2. package/dist/index.js +187 -133
  3. package/lib/drawer/CircuitToCanvasDrawer.ts +31 -20
  4. package/lib/drawer/elements/pcb-board.ts +5 -5
  5. package/lib/drawer/elements/pcb-copper-pour.ts +13 -10
  6. package/lib/drawer/elements/pcb-copper-text.ts +4 -4
  7. package/lib/drawer/elements/pcb-cutout.ts +5 -5
  8. package/lib/drawer/elements/pcb-fabrication-note-path.ts +3 -3
  9. package/lib/drawer/elements/pcb-fabrication-note-rect.ts +3 -3
  10. package/lib/drawer/elements/pcb-fabrication-note-text.ts +4 -4
  11. package/lib/drawer/elements/pcb-hole.ts +8 -8
  12. package/lib/drawer/elements/pcb-note-line.ts +46 -0
  13. package/lib/drawer/elements/pcb-note-path.ts +3 -3
  14. package/lib/drawer/elements/pcb-note-rect.ts +3 -3
  15. package/lib/drawer/elements/pcb-note-text.ts +4 -4
  16. package/lib/drawer/elements/pcb-plated-hole.ts +14 -14
  17. package/lib/drawer/elements/pcb-silkscreen.ts +16 -16
  18. package/lib/drawer/elements/pcb-smtpad.ts +8 -8
  19. package/lib/drawer/elements/pcb-trace.ts +3 -3
  20. package/lib/drawer/elements/pcb-via.ts +4 -4
  21. package/lib/drawer/shapes/circle.ts +4 -4
  22. package/lib/drawer/shapes/line.ts +5 -5
  23. package/lib/drawer/shapes/oval.ts +13 -5
  24. package/lib/drawer/shapes/path.ts +8 -8
  25. package/lib/drawer/shapes/pill.ts +13 -5
  26. package/lib/drawer/shapes/polygon.ts +7 -7
  27. package/lib/drawer/shapes/rect.ts +7 -7
  28. package/lib/drawer/shapes/text.ts +5 -5
  29. package/lib/drawer/types.ts +1 -1
  30. package/package.json +1 -1
  31. package/tests/elements/__snapshots__/pcb-note-line-all-features.snap.png +0 -0
  32. package/tests/elements/__snapshots__/pcb-note-line-custom-color.snap.png +0 -0
  33. package/tests/elements/__snapshots__/pcb-note-line-dashed.snap.png +0 -0
  34. package/tests/elements/pcb-note-line-all-features.test.ts +36 -0
  35. package/tests/elements/pcb-note-line-custom-color.test.ts +30 -0
  36. package/tests/elements/pcb-note-line-dashed.test.ts +30 -0
  37. package/tests/shapes/circle.test.ts +1 -1
  38. package/tests/shapes/oval.test.ts +1 -1
  39. package/tests/shapes/pill.test.ts +2 -2
  40. package/tests/shapes/rect.test.ts +2 -2
@@ -0,0 +1,36 @@
1
+ import { expect, test } from "bun:test"
2
+ import { createCanvas } from "@napi-rs/canvas"
3
+ import type { PcbNoteLine } from "circuit-json"
4
+ import { CircuitToCanvasDrawer } from "../../lib/drawer"
5
+
6
+ test("draw pcb note line 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 line: PcbNoteLine = {
15
+ type: "pcb_note_line",
16
+ pcb_note_line_id: "note_line1",
17
+ pcb_component_id: "component1",
18
+ pcb_group_id: "group1",
19
+ subcircuit_id: "subcircuit1",
20
+ name: "Test Note Line",
21
+ text: "This is a test note line",
22
+ x1: 10,
23
+ y1: 10,
24
+ x2: 90,
25
+ y2: 90,
26
+ stroke_width: 2,
27
+ color: "#00FFFF", // Cyan color
28
+ is_dashed: true,
29
+ }
30
+
31
+ drawer.drawElements([line])
32
+
33
+ await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
34
+ import.meta.path,
35
+ )
36
+ })
@@ -0,0 +1,30 @@
1
+ import { expect, test } from "bun:test"
2
+ import { createCanvas } from "@napi-rs/canvas"
3
+ import type { PcbNoteLine } from "circuit-json"
4
+ import { CircuitToCanvasDrawer } from "../../lib/drawer"
5
+
6
+ test("draw pcb note line 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 line: PcbNoteLine = {
15
+ type: "pcb_note_line",
16
+ pcb_note_line_id: "note_line_custom_color",
17
+ x1: 10,
18
+ y1: 10,
19
+ x2: 90,
20
+ y2: 90,
21
+ stroke_width: 2,
22
+ color: "rgba(255, 0, 255, 0.8)", // Magenta with transparency
23
+ }
24
+
25
+ drawer.drawElements([line])
26
+
27
+ await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
28
+ import.meta.path,
29
+ )
30
+ })
@@ -0,0 +1,30 @@
1
+ import { expect, test } from "bun:test"
2
+ import { createCanvas } from "@napi-rs/canvas"
3
+ import type { PcbNoteLine } from "circuit-json"
4
+ import { CircuitToCanvasDrawer } from "../../lib/drawer"
5
+
6
+ test("draw pcb note line 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 line: PcbNoteLine = {
15
+ type: "pcb_note_line",
16
+ pcb_note_line_id: "note_line_dashed",
17
+ x1: 10,
18
+ y1: 50,
19
+ x2: 90,
20
+ y2: 50,
21
+ stroke_width: 2,
22
+ is_dashed: true,
23
+ }
24
+
25
+ drawer.drawElements([line])
26
+
27
+ await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
28
+ import.meta.path,
29
+ )
30
+ })
@@ -15,7 +15,7 @@ test("draw circle", async () => {
15
15
  center: { x: 50, y: 50 },
16
16
  radius: 30,
17
17
  fill: "#ff0000",
18
- transform: identity(),
18
+ realToCanvasMat: identity(),
19
19
  })
20
20
 
21
21
  await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
@@ -16,7 +16,7 @@ test("draw oval", async () => {
16
16
  width: 70,
17
17
  height: 40,
18
18
  fill: "#0000ff",
19
- transform: identity(),
19
+ realToCanvasMat: identity(),
20
20
  })
21
21
 
22
22
  await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
@@ -16,7 +16,7 @@ test("draw horizontal pill", async () => {
16
16
  width: 70,
17
17
  height: 30,
18
18
  fill: "#ff00ff",
19
- transform: identity(),
19
+ realToCanvasMat: identity(),
20
20
  })
21
21
 
22
22
  await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
@@ -37,7 +37,7 @@ test("draw vertical pill", async () => {
37
37
  width: 30,
38
38
  height: 70,
39
39
  fill: "#ff00ff",
40
- transform: identity(),
40
+ realToCanvasMat: identity(),
41
41
  })
42
42
 
43
43
  await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
@@ -16,7 +16,7 @@ test("draw rect", async () => {
16
16
  width: 60,
17
17
  height: 40,
18
18
  fill: "#00ff00",
19
- transform: identity(),
19
+ realToCanvasMat: identity(),
20
20
  })
21
21
 
22
22
  await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
@@ -37,7 +37,7 @@ test("draw rect with border radius", async () => {
37
37
  width: 60,
38
38
  height: 40,
39
39
  fill: "#00ff00",
40
- transform: identity(),
40
+ realToCanvasMat: identity(),
41
41
  borderRadius: 10,
42
42
  })
43
43