circuit-to-canvas 0.0.22 → 0.0.24

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 (47) hide show
  1. package/dist/index.d.ts +8 -4
  2. package/dist/index.js +26 -6
  3. package/lib/drawer/CircuitToCanvasDrawer.ts +5 -7
  4. package/lib/drawer/elements/index.ts +17 -5
  5. package/lib/drawer/elements/pcb-silkscreen-circle.ts +33 -0
  6. package/lib/drawer/elements/pcb-silkscreen-line.ts +34 -0
  7. package/lib/drawer/elements/pcb-silkscreen-path.ts +44 -0
  8. package/lib/drawer/elements/pcb-silkscreen-rect.ts +34 -0
  9. package/lib/drawer/elements/pcb-silkscreen-text.ts +71 -0
  10. package/package.json +1 -1
  11. package/tests/elements/__snapshots__/fabrication-note-text-full-charset.snap.png +0 -0
  12. package/tests/elements/__snapshots__/pcb-board.snap.png +0 -0
  13. package/tests/elements/pcb-silkscreen-circle.test.ts +29 -0
  14. package/tests/elements/pcb-silkscreen-line.test.ts +31 -0
  15. package/tests/elements/pcb-silkscreen-on-component.test.ts +75 -0
  16. package/tests/elements/pcb-silkscreen-path.test.ts +36 -0
  17. package/tests/elements/pcb-silkscreen-rect.test.ts +30 -0
  18. package/tests/elements/pcb-silkscreen-text-bottom-rotated.test.ts +84 -0
  19. package/tests/elements/pcb-silkscreen-text-bottom.test.ts +31 -0
  20. package/tests/elements/pcb-silkscreen-text-rotated.test.ts +32 -0
  21. package/tests/elements/pcb-silkscreen-text.test.ts +31 -0
  22. package/tests/elements/pcb-smtpad-bottom-layer.test.ts +30 -0
  23. package/tests/elements/pcb-smtpad-circle.test.ts +29 -0
  24. package/tests/elements/pcb-smtpad-pill.test.ts +31 -0
  25. package/tests/elements/pcb-smtpad-polygon.test.ts +34 -0
  26. package/tests/elements/pcb-smtpad-rect-border-radius.test.ts +31 -0
  27. package/tests/elements/pcb-smtpad-rect.test.ts +30 -0
  28. package/tests/elements/pcb-smtpad-rotated-rect.test.ts +31 -0
  29. package/lib/drawer/elements/pcb-silkscreen.ts +0 -186
  30. package/tests/elements/pcb-silkscreen.test.ts +0 -362
  31. package/tests/elements/pcb-smtpad.test.ts +0 -198
  32. /package/tests/elements/__snapshots__/{silkscreen-circle.snap.png → pcb-silkscreen-circle.snap.png} +0 -0
  33. /package/tests/elements/__snapshots__/{silkscreen-line.snap.png → pcb-silkscreen-line.snap.png} +0 -0
  34. /package/tests/elements/__snapshots__/{silkscreen-on-component.snap.png → pcb-silkscreen-on-component.snap.png} +0 -0
  35. /package/tests/elements/__snapshots__/{silkscreen-path.snap.png → pcb-silkscreen-path.snap.png} +0 -0
  36. /package/tests/elements/__snapshots__/{silkscreen-rect.snap.png → pcb-silkscreen-rect.snap.png} +0 -0
  37. /package/tests/elements/__snapshots__/{silkscreen-text-bottom-rotated.snap.png → pcb-silkscreen-text-bottom-rotated.snap.png} +0 -0
  38. /package/tests/elements/__snapshots__/{silkscreen-text-bottom.snap.png → pcb-silkscreen-text-bottom.snap.png} +0 -0
  39. /package/tests/elements/__snapshots__/{silkscreen-text-rotated.snap.png → pcb-silkscreen-text-rotated.snap.png} +0 -0
  40. /package/tests/elements/__snapshots__/{pcb-silkscreen.snap.png → pcb-silkscreen-text.snap.png} +0 -0
  41. /package/tests/elements/__snapshots__/{bottom-layer-pad.snap.png → pcb-smtpad-bottom-layer.snap.png} +0 -0
  42. /package/tests/elements/__snapshots__/{circular-pad.snap.png → pcb-smtpad-circle.snap.png} +0 -0
  43. /package/tests/elements/__snapshots__/{pill-pad.snap.png → pcb-smtpad-pill.snap.png} +0 -0
  44. /package/tests/elements/__snapshots__/{polygon-pad.snap.png → pcb-smtpad-polygon.snap.png} +0 -0
  45. /package/tests/elements/__snapshots__/{rect-pad-with-border-radius.snap.png → pcb-smtpad-rect-border-radius.snap.png} +0 -0
  46. /package/tests/elements/__snapshots__/{pcb-smtpad.snap.png → pcb-smtpad-rect.snap.png} +0 -0
  47. /package/tests/elements/__snapshots__/{rotated-rect-pad.snap.png → pcb-smtpad-rotated-rect.snap.png} +0 -0
@@ -1,362 +0,0 @@
1
- import { expect, test } from "bun:test"
2
- import { createCanvas } from "@napi-rs/canvas"
3
- import type {
4
- PcbSilkscreenText,
5
- PcbSilkscreenRect,
6
- PcbSilkscreenCircle,
7
- PcbSilkscreenLine,
8
- PcbSilkscreenPath,
9
- } from "circuit-json"
10
- import { CircuitToCanvasDrawer } from "../../lib/drawer"
11
-
12
- test("draw silkscreen text", async () => {
13
- const canvas = createCanvas(100, 100)
14
- const ctx = canvas.getContext("2d")
15
- const drawer = new CircuitToCanvasDrawer(ctx)
16
-
17
- ctx.fillStyle = "#1a1a1a"
18
- ctx.fillRect(0, 0, 100, 100)
19
-
20
- const text: PcbSilkscreenText = {
21
- type: "pcb_silkscreen_text",
22
- pcb_silkscreen_text_id: "text1",
23
- pcb_component_id: "component1",
24
- layer: "top",
25
- text: "U1",
26
- anchor_position: { x: 50, y: 50 },
27
- anchor_alignment: "center",
28
- font: "tscircuit2024",
29
- font_size: 8,
30
- }
31
-
32
- drawer.drawElements([text])
33
-
34
- await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
35
- import.meta.path,
36
- )
37
- })
38
-
39
- test("draw silkscreen text bottom layer", async () => {
40
- const canvas = createCanvas(100, 100)
41
- const ctx = canvas.getContext("2d")
42
- const drawer = new CircuitToCanvasDrawer(ctx)
43
-
44
- ctx.fillStyle = "#1a1a1a"
45
- ctx.fillRect(0, 0, 100, 100)
46
-
47
- const text: PcbSilkscreenText = {
48
- type: "pcb_silkscreen_text",
49
- pcb_silkscreen_text_id: "text1",
50
- pcb_component_id: "component1",
51
- layer: "bottom",
52
- text: "BOTTOM",
53
- anchor_position: { x: 50, y: 50 },
54
- anchor_alignment: "center",
55
- font: "tscircuit2024",
56
- font_size: 8,
57
- }
58
-
59
- drawer.drawElements([text])
60
-
61
- await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
62
- import.meta.path,
63
- "silkscreen-text-bottom",
64
- )
65
- })
66
-
67
- test("draw silkscreen text with rotation", async () => {
68
- const canvas = createCanvas(100, 100)
69
- const ctx = canvas.getContext("2d")
70
- const drawer = new CircuitToCanvasDrawer(ctx)
71
-
72
- ctx.fillStyle = "#1a1a1a"
73
- ctx.fillRect(0, 0, 100, 100)
74
-
75
- const text: PcbSilkscreenText = {
76
- type: "pcb_silkscreen_text",
77
- pcb_silkscreen_text_id: "text1",
78
- pcb_component_id: "component1",
79
- layer: "top",
80
- text: "ROT45",
81
- anchor_position: { x: 50, y: 50 },
82
- anchor_alignment: "center",
83
- font: "tscircuit2024",
84
- font_size: 8,
85
- ccw_rotation: 45,
86
- }
87
-
88
- drawer.drawElements([text])
89
-
90
- await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
91
- import.meta.path,
92
- "silkscreen-text-rotated",
93
- )
94
- })
95
-
96
- test("draw silkscreen text bottom layer with rotation - tests transform order", async () => {
97
- const canvas = createCanvas(150, 150)
98
- const ctx = canvas.getContext("2d")
99
- const drawer = new CircuitToCanvasDrawer(ctx)
100
-
101
- ctx.fillStyle = "#1a1a1a"
102
- ctx.fillRect(0, 0, 150, 150)
103
-
104
- // This test verifies the transform order (translate -> rotate -> scale) is correct
105
- // by testing bottom layer text with various rotations
106
- const texts: PcbSilkscreenText[] = [
107
- {
108
- type: "pcb_silkscreen_text",
109
- pcb_silkscreen_text_id: "text1",
110
- pcb_component_id: "component1",
111
- layer: "bottom",
112
- text: "0",
113
- anchor_position: { x: 75, y: 30 },
114
- anchor_alignment: "center",
115
- font: "tscircuit2024",
116
- font_size: 6,
117
- ccw_rotation: 0,
118
- },
119
- {
120
- type: "pcb_silkscreen_text",
121
- pcb_silkscreen_text_id: "text2",
122
- pcb_component_id: "component1",
123
- layer: "bottom",
124
- text: "90",
125
- anchor_position: { x: 120, y: 75 },
126
- anchor_alignment: "center",
127
- font: "tscircuit2024",
128
- font_size: 6,
129
- ccw_rotation: 90,
130
- },
131
- {
132
- type: "pcb_silkscreen_text",
133
- pcb_silkscreen_text_id: "text3",
134
- pcb_component_id: "component1",
135
- layer: "bottom",
136
- text: "180",
137
- anchor_position: { x: 75, y: 120 },
138
- anchor_alignment: "center",
139
- font: "tscircuit2024",
140
- font_size: 6,
141
- ccw_rotation: 180,
142
- },
143
- {
144
- type: "pcb_silkscreen_text",
145
- pcb_silkscreen_text_id: "text4",
146
- pcb_component_id: "component1",
147
- layer: "bottom",
148
- text: "270",
149
- anchor_position: { x: 30, y: 75 },
150
- anchor_alignment: "center",
151
- font: "tscircuit2024",
152
- font_size: 6,
153
- ccw_rotation: 270,
154
- },
155
- {
156
- type: "pcb_silkscreen_text",
157
- pcb_silkscreen_text_id: "text5",
158
- pcb_component_id: "component1",
159
- layer: "bottom",
160
- text: "BTM",
161
- anchor_position: { x: 75, y: 75 },
162
- anchor_alignment: "center",
163
- font: "tscircuit2024",
164
- font_size: 8,
165
- ccw_rotation: 45,
166
- },
167
- ]
168
-
169
- drawer.drawElements(texts)
170
-
171
- await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
172
- import.meta.path,
173
- "silkscreen-text-bottom-rotated",
174
- )
175
- })
176
-
177
- test("draw silkscreen rect", async () => {
178
- const canvas = createCanvas(100, 100)
179
- const ctx = canvas.getContext("2d")
180
- const drawer = new CircuitToCanvasDrawer(ctx)
181
-
182
- ctx.fillStyle = "#1a1a1a"
183
- ctx.fillRect(0, 0, 100, 100)
184
-
185
- const rect: PcbSilkscreenRect = {
186
- type: "pcb_silkscreen_rect",
187
- pcb_silkscreen_rect_id: "rect1",
188
- pcb_component_id: "component1",
189
- layer: "top",
190
- center: { x: 50, y: 50 },
191
- width: 40,
192
- height: 20,
193
- stroke_width: 0.2,
194
- }
195
-
196
- drawer.drawElements([rect])
197
-
198
- await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
199
- import.meta.path,
200
- "silkscreen-rect",
201
- )
202
- })
203
-
204
- test("draw silkscreen circle", async () => {
205
- const canvas = createCanvas(100, 100)
206
- const ctx = canvas.getContext("2d")
207
- const drawer = new CircuitToCanvasDrawer(ctx)
208
-
209
- ctx.fillStyle = "#1a1a1a"
210
- ctx.fillRect(0, 0, 100, 100)
211
-
212
- const circle: PcbSilkscreenCircle = {
213
- type: "pcb_silkscreen_circle",
214
- pcb_silkscreen_circle_id: "circle1",
215
- pcb_component_id: "component1",
216
- layer: "top",
217
- center: { x: 50, y: 50 },
218
- radius: 20,
219
- stroke_width: 0.2,
220
- }
221
-
222
- drawer.drawElements([circle])
223
-
224
- await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
225
- import.meta.path,
226
- "silkscreen-circle",
227
- )
228
- })
229
-
230
- test("draw silkscreen line", async () => {
231
- const canvas = createCanvas(100, 100)
232
- const ctx = canvas.getContext("2d")
233
- const drawer = new CircuitToCanvasDrawer(ctx)
234
-
235
- ctx.fillStyle = "#1a1a1a"
236
- ctx.fillRect(0, 0, 100, 100)
237
-
238
- const line: PcbSilkscreenLine = {
239
- type: "pcb_silkscreen_line",
240
- pcb_silkscreen_line_id: "line1",
241
- pcb_component_id: "component1",
242
- layer: "top",
243
- x1: 20,
244
- y1: 20,
245
- x2: 80,
246
- y2: 80,
247
- stroke_width: 2,
248
- }
249
-
250
- drawer.drawElements([line])
251
-
252
- await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
253
- import.meta.path,
254
- "silkscreen-line",
255
- )
256
- })
257
-
258
- test("draw silkscreen path", async () => {
259
- const canvas = createCanvas(100, 100)
260
- const ctx = canvas.getContext("2d")
261
- const drawer = new CircuitToCanvasDrawer(ctx)
262
-
263
- ctx.fillStyle = "#1a1a1a"
264
- ctx.fillRect(0, 0, 100, 100)
265
-
266
- const path: PcbSilkscreenPath = {
267
- type: "pcb_silkscreen_path",
268
- pcb_silkscreen_path_id: "path1",
269
- pcb_component_id: "component1",
270
- layer: "top",
271
- route: [
272
- { x: 10, y: 50 },
273
- { x: 30, y: 20 },
274
- { x: 70, y: 20 },
275
- { x: 90, y: 50 },
276
- { x: 70, y: 80 },
277
- { x: 30, y: 80 },
278
- { x: 10, y: 50 },
279
- ],
280
- stroke_width: 2,
281
- }
282
-
283
- drawer.drawElements([path])
284
-
285
- await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
286
- import.meta.path,
287
- "silkscreen-path",
288
- )
289
- })
290
-
291
- test("draw silkscreen on component", async () => {
292
- const canvas = createCanvas(150, 100)
293
- const ctx = canvas.getContext("2d")
294
- const drawer = new CircuitToCanvasDrawer(ctx)
295
-
296
- ctx.fillStyle = "#1a1a1a"
297
- ctx.fillRect(0, 0, 150, 100)
298
-
299
- const elements = [
300
- // Component outline
301
- {
302
- type: "pcb_silkscreen_rect" as const,
303
- pcb_silkscreen_rect_id: "outline1",
304
- pcb_component_id: "component1",
305
- layer: "top" as const,
306
- center: { x: 75, y: 50 },
307
- width: 60,
308
- height: 30,
309
- stroke_width: 0.2,
310
- },
311
- // Pin 1 indicator
312
- {
313
- type: "pcb_silkscreen_circle" as const,
314
- pcb_silkscreen_circle_id: "pin1marker",
315
- pcb_component_id: "component1",
316
- layer: "top" as const,
317
- center: { x: 55, y: 40 },
318
- radius: 3,
319
- stroke_width: 0.2,
320
- },
321
- // Component label
322
- {
323
- type: "pcb_silkscreen_text" as const,
324
- pcb_silkscreen_text_id: "label1",
325
- pcb_component_id: "component1",
326
- layer: "top" as const,
327
- text: "IC1",
328
- anchor_position: { x: 75, y: 50 },
329
- anchor_alignment: "center" as const,
330
- font: "tscircuit2024" as const,
331
- font_size: 8,
332
- },
333
- // SMT pads
334
- {
335
- type: "pcb_smtpad" as const,
336
- pcb_smtpad_id: "pad1",
337
- shape: "rect" as const,
338
- x: 55,
339
- y: 50,
340
- width: 10,
341
- height: 5,
342
- layer: "top" as const,
343
- },
344
- {
345
- type: "pcb_smtpad" as const,
346
- pcb_smtpad_id: "pad2",
347
- shape: "rect" as const,
348
- x: 95,
349
- y: 50,
350
- width: 10,
351
- height: 5,
352
- layer: "top" as const,
353
- },
354
- ]
355
-
356
- drawer.drawElements(elements)
357
-
358
- await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
359
- import.meta.path,
360
- "silkscreen-on-component",
361
- )
362
- })
@@ -1,198 +0,0 @@
1
- import { expect, test } from "bun:test"
2
- import { createCanvas } from "@napi-rs/canvas"
3
- import type { PcbSmtPad } from "circuit-json"
4
- import { CircuitToCanvasDrawer } from "../../lib/drawer"
5
-
6
- test("draw rectangular smt pad", 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 pad: PcbSmtPad = {
15
- type: "pcb_smtpad",
16
- pcb_smtpad_id: "pad1",
17
- shape: "rect",
18
- x: 50,
19
- y: 50,
20
- width: 40,
21
- height: 20,
22
- layer: "top",
23
- }
24
-
25
- drawer.drawElements([pad])
26
-
27
- await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
28
- import.meta.path,
29
- )
30
- })
31
-
32
- test("draw rectangular smt pad with border radius", async () => {
33
- const canvas = createCanvas(100, 100)
34
- const ctx = canvas.getContext("2d")
35
- const drawer = new CircuitToCanvasDrawer(ctx)
36
-
37
- ctx.fillStyle = "#1a1a1a"
38
- ctx.fillRect(0, 0, 100, 100)
39
-
40
- const pad: PcbSmtPad = {
41
- type: "pcb_smtpad",
42
- pcb_smtpad_id: "pad1",
43
- shape: "rect",
44
- x: 50,
45
- y: 50,
46
- width: 40,
47
- height: 20,
48
- layer: "top",
49
- rect_border_radius: 5,
50
- }
51
-
52
- drawer.drawElements([pad])
53
-
54
- await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
55
- import.meta.path,
56
- "rect-pad-with-border-radius",
57
- )
58
- })
59
-
60
- test("draw rotated rectangular smt pad", async () => {
61
- const canvas = createCanvas(100, 100)
62
- const ctx = canvas.getContext("2d")
63
- const drawer = new CircuitToCanvasDrawer(ctx)
64
-
65
- ctx.fillStyle = "#1a1a1a"
66
- ctx.fillRect(0, 0, 100, 100)
67
-
68
- const pad: PcbSmtPad = {
69
- type: "pcb_smtpad",
70
- pcb_smtpad_id: "pad1",
71
- shape: "rotated_rect",
72
- x: 50,
73
- y: 50,
74
- width: 40,
75
- height: 20,
76
- layer: "top",
77
- ccw_rotation: 45,
78
- }
79
-
80
- drawer.drawElements([pad])
81
-
82
- await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
83
- import.meta.path,
84
- "rotated-rect-pad",
85
- )
86
- })
87
-
88
- test("draw circular smt pad", async () => {
89
- const canvas = createCanvas(100, 100)
90
- const ctx = canvas.getContext("2d")
91
- const drawer = new CircuitToCanvasDrawer(ctx)
92
-
93
- ctx.fillStyle = "#1a1a1a"
94
- ctx.fillRect(0, 0, 100, 100)
95
-
96
- const pad: PcbSmtPad = {
97
- type: "pcb_smtpad",
98
- pcb_smtpad_id: "pad1",
99
- shape: "circle",
100
- x: 50,
101
- y: 50,
102
- radius: 20,
103
- layer: "top",
104
- }
105
-
106
- drawer.drawElements([pad])
107
-
108
- await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
109
- import.meta.path,
110
- "circular-pad",
111
- )
112
- })
113
-
114
- test("draw pill smt pad", async () => {
115
- const canvas = createCanvas(100, 100)
116
- const ctx = canvas.getContext("2d")
117
- const drawer = new CircuitToCanvasDrawer(ctx)
118
-
119
- ctx.fillStyle = "#1a1a1a"
120
- ctx.fillRect(0, 0, 100, 100)
121
-
122
- const pad: PcbSmtPad = {
123
- type: "pcb_smtpad",
124
- pcb_smtpad_id: "pad1",
125
- shape: "pill",
126
- x: 50,
127
- y: 50,
128
- width: 50,
129
- height: 25,
130
- radius: 12.5,
131
- layer: "top",
132
- }
133
-
134
- drawer.drawElements([pad])
135
-
136
- await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
137
- import.meta.path,
138
- "pill-pad",
139
- )
140
- })
141
-
142
- test("draw polygon smt pad", async () => {
143
- const canvas = createCanvas(100, 100)
144
- const ctx = canvas.getContext("2d")
145
- const drawer = new CircuitToCanvasDrawer(ctx)
146
-
147
- ctx.fillStyle = "#1a1a1a"
148
- ctx.fillRect(0, 0, 100, 100)
149
-
150
- const pad: PcbSmtPad = {
151
- type: "pcb_smtpad",
152
- pcb_smtpad_id: "pad1",
153
- shape: "polygon",
154
- layer: "top",
155
- points: [
156
- { x: 30, y: 30 },
157
- { x: 70, y: 30 },
158
- { x: 80, y: 50 },
159
- { x: 70, y: 70 },
160
- { x: 30, y: 70 },
161
- { x: 20, y: 50 },
162
- ],
163
- }
164
-
165
- drawer.drawElements([pad])
166
-
167
- await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
168
- import.meta.path,
169
- "polygon-pad",
170
- )
171
- })
172
-
173
- test("draw bottom layer smt pad", async () => {
174
- const canvas = createCanvas(100, 100)
175
- const ctx = canvas.getContext("2d")
176
- const drawer = new CircuitToCanvasDrawer(ctx)
177
-
178
- ctx.fillStyle = "#1a1a1a"
179
- ctx.fillRect(0, 0, 100, 100)
180
-
181
- const pad: PcbSmtPad = {
182
- type: "pcb_smtpad",
183
- pcb_smtpad_id: "pad1",
184
- shape: "rect",
185
- x: 50,
186
- y: 50,
187
- width: 40,
188
- height: 20,
189
- layer: "bottom",
190
- }
191
-
192
- drawer.drawElements([pad])
193
-
194
- await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
195
- import.meta.path,
196
- "bottom-layer-pad",
197
- )
198
- })