circuit-to-svg 0.0.289 → 0.0.291
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 +122 -23
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -5445,8 +5445,25 @@ import { applyToPoint as applyToPoint32 } from "transformation-matrix";
|
|
|
5445
5445
|
var DEFAULT_GROUP_COLOR = "rgba(100, 200, 255, 0.6)";
|
|
5446
5446
|
var DEFAULT_STROKE_WIDTH = 0.1;
|
|
5447
5447
|
function createSvgObjectsFromPcbGroup(pcbGroup, ctx) {
|
|
5448
|
-
const { transform } = ctx;
|
|
5448
|
+
const { transform, circuitJson } = ctx;
|
|
5449
5449
|
const { center, width, height } = pcbGroup;
|
|
5450
|
+
const svgObjects = [];
|
|
5451
|
+
if (ctx.showAnchorOffsets && pcbGroup.position_mode === "relative_to_group_anchor" && circuitJson) {
|
|
5452
|
+
const anchorPosition = getAnchorPosition2(pcbGroup, circuitJson);
|
|
5453
|
+
if (anchorPosition) {
|
|
5454
|
+
svgObjects.push(
|
|
5455
|
+
...createAnchorOffsetIndicators({
|
|
5456
|
+
groupAnchorPosition: anchorPosition,
|
|
5457
|
+
componentPosition: pcbGroup.center,
|
|
5458
|
+
transform,
|
|
5459
|
+
componentWidth: pcbGroup.width,
|
|
5460
|
+
componentHeight: pcbGroup.height,
|
|
5461
|
+
displayXOffset: pcbGroup.display_offset_x,
|
|
5462
|
+
displayYOffset: pcbGroup.display_offset_y
|
|
5463
|
+
})
|
|
5464
|
+
);
|
|
5465
|
+
}
|
|
5466
|
+
}
|
|
5450
5467
|
const outline = Array.isArray(pcbGroup.outline) ? pcbGroup.outline : void 0;
|
|
5451
5468
|
const transformedStrokeWidth = DEFAULT_STROKE_WIDTH * Math.abs(transform.a);
|
|
5452
5469
|
const dashLength = 0.3 * Math.abs(transform.a);
|
|
@@ -5471,22 +5488,21 @@ function createSvgObjectsFromPcbGroup(pcbGroup, ctx) {
|
|
|
5471
5488
|
const [x, y] = applyToPoint32(transform, [point.x, point.y]);
|
|
5472
5489
|
return index === 0 ? `M ${x} ${y}` : `L ${x} ${y}`;
|
|
5473
5490
|
}).join(" ");
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
|
|
5481
|
-
|
|
5482
|
-
d: `${path} Z`
|
|
5483
|
-
}
|
|
5491
|
+
svgObjects.push({
|
|
5492
|
+
name: "path",
|
|
5493
|
+
type: "element",
|
|
5494
|
+
value: "",
|
|
5495
|
+
children: [],
|
|
5496
|
+
attributes: {
|
|
5497
|
+
...baseAttributes,
|
|
5498
|
+
d: `${path} Z`
|
|
5484
5499
|
}
|
|
5485
|
-
|
|
5500
|
+
});
|
|
5501
|
+
return svgObjects;
|
|
5486
5502
|
}
|
|
5487
5503
|
if (!center || typeof center.x !== "number" || typeof center.y !== "number" || typeof width !== "number" || typeof height !== "number") {
|
|
5488
5504
|
console.error("Invalid pcb_group data", { center, width, height });
|
|
5489
|
-
return
|
|
5505
|
+
return svgObjects;
|
|
5490
5506
|
}
|
|
5491
5507
|
const halfWidth = width / 2;
|
|
5492
5508
|
const halfHeight = height / 2;
|
|
@@ -5515,7 +5531,23 @@ function createSvgObjectsFromPcbGroup(pcbGroup, ctx) {
|
|
|
5515
5531
|
},
|
|
5516
5532
|
children: []
|
|
5517
5533
|
};
|
|
5518
|
-
|
|
5534
|
+
svgObjects.push(svgObject);
|
|
5535
|
+
return svgObjects;
|
|
5536
|
+
}
|
|
5537
|
+
function getAnchorPosition2(group, circuitJson) {
|
|
5538
|
+
if (group.positioned_relative_to_pcb_group_id) {
|
|
5539
|
+
const pcbGroup = circuitJson.find(
|
|
5540
|
+
(elm) => elm.type === "pcb_group" && elm.pcb_group_id === group.positioned_relative_to_pcb_group_id
|
|
5541
|
+
);
|
|
5542
|
+
if (pcbGroup?.center) return pcbGroup.center;
|
|
5543
|
+
}
|
|
5544
|
+
if (group.positioned_relative_to_pcb_board_id) {
|
|
5545
|
+
const pcbBoard = circuitJson.find(
|
|
5546
|
+
(elm) => elm.type === "pcb_board" && elm.pcb_board_id === group.positioned_relative_to_pcb_board_id
|
|
5547
|
+
);
|
|
5548
|
+
if (pcbBoard?.center) return pcbBoard.center;
|
|
5549
|
+
}
|
|
5550
|
+
return void 0;
|
|
5519
5551
|
}
|
|
5520
5552
|
|
|
5521
5553
|
// lib/utils/get-software-used-string.ts
|
|
@@ -5530,7 +5562,7 @@ function getSoftwareUsedString(circuitJson) {
|
|
|
5530
5562
|
var package_default = {
|
|
5531
5563
|
name: "circuit-to-svg",
|
|
5532
5564
|
type: "module",
|
|
5533
|
-
version: "0.0.
|
|
5565
|
+
version: "0.0.290",
|
|
5534
5566
|
description: "Convert Circuit JSON to SVG",
|
|
5535
5567
|
main: "dist/index.js",
|
|
5536
5568
|
files: [
|
|
@@ -5553,7 +5585,7 @@ var package_default = {
|
|
|
5553
5585
|
"@vitejs/plugin-react": "5.0.0",
|
|
5554
5586
|
biome: "^0.3.3",
|
|
5555
5587
|
"bun-match-svg": "^0.0.12",
|
|
5556
|
-
"circuit-json": "^0.0.
|
|
5588
|
+
"circuit-json": "^0.0.333",
|
|
5557
5589
|
esbuild: "^0.20.2",
|
|
5558
5590
|
"performance-now": "^2.1.0",
|
|
5559
5591
|
react: "19.1.0",
|
|
@@ -10491,19 +10523,86 @@ function createSvgObjectsFromSchVoltageProbe({
|
|
|
10491
10523
|
const probeColor = probe.color ?? colorMap2.schematic.reference;
|
|
10492
10524
|
const arrowLength = Math.abs(transform.a) * 0.6;
|
|
10493
10525
|
const arrowWidth = Math.abs(transform.a) * 0.28;
|
|
10494
|
-
const
|
|
10495
|
-
|
|
10526
|
+
const labelAlignment = probe.label_alignment ?? "top_right";
|
|
10527
|
+
let baseAngleRad;
|
|
10528
|
+
let textAnchor;
|
|
10529
|
+
let textOffsetX;
|
|
10530
|
+
let textOffsetY;
|
|
10531
|
+
switch (labelAlignment) {
|
|
10532
|
+
case "top_left":
|
|
10533
|
+
baseAngleRad = -135 * Math.PI / 180;
|
|
10534
|
+
textAnchor = "end";
|
|
10535
|
+
textOffsetX = -8;
|
|
10536
|
+
textOffsetY = -8;
|
|
10537
|
+
break;
|
|
10538
|
+
case "top_center":
|
|
10539
|
+
baseAngleRad = -90 * Math.PI / 180;
|
|
10540
|
+
textAnchor = "middle";
|
|
10541
|
+
textOffsetX = 0;
|
|
10542
|
+
textOffsetY = -8;
|
|
10543
|
+
break;
|
|
10544
|
+
case "top_right":
|
|
10545
|
+
baseAngleRad = -45 * Math.PI / 180;
|
|
10546
|
+
textAnchor = "start";
|
|
10547
|
+
textOffsetX = 8;
|
|
10548
|
+
textOffsetY = -8;
|
|
10549
|
+
break;
|
|
10550
|
+
case "center_left":
|
|
10551
|
+
baseAngleRad = 180 * Math.PI / 180;
|
|
10552
|
+
textAnchor = "end";
|
|
10553
|
+
textOffsetX = -8;
|
|
10554
|
+
textOffsetY = 0;
|
|
10555
|
+
break;
|
|
10556
|
+
case "center":
|
|
10557
|
+
baseAngleRad = -90 * Math.PI / 180;
|
|
10558
|
+
textAnchor = "middle";
|
|
10559
|
+
textOffsetX = 0;
|
|
10560
|
+
textOffsetY = -8;
|
|
10561
|
+
break;
|
|
10562
|
+
case "center_right":
|
|
10563
|
+
baseAngleRad = 0 * Math.PI / 180;
|
|
10564
|
+
textAnchor = "start";
|
|
10565
|
+
textOffsetX = 8;
|
|
10566
|
+
textOffsetY = 0;
|
|
10567
|
+
break;
|
|
10568
|
+
case "bottom_left":
|
|
10569
|
+
baseAngleRad = 135 * Math.PI / 180;
|
|
10570
|
+
textAnchor = "end";
|
|
10571
|
+
textOffsetX = -8;
|
|
10572
|
+
textOffsetY = 8;
|
|
10573
|
+
break;
|
|
10574
|
+
case "bottom_center":
|
|
10575
|
+
baseAngleRad = 90 * Math.PI / 180;
|
|
10576
|
+
textAnchor = "middle";
|
|
10577
|
+
textOffsetX = 0;
|
|
10578
|
+
textOffsetY = 8;
|
|
10579
|
+
break;
|
|
10580
|
+
case "bottom_right":
|
|
10581
|
+
baseAngleRad = 45 * Math.PI / 180;
|
|
10582
|
+
textAnchor = "start";
|
|
10583
|
+
textOffsetX = 8;
|
|
10584
|
+
textOffsetY = 8;
|
|
10585
|
+
break;
|
|
10586
|
+
default:
|
|
10587
|
+
baseAngleRad = -50 * Math.PI / 180;
|
|
10588
|
+
textAnchor = "start";
|
|
10589
|
+
textOffsetX = 8;
|
|
10590
|
+
textOffsetY = 0;
|
|
10591
|
+
}
|
|
10592
|
+
const baseX = screenX + arrowLength * Math.cos(baseAngleRad);
|
|
10593
|
+
const baseY = screenY + arrowLength * Math.sin(baseAngleRad);
|
|
10496
10594
|
const tipX = screenX;
|
|
10497
10595
|
const tipY = screenY;
|
|
10498
10596
|
const arrowPath = [
|
|
10499
10597
|
`M ${baseX},${baseY}`,
|
|
10500
10598
|
`L ${tipX},${tipY}`,
|
|
10501
10599
|
`M ${tipX},${tipY}`,
|
|
10502
|
-
`L ${tipX - arrowWidth * Math.cos((
|
|
10503
|
-
`L ${tipX - arrowWidth * Math.cos((
|
|
10600
|
+
`L ${tipX - arrowWidth * Math.cos((baseAngleRad * 180 / Math.PI + 150) * Math.PI / 180)},${tipY - arrowWidth * Math.sin((baseAngleRad * 180 / Math.PI + 150) * Math.PI / 180)}`,
|
|
10601
|
+
`L ${tipX - arrowWidth * Math.cos((baseAngleRad * 180 / Math.PI + 210) * Math.PI / 180)},${tipY - arrowWidth * Math.sin((baseAngleRad * 180 / Math.PI + 210) * Math.PI / 180)}`,
|
|
10504
10602
|
"Z"
|
|
10505
10603
|
].join(" ");
|
|
10506
|
-
const x = (baseX +
|
|
10604
|
+
const x = (baseX + textOffsetX).toString();
|
|
10605
|
+
const y = (baseY + textOffsetY).toString();
|
|
10507
10606
|
const textChildren = [];
|
|
10508
10607
|
if (probe.name && probe.voltage !== void 0) {
|
|
10509
10608
|
textChildren.push({
|
|
@@ -10576,9 +10675,9 @@ function createSvgObjectsFromSchVoltageProbe({
|
|
|
10576
10675
|
value: "",
|
|
10577
10676
|
attributes: {
|
|
10578
10677
|
x,
|
|
10579
|
-
y
|
|
10678
|
+
y,
|
|
10580
10679
|
fill: probeColor,
|
|
10581
|
-
"text-anchor":
|
|
10680
|
+
"text-anchor": textAnchor,
|
|
10582
10681
|
"dominant-baseline": "middle",
|
|
10583
10682
|
"font-family": "sans-serif",
|
|
10584
10683
|
"font-size": `${getSchScreenFontSize(transform, "reference_designator")}px`,
|