circuit-to-svg 0.0.115 → 0.0.117
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 +41 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1352,7 +1352,7 @@ var getSchScreenFontSize = (transform, textType) => {
|
|
|
1352
1352
|
|
|
1353
1353
|
// lib/assembly/svg-object-fns/create-svg-objects-from-assembly-component.ts
|
|
1354
1354
|
function createSvgObjectsFromAssemblyComponent(component, transform, firstPin, name) {
|
|
1355
|
-
const { center, width, height, rotation = 0 } = component;
|
|
1355
|
+
const { center, width, height, rotation = 0, layer = "top" } = component;
|
|
1356
1356
|
const [x, y] = applyToPoint19(transform, [center.x, center.y]);
|
|
1357
1357
|
const [pinX, pinY] = applyToPoint19(transform, [firstPin.x, firstPin.y]);
|
|
1358
1358
|
const scaledWidth = width * Math.abs(transform.a);
|
|
@@ -1362,7 +1362,7 @@ function createSvgObjectsFromAssemblyComponent(component, transform, firstPin, n
|
|
|
1362
1362
|
type: "element",
|
|
1363
1363
|
value: "",
|
|
1364
1364
|
attributes: {
|
|
1365
|
-
transform: `translate(${x}, ${y})
|
|
1365
|
+
transform: `translate(${x}, ${y}) scale(1, -1)`
|
|
1366
1366
|
},
|
|
1367
1367
|
children: [
|
|
1368
1368
|
createComponentPath(
|
|
@@ -1372,45 +1372,57 @@ function createSvgObjectsFromAssemblyComponent(component, transform, firstPin, n
|
|
|
1372
1372
|
y,
|
|
1373
1373
|
pinX,
|
|
1374
1374
|
pinY,
|
|
1375
|
-
rotation
|
|
1375
|
+
rotation,
|
|
1376
|
+
layer
|
|
1376
1377
|
),
|
|
1377
1378
|
createComponentLabel(scaledWidth, scaledHeight, name ?? "", transform)
|
|
1378
1379
|
]
|
|
1379
1380
|
};
|
|
1380
1381
|
}
|
|
1381
|
-
function createComponentPath(scaledWidth, scaledHeight, centerX, centerY, pinX, pinY, rotation) {
|
|
1382
|
+
function createComponentPath(scaledWidth, scaledHeight, centerX, centerY, pinX, pinY, rotation, layer) {
|
|
1382
1383
|
const w = scaledWidth / 2;
|
|
1383
1384
|
const h = scaledHeight / 2;
|
|
1384
1385
|
const cornerSize = Math.min(w, h) * 0.3;
|
|
1385
1386
|
const isTop = pinY > centerY;
|
|
1386
1387
|
const isLeft = pinX < centerX;
|
|
1388
|
+
const strokeWidth = 0.8;
|
|
1387
1389
|
const path = getComponentPathData(w, h, cornerSize, isTop, isLeft, rotation);
|
|
1388
1390
|
return {
|
|
1389
1391
|
name: "path",
|
|
1390
1392
|
type: "element",
|
|
1391
1393
|
attributes: {
|
|
1392
1394
|
class: "assembly-component",
|
|
1393
|
-
d: path
|
|
1395
|
+
d: path,
|
|
1396
|
+
"stroke-width": strokeWidth.toFixed(2),
|
|
1397
|
+
transform: `rotate(${-rotation})`,
|
|
1398
|
+
"stroke-dasharray": layer === "bottom" ? "2,2" : ""
|
|
1394
1399
|
},
|
|
1395
1400
|
value: "",
|
|
1396
1401
|
children: []
|
|
1397
1402
|
};
|
|
1398
1403
|
}
|
|
1399
1404
|
function createComponentLabel(scaledWidth, scaledHeight, name, transform) {
|
|
1400
|
-
const
|
|
1401
|
-
const
|
|
1402
|
-
const
|
|
1405
|
+
const size = Math.min(scaledWidth, scaledHeight);
|
|
1406
|
+
const minFontSize = 3;
|
|
1407
|
+
const maxFontSize = 58;
|
|
1408
|
+
const fontScale = 0.8;
|
|
1409
|
+
const fontSize = Math.min(
|
|
1410
|
+
maxFontSize,
|
|
1411
|
+
Math.max(minFontSize, size * fontScale)
|
|
1412
|
+
);
|
|
1413
|
+
const isTall = scaledHeight > scaledWidth;
|
|
1403
1414
|
return {
|
|
1404
1415
|
name: "text",
|
|
1405
1416
|
type: "element",
|
|
1406
1417
|
attributes: {
|
|
1407
1418
|
x: "0",
|
|
1408
|
-
y:
|
|
1419
|
+
y: "0",
|
|
1409
1420
|
class: "assembly-component-label",
|
|
1410
1421
|
"text-anchor": "middle",
|
|
1411
|
-
|
|
1412
|
-
"
|
|
1413
|
-
|
|
1422
|
+
dy: ".10em",
|
|
1423
|
+
style: "pointer-events: none",
|
|
1424
|
+
"font-size": `${fontSize.toFixed(1)}px`,
|
|
1425
|
+
transform: isTall ? "rotate(90) scale(1, -1)" : "scale(1, -1)"
|
|
1414
1426
|
},
|
|
1415
1427
|
children: [
|
|
1416
1428
|
{
|
|
@@ -1466,7 +1478,7 @@ function getComponentPathData(w, h, cornerSize, isTop, isLeft, rotation) {
|
|
|
1466
1478
|
];
|
|
1467
1479
|
}
|
|
1468
1480
|
const rotatedCorners = corners.map(([x, y]) => rotatePoint(x, y, rotation));
|
|
1469
|
-
const path = rotatedCorners.map(([x, y],
|
|
1481
|
+
const path = rotatedCorners.map(([x, y], i) => i === 0 ? `M${x},${y}` : `L${x},${y}`).join(" ");
|
|
1470
1482
|
return `${path} Z`;
|
|
1471
1483
|
}
|
|
1472
1484
|
|
|
@@ -1526,14 +1538,27 @@ function convertCircuitJsonToAssemblySvg(soup, options) {
|
|
|
1526
1538
|
{
|
|
1527
1539
|
type: "text",
|
|
1528
1540
|
value: `
|
|
1529
|
-
.assembly-component {
|
|
1530
|
-
|
|
1541
|
+
.assembly-component {
|
|
1542
|
+
fill: #fff;
|
|
1543
|
+
stroke: #000;
|
|
1544
|
+
}
|
|
1545
|
+
.assembly-board {
|
|
1546
|
+
fill: #f2f2f2;
|
|
1547
|
+
stroke: rgb(0,0,0);
|
|
1548
|
+
stroke-opacity: 0.8;
|
|
1549
|
+
}
|
|
1531
1550
|
.assembly-component-label {
|
|
1532
1551
|
fill: #000;
|
|
1533
1552
|
font-family: Arial, serif;
|
|
1534
1553
|
font-weight: bold;
|
|
1554
|
+
dominant-baseline: middle;
|
|
1555
|
+
text-anchor: middle;
|
|
1556
|
+
}
|
|
1557
|
+
.assembly-boundary {
|
|
1558
|
+
fill: none;
|
|
1559
|
+
stroke: #fff;
|
|
1560
|
+
stroke-width: 0.2;
|
|
1535
1561
|
}
|
|
1536
|
-
.assembly-boundary { fill: none; stroke: #fff; stroke-width: 0.3; }
|
|
1537
1562
|
`,
|
|
1538
1563
|
name: "",
|
|
1539
1564
|
attributes: {},
|