circuit-to-canvas 0.0.67 → 0.0.69

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.
@@ -0,0 +1 @@
1
+ * @ShiboSoftwareDev @Abse2001
package/dist/index.d.ts CHANGED
@@ -98,6 +98,8 @@ interface DrawElementsOptions {
98
98
  drawSoldermask?: boolean;
99
99
  /** Whether to render the board material (substrate fill). Defaults to false. */
100
100
  drawBoardMaterial?: boolean;
101
+ /** Minimum on-screen outline stroke width for pcb_board only. */
102
+ minBoardOutlineStrokePx?: number;
101
103
  }
102
104
  interface CanvasLike {
103
105
  getContext(contextId: "2d"): CanvasContext | null;
@@ -214,6 +216,7 @@ interface DrawPathParams {
214
216
  fill?: string;
215
217
  stroke?: string;
216
218
  strokeWidth?: number;
219
+ minStrokePx?: number;
217
220
  realToCanvasMat: Matrix;
218
221
  closePath?: boolean;
219
222
  }
@@ -389,6 +392,7 @@ interface DrawPcbBoardParams {
389
392
  realToCanvasMat: Matrix;
390
393
  colorMap: PcbColorMap;
391
394
  drawBoardMaterial: boolean;
395
+ minBoardOutlineStrokePx?: number;
392
396
  }
393
397
  declare function drawPcbBoard(params: DrawPcbBoardParams): void;
394
398
 
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ function drawPath(params) {
15
15
  fill,
16
16
  stroke,
17
17
  strokeWidth = 1,
18
+ minStrokePx,
18
19
  realToCanvasMat,
19
20
  closePath = false
20
21
  } = params;
@@ -42,8 +43,9 @@ function drawPath(params) {
42
43
  }
43
44
  if (stroke) {
44
45
  const scaledStrokeWidth = strokeWidth * Math.abs(realToCanvasMat.a);
46
+ const clampedStrokeWidth = minStrokePx === void 0 ? scaledStrokeWidth : Math.max(scaledStrokeWidth, minStrokePx);
45
47
  ctx.strokeStyle = stroke;
46
- ctx.lineWidth = scaledStrokeWidth;
48
+ ctx.lineWidth = clampedStrokeWidth;
47
49
  ctx.stroke();
48
50
  }
49
51
  }
@@ -116,7 +118,14 @@ function drawRect(params) {
116
118
 
117
119
  // lib/drawer/elements/pcb-board.ts
118
120
  function drawPcbBoard(params) {
119
- const { ctx, board, realToCanvasMat, colorMap, drawBoardMaterial } = params;
121
+ const {
122
+ ctx,
123
+ board,
124
+ realToCanvasMat,
125
+ colorMap,
126
+ drawBoardMaterial,
127
+ minBoardOutlineStrokePx
128
+ } = params;
120
129
  const { width, height, center, outline } = board;
121
130
  if (outline && Array.isArray(outline) && outline.length >= 3) {
122
131
  if (drawBoardMaterial) {
@@ -134,7 +143,8 @@ function drawPcbBoard(params) {
134
143
  stroke: colorMap.boardOutline,
135
144
  strokeWidth: 0.1,
136
145
  realToCanvasMat,
137
- closePath: true
146
+ closePath: true,
147
+ minStrokePx: minBoardOutlineStrokePx
138
148
  });
139
149
  return;
140
150
  }
@@ -163,7 +173,8 @@ function drawPcbBoard(params) {
163
173
  stroke: colorMap.boardOutline,
164
174
  strokeWidth: 0.1,
165
175
  realToCanvasMat,
166
- closePath: true
176
+ closePath: true,
177
+ minStrokePx: minBoardOutlineStrokePx
167
178
  });
168
179
  }
169
180
  }
@@ -3516,7 +3527,8 @@ var CircuitToCanvasDrawer = class {
3516
3527
  board,
3517
3528
  realToCanvasMat: this.realToCanvasMat,
3518
3529
  colorMap: this.colorMap,
3519
- drawBoardMaterial: options.drawBoardMaterial ?? false
3530
+ drawBoardMaterial: options.drawBoardMaterial ?? false,
3531
+ minBoardOutlineStrokePx: options.minBoardOutlineStrokePx
3520
3532
  });
3521
3533
  }
3522
3534
  for (const element of elements) {
@@ -84,6 +84,8 @@ export interface DrawElementsOptions {
84
84
  drawSoldermask?: boolean
85
85
  /** Whether to render the board material (substrate fill). Defaults to false. */
86
86
  drawBoardMaterial?: boolean
87
+ /** Minimum on-screen outline stroke width for pcb_board only. */
88
+ minBoardOutlineStrokePx?: number
87
89
  }
88
90
 
89
91
  interface CanvasLike {
@@ -210,6 +212,7 @@ export class CircuitToCanvasDrawer {
210
212
  realToCanvasMat: this.realToCanvasMat,
211
213
  colorMap: this.colorMap,
212
214
  drawBoardMaterial: options.drawBoardMaterial ?? false,
215
+ minBoardOutlineStrokePx: options.minBoardOutlineStrokePx,
213
216
  })
214
217
  }
215
218
 
@@ -10,10 +10,18 @@ export interface DrawPcbBoardParams {
10
10
  realToCanvasMat: Matrix
11
11
  colorMap: PcbColorMap
12
12
  drawBoardMaterial: boolean
13
+ minBoardOutlineStrokePx?: number
13
14
  }
14
15
 
15
16
  export function drawPcbBoard(params: DrawPcbBoardParams): void {
16
- const { ctx, board, realToCanvasMat, colorMap, drawBoardMaterial } = params
17
+ const {
18
+ ctx,
19
+ board,
20
+ realToCanvasMat,
21
+ colorMap,
22
+ drawBoardMaterial,
23
+ minBoardOutlineStrokePx,
24
+ } = params
17
25
  const { width, height, center, outline } = board
18
26
 
19
27
  // If the board has a custom outline, draw substrate and outline
@@ -37,6 +45,7 @@ export function drawPcbBoard(params: DrawPcbBoardParams): void {
37
45
  strokeWidth: 0.1,
38
46
  realToCanvasMat,
39
47
  closePath: true,
48
+ minStrokePx: minBoardOutlineStrokePx,
40
49
  })
41
50
  return
42
51
  }
@@ -72,6 +81,7 @@ export function drawPcbBoard(params: DrawPcbBoardParams): void {
72
81
  strokeWidth: 0.1,
73
82
  realToCanvasMat,
74
83
  closePath: true,
84
+ minStrokePx: minBoardOutlineStrokePx,
75
85
  })
76
86
  }
77
87
  }
@@ -8,6 +8,7 @@ export interface DrawPathParams {
8
8
  fill?: string
9
9
  stroke?: string
10
10
  strokeWidth?: number
11
+ minStrokePx?: number
11
12
  realToCanvasMat: Matrix
12
13
  closePath?: boolean
13
14
  }
@@ -19,6 +20,7 @@ export function drawPath(params: DrawPathParams): void {
19
20
  fill,
20
21
  stroke,
21
22
  strokeWidth = 1,
23
+ minStrokePx,
22
24
  realToCanvasMat,
23
25
  closePath = false,
24
26
  } = params
@@ -54,8 +56,12 @@ export function drawPath(params: DrawPathParams): void {
54
56
 
55
57
  if (stroke) {
56
58
  const scaledStrokeWidth = strokeWidth * Math.abs(realToCanvasMat.a)
59
+ const clampedStrokeWidth =
60
+ minStrokePx === undefined
61
+ ? scaledStrokeWidth
62
+ : Math.max(scaledStrokeWidth, minStrokePx)
57
63
  ctx.strokeStyle = stroke
58
- ctx.lineWidth = scaledStrokeWidth
64
+ ctx.lineWidth = clampedStrokeWidth
59
65
  ctx.stroke()
60
66
  }
61
67
  }
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.67",
4
+ "version": "0.0.69",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "tsup-node ./lib/index.ts --format esm --dts",