circuit-to-svg 0.0.122 → 0.0.124
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 +109 -69
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -1046,7 +1046,7 @@ import "svgson";
|
|
|
1046
1046
|
import { applyToPoint as applyToPoint15 } from "transformation-matrix";
|
|
1047
1047
|
|
|
1048
1048
|
// lib/pcb/create-svg-objects-from-pcb-rats-nest/get-element-position.ts
|
|
1049
|
-
import { su } from "@tscircuit/
|
|
1049
|
+
import { su } from "@tscircuit/circuit-json-util";
|
|
1050
1050
|
var getElementPosition = (id, circuitJson) => {
|
|
1051
1051
|
const pcbSmtpad = su(circuitJson).pcb_smtpad.get(id);
|
|
1052
1052
|
if (pcbSmtpad && "x" in pcbSmtpad && "y" in pcbSmtpad) {
|
|
@@ -1081,7 +1081,7 @@ var findNearestPointInNet = (sourcePoint, netId, connectivity, circuitJson) => {
|
|
|
1081
1081
|
};
|
|
1082
1082
|
|
|
1083
1083
|
// lib/pcb/svg-object-fns/create-svg-objects-from-pcb-rats-nests.ts
|
|
1084
|
-
import { su as su2 } from "@tscircuit/
|
|
1084
|
+
import { su as su2 } from "@tscircuit/circuit-json-util";
|
|
1085
1085
|
function createSvgObjectsForRatsNest(circuitJson, transform) {
|
|
1086
1086
|
const connectivity = getFullConnectivityMapFromCircuitJson(circuitJson);
|
|
1087
1087
|
const pcbPorts = circuitJson.filter((elm) => elm.type === "pcb_port");
|
|
@@ -1409,7 +1409,7 @@ var circuitJsonToPcbSvg = convertCircuitJsonToPcbSvg;
|
|
|
1409
1409
|
|
|
1410
1410
|
// lib/assembly/convert-circuit-json-to-assembly-svg.ts
|
|
1411
1411
|
import { stringify as stringify2 } from "svgson";
|
|
1412
|
-
import { su as su3 } from "@tscircuit/
|
|
1412
|
+
import { su as su3 } from "@tscircuit/circuit-json-util";
|
|
1413
1413
|
import {
|
|
1414
1414
|
applyToPoint as applyToPoint20,
|
|
1415
1415
|
compose as compose4,
|
|
@@ -1486,12 +1486,35 @@ var getSchScreenFontSize = (transform, textType) => {
|
|
|
1486
1486
|
};
|
|
1487
1487
|
|
|
1488
1488
|
// lib/assembly/svg-object-fns/create-svg-objects-from-assembly-component.ts
|
|
1489
|
-
function createSvgObjectsFromAssemblyComponent(
|
|
1490
|
-
const {
|
|
1489
|
+
function createSvgObjectsFromAssemblyComponent(params, ctx) {
|
|
1490
|
+
const { elm, portPosition, name, arePinsInterchangeable } = params;
|
|
1491
|
+
const { transform } = ctx;
|
|
1492
|
+
const { center, width, height, rotation = 0, layer = "top" } = elm;
|
|
1493
|
+
if (!center || typeof width !== "number" || typeof height !== "number")
|
|
1494
|
+
return null;
|
|
1491
1495
|
const [x, y] = applyToPoint19(transform, [center.x, center.y]);
|
|
1492
|
-
const [pinX, pinY] = applyToPoint19(transform, [
|
|
1496
|
+
const [pinX, pinY] = applyToPoint19(transform, [portPosition.x, portPosition.y]);
|
|
1493
1497
|
const scaledWidth = width * Math.abs(transform.a);
|
|
1494
1498
|
const scaledHeight = height * Math.abs(transform.d);
|
|
1499
|
+
const isTopLayer = layer === "top";
|
|
1500
|
+
const isPinTop = pinY > y;
|
|
1501
|
+
const isPinLeft = pinX < x;
|
|
1502
|
+
const children = [
|
|
1503
|
+
createComponentPath(scaledWidth, scaledHeight, rotation, layer),
|
|
1504
|
+
createComponentLabel(scaledWidth, scaledHeight, name ?? "", transform)
|
|
1505
|
+
];
|
|
1506
|
+
if (!arePinsInterchangeable) {
|
|
1507
|
+
children.push(
|
|
1508
|
+
createPin1Indicator(
|
|
1509
|
+
scaledWidth,
|
|
1510
|
+
scaledHeight,
|
|
1511
|
+
rotation,
|
|
1512
|
+
layer,
|
|
1513
|
+
isPinTop,
|
|
1514
|
+
isPinLeft
|
|
1515
|
+
)
|
|
1516
|
+
);
|
|
1517
|
+
}
|
|
1495
1518
|
return {
|
|
1496
1519
|
name: "g",
|
|
1497
1520
|
type: "element",
|
|
@@ -1499,29 +1522,14 @@ function createSvgObjectsFromAssemblyComponent(component, transform, firstPin, n
|
|
|
1499
1522
|
attributes: {
|
|
1500
1523
|
transform: `translate(${x}, ${y}) scale(1, -1)`
|
|
1501
1524
|
},
|
|
1502
|
-
children
|
|
1503
|
-
createComponentPath(
|
|
1504
|
-
scaledWidth,
|
|
1505
|
-
scaledHeight,
|
|
1506
|
-
x,
|
|
1507
|
-
y,
|
|
1508
|
-
pinX,
|
|
1509
|
-
pinY,
|
|
1510
|
-
rotation,
|
|
1511
|
-
layer
|
|
1512
|
-
),
|
|
1513
|
-
createComponentLabel(scaledWidth, scaledHeight, name ?? "", transform)
|
|
1514
|
-
]
|
|
1525
|
+
children
|
|
1515
1526
|
};
|
|
1516
1527
|
}
|
|
1517
|
-
function createComponentPath(scaledWidth, scaledHeight,
|
|
1528
|
+
function createComponentPath(scaledWidth, scaledHeight, rotation, layer) {
|
|
1518
1529
|
const w = scaledWidth / 2;
|
|
1519
1530
|
const h = scaledHeight / 2;
|
|
1520
|
-
const cornerSize = Math.min(w, h) * 0.3;
|
|
1521
|
-
const isTop = pinY > centerY;
|
|
1522
|
-
const isLeft = pinX < centerX;
|
|
1523
1531
|
const strokeWidth = 0.8;
|
|
1524
|
-
const path =
|
|
1532
|
+
const path = getRectPathData(w, h, rotation);
|
|
1525
1533
|
return {
|
|
1526
1534
|
name: "path",
|
|
1527
1535
|
type: "element",
|
|
@@ -1571,47 +1579,76 @@ function createComponentLabel(scaledWidth, scaledHeight, name, transform) {
|
|
|
1571
1579
|
value: ""
|
|
1572
1580
|
};
|
|
1573
1581
|
}
|
|
1574
|
-
function
|
|
1575
|
-
const
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
let corners;
|
|
1582
|
-
if (isTop && isLeft) {
|
|
1583
|
-
corners = [
|
|
1584
|
-
[-w, -h + cornerSize],
|
|
1585
|
-
[-w + cornerSize, -h],
|
|
1586
|
-
[w, -h],
|
|
1587
|
-
[w, h],
|
|
1588
|
-
[-w, h]
|
|
1589
|
-
];
|
|
1590
|
-
} else if (isTop && !isLeft) {
|
|
1591
|
-
corners = [
|
|
1582
|
+
function createPin1Indicator(scaledWidth, scaledHeight, rotation, layer, isPinTop, isPinLeft) {
|
|
1583
|
+
const w = scaledWidth / 2;
|
|
1584
|
+
const h = scaledHeight / 2;
|
|
1585
|
+
const indicatorSize = Math.min(w, h) * 0.5;
|
|
1586
|
+
let points;
|
|
1587
|
+
if (isPinTop && isPinLeft) {
|
|
1588
|
+
points = [
|
|
1592
1589
|
[-w, -h],
|
|
1593
|
-
|
|
1594
|
-
[w, -h
|
|
1595
|
-
|
|
1596
|
-
[-w, h]
|
|
1590
|
+
// Corner point
|
|
1591
|
+
[-w + indicatorSize, -h],
|
|
1592
|
+
// Point along top edge
|
|
1593
|
+
[-w, -h + indicatorSize]
|
|
1594
|
+
// Point along left edge
|
|
1597
1595
|
];
|
|
1598
|
-
} else if (
|
|
1599
|
-
|
|
1600
|
-
[-w, -h],
|
|
1596
|
+
} else if (isPinTop && !isPinLeft) {
|
|
1597
|
+
points = [
|
|
1601
1598
|
[w, -h],
|
|
1602
|
-
|
|
1603
|
-
[
|
|
1604
|
-
|
|
1599
|
+
// Corner point
|
|
1600
|
+
[w - indicatorSize, -h],
|
|
1601
|
+
// Point along top edge
|
|
1602
|
+
[w, -h + indicatorSize]
|
|
1603
|
+
// Point along right edge
|
|
1604
|
+
];
|
|
1605
|
+
} else if (!isPinTop && isPinLeft) {
|
|
1606
|
+
points = [
|
|
1607
|
+
[-w, h],
|
|
1608
|
+
// Corner point
|
|
1609
|
+
[-w + indicatorSize, h],
|
|
1610
|
+
// Point along bottom edge
|
|
1611
|
+
[-w, h - indicatorSize]
|
|
1612
|
+
// Point along left edge
|
|
1605
1613
|
];
|
|
1606
1614
|
} else {
|
|
1607
|
-
|
|
1608
|
-
[
|
|
1609
|
-
|
|
1610
|
-
[w, h
|
|
1611
|
-
|
|
1612
|
-
[
|
|
1615
|
+
points = [
|
|
1616
|
+
[w, h],
|
|
1617
|
+
// Corner point
|
|
1618
|
+
[w - indicatorSize, h],
|
|
1619
|
+
// Point along bottom edge
|
|
1620
|
+
[w, h - indicatorSize]
|
|
1621
|
+
// Point along right edge
|
|
1613
1622
|
];
|
|
1614
1623
|
}
|
|
1624
|
+
const pointsString = points.map((p) => p.join(",")).join(" ");
|
|
1625
|
+
return {
|
|
1626
|
+
name: "polygon",
|
|
1627
|
+
type: "element",
|
|
1628
|
+
attributes: {
|
|
1629
|
+
class: "assembly-pin1-indicator",
|
|
1630
|
+
points: pointsString,
|
|
1631
|
+
fill: "#333",
|
|
1632
|
+
stroke: "none",
|
|
1633
|
+
transform: `rotate(${-rotation})`
|
|
1634
|
+
},
|
|
1635
|
+
value: "",
|
|
1636
|
+
children: []
|
|
1637
|
+
};
|
|
1638
|
+
}
|
|
1639
|
+
function getRectPathData(w, h, rotation) {
|
|
1640
|
+
const rotatePoint = (x, y, angle) => {
|
|
1641
|
+
const rad = Math.PI / 180 * angle;
|
|
1642
|
+
const cos = Math.cos(rad);
|
|
1643
|
+
const sin = Math.sin(rad);
|
|
1644
|
+
return [x * cos - y * sin, x * sin + y * cos];
|
|
1645
|
+
};
|
|
1646
|
+
const corners = [
|
|
1647
|
+
[-w, -h],
|
|
1648
|
+
[w, -h],
|
|
1649
|
+
[w, h],
|
|
1650
|
+
[-w, h]
|
|
1651
|
+
];
|
|
1615
1652
|
const rotatedCorners = corners.map(([x, y]) => rotatePoint(x, y, rotation));
|
|
1616
1653
|
const path = rotatedCorners.map(([x, y], i) => i === 0 ? `M${x},${y}` : `L${x},${y}`).join(" ");
|
|
1617
1654
|
return `${path} Z`;
|
|
@@ -1734,14 +1771,17 @@ function createSvgObjects2(elm, transform, soup) {
|
|
|
1734
1771
|
const ports = su3(soup).pcb_port.list().filter((port) => port.pcb_component_id === elm.pcb_component_id);
|
|
1735
1772
|
const firstPort = ports[0];
|
|
1736
1773
|
if (sourceComponent && firstPort) {
|
|
1737
|
-
|
|
1738
|
-
|
|
1774
|
+
const arePinsInterchangeable = sourceComponent.are_pins_interchangeable;
|
|
1775
|
+
const obj = createSvgObjectsFromAssemblyComponent(
|
|
1776
|
+
{
|
|
1739
1777
|
elm,
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1778
|
+
portPosition: { x: firstPort.x, y: firstPort.y },
|
|
1779
|
+
name: sourceComponent.name,
|
|
1780
|
+
arePinsInterchangeable
|
|
1781
|
+
},
|
|
1782
|
+
{ transform }
|
|
1783
|
+
);
|
|
1784
|
+
return obj ? [obj] : [];
|
|
1745
1785
|
}
|
|
1746
1786
|
return [];
|
|
1747
1787
|
}
|
|
@@ -2223,7 +2263,7 @@ function getSchematicBoundsFromCircuitJson(soup, padding = 0.5) {
|
|
|
2223
2263
|
}
|
|
2224
2264
|
|
|
2225
2265
|
// lib/sch/svg-object-fns/create-svg-objects-from-sch-component-with-symbol.ts
|
|
2226
|
-
import { su as su4 } from "@tscircuit/
|
|
2266
|
+
import { su as su4 } from "@tscircuit/circuit-json-util";
|
|
2227
2267
|
import { symbols } from "schematic-symbols";
|
|
2228
2268
|
import "svgson";
|
|
2229
2269
|
import {
|
|
@@ -2548,18 +2588,18 @@ var createSvgObjectsFromSchematicComponentWithSymbol = ({
|
|
|
2548
2588
|
};
|
|
2549
2589
|
|
|
2550
2590
|
// lib/sch/svg-object-fns/create-svg-objects-from-sch-component-with-box.ts
|
|
2551
|
-
import { su as su7 } from "@tscircuit/
|
|
2591
|
+
import { su as su7 } from "@tscircuit/circuit-json-util";
|
|
2552
2592
|
import "schematic-symbols";
|
|
2553
2593
|
import "svgson";
|
|
2554
2594
|
import { applyToPoint as applyToPoint30 } from "transformation-matrix";
|
|
2555
2595
|
|
|
2556
2596
|
// lib/sch/svg-object-fns/create-svg-objects-from-sch-port-on-box.ts
|
|
2557
2597
|
import "transformation-matrix";
|
|
2558
|
-
import "@tscircuit/
|
|
2598
|
+
import "@tscircuit/circuit-json-util";
|
|
2559
2599
|
|
|
2560
2600
|
// lib/sch/svg-object-fns/create-svg-objects-for-sch-port-box-line.ts
|
|
2561
2601
|
import { applyToPoint as applyToPoint25 } from "transformation-matrix";
|
|
2562
|
-
import { su as su5 } from "@tscircuit/
|
|
2602
|
+
import { su as su5 } from "@tscircuit/circuit-json-util";
|
|
2563
2603
|
var PIN_CIRCLE_RADIUS_MM = 0.02;
|
|
2564
2604
|
var createSvgObjectsForSchPortBoxLine = ({
|
|
2565
2605
|
schPort,
|