circuit-to-canvas 0.0.13 → 0.0.15

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 (40) hide show
  1. package/dist/index.d.ts +29 -29
  2. package/dist/index.js +187 -133
  3. package/lib/drawer/CircuitToCanvasDrawer.ts +31 -20
  4. package/lib/drawer/elements/pcb-board.ts +5 -5
  5. package/lib/drawer/elements/pcb-copper-pour.ts +13 -10
  6. package/lib/drawer/elements/pcb-copper-text.ts +4 -4
  7. package/lib/drawer/elements/pcb-cutout.ts +5 -5
  8. package/lib/drawer/elements/pcb-fabrication-note-path.ts +3 -3
  9. package/lib/drawer/elements/pcb-fabrication-note-rect.ts +3 -3
  10. package/lib/drawer/elements/pcb-fabrication-note-text.ts +4 -4
  11. package/lib/drawer/elements/pcb-hole.ts +8 -8
  12. package/lib/drawer/elements/pcb-note-line.ts +46 -0
  13. package/lib/drawer/elements/pcb-note-path.ts +3 -3
  14. package/lib/drawer/elements/pcb-note-rect.ts +3 -3
  15. package/lib/drawer/elements/pcb-note-text.ts +4 -4
  16. package/lib/drawer/elements/pcb-plated-hole.ts +14 -14
  17. package/lib/drawer/elements/pcb-silkscreen.ts +16 -16
  18. package/lib/drawer/elements/pcb-smtpad.ts +8 -8
  19. package/lib/drawer/elements/pcb-trace.ts +3 -3
  20. package/lib/drawer/elements/pcb-via.ts +4 -4
  21. package/lib/drawer/shapes/circle.ts +4 -4
  22. package/lib/drawer/shapes/line.ts +5 -5
  23. package/lib/drawer/shapes/oval.ts +13 -5
  24. package/lib/drawer/shapes/path.ts +8 -8
  25. package/lib/drawer/shapes/pill.ts +13 -5
  26. package/lib/drawer/shapes/polygon.ts +7 -7
  27. package/lib/drawer/shapes/rect.ts +7 -7
  28. package/lib/drawer/shapes/text.ts +5 -5
  29. package/lib/drawer/types.ts +1 -1
  30. package/package.json +1 -1
  31. package/tests/elements/__snapshots__/pcb-note-line-all-features.snap.png +0 -0
  32. package/tests/elements/__snapshots__/pcb-note-line-custom-color.snap.png +0 -0
  33. package/tests/elements/__snapshots__/pcb-note-line-dashed.snap.png +0 -0
  34. package/tests/elements/pcb-note-line-all-features.test.ts +36 -0
  35. package/tests/elements/pcb-note-line-custom-color.test.ts +30 -0
  36. package/tests/elements/pcb-note-line-dashed.test.ts +30 -0
  37. package/tests/shapes/circle.test.ts +1 -1
  38. package/tests/shapes/oval.test.ts +1 -1
  39. package/tests/shapes/pill.test.ts +2 -2
  40. package/tests/shapes/rect.test.ts +2 -2
package/dist/index.js CHANGED
@@ -38,9 +38,9 @@ var DEFAULT_PCB_COLOR_MAP = {
38
38
  // lib/drawer/shapes/circle.ts
39
39
  import { applyToPoint } from "transformation-matrix";
40
40
  function drawCircle(params) {
41
- const { ctx, center, radius, fill, transform } = params;
42
- const [cx, cy] = applyToPoint(transform, [center.x, center.y]);
43
- const scaledRadius = radius * Math.abs(transform.a);
41
+ const { ctx, center, radius, fill, realToCanvasMat } = params;
42
+ const [cx, cy] = applyToPoint(realToCanvasMat, [center.x, center.y]);
43
+ const scaledRadius = radius * Math.abs(realToCanvasMat.a);
44
44
  ctx.beginPath();
45
45
  ctx.arc(cx, cy, scaledRadius, 0, Math.PI * 2);
46
46
  ctx.fillStyle = fill;
@@ -56,18 +56,18 @@ function drawRect(params) {
56
56
  width,
57
57
  height,
58
58
  fill,
59
- transform,
59
+ realToCanvasMat,
60
60
  borderRadius = 0,
61
61
  rotation = 0,
62
62
  stroke,
63
63
  strokeWidth,
64
64
  isStrokeDashed = false
65
65
  } = params;
66
- const [cx, cy] = applyToPoint2(transform, [center.x, center.y]);
67
- const scaledWidth = width * Math.abs(transform.a);
68
- const scaledHeight = height * Math.abs(transform.a);
69
- const scaledRadius = borderRadius * Math.abs(transform.a);
70
- const scaledStrokeWidth = strokeWidth ? strokeWidth * Math.abs(transform.a) : void 0;
66
+ const [cx, cy] = applyToPoint2(realToCanvasMat, [center.x, center.y]);
67
+ const scaledWidth = width * Math.abs(realToCanvasMat.a);
68
+ const scaledHeight = height * Math.abs(realToCanvasMat.a);
69
+ const scaledRadius = borderRadius * Math.abs(realToCanvasMat.a);
70
+ const scaledStrokeWidth = strokeWidth ? strokeWidth * Math.abs(realToCanvasMat.a) : void 0;
71
71
  ctx.save();
72
72
  ctx.translate(cx, cy);
73
73
  if (rotation !== 0) {
@@ -116,10 +116,18 @@ function drawRect(params) {
116
116
  // lib/drawer/shapes/oval.ts
117
117
  import { applyToPoint as applyToPoint3 } from "transformation-matrix";
118
118
  function drawOval(params) {
119
- const { ctx, center, width, height, fill, transform, rotation = 0 } = params;
120
- const [cx, cy] = applyToPoint3(transform, [center.x, center.y]);
121
- const scaledWidth = width * Math.abs(transform.a);
122
- const scaledHeight = height * Math.abs(transform.a);
119
+ const {
120
+ ctx,
121
+ center,
122
+ width,
123
+ height,
124
+ fill,
125
+ realToCanvasMat,
126
+ rotation = 0
127
+ } = params;
128
+ const [cx, cy] = applyToPoint3(realToCanvasMat, [center.x, center.y]);
129
+ const scaledWidth = width * Math.abs(realToCanvasMat.a);
130
+ const scaledHeight = height * Math.abs(realToCanvasMat.a);
123
131
  ctx.save();
124
132
  ctx.translate(cx, cy);
125
133
  if (rotation !== 0) {
@@ -135,10 +143,18 @@ function drawOval(params) {
135
143
  // lib/drawer/shapes/pill.ts
136
144
  import { applyToPoint as applyToPoint4 } from "transformation-matrix";
137
145
  function drawPill(params) {
138
- const { ctx, center, width, height, fill, transform, rotation = 0 } = params;
139
- const [cx, cy] = applyToPoint4(transform, [center.x, center.y]);
140
- const scaledWidth = width * Math.abs(transform.a);
141
- const scaledHeight = height * Math.abs(transform.a);
146
+ const {
147
+ ctx,
148
+ center,
149
+ width,
150
+ height,
151
+ fill,
152
+ realToCanvasMat,
153
+ rotation = 0
154
+ } = params;
155
+ const [cx, cy] = applyToPoint4(realToCanvasMat, [center.x, center.y]);
156
+ const scaledWidth = width * Math.abs(realToCanvasMat.a);
157
+ const scaledHeight = height * Math.abs(realToCanvasMat.a);
142
158
  ctx.save();
143
159
  ctx.translate(cx, cy);
144
160
  if (rotation !== 0) {
@@ -172,21 +188,21 @@ function drawPill(params) {
172
188
 
173
189
  // lib/drawer/elements/pcb-plated-hole.ts
174
190
  function drawPcbPlatedHole(params) {
175
- const { ctx, hole, transform, colorMap } = params;
191
+ const { ctx, hole, realToCanvasMat, colorMap } = params;
176
192
  if (hole.shape === "circle") {
177
193
  drawCircle({
178
194
  ctx,
179
195
  center: { x: hole.x, y: hole.y },
180
196
  radius: hole.outer_diameter / 2,
181
197
  fill: colorMap.copper.top,
182
- transform
198
+ realToCanvasMat
183
199
  });
184
200
  drawCircle({
185
201
  ctx,
186
202
  center: { x: hole.x, y: hole.y },
187
203
  radius: hole.hole_diameter / 2,
188
204
  fill: colorMap.drill,
189
- transform
205
+ realToCanvasMat
190
206
  });
191
207
  return;
192
208
  }
@@ -197,7 +213,7 @@ function drawPcbPlatedHole(params) {
197
213
  width: hole.outer_width,
198
214
  height: hole.outer_height,
199
215
  fill: colorMap.copper.top,
200
- transform,
216
+ realToCanvasMat,
201
217
  rotation: hole.ccw_rotation
202
218
  });
203
219
  drawOval({
@@ -206,7 +222,7 @@ function drawPcbPlatedHole(params) {
206
222
  width: hole.hole_width,
207
223
  height: hole.hole_height,
208
224
  fill: colorMap.drill,
209
- transform,
225
+ realToCanvasMat,
210
226
  rotation: hole.ccw_rotation
211
227
  });
212
228
  return;
@@ -218,7 +234,7 @@ function drawPcbPlatedHole(params) {
218
234
  width: hole.outer_width,
219
235
  height: hole.outer_height,
220
236
  fill: colorMap.copper.top,
221
- transform,
237
+ realToCanvasMat,
222
238
  rotation: hole.ccw_rotation
223
239
  });
224
240
  drawPill({
@@ -227,7 +243,7 @@ function drawPcbPlatedHole(params) {
227
243
  width: hole.hole_width,
228
244
  height: hole.hole_height,
229
245
  fill: colorMap.drill,
230
- transform,
246
+ realToCanvasMat,
231
247
  rotation: hole.ccw_rotation
232
248
  });
233
249
  return;
@@ -239,7 +255,7 @@ function drawPcbPlatedHole(params) {
239
255
  width: hole.rect_pad_width,
240
256
  height: hole.rect_pad_height,
241
257
  fill: colorMap.copper.top,
242
- transform,
258
+ realToCanvasMat,
243
259
  borderRadius: hole.rect_border_radius ?? 0
244
260
  });
245
261
  const holeX = hole.x + (hole.hole_offset_x ?? 0);
@@ -249,7 +265,7 @@ function drawPcbPlatedHole(params) {
249
265
  center: { x: holeX, y: holeY },
250
266
  radius: hole.hole_diameter / 2,
251
267
  fill: colorMap.drill,
252
- transform
268
+ realToCanvasMat
253
269
  });
254
270
  return;
255
271
  }
@@ -260,7 +276,7 @@ function drawPcbPlatedHole(params) {
260
276
  width: hole.rect_pad_width,
261
277
  height: hole.rect_pad_height,
262
278
  fill: colorMap.copper.top,
263
- transform,
279
+ realToCanvasMat,
264
280
  borderRadius: hole.rect_border_radius ?? 0
265
281
  });
266
282
  const holeX = hole.x + (hole.hole_offset_x ?? 0);
@@ -271,7 +287,7 @@ function drawPcbPlatedHole(params) {
271
287
  width: hole.hole_width,
272
288
  height: hole.hole_height,
273
289
  fill: colorMap.drill,
274
- transform
290
+ realToCanvasMat
275
291
  });
276
292
  return;
277
293
  }
@@ -282,7 +298,7 @@ function drawPcbPlatedHole(params) {
282
298
  width: hole.rect_pad_width,
283
299
  height: hole.rect_pad_height,
284
300
  fill: colorMap.copper.top,
285
- transform,
301
+ realToCanvasMat,
286
302
  borderRadius: hole.rect_border_radius ?? 0,
287
303
  rotation: hole.rect_ccw_rotation
288
304
  });
@@ -294,7 +310,7 @@ function drawPcbPlatedHole(params) {
294
310
  width: hole.hole_width,
295
311
  height: hole.hole_height,
296
312
  fill: colorMap.drill,
297
- transform,
313
+ realToCanvasMat,
298
314
  rotation: hole.hole_ccw_rotation
299
315
  });
300
316
  return;
@@ -303,33 +319,33 @@ function drawPcbPlatedHole(params) {
303
319
 
304
320
  // lib/drawer/elements/pcb-via.ts
305
321
  function drawPcbVia(params) {
306
- const { ctx, via, transform, colorMap } = params;
322
+ const { ctx, via, realToCanvasMat, colorMap } = params;
307
323
  drawCircle({
308
324
  ctx,
309
325
  center: { x: via.x, y: via.y },
310
326
  radius: via.outer_diameter / 2,
311
327
  fill: colorMap.copper.top,
312
- transform
328
+ realToCanvasMat
313
329
  });
314
330
  drawCircle({
315
331
  ctx,
316
332
  center: { x: via.x, y: via.y },
317
333
  radius: via.hole_diameter / 2,
318
334
  fill: colorMap.drill,
319
- transform
335
+ realToCanvasMat
320
336
  });
321
337
  }
322
338
 
323
339
  // lib/drawer/elements/pcb-hole.ts
324
340
  function drawPcbHole(params) {
325
- const { ctx, hole, transform, colorMap } = params;
341
+ const { ctx, hole, realToCanvasMat, colorMap } = params;
326
342
  if (hole.hole_shape === "circle") {
327
343
  drawCircle({
328
344
  ctx,
329
345
  center: { x: hole.x, y: hole.y },
330
346
  radius: hole.hole_diameter / 2,
331
347
  fill: colorMap.drill,
332
- transform
348
+ realToCanvasMat
333
349
  });
334
350
  return;
335
351
  }
@@ -340,7 +356,7 @@ function drawPcbHole(params) {
340
356
  width: hole.hole_diameter,
341
357
  height: hole.hole_diameter,
342
358
  fill: colorMap.drill,
343
- transform
359
+ realToCanvasMat
344
360
  });
345
361
  return;
346
362
  }
@@ -351,7 +367,7 @@ function drawPcbHole(params) {
351
367
  width: hole.hole_width,
352
368
  height: hole.hole_height,
353
369
  fill: colorMap.drill,
354
- transform
370
+ realToCanvasMat
355
371
  });
356
372
  return;
357
373
  }
@@ -362,7 +378,7 @@ function drawPcbHole(params) {
362
378
  width: hole.hole_width,
363
379
  height: hole.hole_height,
364
380
  fill: colorMap.drill,
365
- transform
381
+ realToCanvasMat
366
382
  });
367
383
  return;
368
384
  }
@@ -373,7 +389,7 @@ function drawPcbHole(params) {
373
389
  width: hole.hole_width,
374
390
  height: hole.hole_height,
375
391
  fill: colorMap.drill,
376
- transform
392
+ realToCanvasMat
377
393
  });
378
394
  return;
379
395
  }
@@ -384,7 +400,7 @@ function drawPcbHole(params) {
384
400
  width: hole.hole_width,
385
401
  height: hole.hole_height,
386
402
  fill: colorMap.drill,
387
- transform,
403
+ realToCanvasMat,
388
404
  rotation: hole.ccw_rotation ?? 0
389
405
  });
390
406
  return;
@@ -394,18 +410,18 @@ function drawPcbHole(params) {
394
410
  // lib/drawer/shapes/polygon.ts
395
411
  import { applyToPoint as applyToPoint5 } from "transformation-matrix";
396
412
  function drawPolygon(params) {
397
- const { ctx, points, fill, transform } = params;
413
+ const { ctx, points, fill, realToCanvasMat } = params;
398
414
  if (points.length < 3) return;
399
415
  ctx.beginPath();
400
- const transformedPoints = points.map(
401
- (p) => applyToPoint5(transform, [p.x, p.y])
416
+ const canvasPoints = points.map(
417
+ (p) => applyToPoint5(realToCanvasMat, [p.x, p.y])
402
418
  );
403
- const firstPoint = transformedPoints[0];
419
+ const firstPoint = canvasPoints[0];
404
420
  if (!firstPoint) return;
405
421
  const [firstX, firstY] = firstPoint;
406
422
  ctx.moveTo(firstX, firstY);
407
- for (let i = 1; i < transformedPoints.length; i++) {
408
- const point = transformedPoints[i];
423
+ for (let i = 1; i < canvasPoints.length; i++) {
424
+ const point = canvasPoints[i];
409
425
  if (!point) continue;
410
426
  const [x, y] = point;
411
427
  ctx.lineTo(x, y);
@@ -420,7 +436,7 @@ function layerToColor(layer, colorMap) {
420
436
  return colorMap.copper[layer] ?? colorMap.copper.top;
421
437
  }
422
438
  function drawPcbSmtPad(params) {
423
- const { ctx, pad, transform, colorMap } = params;
439
+ const { ctx, pad, realToCanvasMat, colorMap } = params;
424
440
  const color = layerToColor(pad.layer, colorMap);
425
441
  if (pad.shape === "rect") {
426
442
  drawRect({
@@ -429,7 +445,7 @@ function drawPcbSmtPad(params) {
429
445
  width: pad.width,
430
446
  height: pad.height,
431
447
  fill: color,
432
- transform,
448
+ realToCanvasMat,
433
449
  borderRadius: pad.corner_radius ?? pad.rect_border_radius ?? 0
434
450
  });
435
451
  return;
@@ -441,7 +457,7 @@ function drawPcbSmtPad(params) {
441
457
  width: pad.width,
442
458
  height: pad.height,
443
459
  fill: color,
444
- transform,
460
+ realToCanvasMat,
445
461
  borderRadius: pad.corner_radius ?? pad.rect_border_radius ?? 0,
446
462
  rotation: pad.ccw_rotation ?? 0
447
463
  });
@@ -453,7 +469,7 @@ function drawPcbSmtPad(params) {
453
469
  center: { x: pad.x, y: pad.y },
454
470
  radius: pad.radius,
455
471
  fill: color,
456
- transform
472
+ realToCanvasMat
457
473
  });
458
474
  return;
459
475
  }
@@ -464,7 +480,7 @@ function drawPcbSmtPad(params) {
464
480
  width: pad.width,
465
481
  height: pad.height,
466
482
  fill: color,
467
- transform
483
+ realToCanvasMat
468
484
  });
469
485
  return;
470
486
  }
@@ -475,7 +491,7 @@ function drawPcbSmtPad(params) {
475
491
  width: pad.width,
476
492
  height: pad.height,
477
493
  fill: color,
478
- transform,
494
+ realToCanvasMat,
479
495
  rotation: pad.ccw_rotation ?? 0
480
496
  });
481
497
  return;
@@ -486,7 +502,7 @@ function drawPcbSmtPad(params) {
486
502
  ctx,
487
503
  points: pad.points,
488
504
  fill: color,
489
- transform
505
+ realToCanvasMat
490
506
  });
491
507
  }
492
508
  return;
@@ -502,12 +518,12 @@ function drawLine(params) {
502
518
  end,
503
519
  strokeWidth,
504
520
  stroke,
505
- transform,
521
+ realToCanvasMat,
506
522
  lineCap = "round"
507
523
  } = params;
508
- const [x1, y1] = applyToPoint6(transform, [start.x, start.y]);
509
- const [x2, y2] = applyToPoint6(transform, [end.x, end.y]);
510
- const scaledStrokeWidth = strokeWidth * Math.abs(transform.a);
524
+ const [x1, y1] = applyToPoint6(realToCanvasMat, [start.x, start.y]);
525
+ const [x2, y2] = applyToPoint6(realToCanvasMat, [end.x, end.y]);
526
+ const scaledStrokeWidth = strokeWidth * Math.abs(realToCanvasMat.a);
511
527
  ctx.beginPath();
512
528
  ctx.moveTo(x1, y1);
513
529
  ctx.lineTo(x2, y2);
@@ -522,7 +538,7 @@ function layerToColor2(layer, colorMap) {
522
538
  return colorMap.copper[layer] ?? colorMap.copper.top;
523
539
  }
524
540
  function drawPcbTrace(params) {
525
- const { ctx, trace, transform, colorMap } = params;
541
+ const { ctx, trace, realToCanvasMat, colorMap } = params;
526
542
  if (!trace.route || !Array.isArray(trace.route) || trace.route.length < 2) {
527
543
  return;
528
544
  }
@@ -540,7 +556,7 @@ function drawPcbTrace(params) {
540
556
  end: { x: end.x, y: end.y },
541
557
  strokeWidth: traceWidth,
542
558
  stroke: color,
543
- transform,
559
+ realToCanvasMat,
544
560
  lineCap: "round"
545
561
  });
546
562
  }
@@ -555,20 +571,20 @@ function drawPath(params) {
555
571
  fill,
556
572
  stroke,
557
573
  strokeWidth = 1,
558
- transform,
574
+ realToCanvasMat,
559
575
  closePath = false
560
576
  } = params;
561
577
  if (points.length < 2) return;
562
578
  ctx.beginPath();
563
- const transformedPoints = points.map(
564
- (p) => applyToPoint7(transform, [p.x, p.y])
579
+ const canvasPoints = points.map(
580
+ (p) => applyToPoint7(realToCanvasMat, [p.x, p.y])
565
581
  );
566
- const firstPoint = transformedPoints[0];
582
+ const firstPoint = canvasPoints[0];
567
583
  if (!firstPoint) return;
568
584
  const [firstX, firstY] = firstPoint;
569
585
  ctx.moveTo(firstX, firstY);
570
- for (let i = 1; i < transformedPoints.length; i++) {
571
- const point = transformedPoints[i];
586
+ for (let i = 1; i < canvasPoints.length; i++) {
587
+ const point = canvasPoints[i];
572
588
  if (!point) continue;
573
589
  const [x, y] = point;
574
590
  ctx.lineTo(x, y);
@@ -581,7 +597,7 @@ function drawPath(params) {
581
597
  ctx.fill();
582
598
  }
583
599
  if (stroke) {
584
- const scaledStrokeWidth = strokeWidth * Math.abs(transform.a);
600
+ const scaledStrokeWidth = strokeWidth * Math.abs(realToCanvasMat.a);
585
601
  ctx.strokeStyle = stroke;
586
602
  ctx.lineWidth = scaledStrokeWidth;
587
603
  ctx.stroke();
@@ -590,7 +606,7 @@ function drawPath(params) {
590
606
 
591
607
  // lib/drawer/elements/pcb-board.ts
592
608
  function drawPcbBoard(params) {
593
- const { ctx, board, transform, colorMap } = params;
609
+ const { ctx, board, realToCanvasMat, colorMap } = params;
594
610
  const { width, height, center, outline } = board;
595
611
  if (outline && Array.isArray(outline) && outline.length >= 3) {
596
612
  drawPath({
@@ -598,7 +614,7 @@ function drawPcbBoard(params) {
598
614
  points: outline.map((p) => ({ x: p.x, y: p.y })),
599
615
  stroke: colorMap.boardOutline,
600
616
  strokeWidth: 0.1,
601
- transform,
617
+ realToCanvasMat,
602
618
  closePath: true
603
619
  });
604
620
  return;
@@ -610,7 +626,7 @@ function drawPcbBoard(params) {
610
626
  width,
611
627
  height,
612
628
  fill: "transparent",
613
- transform
629
+ realToCanvasMat
614
630
  });
615
631
  const halfWidth = width / 2;
616
632
  const halfHeight = height / 2;
@@ -625,7 +641,7 @@ function drawPcbBoard(params) {
625
641
  points: corners,
626
642
  stroke: colorMap.boardOutline,
627
643
  strokeWidth: 0.1,
628
- transform,
644
+ realToCanvasMat,
629
645
  closePath: true
630
646
  });
631
647
  }
@@ -643,13 +659,13 @@ function mapAnchorAlignment(alignment) {
643
659
  return "center";
644
660
  }
645
661
  function drawPcbSilkscreenText(params) {
646
- const { ctx, text, transform, colorMap } = params;
662
+ const { ctx, text, realToCanvasMat, colorMap } = params;
647
663
  const color = layerToSilkscreenColor(text.layer, colorMap);
648
- const [x, y] = applyToPoint8(transform, [
664
+ const [x, y] = applyToPoint8(realToCanvasMat, [
649
665
  text.anchor_position.x,
650
666
  text.anchor_position.y
651
667
  ]);
652
- const fontSize = (text.font_size ?? 1) * Math.abs(transform.a);
668
+ const fontSize = (text.font_size ?? 1) * Math.abs(realToCanvasMat.a);
653
669
  const rotation = text.ccw_rotation ?? 0;
654
670
  ctx.save();
655
671
  ctx.translate(x, y);
@@ -663,7 +679,7 @@ function drawPcbSilkscreenText(params) {
663
679
  ctx.restore();
664
680
  }
665
681
  function drawPcbSilkscreenRect(params) {
666
- const { ctx, rect, transform, colorMap } = params;
682
+ const { ctx, rect, realToCanvasMat, colorMap } = params;
667
683
  const color = layerToSilkscreenColor(rect.layer, colorMap);
668
684
  drawRect({
669
685
  ctx,
@@ -671,22 +687,22 @@ function drawPcbSilkscreenRect(params) {
671
687
  width: rect.width,
672
688
  height: rect.height,
673
689
  fill: color,
674
- transform
690
+ realToCanvasMat
675
691
  });
676
692
  }
677
693
  function drawPcbSilkscreenCircle(params) {
678
- const { ctx, circle, transform, colorMap } = params;
694
+ const { ctx, circle, realToCanvasMat, colorMap } = params;
679
695
  const color = layerToSilkscreenColor(circle.layer, colorMap);
680
696
  drawCircle({
681
697
  ctx,
682
698
  center: circle.center,
683
699
  radius: circle.radius,
684
700
  fill: color,
685
- transform
701
+ realToCanvasMat
686
702
  });
687
703
  }
688
704
  function drawPcbSilkscreenLine(params) {
689
- const { ctx, line, transform, colorMap } = params;
705
+ const { ctx, line, realToCanvasMat, colorMap } = params;
690
706
  const color = layerToSilkscreenColor(line.layer, colorMap);
691
707
  drawLine({
692
708
  ctx,
@@ -694,11 +710,11 @@ function drawPcbSilkscreenLine(params) {
694
710
  end: { x: line.x2, y: line.y2 },
695
711
  strokeWidth: line.stroke_width ?? 0.1,
696
712
  stroke: color,
697
- transform
713
+ realToCanvasMat
698
714
  });
699
715
  }
700
716
  function drawPcbSilkscreenPath(params) {
701
- const { ctx, path, transform, colorMap } = params;
717
+ const { ctx, path, realToCanvasMat, colorMap } = params;
702
718
  const color = layerToSilkscreenColor(path.layer, colorMap);
703
719
  if (!path.route || path.route.length < 2) return;
704
720
  for (let i = 0; i < path.route.length - 1; i++) {
@@ -711,14 +727,14 @@ function drawPcbSilkscreenPath(params) {
711
727
  end: { x: end.x, y: end.y },
712
728
  strokeWidth: path.stroke_width ?? 0.1,
713
729
  stroke: color,
714
- transform
730
+ realToCanvasMat
715
731
  });
716
732
  }
717
733
  }
718
734
 
719
735
  // lib/drawer/elements/pcb-cutout.ts
720
736
  function drawPcbCutout(params) {
721
- const { ctx, cutout, transform, colorMap } = params;
737
+ const { ctx, cutout, realToCanvasMat, colorMap } = params;
722
738
  if (cutout.shape === "rect") {
723
739
  drawRect({
724
740
  ctx,
@@ -726,7 +742,7 @@ function drawPcbCutout(params) {
726
742
  width: cutout.width,
727
743
  height: cutout.height,
728
744
  fill: colorMap.drill,
729
- transform,
745
+ realToCanvasMat,
730
746
  rotation: cutout.rotation ?? 0
731
747
  });
732
748
  return;
@@ -737,7 +753,7 @@ function drawPcbCutout(params) {
737
753
  center: cutout.center,
738
754
  radius: cutout.radius,
739
755
  fill: colorMap.drill,
740
- transform
756
+ realToCanvasMat
741
757
  });
742
758
  return;
743
759
  }
@@ -747,7 +763,7 @@ function drawPcbCutout(params) {
747
763
  ctx,
748
764
  points: cutout.points,
749
765
  fill: colorMap.drill,
750
- transform
766
+ realToCanvasMat
751
767
  });
752
768
  }
753
769
  return;
@@ -760,13 +776,16 @@ function layerToColor3(layer, colorMap) {
760
776
  return colorMap.copper[layer] ?? colorMap.copper.top;
761
777
  }
762
778
  function drawPcbCopperPour(params) {
763
- const { ctx, pour, transform, colorMap } = params;
779
+ const { ctx, pour, realToCanvasMat, colorMap } = params;
764
780
  const color = layerToColor3(pour.layer, colorMap);
765
781
  ctx.save();
766
782
  if (pour.shape === "rect") {
767
- const [cx, cy] = applyToPoint9(transform, [pour.center.x, pour.center.y]);
768
- const scaledWidth = pour.width * Math.abs(transform.a);
769
- const scaledHeight = pour.height * Math.abs(transform.a);
783
+ const [cx, cy] = applyToPoint9(realToCanvasMat, [
784
+ pour.center.x,
785
+ pour.center.y
786
+ ]);
787
+ const scaledWidth = pour.width * Math.abs(realToCanvasMat.a);
788
+ const scaledHeight = pour.height * Math.abs(realToCanvasMat.a);
770
789
  ctx.translate(cx, cy);
771
790
  if (pour.rotation) {
772
791
  ctx.rotate(-pour.rotation * (Math.PI / 180));
@@ -781,10 +800,10 @@ function drawPcbCopperPour(params) {
781
800
  }
782
801
  if (pour.shape === "polygon") {
783
802
  if (pour.points && pour.points.length >= 3) {
784
- const transformedPoints = pour.points.map(
785
- (p) => applyToPoint9(transform, [p.x, p.y])
803
+ const canvasPoints = pour.points.map(
804
+ (p) => applyToPoint9(realToCanvasMat, [p.x, p.y])
786
805
  );
787
- const firstPoint = transformedPoints[0];
806
+ const firstPoint = canvasPoints[0];
788
807
  if (!firstPoint) {
789
808
  ctx.restore();
790
809
  return;
@@ -792,8 +811,8 @@ function drawPcbCopperPour(params) {
792
811
  ctx.beginPath();
793
812
  const [firstX, firstY] = firstPoint;
794
813
  ctx.moveTo(firstX, firstY);
795
- for (let i = 1; i < transformedPoints.length; i++) {
796
- const point = transformedPoints[i];
814
+ for (let i = 1; i < canvasPoints.length; i++) {
815
+ const point = canvasPoints[i];
797
816
  if (!point) continue;
798
817
  const [x, y] = point;
799
818
  ctx.lineTo(x, y);
@@ -898,18 +917,18 @@ function drawText(params) {
898
917
  y,
899
918
  fontSize,
900
919
  color,
901
- transform,
920
+ realToCanvasMat,
902
921
  anchorAlignment,
903
922
  rotation = 0
904
923
  } = params;
905
924
  if (!text) return;
906
- const [transformedX, transformedY] = applyToPoint10(transform, [x, y]);
907
- const scale2 = Math.abs(transform.a);
925
+ const [canvasX, canvasY] = applyToPoint10(realToCanvasMat, [x, y]);
926
+ const scale2 = Math.abs(realToCanvasMat.a);
908
927
  const scaledFontSize = fontSize * scale2;
909
928
  const layout = getAlphabetLayout(text, scaledFontSize);
910
929
  const startPos = getTextStartPosition(anchorAlignment, layout);
911
930
  ctx.save();
912
- ctx.translate(transformedX, transformedY);
931
+ ctx.translate(canvasX, canvasY);
913
932
  if (rotation !== 0) {
914
933
  ctx.rotate(-rotation * (Math.PI / 180));
915
934
  }
@@ -933,14 +952,14 @@ function mapAnchorAlignment2(alignment) {
933
952
  return "center";
934
953
  }
935
954
  function drawPcbCopperText(params) {
936
- const { ctx, text, transform, colorMap } = params;
955
+ const { ctx, text, realToCanvasMat, colorMap } = params;
937
956
  const content = text.text ?? "";
938
957
  if (!content) return;
939
- const [x, y] = applyToPoint11(transform, [
958
+ const [x, y] = applyToPoint11(realToCanvasMat, [
940
959
  text.anchor_position.x,
941
960
  text.anchor_position.y
942
961
  ]);
943
- const scale2 = Math.abs(transform.a);
962
+ const scale2 = Math.abs(realToCanvasMat.a);
944
963
  const fontSize = (text.font_size ?? 1) * scale2;
945
964
  const rotation = text.ccw_rotation ?? 0;
946
965
  const padding = {
@@ -998,7 +1017,7 @@ function layerToColor4(layer, colorMap) {
998
1017
  return DEFAULT_FABRICATION_NOTE_COLOR;
999
1018
  }
1000
1019
  function drawPcbFabricationNoteText(params) {
1001
- const { ctx, text, transform, colorMap } = params;
1020
+ const { ctx, text, realToCanvasMat, colorMap } = params;
1002
1021
  const defaultColor = layerToColor4(text.layer, colorMap);
1003
1022
  const color = text.color ?? defaultColor;
1004
1023
  const fontSize = text.font_size;
@@ -1009,14 +1028,14 @@ function drawPcbFabricationNoteText(params) {
1009
1028
  y: text.anchor_position.y,
1010
1029
  fontSize,
1011
1030
  color,
1012
- transform,
1031
+ realToCanvasMat,
1013
1032
  anchorAlignment: text.anchor_alignment
1014
1033
  });
1015
1034
  }
1016
1035
 
1017
1036
  // lib/drawer/elements/pcb-fabrication-note-rect.ts
1018
1037
  function drawPcbFabricationNoteRect(params) {
1019
- const { ctx, rect, transform, colorMap } = params;
1038
+ const { ctx, rect, realToCanvasMat, colorMap } = params;
1020
1039
  const defaultColor = "rgba(255,255,255,0.5)";
1021
1040
  const color = rect.color ?? defaultColor;
1022
1041
  const isFilled = rect.is_filled ?? false;
@@ -1031,14 +1050,14 @@ function drawPcbFabricationNoteRect(params) {
1031
1050
  stroke: hasStroke ? color : void 0,
1032
1051
  strokeWidth: hasStroke ? rect.stroke_width : void 0,
1033
1052
  borderRadius: rect.corner_radius,
1034
- transform,
1053
+ realToCanvasMat,
1035
1054
  isStrokeDashed
1036
1055
  });
1037
1056
  }
1038
1057
 
1039
1058
  // lib/drawer/elements/pcb-note-rect.ts
1040
1059
  function drawPcbNoteRect(params) {
1041
- const { ctx, rect, transform, colorMap } = params;
1060
+ const { ctx, rect, realToCanvasMat, colorMap } = params;
1042
1061
  const defaultColor = "rgb(89, 148, 220)";
1043
1062
  const color = rect.color ?? defaultColor;
1044
1063
  const isFilled = rect.is_filled ?? false;
@@ -1053,14 +1072,14 @@ function drawPcbNoteRect(params) {
1053
1072
  stroke: hasStroke ? color : void 0,
1054
1073
  strokeWidth: hasStroke ? rect.stroke_width : void 0,
1055
1074
  borderRadius: rect.corner_radius,
1056
- transform,
1075
+ realToCanvasMat,
1057
1076
  isStrokeDashed
1058
1077
  });
1059
1078
  }
1060
1079
 
1061
1080
  // lib/drawer/elements/pcb-fabrication-note-path.ts
1062
1081
  function drawPcbFabricationNotePath(params) {
1063
- const { ctx, path, transform, colorMap } = params;
1082
+ const { ctx, path, realToCanvasMat, colorMap } = params;
1064
1083
  const defaultColor = "rgba(255,255,255,0.5)";
1065
1084
  const color = path.color ?? defaultColor;
1066
1085
  if (!path.route || path.route.length < 2) return;
@@ -1074,14 +1093,14 @@ function drawPcbFabricationNotePath(params) {
1074
1093
  end: { x: end.x, y: end.y },
1075
1094
  strokeWidth: path.stroke_width ?? 0.1,
1076
1095
  stroke: color,
1077
- transform
1096
+ realToCanvasMat
1078
1097
  });
1079
1098
  }
1080
1099
  }
1081
1100
 
1082
1101
  // lib/drawer/elements/pcb-note-path.ts
1083
1102
  function drawPcbNotePath(params) {
1084
- const { ctx, path, transform, colorMap } = params;
1103
+ const { ctx, path, realToCanvasMat, colorMap } = params;
1085
1104
  const defaultColor = "rgb(89, 148, 220)";
1086
1105
  const color = path.color ?? defaultColor;
1087
1106
  if (!path.route || path.route.length < 2) return;
@@ -1095,7 +1114,7 @@ function drawPcbNotePath(params) {
1095
1114
  end: { x: end.x, y: end.y },
1096
1115
  strokeWidth: path.stroke_width ?? 0.1,
1097
1116
  stroke: color,
1098
- transform
1117
+ realToCanvasMat
1099
1118
  });
1100
1119
  }
1101
1120
  }
@@ -1103,7 +1122,7 @@ function drawPcbNotePath(params) {
1103
1122
  // lib/drawer/elements/pcb-note-text.ts
1104
1123
  var DEFAULT_NOTE_TEXT_COLOR = "rgb(89, 148, 220)";
1105
1124
  function drawPcbNoteText(params) {
1106
- const { ctx, text, transform, colorMap } = params;
1125
+ const { ctx, text, realToCanvasMat, colorMap } = params;
1107
1126
  const defaultColor = DEFAULT_NOTE_TEXT_COLOR;
1108
1127
  const color = text.color ?? defaultColor;
1109
1128
  const fontSize = text.font_size ?? 1;
@@ -1114,11 +1133,38 @@ function drawPcbNoteText(params) {
1114
1133
  y: text.anchor_position.y,
1115
1134
  fontSize,
1116
1135
  color,
1117
- transform,
1136
+ realToCanvasMat,
1118
1137
  anchorAlignment: text.anchor_alignment ?? "center"
1119
1138
  });
1120
1139
  }
1121
1140
 
1141
+ // lib/drawer/elements/pcb-note-line.ts
1142
+ import { applyToPoint as applyToPoint12 } from "transformation-matrix";
1143
+ function drawPcbNoteLine(params) {
1144
+ const { ctx, line, realToCanvasMat, colorMap } = params;
1145
+ const defaultColor = "rgb(89, 148, 220)";
1146
+ const color = line.color ?? defaultColor;
1147
+ const strokeWidth = line.stroke_width ?? 0.1;
1148
+ const isDashed = line.is_dashed ?? false;
1149
+ const [x1, y1] = applyToPoint12(realToCanvasMat, [line.x1, line.y1]);
1150
+ const [x2, y2] = applyToPoint12(realToCanvasMat, [line.x2, line.y2]);
1151
+ const scaledStrokeWidth = strokeWidth * Math.abs(realToCanvasMat.a);
1152
+ ctx.save();
1153
+ if (isDashed) {
1154
+ ctx.setLineDash([scaledStrokeWidth * 2, scaledStrokeWidth * 2]);
1155
+ } else {
1156
+ ctx.setLineDash([]);
1157
+ }
1158
+ ctx.beginPath();
1159
+ ctx.moveTo(x1, y1);
1160
+ ctx.lineTo(x2, y2);
1161
+ ctx.lineWidth = scaledStrokeWidth;
1162
+ ctx.strokeStyle = color;
1163
+ ctx.lineCap = "round";
1164
+ ctx.stroke();
1165
+ ctx.restore();
1166
+ }
1167
+
1122
1168
  // lib/drawer/CircuitToCanvasDrawer.ts
1123
1169
  var CircuitToCanvasDrawer = class {
1124
1170
  ctx;
@@ -1192,7 +1238,7 @@ var CircuitToCanvasDrawer = class {
1192
1238
  drawPcbPlatedHole({
1193
1239
  ctx: this.ctx,
1194
1240
  hole: element,
1195
- transform: this.realToCanvasMat,
1241
+ realToCanvasMat: this.realToCanvasMat,
1196
1242
  colorMap: this.colorMap
1197
1243
  });
1198
1244
  }
@@ -1200,7 +1246,7 @@ var CircuitToCanvasDrawer = class {
1200
1246
  drawPcbVia({
1201
1247
  ctx: this.ctx,
1202
1248
  via: element,
1203
- transform: this.realToCanvasMat,
1249
+ realToCanvasMat: this.realToCanvasMat,
1204
1250
  colorMap: this.colorMap
1205
1251
  });
1206
1252
  }
@@ -1208,7 +1254,7 @@ var CircuitToCanvasDrawer = class {
1208
1254
  drawPcbHole({
1209
1255
  ctx: this.ctx,
1210
1256
  hole: element,
1211
- transform: this.realToCanvasMat,
1257
+ realToCanvasMat: this.realToCanvasMat,
1212
1258
  colorMap: this.colorMap
1213
1259
  });
1214
1260
  }
@@ -1216,7 +1262,7 @@ var CircuitToCanvasDrawer = class {
1216
1262
  drawPcbSmtPad({
1217
1263
  ctx: this.ctx,
1218
1264
  pad: element,
1219
- transform: this.realToCanvasMat,
1265
+ realToCanvasMat: this.realToCanvasMat,
1220
1266
  colorMap: this.colorMap
1221
1267
  });
1222
1268
  }
@@ -1224,7 +1270,7 @@ var CircuitToCanvasDrawer = class {
1224
1270
  drawPcbTrace({
1225
1271
  ctx: this.ctx,
1226
1272
  trace: element,
1227
- transform: this.realToCanvasMat,
1273
+ realToCanvasMat: this.realToCanvasMat,
1228
1274
  colorMap: this.colorMap
1229
1275
  });
1230
1276
  }
@@ -1232,7 +1278,7 @@ var CircuitToCanvasDrawer = class {
1232
1278
  drawPcbBoard({
1233
1279
  ctx: this.ctx,
1234
1280
  board: element,
1235
- transform: this.realToCanvasMat,
1281
+ realToCanvasMat: this.realToCanvasMat,
1236
1282
  colorMap: this.colorMap
1237
1283
  });
1238
1284
  }
@@ -1240,7 +1286,7 @@ var CircuitToCanvasDrawer = class {
1240
1286
  drawPcbSilkscreenText({
1241
1287
  ctx: this.ctx,
1242
1288
  text: element,
1243
- transform: this.realToCanvasMat,
1289
+ realToCanvasMat: this.realToCanvasMat,
1244
1290
  colorMap: this.colorMap
1245
1291
  });
1246
1292
  }
@@ -1248,7 +1294,7 @@ var CircuitToCanvasDrawer = class {
1248
1294
  drawPcbSilkscreenRect({
1249
1295
  ctx: this.ctx,
1250
1296
  rect: element,
1251
- transform: this.realToCanvasMat,
1297
+ realToCanvasMat: this.realToCanvasMat,
1252
1298
  colorMap: this.colorMap
1253
1299
  });
1254
1300
  }
@@ -1256,7 +1302,7 @@ var CircuitToCanvasDrawer = class {
1256
1302
  drawPcbSilkscreenCircle({
1257
1303
  ctx: this.ctx,
1258
1304
  circle: element,
1259
- transform: this.realToCanvasMat,
1305
+ realToCanvasMat: this.realToCanvasMat,
1260
1306
  colorMap: this.colorMap
1261
1307
  });
1262
1308
  }
@@ -1264,7 +1310,7 @@ var CircuitToCanvasDrawer = class {
1264
1310
  drawPcbSilkscreenLine({
1265
1311
  ctx: this.ctx,
1266
1312
  line: element,
1267
- transform: this.realToCanvasMat,
1313
+ realToCanvasMat: this.realToCanvasMat,
1268
1314
  colorMap: this.colorMap
1269
1315
  });
1270
1316
  }
@@ -1272,7 +1318,7 @@ var CircuitToCanvasDrawer = class {
1272
1318
  drawPcbSilkscreenPath({
1273
1319
  ctx: this.ctx,
1274
1320
  path: element,
1275
- transform: this.realToCanvasMat,
1321
+ realToCanvasMat: this.realToCanvasMat,
1276
1322
  colorMap: this.colorMap
1277
1323
  });
1278
1324
  }
@@ -1280,7 +1326,7 @@ var CircuitToCanvasDrawer = class {
1280
1326
  drawPcbCutout({
1281
1327
  ctx: this.ctx,
1282
1328
  cutout: element,
1283
- transform: this.realToCanvasMat,
1329
+ realToCanvasMat: this.realToCanvasMat,
1284
1330
  colorMap: this.colorMap
1285
1331
  });
1286
1332
  }
@@ -1288,7 +1334,7 @@ var CircuitToCanvasDrawer = class {
1288
1334
  drawPcbCopperPour({
1289
1335
  ctx: this.ctx,
1290
1336
  pour: element,
1291
- transform: this.realToCanvasMat,
1337
+ realToCanvasMat: this.realToCanvasMat,
1292
1338
  colorMap: this.colorMap
1293
1339
  });
1294
1340
  }
@@ -1296,7 +1342,7 @@ var CircuitToCanvasDrawer = class {
1296
1342
  drawPcbCopperText({
1297
1343
  ctx: this.ctx,
1298
1344
  text: element,
1299
- transform: this.realToCanvasMat,
1345
+ realToCanvasMat: this.realToCanvasMat,
1300
1346
  colorMap: this.colorMap
1301
1347
  });
1302
1348
  }
@@ -1304,7 +1350,7 @@ var CircuitToCanvasDrawer = class {
1304
1350
  drawPcbFabricationNoteText({
1305
1351
  ctx: this.ctx,
1306
1352
  text: element,
1307
- transform: this.realToCanvasMat,
1353
+ realToCanvasMat: this.realToCanvasMat,
1308
1354
  colorMap: this.colorMap
1309
1355
  });
1310
1356
  }
@@ -1312,13 +1358,13 @@ var CircuitToCanvasDrawer = class {
1312
1358
  drawPcbFabricationNoteRect({
1313
1359
  ctx: this.ctx,
1314
1360
  rect: element,
1315
- transform: this.realToCanvasMat,
1361
+ realToCanvasMat: this.realToCanvasMat,
1316
1362
  colorMap: this.colorMap
1317
1363
  });
1318
1364
  }
1319
1365
  if (element.type === "pcb_note_rect") {
1320
1366
  drawPcbNoteRect({
1321
- transform: this.realToCanvasMat,
1367
+ realToCanvasMat: this.realToCanvasMat,
1322
1368
  colorMap: this.colorMap,
1323
1369
  ctx: this.ctx,
1324
1370
  rect: element
@@ -1328,7 +1374,7 @@ var CircuitToCanvasDrawer = class {
1328
1374
  drawPcbFabricationNotePath({
1329
1375
  ctx: this.ctx,
1330
1376
  path: element,
1331
- transform: this.realToCanvasMat,
1377
+ realToCanvasMat: this.realToCanvasMat,
1332
1378
  colorMap: this.colorMap
1333
1379
  });
1334
1380
  }
@@ -1336,7 +1382,7 @@ var CircuitToCanvasDrawer = class {
1336
1382
  drawPcbNotePath({
1337
1383
  ctx: this.ctx,
1338
1384
  path: element,
1339
- transform: this.realToCanvasMat,
1385
+ realToCanvasMat: this.realToCanvasMat,
1340
1386
  colorMap: this.colorMap
1341
1387
  });
1342
1388
  }
@@ -1344,7 +1390,15 @@ var CircuitToCanvasDrawer = class {
1344
1390
  drawPcbNoteText({
1345
1391
  ctx: this.ctx,
1346
1392
  text: element,
1347
- transform: this.realToCanvasMat,
1393
+ realToCanvasMat: this.realToCanvasMat,
1394
+ colorMap: this.colorMap
1395
+ });
1396
+ }
1397
+ if (element.type === "pcb_note_line") {
1398
+ drawPcbNoteLine({
1399
+ ctx: this.ctx,
1400
+ line: element,
1401
+ realToCanvasMat: this.realToCanvasMat,
1348
1402
  colorMap: this.colorMap
1349
1403
  });
1350
1404
  }