circuit-to-svg 0.0.111 → 0.0.112
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.js +40 -30
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { stringify } from "svgson";
|
|
|
3
3
|
import {
|
|
4
4
|
applyToPoint as applyToPoint16,
|
|
5
5
|
compose as compose3,
|
|
6
|
-
scale,
|
|
6
|
+
scale as scale2,
|
|
7
7
|
translate as translate3
|
|
8
8
|
} from "transformation-matrix";
|
|
9
9
|
|
|
@@ -338,6 +338,13 @@ function createSvgObjectsFromPcbPlatedHole(hole, transform) {
|
|
|
338
338
|
|
|
339
339
|
// lib/pcb/svg-object-fns/create-svg-objects-from-pcb-silkscreen-path.ts
|
|
340
340
|
import { applyToPoint as applyToPoint5 } from "transformation-matrix";
|
|
341
|
+
|
|
342
|
+
// lib/pcb/colors.ts
|
|
343
|
+
var HOLE_COLOR = "#FF26E2";
|
|
344
|
+
var SILKSCREEN_TOP_COLOR = "#f2eda1";
|
|
345
|
+
var SILKSCREEN_BOTTOM_COLOR = "#5da9e9";
|
|
346
|
+
|
|
347
|
+
// lib/pcb/svg-object-fns/create-svg-objects-from-pcb-silkscreen-path.ts
|
|
341
348
|
function createSvgObjectsFromPcbSilkscreenPath(silkscreenPath, transform) {
|
|
342
349
|
if (!silkscreenPath.route || !Array.isArray(silkscreenPath.route)) return [];
|
|
343
350
|
let path = silkscreenPath.route.map((point, index) => {
|
|
@@ -349,15 +356,17 @@ function createSvgObjectsFromPcbSilkscreenPath(silkscreenPath, transform) {
|
|
|
349
356
|
if (firstPoint && lastPoint && firstPoint.x === lastPoint.x && firstPoint.y === lastPoint.y) {
|
|
350
357
|
path += " Z";
|
|
351
358
|
}
|
|
359
|
+
const layer = silkscreenPath.layer || "top";
|
|
360
|
+
const color = layer === "bottom" ? SILKSCREEN_BOTTOM_COLOR : SILKSCREEN_TOP_COLOR;
|
|
352
361
|
return [
|
|
353
362
|
{
|
|
354
363
|
name: "path",
|
|
355
364
|
type: "element",
|
|
356
365
|
attributes: {
|
|
357
|
-
class: `pcb-silkscreen pcb-silkscreen-${
|
|
366
|
+
class: `pcb-silkscreen pcb-silkscreen-${layer}`,
|
|
358
367
|
d: path,
|
|
359
368
|
fill: "none",
|
|
360
|
-
stroke:
|
|
369
|
+
stroke: color,
|
|
361
370
|
"stroke-width": (silkscreenPath.stroke_width * Math.abs(transform.a)).toString(),
|
|
362
371
|
"data-pcb-component-id": silkscreenPath.pcb_component_id,
|
|
363
372
|
"data-pcb-silkscreen-path-id": silkscreenPath.pcb_silkscreen_path_id
|
|
@@ -374,6 +383,7 @@ import {
|
|
|
374
383
|
compose as compose2,
|
|
375
384
|
rotate as rotate2,
|
|
376
385
|
translate as translate2,
|
|
386
|
+
scale,
|
|
377
387
|
toString as matrixToString2
|
|
378
388
|
} from "transformation-matrix";
|
|
379
389
|
function createSvgObjectsFromPcbSilkscreenText(pcbSilkscreenText, transform) {
|
|
@@ -397,15 +407,17 @@ function createSvgObjectsFromPcbSilkscreenText(pcbSilkscreenText, transform) {
|
|
|
397
407
|
const transformedStrokeWidth = stroke_width * Math.abs(transform.a);
|
|
398
408
|
const textTransform = compose2(
|
|
399
409
|
translate2(transformedX, transformedY),
|
|
400
|
-
rotate2(ccw_rotation * Math.PI / 180)
|
|
410
|
+
rotate2(ccw_rotation * Math.PI / 180),
|
|
411
|
+
...layer === "bottom" ? [scale(-1, 1)] : []
|
|
401
412
|
);
|
|
413
|
+
const color = layer === "bottom" ? SILKSCREEN_BOTTOM_COLOR : SILKSCREEN_TOP_COLOR;
|
|
402
414
|
const svgObject = {
|
|
403
415
|
name: "text",
|
|
404
416
|
type: "element",
|
|
405
417
|
attributes: {
|
|
406
418
|
x: "0",
|
|
407
419
|
y: "0",
|
|
408
|
-
fill:
|
|
420
|
+
fill: color,
|
|
409
421
|
"font-family": "Arial, sans-serif",
|
|
410
422
|
"font-size": transformedFontSize.toString(),
|
|
411
423
|
"text-anchor": "middle",
|
|
@@ -413,7 +425,7 @@ function createSvgObjectsFromPcbSilkscreenText(pcbSilkscreenText, transform) {
|
|
|
413
425
|
transform: matrixToString2(textTransform),
|
|
414
426
|
class: `pcb-silkscreen-text pcb-silkscreen-${layer}`,
|
|
415
427
|
"data-pcb-silkscreen-text-id": pcbSilkscreenText.pcb_component_id,
|
|
416
|
-
stroke:
|
|
428
|
+
stroke: color,
|
|
417
429
|
"stroke-width": transformedStrokeWidth.toString()
|
|
418
430
|
},
|
|
419
431
|
children: [
|
|
@@ -454,6 +466,7 @@ function createSvgObjectsFromPcbSilkscreenRect(pcbSilkscreenRect, transform) {
|
|
|
454
466
|
const transformedWidth = width * Math.abs(transform.a);
|
|
455
467
|
const transformedHeight = height * Math.abs(transform.d);
|
|
456
468
|
const transformedStrokeWidth = stroke_width * Math.abs(transform.a);
|
|
469
|
+
const color = layer === "bottom" ? SILKSCREEN_BOTTOM_COLOR : SILKSCREEN_TOP_COLOR;
|
|
457
470
|
const svgObject = {
|
|
458
471
|
name: "rect",
|
|
459
472
|
type: "element",
|
|
@@ -464,7 +477,7 @@ function createSvgObjectsFromPcbSilkscreenRect(pcbSilkscreenRect, transform) {
|
|
|
464
477
|
height: transformedHeight.toString(),
|
|
465
478
|
class: `pcb-silkscreen-rect pcb-silkscreen-${layer}`,
|
|
466
479
|
fill: "none",
|
|
467
|
-
stroke:
|
|
480
|
+
stroke: color,
|
|
468
481
|
"stroke-width": transformedStrokeWidth.toString(),
|
|
469
482
|
"data-pcb-silkscreen-rect-id": pcb_silkscreen_rect_id
|
|
470
483
|
},
|
|
@@ -496,6 +509,7 @@ function createSvgObjectsFromPcbSilkscreenCircle(pcbSilkscreenCircle, transform)
|
|
|
496
509
|
]);
|
|
497
510
|
const transformedRadius = radius * Math.abs(transform.a);
|
|
498
511
|
const transformedStrokeWidth = stroke_width * Math.abs(transform.a);
|
|
512
|
+
const color = layer === "bottom" ? SILKSCREEN_BOTTOM_COLOR : SILKSCREEN_TOP_COLOR;
|
|
499
513
|
const svgObject = {
|
|
500
514
|
name: "circle",
|
|
501
515
|
type: "element",
|
|
@@ -504,7 +518,7 @@ function createSvgObjectsFromPcbSilkscreenCircle(pcbSilkscreenCircle, transform)
|
|
|
504
518
|
cy: transformedY.toString(),
|
|
505
519
|
r: transformedRadius.toString(),
|
|
506
520
|
class: `pcb-silkscreen-circle pcb-silkscreen-${layer}`,
|
|
507
|
-
stroke:
|
|
521
|
+
stroke: color,
|
|
508
522
|
"stroke-width": transformedStrokeWidth.toString(),
|
|
509
523
|
"data-pcb-silkscreen-circle-id": pcb_silkscreen_circle_id
|
|
510
524
|
},
|
|
@@ -535,6 +549,7 @@ function createSvgObjectsFromPcbSilkscreenLine(pcbSilkscreenLine, transform) {
|
|
|
535
549
|
const [transformedX1, transformedY1] = applyToPoint9(transform, [x1, y1]);
|
|
536
550
|
const [transformedX2, transformedY2] = applyToPoint9(transform, [x2, y2]);
|
|
537
551
|
const transformedStrokeWidth = stroke_width * Math.abs(transform.a);
|
|
552
|
+
const color = layer === "bottom" ? SILKSCREEN_BOTTOM_COLOR : SILKSCREEN_TOP_COLOR;
|
|
538
553
|
return [
|
|
539
554
|
{
|
|
540
555
|
name: "line",
|
|
@@ -544,7 +559,7 @@ function createSvgObjectsFromPcbSilkscreenLine(pcbSilkscreenLine, transform) {
|
|
|
544
559
|
y1: transformedY1.toString(),
|
|
545
560
|
x2: transformedX2.toString(),
|
|
546
561
|
y2: transformedY2.toString(),
|
|
547
|
-
stroke:
|
|
562
|
+
stroke: color,
|
|
548
563
|
"stroke-width": transformedStrokeWidth.toString(),
|
|
549
564
|
class: `pcb-silkscreen-line pcb-silkscreen-${layer}`,
|
|
550
565
|
"data-pcb-silkscreen-line-id": pcb_silkscreen_line_id
|
|
@@ -776,11 +791,6 @@ function createSvgObjectsFromPcbVia(hole, transform) {
|
|
|
776
791
|
|
|
777
792
|
// lib/pcb/svg-object-fns/create-svg-objects-from-pcb-hole.ts
|
|
778
793
|
import { applyToPoint as applyToPoint14 } from "transformation-matrix";
|
|
779
|
-
|
|
780
|
-
// lib/pcb/colors.ts
|
|
781
|
-
var HOLE_COLOR = "#FF26E2";
|
|
782
|
-
|
|
783
|
-
// lib/pcb/svg-object-fns/create-svg-objects-from-pcb-hole.ts
|
|
784
794
|
function createSvgObjectsFromPcbHole(hole, transform) {
|
|
785
795
|
const [x, y] = applyToPoint14(transform, [hole.x, hole.y]);
|
|
786
796
|
if (hole.hole_shape === "circle" || hole.hole_shape === "square") {
|
|
@@ -1011,7 +1021,7 @@ function convertCircuitJsonToPcbSvg(soup, options) {
|
|
|
1011
1021
|
offsetX - minX * scaleFactor + padding * scaleFactor,
|
|
1012
1022
|
svgHeight - offsetY + minY * scaleFactor - padding * scaleFactor
|
|
1013
1023
|
),
|
|
1014
|
-
|
|
1024
|
+
scale2(scaleFactor, -scaleFactor)
|
|
1015
1025
|
// Flip in y-direction
|
|
1016
1026
|
);
|
|
1017
1027
|
let svgObjects = soup.sort(
|
|
@@ -1220,7 +1230,7 @@ import { su as su3 } from "@tscircuit/soup-util";
|
|
|
1220
1230
|
import {
|
|
1221
1231
|
applyToPoint as applyToPoint20,
|
|
1222
1232
|
compose as compose4,
|
|
1223
|
-
scale as
|
|
1233
|
+
scale as scale3,
|
|
1224
1234
|
translate as translate4
|
|
1225
1235
|
} from "transformation-matrix";
|
|
1226
1236
|
|
|
@@ -1339,9 +1349,9 @@ function createComponentPath(scaledWidth, scaledHeight, centerX, centerY, pinX,
|
|
|
1339
1349
|
};
|
|
1340
1350
|
}
|
|
1341
1351
|
function createComponentLabel(scaledWidth, scaledHeight, name, transform) {
|
|
1342
|
-
const
|
|
1343
|
-
const fontSize = getSchScreenFontSize(transform, "net_label") * (
|
|
1344
|
-
const scaledFontSize =
|
|
1352
|
+
const scale8 = Math.min(scaledWidth, scaledHeight) * 0.4;
|
|
1353
|
+
const fontSize = getSchScreenFontSize(transform, "net_label") * (scale8 / 2.5);
|
|
1354
|
+
const scaledFontSize = scale8 < 25 ? fontSize : fontSize * 0.6;
|
|
1345
1355
|
return {
|
|
1346
1356
|
name: "text",
|
|
1347
1357
|
type: "element",
|
|
@@ -1445,7 +1455,7 @@ function convertCircuitJsonToAssemblySvg(soup, options) {
|
|
|
1445
1455
|
offsetX - minX * scaleFactor + padding * scaleFactor,
|
|
1446
1456
|
svgHeight - offsetY + minY * scaleFactor - padding * scaleFactor
|
|
1447
1457
|
),
|
|
1448
|
-
|
|
1458
|
+
scale3(scaleFactor, -scaleFactor)
|
|
1449
1459
|
// Flip in y-direction
|
|
1450
1460
|
);
|
|
1451
1461
|
const svgObjects = soup.sort(
|
|
@@ -2079,7 +2089,7 @@ var matchSchPortsToSymbolPorts = ({
|
|
|
2079
2089
|
};
|
|
2080
2090
|
|
|
2081
2091
|
// lib/utils/point-pairs-to-matrix.ts
|
|
2082
|
-
import { compose as compose5, scale as
|
|
2092
|
+
import { compose as compose5, scale as scale4, translate as translate5 } from "transformation-matrix";
|
|
2083
2093
|
function pointPairsToMatrix(a1, a2, b1, b2) {
|
|
2084
2094
|
const tx = a2.x - a1.x;
|
|
2085
2095
|
const ty = a2.y - a1.y;
|
|
@@ -2087,7 +2097,7 @@ function pointPairsToMatrix(a1, a2, b1, b2) {
|
|
|
2087
2097
|
const transformedDistance = Math.sqrt((b2.x - a2.x) ** 2 + (b2.y - a2.y) ** 2);
|
|
2088
2098
|
const a = transformedDistance / originalDistance;
|
|
2089
2099
|
const translateMatrix = translate5(tx, ty);
|
|
2090
|
-
const scaleMatrix =
|
|
2100
|
+
const scaleMatrix = scale4(a, a);
|
|
2091
2101
|
return compose5(translateMatrix, scaleMatrix);
|
|
2092
2102
|
}
|
|
2093
2103
|
|
|
@@ -2989,7 +2999,7 @@ import {
|
|
|
2989
2999
|
applyToPoint as applyToPoint35,
|
|
2990
3000
|
compose as compose8,
|
|
2991
3001
|
rotate as rotate4,
|
|
2992
|
-
scale as
|
|
3002
|
+
scale as scale6,
|
|
2993
3003
|
translate as translate8
|
|
2994
3004
|
} from "transformation-matrix";
|
|
2995
3005
|
|
|
@@ -3777,7 +3787,7 @@ import {
|
|
|
3777
3787
|
applyToPoint as applyToPoint34,
|
|
3778
3788
|
compose as compose7,
|
|
3779
3789
|
rotate as rotate3,
|
|
3780
|
-
scale as
|
|
3790
|
+
scale as scale5,
|
|
3781
3791
|
translate as translate7
|
|
3782
3792
|
} from "transformation-matrix";
|
|
3783
3793
|
import { symbols as symbols3 } from "schematic-symbols";
|
|
@@ -3811,8 +3821,8 @@ var ninePointAnchorToDominantBaseline = {
|
|
|
3811
3821
|
middle_bottom: "hanging"
|
|
3812
3822
|
};
|
|
3813
3823
|
function getTextOffsets(pathRotation, transform) {
|
|
3814
|
-
const
|
|
3815
|
-
const baseOffset =
|
|
3824
|
+
const scale8 = Math.abs(transform.a);
|
|
3825
|
+
const baseOffset = scale8 * 0.1;
|
|
3816
3826
|
const rotationOffsetMap = {
|
|
3817
3827
|
"0": { x: baseOffset * 0.8, y: -baseOffset },
|
|
3818
3828
|
// Left
|
|
@@ -3901,7 +3911,7 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
|
|
|
3901
3911
|
realAnchorPosition.y - rotatedSymbolEnd.y
|
|
3902
3912
|
),
|
|
3903
3913
|
rotationMatrix,
|
|
3904
|
-
|
|
3914
|
+
scale5(1)
|
|
3905
3915
|
// Use full symbol size
|
|
3906
3916
|
);
|
|
3907
3917
|
const [screenMinX, screenMinY] = applyToPoint34(
|
|
@@ -3962,8 +3972,8 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
|
|
|
3962
3972
|
} else if (textValue === "{VAL}") {
|
|
3963
3973
|
textValue = "";
|
|
3964
3974
|
}
|
|
3965
|
-
const
|
|
3966
|
-
const baseOffset =
|
|
3975
|
+
const scale8 = Math.abs(realToScreenTransform.a);
|
|
3976
|
+
const baseOffset = scale8 * 0.1;
|
|
3967
3977
|
const rotationOffset = getTextOffsets(pathRotation, realToScreenTransform);
|
|
3968
3978
|
const offsetScreenPos = {
|
|
3969
3979
|
x: screenTextPos.x + rotationOffset.x,
|
|
@@ -4108,7 +4118,7 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
|
|
|
4108
4118
|
compose8(
|
|
4109
4119
|
realToScreenTransform,
|
|
4110
4120
|
translate8(realAnchorPosition.x, realAnchorPosition.y),
|
|
4111
|
-
|
|
4121
|
+
scale6(fontSizeMm),
|
|
4112
4122
|
rotate4(pathRotation / 180 * Math.PI)
|
|
4113
4123
|
),
|
|
4114
4124
|
fontRelativePoint
|