circuit-to-canvas 0.0.4 → 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.
- package/dist/index.d.ts +10 -2
- package/dist/index.js +31 -0
- package/lib/drawer/CircuitToCanvasDrawer.ts +11 -0
- package/lib/drawer/elements/index.ts +5 -0
- package/lib/drawer/elements/pcb-note-rect.ts +37 -0
- package/package.json +1 -1
- package/tests/elements/__snapshots__/pcb-note-rect-all-features.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-note-rect-dashed-stroke.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-note-rect-filled-no-stroke.snap.png +0 -0
- package/tests/elements/pcb-note-rect-all-features.test.ts +38 -0
- package/tests/elements/pcb-note-rect-dashed-stroke.test.ts +32 -0
- package/tests/elements/pcb-note-rect-filled-no-stroke.test.ts +32 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyCircuitElement, PcbPlatedHole, PCBVia, PCBHole, PcbSmtPad, PCBTrace, PcbBoard, PcbSilkscreenText, PcbSilkscreenRect, PcbSilkscreenCircle, PcbSilkscreenLine, PcbSilkscreenPath, PcbCutout, PcbCopperPour, PcbCopperText, PcbFabricationNoteText, PcbFabricationNoteRect, PcbFabricationNotePath } from 'circuit-json';
|
|
1
|
+
import { AnyCircuitElement, PcbPlatedHole, PCBVia, PCBHole, PcbSmtPad, PCBTrace, PcbBoard, PcbSilkscreenText, PcbSilkscreenRect, PcbSilkscreenCircle, PcbSilkscreenLine, PcbSilkscreenPath, PcbCutout, PcbCopperPour, PcbCopperText, PcbFabricationNoteText, PcbFabricationNoteRect, PcbNoteRect, PcbFabricationNotePath } from 'circuit-json';
|
|
2
2
|
import { Matrix } from 'transformation-matrix';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -355,6 +355,14 @@ interface DrawPcbFabricationNoteRectParams {
|
|
|
355
355
|
}
|
|
356
356
|
declare function drawPcbFabricationNoteRect(params: DrawPcbFabricationNoteRectParams): void;
|
|
357
357
|
|
|
358
|
+
interface DrawPcbNoteRectParams {
|
|
359
|
+
ctx: CanvasContext;
|
|
360
|
+
rect: PcbNoteRect;
|
|
361
|
+
transform: Matrix;
|
|
362
|
+
colorMap: PcbColorMap;
|
|
363
|
+
}
|
|
364
|
+
declare function drawPcbNoteRect(params: DrawPcbNoteRectParams): void;
|
|
365
|
+
|
|
358
366
|
interface DrawPcbFabricationNotePathParams {
|
|
359
367
|
ctx: CanvasContext;
|
|
360
368
|
path: PcbFabricationNotePath;
|
|
@@ -363,4 +371,4 @@ interface DrawPcbFabricationNotePathParams {
|
|
|
363
371
|
}
|
|
364
372
|
declare function drawPcbFabricationNotePath(params: DrawPcbFabricationNotePathParams): void;
|
|
365
373
|
|
|
366
|
-
export { type AlphabetLayout, type AnchorAlignment, type CameraBounds, type CanvasContext, CircuitToCanvasDrawer, type CopperColorMap, type CopperLayerName, DEFAULT_PCB_COLOR_MAP, type DrawCircleParams, type DrawContext, type DrawElementsOptions, type DrawLineParams, type DrawOvalParams, type DrawPathParams, type DrawPcbBoardParams, type DrawPcbCopperPourParams, type DrawPcbCopperTextParams, type DrawPcbCutoutParams, type DrawPcbFabricationNotePathParams, type DrawPcbFabricationNoteRectParams, type DrawPcbFabricationNoteTextParams, type DrawPcbHoleParams, type DrawPcbPlatedHoleParams, type DrawPcbSilkscreenCircleParams, type DrawPcbSilkscreenLineParams, type DrawPcbSilkscreenPathParams, type DrawPcbSilkscreenRectParams, type DrawPcbSilkscreenTextParams, type DrawPcbSmtPadParams, type DrawPcbTraceParams, type DrawPcbViaParams, type DrawPillParams, type DrawPolygonParams, type DrawRectParams, type DrawTextParams, type DrawerConfig, type PcbColorMap, drawCircle, drawLine, drawOval, drawPath, drawPcbBoard, drawPcbCopperPour, drawPcbCopperText, drawPcbCutout, drawPcbFabricationNotePath, drawPcbFabricationNoteRect, drawPcbFabricationNoteText, drawPcbHole, drawPcbPlatedHole, drawPcbSilkscreenCircle, drawPcbSilkscreenLine, drawPcbSilkscreenPath, drawPcbSilkscreenRect, drawPcbSilkscreenText, drawPcbSmtPad, drawPcbTrace, drawPcbVia, drawPill, drawPolygon, drawRect, drawText, getAlphabetLayout, getTextStartPosition, strokeAlphabetText };
|
|
374
|
+
export { type AlphabetLayout, type AnchorAlignment, type CameraBounds, type CanvasContext, CircuitToCanvasDrawer, type CopperColorMap, type CopperLayerName, DEFAULT_PCB_COLOR_MAP, type DrawCircleParams, type DrawContext, type DrawElementsOptions, type DrawLineParams, type DrawOvalParams, type DrawPathParams, type DrawPcbBoardParams, type DrawPcbCopperPourParams, type DrawPcbCopperTextParams, type DrawPcbCutoutParams, type DrawPcbFabricationNotePathParams, type DrawPcbFabricationNoteRectParams, type DrawPcbFabricationNoteTextParams, type DrawPcbHoleParams, type DrawPcbNoteRectParams, type DrawPcbPlatedHoleParams, type DrawPcbSilkscreenCircleParams, type DrawPcbSilkscreenLineParams, type DrawPcbSilkscreenPathParams, type DrawPcbSilkscreenRectParams, type DrawPcbSilkscreenTextParams, type DrawPcbSmtPadParams, type DrawPcbTraceParams, type DrawPcbViaParams, type DrawPillParams, type DrawPolygonParams, type DrawRectParams, type DrawTextParams, type DrawerConfig, type PcbColorMap, drawCircle, drawLine, drawOval, drawPath, drawPcbBoard, drawPcbCopperPour, drawPcbCopperText, drawPcbCutout, drawPcbFabricationNotePath, drawPcbFabricationNoteRect, drawPcbFabricationNoteText, drawPcbHole, drawPcbNoteRect, drawPcbPlatedHole, drawPcbSilkscreenCircle, drawPcbSilkscreenLine, drawPcbSilkscreenPath, drawPcbSilkscreenRect, drawPcbSilkscreenText, drawPcbSmtPad, drawPcbTrace, drawPcbVia, drawPill, drawPolygon, drawRect, drawText, getAlphabetLayout, getTextStartPosition, strokeAlphabetText };
|
package/dist/index.js
CHANGED
|
@@ -1055,6 +1055,28 @@ function drawPcbFabricationNoteRect(params) {
|
|
|
1055
1055
|
});
|
|
1056
1056
|
}
|
|
1057
1057
|
|
|
1058
|
+
// lib/drawer/elements/pcb-note-rect.ts
|
|
1059
|
+
function drawPcbNoteRect(params) {
|
|
1060
|
+
const { ctx, rect, transform, colorMap } = params;
|
|
1061
|
+
const defaultColor = "rgb(89, 148, 220)";
|
|
1062
|
+
const color = rect.color ?? defaultColor;
|
|
1063
|
+
const isFilled = rect.is_filled ?? false;
|
|
1064
|
+
const hasStroke = rect.has_stroke ?? true;
|
|
1065
|
+
const isStrokeDashed = rect.is_stroke_dashed ?? false;
|
|
1066
|
+
drawRect({
|
|
1067
|
+
ctx,
|
|
1068
|
+
center: rect.center,
|
|
1069
|
+
width: rect.width,
|
|
1070
|
+
height: rect.height,
|
|
1071
|
+
fill: isFilled ? color : void 0,
|
|
1072
|
+
stroke: hasStroke ? color : void 0,
|
|
1073
|
+
strokeWidth: hasStroke ? rect.stroke_width : void 0,
|
|
1074
|
+
borderRadius: rect.corner_radius,
|
|
1075
|
+
transform,
|
|
1076
|
+
isStrokeDashed
|
|
1077
|
+
});
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1058
1080
|
// lib/drawer/elements/pcb-fabrication-note-path.ts
|
|
1059
1081
|
function drawPcbFabricationNotePath(params) {
|
|
1060
1082
|
const { ctx, path, transform, colorMap } = params;
|
|
@@ -1273,6 +1295,14 @@ var CircuitToCanvasDrawer = class {
|
|
|
1273
1295
|
colorMap: this.colorMap
|
|
1274
1296
|
});
|
|
1275
1297
|
}
|
|
1298
|
+
if (element.type === "pcb_note_rect") {
|
|
1299
|
+
drawPcbNoteRect({
|
|
1300
|
+
transform: this.realToCanvasMat,
|
|
1301
|
+
colorMap: this.colorMap,
|
|
1302
|
+
ctx: this.ctx,
|
|
1303
|
+
rect: element
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1276
1306
|
if (element.type === "pcb_fabrication_note_path") {
|
|
1277
1307
|
drawPcbFabricationNotePath({
|
|
1278
1308
|
ctx: this.ctx,
|
|
@@ -1298,6 +1328,7 @@ export {
|
|
|
1298
1328
|
drawPcbFabricationNoteRect,
|
|
1299
1329
|
drawPcbFabricationNoteText,
|
|
1300
1330
|
drawPcbHole,
|
|
1331
|
+
drawPcbNoteRect,
|
|
1301
1332
|
drawPcbPlatedHole,
|
|
1302
1333
|
drawPcbSilkscreenCircle,
|
|
1303
1334
|
drawPcbSilkscreenLine,
|
|
@@ -16,6 +16,7 @@ import type {
|
|
|
16
16
|
PcbCopperText,
|
|
17
17
|
PcbFabricationNoteText,
|
|
18
18
|
PcbFabricationNoteRect,
|
|
19
|
+
PcbNoteRect,
|
|
19
20
|
PcbFabricationNotePath,
|
|
20
21
|
} from "circuit-json"
|
|
21
22
|
import { identity, compose, translate, scale } from "transformation-matrix"
|
|
@@ -45,6 +46,7 @@ import { drawPcbCopperPour } from "./elements/pcb-copper-pour"
|
|
|
45
46
|
import { drawPcbCopperText } from "./elements/pcb-copper-text"
|
|
46
47
|
import { drawPcbFabricationNoteText } from "./elements/pcb-fabrication-note-text"
|
|
47
48
|
import { drawPcbFabricationNoteRect } from "./elements/pcb-fabrication-note-rect"
|
|
49
|
+
import { drawPcbNoteRect } from "./elements/pcb-note-rect"
|
|
48
50
|
import { drawPcbFabricationNotePath } from "./elements/pcb-fabrication-note-path"
|
|
49
51
|
|
|
50
52
|
export interface DrawElementsOptions {
|
|
@@ -288,6 +290,15 @@ export class CircuitToCanvasDrawer {
|
|
|
288
290
|
})
|
|
289
291
|
}
|
|
290
292
|
|
|
293
|
+
if (element.type === "pcb_note_rect") {
|
|
294
|
+
drawPcbNoteRect({
|
|
295
|
+
transform: this.realToCanvasMat,
|
|
296
|
+
colorMap: this.colorMap,
|
|
297
|
+
ctx: this.ctx,
|
|
298
|
+
rect: element as PcbNoteRect,
|
|
299
|
+
})
|
|
300
|
+
}
|
|
301
|
+
|
|
291
302
|
if (element.type === "pcb_fabrication_note_path") {
|
|
292
303
|
drawPcbFabricationNotePath({
|
|
293
304
|
ctx: this.ctx,
|
|
@@ -48,6 +48,11 @@ export {
|
|
|
48
48
|
type DrawPcbFabricationNoteRectParams,
|
|
49
49
|
} from "./pcb-fabrication-note-rect"
|
|
50
50
|
|
|
51
|
+
export {
|
|
52
|
+
drawPcbNoteRect,
|
|
53
|
+
type DrawPcbNoteRectParams,
|
|
54
|
+
} from "./pcb-note-rect"
|
|
55
|
+
|
|
51
56
|
export {
|
|
52
57
|
drawPcbFabricationNotePath,
|
|
53
58
|
type DrawPcbFabricationNotePathParams,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { PcbNoteRect } from "circuit-json"
|
|
2
|
+
import type { Matrix } from "transformation-matrix"
|
|
3
|
+
import type { PcbColorMap, CanvasContext } from "../types"
|
|
4
|
+
import { drawRect } from "../shapes/rect"
|
|
5
|
+
|
|
6
|
+
export interface DrawPcbNoteRectParams {
|
|
7
|
+
ctx: CanvasContext
|
|
8
|
+
rect: PcbNoteRect
|
|
9
|
+
transform: Matrix
|
|
10
|
+
colorMap: PcbColorMap
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function drawPcbNoteRect(params: DrawPcbNoteRectParams): void {
|
|
14
|
+
const { ctx, rect, transform, colorMap } = params
|
|
15
|
+
|
|
16
|
+
// Use the color from the rect if provided, otherwise use a default color
|
|
17
|
+
// Notes are typically shown in a distinct color
|
|
18
|
+
const defaultColor = "rgb(89, 148, 220)" // White color for notes
|
|
19
|
+
const color = rect.color ?? defaultColor
|
|
20
|
+
|
|
21
|
+
const isFilled = rect.is_filled ?? false
|
|
22
|
+
const hasStroke = rect.has_stroke ?? true
|
|
23
|
+
const isStrokeDashed = rect.is_stroke_dashed ?? false
|
|
24
|
+
|
|
25
|
+
drawRect({
|
|
26
|
+
ctx,
|
|
27
|
+
center: rect.center,
|
|
28
|
+
width: rect.width,
|
|
29
|
+
height: rect.height,
|
|
30
|
+
fill: isFilled ? color : undefined,
|
|
31
|
+
stroke: hasStroke ? color : undefined,
|
|
32
|
+
strokeWidth: hasStroke ? rect.stroke_width : undefined,
|
|
33
|
+
borderRadius: rect.corner_radius,
|
|
34
|
+
transform,
|
|
35
|
+
isStrokeDashed,
|
|
36
|
+
})
|
|
37
|
+
}
|
package/package.json
CHANGED
|
Binary file
|
|
@@ -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
|
+
})
|