circuit-to-canvas 0.0.63 → 0.0.64
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 +23 -0
- package/lib/drawer/CircuitToCanvasDrawer.ts +11 -0
- package/lib/drawer/elements/index.ts +5 -0
- package/lib/drawer/elements/pcb-courtyard-circle.ts +26 -0
- package/package.json +3 -3
- package/tests/elements/__snapshots__/pcb-courtyard-circle.snap.png +0 -0
- package/tests/elements/pcb-courtyard-circle.test.ts +44 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyCircuitElement, PcbRenderLayer, NinePointAnchor, PcbPlatedHole, PCBVia, PcbHole, PcbSmtPad, PcbTrace, PcbBoard, PcbPanel, PcbSilkscreenText, PcbSilkscreenRect, PcbSilkscreenCircle, PcbSilkscreenLine, PcbSilkscreenPath, PcbSilkscreenPill, PcbSilkscreenOval, PcbCutout, PCBKeepout, PcbCopperPour, PcbCopperText, PcbFabricationNoteText, PcbFabricationNoteRect, PcbNoteRect, PcbFabricationNotePath, PcbNotePath, PcbNoteText, PcbNoteDimension, PcbFabricationNoteDimension } from 'circuit-json';
|
|
1
|
+
import { AnyCircuitElement, PcbRenderLayer, NinePointAnchor, PcbPlatedHole, PCBVia, PcbHole, PcbSmtPad, PcbTrace, PcbBoard, PcbPanel, PcbSilkscreenText, PcbSilkscreenRect, PcbSilkscreenCircle, PcbSilkscreenLine, PcbSilkscreenPath, PcbSilkscreenPill, PcbSilkscreenOval, PcbCutout, PCBKeepout, PcbCopperPour, PcbCopperText, PcbFabricationNoteText, PcbFabricationNoteRect, PcbNoteRect, PcbFabricationNotePath, PcbNotePath, PcbNoteText, PcbNoteDimension, PcbFabricationNoteDimension, PcbCourtyardCircle } from 'circuit-json';
|
|
2
2
|
import { Matrix } from 'transformation-matrix';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -550,4 +550,12 @@ interface DrawPcbFabricationNoteDimensionParams {
|
|
|
550
550
|
}
|
|
551
551
|
declare function drawPcbFabricationNoteDimension(params: DrawPcbFabricationNoteDimensionParams): void;
|
|
552
552
|
|
|
553
|
-
|
|
553
|
+
interface DrawPcbCourtyardCircleParams {
|
|
554
|
+
ctx: CanvasContext;
|
|
555
|
+
circle: PcbCourtyardCircle;
|
|
556
|
+
realToCanvasMat: Matrix;
|
|
557
|
+
colorMap: PcbColorMap;
|
|
558
|
+
}
|
|
559
|
+
declare function drawPcbCourtyardCircle(params: DrawPcbCourtyardCircleParams): void;
|
|
560
|
+
|
|
561
|
+
export { type AlphabetLayout, type AnchorAlignment, type CameraBounds, type CanvasContext, CircuitToCanvasDrawer, type CopperColorMap, type CopperLayerName, DEFAULT_PCB_COLOR_MAP, type DrawArrowParams, type DrawCircleParams, type DrawContext, type DrawDimensionLineParams, type DrawElementsOptions, type DrawLineParams, type DrawOvalParams, type DrawPathParams, type DrawPcbBoardParams, type DrawPcbCopperPourParams, type DrawPcbCopperTextParams, type DrawPcbCourtyardCircleParams, type DrawPcbCutoutParams, type DrawPcbFabricationNoteDimensionParams, type DrawPcbFabricationNotePathParams, type DrawPcbFabricationNoteRectParams, type DrawPcbFabricationNoteTextParams, type DrawPcbHoleParams, type DrawPcbKeepoutParams, type DrawPcbNoteDimensionParams, type DrawPcbNotePathParams, type DrawPcbNoteRectParams, type DrawPcbNoteTextParams, type DrawPcbPanelParams, type DrawPcbPlatedHoleParams, type DrawPcbSilkscreenCircleParams, type DrawPcbSilkscreenLineParams, type DrawPcbSilkscreenOvalParams, type DrawPcbSilkscreenPathParams, type DrawPcbSilkscreenPillParams, type DrawPcbSilkscreenRectParams, type DrawPcbSilkscreenTextParams, type DrawPcbSmtPadParams, type DrawPcbTraceParams, type DrawPcbViaParams, type DrawPillParams, type DrawPolygonParams, type DrawRectParams, type DrawTextParams, type DrawerConfig, type PcbColorMap, drawArrow, drawCircle, drawDimensionLine, drawLine, drawOval, drawPath, drawPcbBoard, drawPcbCopperPour, drawPcbCopperText, drawPcbCourtyardCircle, drawPcbCutout, drawPcbFabricationNoteDimension, drawPcbFabricationNotePath, drawPcbFabricationNoteRect, drawPcbFabricationNoteText, drawPcbHole, drawPcbKeepout, drawPcbNoteDimension, drawPcbNotePath, drawPcbNoteRect, drawPcbNoteText, drawPcbPanelElement, drawPcbPlatedHole, drawPcbSilkscreenCircle, drawPcbSilkscreenLine, drawPcbSilkscreenOval, drawPcbSilkscreenPath, drawPcbSilkscreenPill, drawPcbSilkscreenRect, drawPcbSilkscreenText, drawPcbSmtPad, drawPcbTrace, drawPcbVia, drawPill, drawPolygon, drawRect, drawSoldermaskRingForCircle, drawSoldermaskRingForOval, drawSoldermaskRingForPill, drawSoldermaskRingForRect, drawText, getAlphabetLayout, getTextStartPosition, strokeAlphabetText };
|
package/dist/index.js
CHANGED
|
@@ -673,6 +673,20 @@ function drawCircle(params) {
|
|
|
673
673
|
}
|
|
674
674
|
}
|
|
675
675
|
|
|
676
|
+
// lib/drawer/elements/pcb-courtyard-circle.ts
|
|
677
|
+
function drawPcbCourtyardCircle(params) {
|
|
678
|
+
const { ctx, circle, realToCanvasMat, colorMap } = params;
|
|
679
|
+
drawCircle({
|
|
680
|
+
ctx,
|
|
681
|
+
center: circle.center,
|
|
682
|
+
radius: circle.radius,
|
|
683
|
+
stroke: colorMap.courtyard,
|
|
684
|
+
strokeWidth: 0.05,
|
|
685
|
+
// Default thin line for courtyard info
|
|
686
|
+
realToCanvasMat
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
|
|
676
690
|
// lib/drawer/elements/pcb-cutout.ts
|
|
677
691
|
function drawPcbCutout(params) {
|
|
678
692
|
const { ctx, cutout, realToCanvasMat, colorMap } = params;
|
|
@@ -3657,6 +3671,14 @@ var CircuitToCanvasDrawer = class {
|
|
|
3657
3671
|
colorMap: this.colorMap
|
|
3658
3672
|
});
|
|
3659
3673
|
}
|
|
3674
|
+
if (element.type === "pcb_courtyard_circle") {
|
|
3675
|
+
drawPcbCourtyardCircle({
|
|
3676
|
+
ctx: this.ctx,
|
|
3677
|
+
circle: element,
|
|
3678
|
+
realToCanvasMat: this.realToCanvasMat,
|
|
3679
|
+
colorMap: this.colorMap
|
|
3680
|
+
});
|
|
3681
|
+
}
|
|
3660
3682
|
}
|
|
3661
3683
|
}
|
|
3662
3684
|
};
|
|
@@ -3688,6 +3710,7 @@ export {
|
|
|
3688
3710
|
drawPcbBoard,
|
|
3689
3711
|
drawPcbCopperPour,
|
|
3690
3712
|
drawPcbCopperText,
|
|
3713
|
+
drawPcbCourtyardCircle,
|
|
3691
3714
|
drawPcbCutout,
|
|
3692
3715
|
drawPcbFabricationNoteDimension,
|
|
3693
3716
|
drawPcbFabricationNotePath,
|
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
PcbBoard,
|
|
5
5
|
PcbCopperPour,
|
|
6
6
|
PcbCopperText,
|
|
7
|
+
PcbCourtyardCircle,
|
|
7
8
|
PcbCutout,
|
|
8
9
|
PcbFabricationNoteDimension,
|
|
9
10
|
PcbFabricationNotePath,
|
|
@@ -40,6 +41,7 @@ import {
|
|
|
40
41
|
import { drawPcbBoard } from "./elements/pcb-board"
|
|
41
42
|
import { drawPcbCopperPour } from "./elements/pcb-copper-pour"
|
|
42
43
|
import { drawPcbCopperText } from "./elements/pcb-copper-text"
|
|
44
|
+
import { drawPcbCourtyardCircle } from "./elements/pcb-courtyard-circle"
|
|
43
45
|
import { drawPcbCutout } from "./elements/pcb-cutout"
|
|
44
46
|
import { drawPcbFabricationNoteDimension } from "./elements/pcb-fabrication-note-dimension"
|
|
45
47
|
import { drawPcbFabricationNotePath } from "./elements/pcb-fabrication-note-path"
|
|
@@ -490,6 +492,15 @@ export class CircuitToCanvasDrawer {
|
|
|
490
492
|
colorMap: this.colorMap,
|
|
491
493
|
})
|
|
492
494
|
}
|
|
495
|
+
|
|
496
|
+
if (element.type === "pcb_courtyard_circle") {
|
|
497
|
+
drawPcbCourtyardCircle({
|
|
498
|
+
ctx: this.ctx,
|
|
499
|
+
circle: element as PcbCourtyardCircle,
|
|
500
|
+
realToCanvasMat: this.realToCanvasMat,
|
|
501
|
+
colorMap: this.colorMap,
|
|
502
|
+
})
|
|
503
|
+
}
|
|
493
504
|
}
|
|
494
505
|
}
|
|
495
506
|
}
|
|
@@ -109,3 +109,8 @@ export {
|
|
|
109
109
|
drawPcbFabricationNoteDimension,
|
|
110
110
|
type DrawPcbFabricationNoteDimensionParams,
|
|
111
111
|
} from "./pcb-fabrication-note-dimension"
|
|
112
|
+
|
|
113
|
+
export {
|
|
114
|
+
drawPcbCourtyardCircle,
|
|
115
|
+
type DrawPcbCourtyardCircleParams,
|
|
116
|
+
} from "./pcb-courtyard-circle"
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PcbCourtyardCircle } from "circuit-json"
|
|
2
|
+
import type { Matrix } from "transformation-matrix"
|
|
3
|
+
import type { PcbColorMap, CanvasContext } from "../types"
|
|
4
|
+
import { drawCircle } from "../shapes/circle"
|
|
5
|
+
|
|
6
|
+
export interface DrawPcbCourtyardCircleParams {
|
|
7
|
+
ctx: CanvasContext
|
|
8
|
+
circle: PcbCourtyardCircle
|
|
9
|
+
realToCanvasMat: Matrix
|
|
10
|
+
colorMap: PcbColorMap
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function drawPcbCourtyardCircle(
|
|
14
|
+
params: DrawPcbCourtyardCircleParams,
|
|
15
|
+
): void {
|
|
16
|
+
const { ctx, circle, realToCanvasMat, colorMap } = params
|
|
17
|
+
|
|
18
|
+
drawCircle({
|
|
19
|
+
ctx,
|
|
20
|
+
center: circle.center,
|
|
21
|
+
radius: circle.radius,
|
|
22
|
+
stroke: colorMap.courtyard,
|
|
23
|
+
strokeWidth: 0.05, // Default thin line for courtyard info
|
|
24
|
+
realToCanvasMat,
|
|
25
|
+
})
|
|
26
|
+
}
|
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.64",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsup-node ./lib/index.ts --format esm --dts",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"@tscircuit/math-utils": "^0.0.29",
|
|
18
18
|
"@types/bun": "latest",
|
|
19
19
|
"bun-match-svg": "^0.0.14",
|
|
20
|
-
"circuit-json": "^0.0.
|
|
20
|
+
"circuit-json": "^0.0.374",
|
|
21
21
|
"circuit-json-to-connectivity-map": "^0.0.23",
|
|
22
|
-
"circuit-to-svg": "^0.0.
|
|
22
|
+
"circuit-to-svg": "^0.0.323",
|
|
23
23
|
"looks-same": "^10.0.1",
|
|
24
24
|
"schematic-symbols": "^0.0.202",
|
|
25
25
|
"tsup": "^8.5.1"
|
|
Binary file
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { createCanvas } from "@napi-rs/canvas"
|
|
3
|
+
import type { PcbCourtyardCircle } from "circuit-json"
|
|
4
|
+
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
5
|
+
|
|
6
|
+
test("draw courtyard circle", async () => {
|
|
7
|
+
const canvas = createCanvas(1000, 1000)
|
|
8
|
+
const ctx = canvas.getContext("2d")
|
|
9
|
+
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
10
|
+
|
|
11
|
+
ctx.fillStyle = "#1a1a1a"
|
|
12
|
+
ctx.fillRect(0, 0, 1000, 1000)
|
|
13
|
+
|
|
14
|
+
const circle: PcbCourtyardCircle = {
|
|
15
|
+
type: "pcb_courtyard_circle",
|
|
16
|
+
pcb_courtyard_circle_id: "courtyard_circle1",
|
|
17
|
+
pcb_component_id: "component1",
|
|
18
|
+
layer: "top",
|
|
19
|
+
center: { x: 0, y: 0 },
|
|
20
|
+
radius: 2,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const circle2: PcbCourtyardCircle = {
|
|
24
|
+
type: "pcb_courtyard_circle",
|
|
25
|
+
pcb_courtyard_circle_id: "courtyard_circle2",
|
|
26
|
+
pcb_component_id: "component2",
|
|
27
|
+
layer: "bottom",
|
|
28
|
+
center: { x: 3, y: 3 },
|
|
29
|
+
radius: 1,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
drawer.setCameraBounds({
|
|
33
|
+
minX: -5,
|
|
34
|
+
maxX: 5,
|
|
35
|
+
minY: -5,
|
|
36
|
+
maxY: 5,
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
drawer.drawElements([circle, circle2])
|
|
40
|
+
|
|
41
|
+
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
42
|
+
import.meta.path,
|
|
43
|
+
)
|
|
44
|
+
})
|