circuit-to-svg 0.0.195 → 0.0.197
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 +244 -16
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1743,7 +1743,7 @@ function getSoftwareUsedString(circuitJson) {
|
|
|
1743
1743
|
var package_default = {
|
|
1744
1744
|
name: "circuit-to-svg",
|
|
1745
1745
|
type: "module",
|
|
1746
|
-
version: "0.0.
|
|
1746
|
+
version: "0.0.196",
|
|
1747
1747
|
description: "Convert Circuit JSON to SVG",
|
|
1748
1748
|
main: "dist/index.js",
|
|
1749
1749
|
files: [
|
|
@@ -1767,12 +1767,12 @@ var package_default = {
|
|
|
1767
1767
|
"bun-match-svg": "^0.0.12",
|
|
1768
1768
|
esbuild: "^0.20.2",
|
|
1769
1769
|
"performance-now": "^2.1.0",
|
|
1770
|
-
"circuit-json": "^0.0.
|
|
1770
|
+
"circuit-json": "^0.0.261",
|
|
1771
1771
|
react: "19.1.0",
|
|
1772
1772
|
"react-cosmos": "7.0.0",
|
|
1773
1773
|
"react-cosmos-plugin-vite": "7.0.0",
|
|
1774
1774
|
"react-dom": "19.1.0",
|
|
1775
|
-
tscircuit: "^0.0.
|
|
1775
|
+
tscircuit: "^0.0.654",
|
|
1776
1776
|
tsup: "^8.0.2",
|
|
1777
1777
|
typescript: "^5.4.5",
|
|
1778
1778
|
"vite-tsconfig-paths": "^5.0.1"
|
|
@@ -1885,10 +1885,10 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
|
|
|
1885
1885
|
}
|
|
1886
1886
|
}
|
|
1887
1887
|
const padding = drawPaddingOutsideBoard ? 1 : 0;
|
|
1888
|
-
const boundsMinX = drawPaddingOutsideBoard || !isFinite(boardMinX) ? minX : boardMinX;
|
|
1889
|
-
const boundsMinY = drawPaddingOutsideBoard || !isFinite(boardMinY) ? minY : boardMinY;
|
|
1890
|
-
const boundsMaxX = drawPaddingOutsideBoard || !isFinite(boardMaxX) ? maxX : boardMaxX;
|
|
1891
|
-
const boundsMaxY = drawPaddingOutsideBoard || !isFinite(boardMaxY) ? maxY : boardMaxY;
|
|
1888
|
+
const boundsMinX = drawPaddingOutsideBoard || !Number.isFinite(boardMinX) ? minX : boardMinX;
|
|
1889
|
+
const boundsMinY = drawPaddingOutsideBoard || !Number.isFinite(boardMinY) ? minY : boardMinY;
|
|
1890
|
+
const boundsMaxX = drawPaddingOutsideBoard || !Number.isFinite(boardMaxX) ? maxX : boardMaxX;
|
|
1891
|
+
const boundsMaxY = drawPaddingOutsideBoard || !Number.isFinite(boardMaxY) ? maxY : boardMaxY;
|
|
1892
1892
|
const circuitWidth = boundsMaxX - boundsMinX + 2 * padding;
|
|
1893
1893
|
const circuitHeight = boundsMaxY - boundsMinY + 2 * padding;
|
|
1894
1894
|
let svgWidth = options?.width ?? 800;
|
|
@@ -4467,6 +4467,27 @@ function getSchematicBoundsFromCircuitJson(soup, padding = 0.5) {
|
|
|
4467
4467
|
{ width: totalWidth, height: totalHeight },
|
|
4468
4468
|
0
|
|
4469
4469
|
);
|
|
4470
|
+
} else if (item.type === "schematic_line") {
|
|
4471
|
+
updateBounds({ x: item.x1, y: item.y1 }, { width: 0.02, height: 0.02 }, 0);
|
|
4472
|
+
updateBounds({ x: item.x2, y: item.y2 }, { width: 0.02, height: 0.02 }, 0);
|
|
4473
|
+
} else if (item.type === "schematic_circle") {
|
|
4474
|
+
updateBounds(
|
|
4475
|
+
item.center,
|
|
4476
|
+
{ width: item.radius * 2, height: item.radius * 2 },
|
|
4477
|
+
0
|
|
4478
|
+
);
|
|
4479
|
+
} else if (item.type === "schematic_rect") {
|
|
4480
|
+
updateBounds(
|
|
4481
|
+
item.center,
|
|
4482
|
+
{ width: item.width, height: item.height },
|
|
4483
|
+
item.rotation
|
|
4484
|
+
);
|
|
4485
|
+
} else if (item.type === "schematic_arc") {
|
|
4486
|
+
updateBounds(
|
|
4487
|
+
item.center,
|
|
4488
|
+
{ width: item.radius * 2, height: item.radius * 2 },
|
|
4489
|
+
0
|
|
4490
|
+
);
|
|
4470
4491
|
}
|
|
4471
4492
|
}
|
|
4472
4493
|
minX -= padding;
|
|
@@ -5338,6 +5359,9 @@ var createSvgObjectsFromSchematicComponentWithBox = ({
|
|
|
5338
5359
|
// lib/sch/svg-object-fns/create-svg-objects-from-sch-component.ts
|
|
5339
5360
|
function createSvgObjectsFromSchematicComponent(params) {
|
|
5340
5361
|
const { component } = params;
|
|
5362
|
+
if (component.is_box_with_pins === false) {
|
|
5363
|
+
return [];
|
|
5364
|
+
}
|
|
5341
5365
|
const innerElements = component.symbol_name ? createSvgObjectsFromSchematicComponentWithSymbol(params) : createSvgObjectsFromSchematicComponentWithBox(params);
|
|
5342
5366
|
return [
|
|
5343
5367
|
{
|
|
@@ -6380,6 +6404,170 @@ var createSvgObjectsForSchComponentPortHovers = ({
|
|
|
6380
6404
|
return svgs;
|
|
6381
6405
|
};
|
|
6382
6406
|
|
|
6407
|
+
// lib/sch/svg-object-fns/create-svg-objects-from-sch-line.ts
|
|
6408
|
+
import { applyToPoint as applyToPoint46 } from "transformation-matrix";
|
|
6409
|
+
function createSvgObjectsFromSchematicLine({
|
|
6410
|
+
schLine,
|
|
6411
|
+
transform,
|
|
6412
|
+
colorMap: colorMap2
|
|
6413
|
+
}) {
|
|
6414
|
+
const p1 = applyToPoint46(transform, { x: schLine.x1, y: schLine.y1 });
|
|
6415
|
+
const p2 = applyToPoint46(transform, { x: schLine.x2, y: schLine.y2 });
|
|
6416
|
+
const strokeWidth = schLine.stroke_width ?? 0.02;
|
|
6417
|
+
const transformedStrokeWidth = Math.abs(transform.a) * strokeWidth;
|
|
6418
|
+
return [
|
|
6419
|
+
{
|
|
6420
|
+
name: "line",
|
|
6421
|
+
type: "element",
|
|
6422
|
+
attributes: {
|
|
6423
|
+
x1: p1.x.toString(),
|
|
6424
|
+
y1: p1.y.toString(),
|
|
6425
|
+
x2: p2.x.toString(),
|
|
6426
|
+
y2: p2.y.toString(),
|
|
6427
|
+
stroke: schLine.color,
|
|
6428
|
+
"stroke-width": transformedStrokeWidth.toString(),
|
|
6429
|
+
...schLine.is_dashed && {
|
|
6430
|
+
"stroke-dasharray": (transformedStrokeWidth * 3).toString()
|
|
6431
|
+
},
|
|
6432
|
+
"data-schematic-line-id": schLine.schematic_line_id,
|
|
6433
|
+
...schLine.schematic_component_id && {
|
|
6434
|
+
"data-schematic-component-id": schLine.schematic_component_id
|
|
6435
|
+
}
|
|
6436
|
+
},
|
|
6437
|
+
children: [],
|
|
6438
|
+
value: ""
|
|
6439
|
+
}
|
|
6440
|
+
];
|
|
6441
|
+
}
|
|
6442
|
+
|
|
6443
|
+
// lib/sch/svg-object-fns/create-svg-objects-from-sch-circle.ts
|
|
6444
|
+
import { applyToPoint as applyToPoint47 } from "transformation-matrix";
|
|
6445
|
+
function createSvgObjectsFromSchematicCircle({
|
|
6446
|
+
schCircle,
|
|
6447
|
+
transform,
|
|
6448
|
+
colorMap: colorMap2
|
|
6449
|
+
}) {
|
|
6450
|
+
const center = applyToPoint47(transform, schCircle.center);
|
|
6451
|
+
const transformedRadius = Math.abs(transform.a) * schCircle.radius;
|
|
6452
|
+
const strokeWidth = schCircle.stroke_width ?? 0.02;
|
|
6453
|
+
const transformedStrokeWidth = Math.abs(transform.a) * strokeWidth;
|
|
6454
|
+
return [
|
|
6455
|
+
{
|
|
6456
|
+
name: "circle",
|
|
6457
|
+
type: "element",
|
|
6458
|
+
attributes: {
|
|
6459
|
+
cx: center.x.toString(),
|
|
6460
|
+
cy: center.y.toString(),
|
|
6461
|
+
r: transformedRadius.toString(),
|
|
6462
|
+
fill: schCircle.is_filled ? schCircle.fill_color ?? schCircle.color : "none",
|
|
6463
|
+
stroke: schCircle.color,
|
|
6464
|
+
"stroke-width": transformedStrokeWidth.toString(),
|
|
6465
|
+
...schCircle.is_dashed && {
|
|
6466
|
+
"stroke-dasharray": (transformedStrokeWidth * 3).toString()
|
|
6467
|
+
},
|
|
6468
|
+
"data-schematic-circle-id": schCircle.schematic_circle_id,
|
|
6469
|
+
...schCircle.schematic_component_id && {
|
|
6470
|
+
"data-schematic-component-id": schCircle.schematic_component_id
|
|
6471
|
+
}
|
|
6472
|
+
},
|
|
6473
|
+
children: [],
|
|
6474
|
+
value: ""
|
|
6475
|
+
}
|
|
6476
|
+
];
|
|
6477
|
+
}
|
|
6478
|
+
|
|
6479
|
+
// lib/sch/svg-object-fns/create-svg-objects-from-sch-rect.ts
|
|
6480
|
+
import { applyToPoint as applyToPoint48 } from "transformation-matrix";
|
|
6481
|
+
function createSvgObjectsFromSchematicRect({
|
|
6482
|
+
schRect,
|
|
6483
|
+
transform,
|
|
6484
|
+
colorMap: colorMap2
|
|
6485
|
+
}) {
|
|
6486
|
+
const center = applyToPoint48(transform, schRect.center);
|
|
6487
|
+
const transformedWidth = Math.abs(transform.a) * schRect.width;
|
|
6488
|
+
const transformedHeight = Math.abs(transform.d) * schRect.height;
|
|
6489
|
+
const strokeWidth = schRect.stroke_width ?? 0.02;
|
|
6490
|
+
const transformedStrokeWidth = Math.abs(transform.a) * strokeWidth;
|
|
6491
|
+
const x = center.x - transformedWidth / 2;
|
|
6492
|
+
const y = center.y - transformedHeight / 2;
|
|
6493
|
+
const svgRect = {
|
|
6494
|
+
name: "rect",
|
|
6495
|
+
type: "element",
|
|
6496
|
+
attributes: {
|
|
6497
|
+
x: x.toString(),
|
|
6498
|
+
y: y.toString(),
|
|
6499
|
+
width: transformedWidth.toString(),
|
|
6500
|
+
height: transformedHeight.toString(),
|
|
6501
|
+
fill: schRect.is_filled ? schRect.fill_color ?? schRect.color : "none",
|
|
6502
|
+
stroke: schRect.color,
|
|
6503
|
+
"stroke-width": transformedStrokeWidth.toString(),
|
|
6504
|
+
...schRect.is_dashed && {
|
|
6505
|
+
"stroke-dasharray": (transformedStrokeWidth * 3).toString()
|
|
6506
|
+
},
|
|
6507
|
+
...schRect.rotation !== 0 && {
|
|
6508
|
+
transform: `rotate(${schRect.rotation} ${center.x} ${center.y})`
|
|
6509
|
+
},
|
|
6510
|
+
"data-schematic-rect-id": schRect.schematic_rect_id,
|
|
6511
|
+
...schRect.schematic_component_id && {
|
|
6512
|
+
"data-schematic-component-id": schRect.schematic_component_id
|
|
6513
|
+
}
|
|
6514
|
+
},
|
|
6515
|
+
children: [],
|
|
6516
|
+
value: ""
|
|
6517
|
+
};
|
|
6518
|
+
return [svgRect];
|
|
6519
|
+
}
|
|
6520
|
+
|
|
6521
|
+
// lib/sch/svg-object-fns/create-svg-objects-from-sch-arc.ts
|
|
6522
|
+
import { applyToPoint as applyToPoint49 } from "transformation-matrix";
|
|
6523
|
+
function createSvgObjectsFromSchematicArc({
|
|
6524
|
+
schArc,
|
|
6525
|
+
transform,
|
|
6526
|
+
colorMap: colorMap2
|
|
6527
|
+
}) {
|
|
6528
|
+
const center = applyToPoint49(transform, schArc.center);
|
|
6529
|
+
const transformedRadius = Math.abs(transform.a) * schArc.radius;
|
|
6530
|
+
const strokeWidth = schArc.stroke_width ?? 0.02;
|
|
6531
|
+
const transformedStrokeWidth = Math.abs(transform.a) * strokeWidth;
|
|
6532
|
+
const startAngleRad = schArc.start_angle_degrees * Math.PI / 180;
|
|
6533
|
+
const endAngleRad = schArc.end_angle_degrees * Math.PI / 180;
|
|
6534
|
+
const startX = center.x + transformedRadius * Math.cos(startAngleRad);
|
|
6535
|
+
const startY = center.y + transformedRadius * Math.sin(startAngleRad);
|
|
6536
|
+
const endX = center.x + transformedRadius * Math.cos(endAngleRad);
|
|
6537
|
+
const endY = center.y + transformedRadius * Math.sin(endAngleRad);
|
|
6538
|
+
let angleDiff = schArc.end_angle_degrees - schArc.start_angle_degrees;
|
|
6539
|
+
if (schArc.direction === "clockwise") {
|
|
6540
|
+
angleDiff = -angleDiff;
|
|
6541
|
+
}
|
|
6542
|
+
if (angleDiff < 0) {
|
|
6543
|
+
angleDiff += 360;
|
|
6544
|
+
}
|
|
6545
|
+
const largeArcFlag = angleDiff > 180 ? 1 : 0;
|
|
6546
|
+
const sweepFlag = schArc.direction === "clockwise" ? 1 : 0;
|
|
6547
|
+
const pathData = `M ${startX} ${startY} A ${transformedRadius} ${transformedRadius} 0 ${largeArcFlag} ${sweepFlag} ${endX} ${endY}`;
|
|
6548
|
+
return [
|
|
6549
|
+
{
|
|
6550
|
+
name: "path",
|
|
6551
|
+
type: "element",
|
|
6552
|
+
attributes: {
|
|
6553
|
+
d: pathData,
|
|
6554
|
+
fill: "none",
|
|
6555
|
+
stroke: schArc.color,
|
|
6556
|
+
"stroke-width": transformedStrokeWidth.toString(),
|
|
6557
|
+
...schArc.is_dashed && {
|
|
6558
|
+
"stroke-dasharray": (transformedStrokeWidth * 3).toString()
|
|
6559
|
+
},
|
|
6560
|
+
"data-schematic-arc-id": schArc.schematic_arc_id,
|
|
6561
|
+
...schArc.schematic_component_id && {
|
|
6562
|
+
"data-schematic-component-id": schArc.schematic_component_id
|
|
6563
|
+
}
|
|
6564
|
+
},
|
|
6565
|
+
children: [],
|
|
6566
|
+
value: ""
|
|
6567
|
+
}
|
|
6568
|
+
];
|
|
6569
|
+
}
|
|
6570
|
+
|
|
6383
6571
|
// lib/sch/convert-circuit-json-to-schematic-svg.ts
|
|
6384
6572
|
function buildNetHoverStyles(connectivityKeys) {
|
|
6385
6573
|
const rules = [];
|
|
@@ -6470,6 +6658,10 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
6470
6658
|
const schBoxSvgs = [];
|
|
6471
6659
|
const schTableSvgs = [];
|
|
6472
6660
|
const schPortHoverSvgs = [];
|
|
6661
|
+
const schLineSvgs = [];
|
|
6662
|
+
const schCircleSvgs = [];
|
|
6663
|
+
const schRectSvgs = [];
|
|
6664
|
+
const schArcSvgs = [];
|
|
6473
6665
|
for (const elm of circuitJson) {
|
|
6474
6666
|
if (elm.type === "schematic_debug_object") {
|
|
6475
6667
|
schDebugObjectSvgs.push(
|
|
@@ -6544,6 +6736,38 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
6544
6736
|
circuitJson
|
|
6545
6737
|
})
|
|
6546
6738
|
);
|
|
6739
|
+
} else if (elm.type === "schematic_line") {
|
|
6740
|
+
schLineSvgs.push(
|
|
6741
|
+
...createSvgObjectsFromSchematicLine({
|
|
6742
|
+
schLine: elm,
|
|
6743
|
+
transform,
|
|
6744
|
+
colorMap: colorMap2
|
|
6745
|
+
})
|
|
6746
|
+
);
|
|
6747
|
+
} else if (elm.type === "schematic_circle") {
|
|
6748
|
+
schCircleSvgs.push(
|
|
6749
|
+
...createSvgObjectsFromSchematicCircle({
|
|
6750
|
+
schCircle: elm,
|
|
6751
|
+
transform,
|
|
6752
|
+
colorMap: colorMap2
|
|
6753
|
+
})
|
|
6754
|
+
);
|
|
6755
|
+
} else if (elm.type === "schematic_rect") {
|
|
6756
|
+
schRectSvgs.push(
|
|
6757
|
+
...createSvgObjectsFromSchematicRect({
|
|
6758
|
+
schRect: elm,
|
|
6759
|
+
transform,
|
|
6760
|
+
colorMap: colorMap2
|
|
6761
|
+
})
|
|
6762
|
+
);
|
|
6763
|
+
} else if (elm.type === "schematic_arc") {
|
|
6764
|
+
schArcSvgs.push(
|
|
6765
|
+
...createSvgObjectsFromSchematicArc({
|
|
6766
|
+
schArc: elm,
|
|
6767
|
+
transform,
|
|
6768
|
+
colorMap: colorMap2
|
|
6769
|
+
})
|
|
6770
|
+
);
|
|
6547
6771
|
}
|
|
6548
6772
|
}
|
|
6549
6773
|
const schTraceBaseSvgs = schTraceSvgs.filter(
|
|
@@ -6556,6 +6780,10 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
6556
6780
|
...schDebugObjectSvgs,
|
|
6557
6781
|
...schTraceBaseSvgs,
|
|
6558
6782
|
...schTraceOverlaySvgs,
|
|
6783
|
+
...schLineSvgs,
|
|
6784
|
+
...schCircleSvgs,
|
|
6785
|
+
...schRectSvgs,
|
|
6786
|
+
...schArcSvgs,
|
|
6559
6787
|
...schComponentSvgs,
|
|
6560
6788
|
...schPortHoverSvgs,
|
|
6561
6789
|
...schNetLabel,
|
|
@@ -6644,18 +6872,18 @@ var circuitJsonToSchematicSvg = convertCircuitJsonToSchematicSvg;
|
|
|
6644
6872
|
// lib/pcb/convert-circuit-json-to-solder-paste-mask.ts
|
|
6645
6873
|
import { stringify as stringify4 } from "svgson";
|
|
6646
6874
|
import {
|
|
6647
|
-
applyToPoint as
|
|
6648
|
-
compose as
|
|
6875
|
+
applyToPoint as applyToPoint52,
|
|
6876
|
+
compose as compose13,
|
|
6649
6877
|
scale as scale8,
|
|
6650
|
-
translate as
|
|
6878
|
+
translate as translate13
|
|
6651
6879
|
} from "transformation-matrix";
|
|
6652
6880
|
|
|
6653
6881
|
// lib/pcb/svg-object-fns/convert-circuit-json-to-solder-paste-mask.ts
|
|
6654
|
-
import { applyToPoint as
|
|
6882
|
+
import { applyToPoint as applyToPoint51 } from "transformation-matrix";
|
|
6655
6883
|
function createSvgObjectsFromSolderPaste(solderPaste, ctx) {
|
|
6656
6884
|
const { transform, layer: layerFilter } = ctx;
|
|
6657
6885
|
if (layerFilter && solderPaste.layer !== layerFilter) return [];
|
|
6658
|
-
const [x, y] =
|
|
6886
|
+
const [x, y] = applyToPoint51(transform, [solderPaste.x, solderPaste.y]);
|
|
6659
6887
|
if (solderPaste.shape === "rect" || solderPaste.shape === "rotated_rect") {
|
|
6660
6888
|
const width = solderPaste.width * Math.abs(transform.a);
|
|
6661
6889
|
const height = solderPaste.height * Math.abs(transform.d);
|
|
@@ -6763,8 +6991,8 @@ function convertCircuitJsonToSolderPasteMask(circuitJson, options) {
|
|
|
6763
6991
|
const scaleFactor = Math.min(scaleX, scaleY);
|
|
6764
6992
|
const offsetX = (svgWidth - circuitWidth * scaleFactor) / 2;
|
|
6765
6993
|
const offsetY = (svgHeight - circuitHeight * scaleFactor) / 2;
|
|
6766
|
-
const transform =
|
|
6767
|
-
|
|
6994
|
+
const transform = compose13(
|
|
6995
|
+
translate13(
|
|
6768
6996
|
offsetX - minX * scaleFactor + padding * scaleFactor,
|
|
6769
6997
|
svgHeight - offsetY + minY * scaleFactor - padding * scaleFactor
|
|
6770
6998
|
),
|
|
@@ -6858,8 +7086,8 @@ function createSvgObjects3({ elm, ctx }) {
|
|
|
6858
7086
|
}
|
|
6859
7087
|
}
|
|
6860
7088
|
function createSvgObjectFromPcbBoundary2(transform, minX, minY, maxX, maxY) {
|
|
6861
|
-
const [x1, y1] =
|
|
6862
|
-
const [x2, y2] =
|
|
7089
|
+
const [x1, y1] = applyToPoint52(transform, [minX, minY]);
|
|
7090
|
+
const [x2, y2] = applyToPoint52(transform, [maxX, maxY]);
|
|
6863
7091
|
const width = Math.abs(x2 - x1);
|
|
6864
7092
|
const height = Math.abs(y2 - y1);
|
|
6865
7093
|
const x = Math.min(x1, x2);
|