circuit-to-canvas 0.0.12 → 0.0.14
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.js +35 -0
- package/lib/drawer/CircuitToCanvasDrawer.ts +11 -0
- package/lib/drawer/elements/pcb-note-line.ts +46 -0
- package/package.json +2 -2
- package/tests/elements/__snapshots__/fabrication-note-text-descenders.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-copper-text-knockout.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-fabrication-note-rect-dashed.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-note-line-all-features.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-note-line-custom-color.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-note-line-dashed.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-note-rect-dashed-stroke.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-silkscreen.snap.png +0 -0
- package/tests/elements/__snapshots__/silkscreen-text-bottom.snap.png +0 -0
- package/tests/elements/pcb-board.test.ts +1 -1
- package/tests/elements/pcb-copper-pour.test.ts +1 -1
- package/tests/elements/pcb-copper-text.test.ts +1 -1
- package/tests/elements/pcb-cutout.test.ts +1 -1
- package/tests/elements/pcb-fabrication-note-path-custom-color.test.ts +1 -1
- package/tests/elements/pcb-fabrication-note-path-thick-stroke.test.ts +1 -1
- package/tests/elements/pcb-fabrication-note-path.test.ts +1 -1
- package/tests/elements/pcb-fabrication-note-rect-all-features.test.ts +1 -1
- package/tests/elements/pcb-fabrication-note-rect-corner-radius.test.ts +1 -1
- package/tests/elements/pcb-fabrication-note-rect-custom-color.test.ts +1 -1
- package/tests/elements/pcb-fabrication-note-rect-dashed.test.ts +1 -1
- package/tests/elements/pcb-fabrication-note-rect-default-color.test.ts +1 -1
- package/tests/elements/pcb-fabrication-note-text-descenders.test.ts +1 -1
- package/tests/elements/pcb-fabrication-note-text-full-charset.test.ts +1 -1
- package/tests/elements/pcb-fabrication-note-text-rgba-color.test.ts +1 -1
- package/tests/elements/pcb-fabrication-note-text-small.test.ts +1 -1
- package/tests/elements/pcb-hole.test.ts +1 -1
- package/tests/elements/pcb-note-line-all-features.test.ts +36 -0
- package/tests/elements/pcb-note-line-custom-color.test.ts +30 -0
- package/tests/elements/pcb-note-line-dashed.test.ts +30 -0
- package/tests/elements/pcb-note-path.test.ts +1 -1
- package/tests/elements/pcb-note-rect-all-features.test.ts +1 -1
- package/tests/elements/pcb-note-rect-dashed-stroke.test.ts +1 -1
- package/tests/elements/pcb-note-rect-filled-no-stroke.test.ts +1 -1
- package/tests/elements/pcb-note-text-anchor-alignment.test.ts +1 -1
- package/tests/elements/pcb-note-text-custom-color.test.ts +1 -1
- package/tests/elements/pcb-note-text-small.test.ts +1 -1
- package/tests/elements/pcb-plated-hole.test.ts +1 -1
- package/tests/elements/pcb-silkscreen.test.ts +1 -1
- package/tests/elements/pcb-smtpad.test.ts +1 -1
- package/tests/elements/pcb-trace.test.ts +1 -1
- package/tests/elements/pcb-via.test.ts +1 -1
- package/tests/shapes/circle.test.ts +1 -1
- package/tests/shapes/oval.test.ts +1 -1
- package/tests/shapes/pill.test.ts +1 -1
- package/tests/shapes/rect.test.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -1119,6 +1119,33 @@ function drawPcbNoteText(params) {
|
|
|
1119
1119
|
});
|
|
1120
1120
|
}
|
|
1121
1121
|
|
|
1122
|
+
// lib/drawer/elements/pcb-note-line.ts
|
|
1123
|
+
import { applyToPoint as applyToPoint12 } from "transformation-matrix";
|
|
1124
|
+
function drawPcbNoteLine(params) {
|
|
1125
|
+
const { ctx, line, transform, colorMap } = params;
|
|
1126
|
+
const defaultColor = "rgb(89, 148, 220)";
|
|
1127
|
+
const color = line.color ?? defaultColor;
|
|
1128
|
+
const strokeWidth = line.stroke_width ?? 0.1;
|
|
1129
|
+
const isDashed = line.is_dashed ?? false;
|
|
1130
|
+
const [x1, y1] = applyToPoint12(transform, [line.x1, line.y1]);
|
|
1131
|
+
const [x2, y2] = applyToPoint12(transform, [line.x2, line.y2]);
|
|
1132
|
+
const scaledStrokeWidth = strokeWidth * Math.abs(transform.a);
|
|
1133
|
+
ctx.save();
|
|
1134
|
+
if (isDashed) {
|
|
1135
|
+
ctx.setLineDash([scaledStrokeWidth * 2, scaledStrokeWidth * 2]);
|
|
1136
|
+
} else {
|
|
1137
|
+
ctx.setLineDash([]);
|
|
1138
|
+
}
|
|
1139
|
+
ctx.beginPath();
|
|
1140
|
+
ctx.moveTo(x1, y1);
|
|
1141
|
+
ctx.lineTo(x2, y2);
|
|
1142
|
+
ctx.lineWidth = scaledStrokeWidth;
|
|
1143
|
+
ctx.strokeStyle = color;
|
|
1144
|
+
ctx.lineCap = "round";
|
|
1145
|
+
ctx.stroke();
|
|
1146
|
+
ctx.restore();
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1122
1149
|
// lib/drawer/CircuitToCanvasDrawer.ts
|
|
1123
1150
|
var CircuitToCanvasDrawer = class {
|
|
1124
1151
|
ctx;
|
|
@@ -1348,6 +1375,14 @@ var CircuitToCanvasDrawer = class {
|
|
|
1348
1375
|
colorMap: this.colorMap
|
|
1349
1376
|
});
|
|
1350
1377
|
}
|
|
1378
|
+
if (element.type === "pcb_note_line") {
|
|
1379
|
+
drawPcbNoteLine({
|
|
1380
|
+
ctx: this.ctx,
|
|
1381
|
+
line: element,
|
|
1382
|
+
transform: this.realToCanvasMat,
|
|
1383
|
+
colorMap: this.colorMap
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1351
1386
|
}
|
|
1352
1387
|
};
|
|
1353
1388
|
export {
|
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
PcbFabricationNotePath,
|
|
21
21
|
PcbNotePath,
|
|
22
22
|
PcbNoteText,
|
|
23
|
+
PcbNoteLine,
|
|
23
24
|
} from "circuit-json"
|
|
24
25
|
import { identity, compose, translate, scale } from "transformation-matrix"
|
|
25
26
|
import type { Matrix } from "transformation-matrix"
|
|
@@ -52,6 +53,7 @@ import { drawPcbNoteRect } from "./elements/pcb-note-rect"
|
|
|
52
53
|
import { drawPcbFabricationNotePath } from "./elements/pcb-fabrication-note-path"
|
|
53
54
|
import { drawPcbNotePath } from "./elements/pcb-note-path"
|
|
54
55
|
import { drawPcbNoteText } from "./elements/pcb-note-text"
|
|
56
|
+
import { drawPcbNoteLine } from "./elements/pcb-note-line"
|
|
55
57
|
|
|
56
58
|
export interface DrawElementsOptions {
|
|
57
59
|
layers?: string[]
|
|
@@ -329,5 +331,14 @@ export class CircuitToCanvasDrawer {
|
|
|
329
331
|
colorMap: this.colorMap,
|
|
330
332
|
})
|
|
331
333
|
}
|
|
334
|
+
|
|
335
|
+
if (element.type === "pcb_note_line") {
|
|
336
|
+
drawPcbNoteLine({
|
|
337
|
+
ctx: this.ctx,
|
|
338
|
+
line: element as PcbNoteLine,
|
|
339
|
+
transform: this.realToCanvasMat,
|
|
340
|
+
colorMap: this.colorMap,
|
|
341
|
+
})
|
|
342
|
+
}
|
|
332
343
|
}
|
|
333
344
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { PcbNoteLine } from "circuit-json"
|
|
2
|
+
import type { Matrix } from "transformation-matrix"
|
|
3
|
+
import { applyToPoint } from "transformation-matrix"
|
|
4
|
+
import type { PcbColorMap, CanvasContext } from "../types"
|
|
5
|
+
|
|
6
|
+
export interface DrawPcbNoteLineParams {
|
|
7
|
+
ctx: CanvasContext
|
|
8
|
+
line: PcbNoteLine
|
|
9
|
+
transform: Matrix
|
|
10
|
+
colorMap: PcbColorMap
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function drawPcbNoteLine(params: DrawPcbNoteLineParams): void {
|
|
14
|
+
const { ctx, line, transform, colorMap } = params
|
|
15
|
+
|
|
16
|
+
// Use the color from the line if provided, otherwise use a default color
|
|
17
|
+
// Notes are typically shown in a distinct color
|
|
18
|
+
const defaultColor = "rgb(89, 148, 220)" // Blue color for notes
|
|
19
|
+
const color = line.color ?? defaultColor
|
|
20
|
+
|
|
21
|
+
const strokeWidth = line.stroke_width ?? 0.1
|
|
22
|
+
const isDashed = line.is_dashed ?? false
|
|
23
|
+
|
|
24
|
+
const [x1, y1] = applyToPoint(transform, [line.x1, line.y1])
|
|
25
|
+
const [x2, y2] = applyToPoint(transform, [line.x2, line.y2])
|
|
26
|
+
const scaledStrokeWidth = strokeWidth * Math.abs(transform.a)
|
|
27
|
+
|
|
28
|
+
ctx.save()
|
|
29
|
+
|
|
30
|
+
// Set up dashed line if needed
|
|
31
|
+
if (isDashed) {
|
|
32
|
+
ctx.setLineDash([scaledStrokeWidth * 2, scaledStrokeWidth * 2])
|
|
33
|
+
} else {
|
|
34
|
+
ctx.setLineDash([])
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
ctx.beginPath()
|
|
38
|
+
ctx.moveTo(x1, y1)
|
|
39
|
+
ctx.lineTo(x2, y2)
|
|
40
|
+
ctx.lineWidth = scaledStrokeWidth
|
|
41
|
+
ctx.strokeStyle = color
|
|
42
|
+
ctx.lineCap = "round"
|
|
43
|
+
ctx.stroke()
|
|
44
|
+
|
|
45
|
+
ctx.restore()
|
|
46
|
+
}
|
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.
|
|
4
|
+
"version": "0.0.14",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsup-node ./lib/index.ts --format esm --dts",
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@biomejs/biome": "^2.3.8",
|
|
13
|
+
"@napi-rs/canvas": "^0.1.84",
|
|
13
14
|
"@resvg/resvg-js": "^2.6.2",
|
|
14
15
|
"@tscircuit/alphabet": "^0.0.9",
|
|
15
16
|
"@tscircuit/circuit-json-util": "^0.0.73",
|
|
16
17
|
"@tscircuit/math-utils": "^0.0.29",
|
|
17
18
|
"@types/bun": "latest",
|
|
18
19
|
"bun-match-svg": "^0.0.14",
|
|
19
|
-
"canvas": "^3.2.0",
|
|
20
20
|
"circuit-json": "^0.0.335",
|
|
21
21
|
"circuit-json-to-connectivity-map": "^0.0.23",
|
|
22
22
|
"circuit-to-svg": "^0.0.297",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { expect, test } from "bun:test"
|
|
2
|
-
import { createCanvas } from "canvas"
|
|
2
|
+
import { createCanvas } from "@napi-rs/canvas"
|
|
3
3
|
import type { PcbCopperText } from "circuit-json"
|
|
4
4
|
import { scale } from "transformation-matrix"
|
|
5
5
|
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
@@ -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
|
+
})
|