circuit-to-svg 0.0.195 → 0.0.196
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 +241 -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.195",
|
|
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.260",
|
|
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;
|
|
@@ -6380,6 +6401,170 @@ var createSvgObjectsForSchComponentPortHovers = ({
|
|
|
6380
6401
|
return svgs;
|
|
6381
6402
|
};
|
|
6382
6403
|
|
|
6404
|
+
// lib/sch/svg-object-fns/create-svg-objects-from-sch-line.ts
|
|
6405
|
+
import { applyToPoint as applyToPoint46 } from "transformation-matrix";
|
|
6406
|
+
function createSvgObjectsFromSchematicLine({
|
|
6407
|
+
schLine,
|
|
6408
|
+
transform,
|
|
6409
|
+
colorMap: colorMap2
|
|
6410
|
+
}) {
|
|
6411
|
+
const p1 = applyToPoint46(transform, { x: schLine.x1, y: schLine.y1 });
|
|
6412
|
+
const p2 = applyToPoint46(transform, { x: schLine.x2, y: schLine.y2 });
|
|
6413
|
+
const strokeWidth = schLine.stroke_width ?? 0.02;
|
|
6414
|
+
const transformedStrokeWidth = Math.abs(transform.a) * strokeWidth;
|
|
6415
|
+
return [
|
|
6416
|
+
{
|
|
6417
|
+
name: "line",
|
|
6418
|
+
type: "element",
|
|
6419
|
+
attributes: {
|
|
6420
|
+
x1: p1.x.toString(),
|
|
6421
|
+
y1: p1.y.toString(),
|
|
6422
|
+
x2: p2.x.toString(),
|
|
6423
|
+
y2: p2.y.toString(),
|
|
6424
|
+
stroke: schLine.color,
|
|
6425
|
+
"stroke-width": transformedStrokeWidth.toString(),
|
|
6426
|
+
...schLine.is_dashed && {
|
|
6427
|
+
"stroke-dasharray": (transformedStrokeWidth * 3).toString()
|
|
6428
|
+
},
|
|
6429
|
+
"data-schematic-line-id": schLine.schematic_line_id,
|
|
6430
|
+
...schLine.schematic_component_id && {
|
|
6431
|
+
"data-schematic-component-id": schLine.schematic_component_id
|
|
6432
|
+
}
|
|
6433
|
+
},
|
|
6434
|
+
children: [],
|
|
6435
|
+
value: ""
|
|
6436
|
+
}
|
|
6437
|
+
];
|
|
6438
|
+
}
|
|
6439
|
+
|
|
6440
|
+
// lib/sch/svg-object-fns/create-svg-objects-from-sch-circle.ts
|
|
6441
|
+
import { applyToPoint as applyToPoint47 } from "transformation-matrix";
|
|
6442
|
+
function createSvgObjectsFromSchematicCircle({
|
|
6443
|
+
schCircle,
|
|
6444
|
+
transform,
|
|
6445
|
+
colorMap: colorMap2
|
|
6446
|
+
}) {
|
|
6447
|
+
const center = applyToPoint47(transform, schCircle.center);
|
|
6448
|
+
const transformedRadius = Math.abs(transform.a) * schCircle.radius;
|
|
6449
|
+
const strokeWidth = schCircle.stroke_width ?? 0.02;
|
|
6450
|
+
const transformedStrokeWidth = Math.abs(transform.a) * strokeWidth;
|
|
6451
|
+
return [
|
|
6452
|
+
{
|
|
6453
|
+
name: "circle",
|
|
6454
|
+
type: "element",
|
|
6455
|
+
attributes: {
|
|
6456
|
+
cx: center.x.toString(),
|
|
6457
|
+
cy: center.y.toString(),
|
|
6458
|
+
r: transformedRadius.toString(),
|
|
6459
|
+
fill: schCircle.is_filled ? schCircle.fill_color ?? schCircle.color : "none",
|
|
6460
|
+
stroke: schCircle.color,
|
|
6461
|
+
"stroke-width": transformedStrokeWidth.toString(),
|
|
6462
|
+
...schCircle.is_dashed && {
|
|
6463
|
+
"stroke-dasharray": (transformedStrokeWidth * 3).toString()
|
|
6464
|
+
},
|
|
6465
|
+
"data-schematic-circle-id": schCircle.schematic_circle_id,
|
|
6466
|
+
...schCircle.schematic_component_id && {
|
|
6467
|
+
"data-schematic-component-id": schCircle.schematic_component_id
|
|
6468
|
+
}
|
|
6469
|
+
},
|
|
6470
|
+
children: [],
|
|
6471
|
+
value: ""
|
|
6472
|
+
}
|
|
6473
|
+
];
|
|
6474
|
+
}
|
|
6475
|
+
|
|
6476
|
+
// lib/sch/svg-object-fns/create-svg-objects-from-sch-rect.ts
|
|
6477
|
+
import { applyToPoint as applyToPoint48 } from "transformation-matrix";
|
|
6478
|
+
function createSvgObjectsFromSchematicRect({
|
|
6479
|
+
schRect,
|
|
6480
|
+
transform,
|
|
6481
|
+
colorMap: colorMap2
|
|
6482
|
+
}) {
|
|
6483
|
+
const center = applyToPoint48(transform, schRect.center);
|
|
6484
|
+
const transformedWidth = Math.abs(transform.a) * schRect.width;
|
|
6485
|
+
const transformedHeight = Math.abs(transform.d) * schRect.height;
|
|
6486
|
+
const strokeWidth = schRect.stroke_width ?? 0.02;
|
|
6487
|
+
const transformedStrokeWidth = Math.abs(transform.a) * strokeWidth;
|
|
6488
|
+
const x = center.x - transformedWidth / 2;
|
|
6489
|
+
const y = center.y - transformedHeight / 2;
|
|
6490
|
+
const svgRect = {
|
|
6491
|
+
name: "rect",
|
|
6492
|
+
type: "element",
|
|
6493
|
+
attributes: {
|
|
6494
|
+
x: x.toString(),
|
|
6495
|
+
y: y.toString(),
|
|
6496
|
+
width: transformedWidth.toString(),
|
|
6497
|
+
height: transformedHeight.toString(),
|
|
6498
|
+
fill: schRect.is_filled ? schRect.fill_color ?? schRect.color : "none",
|
|
6499
|
+
stroke: schRect.color,
|
|
6500
|
+
"stroke-width": transformedStrokeWidth.toString(),
|
|
6501
|
+
...schRect.is_dashed && {
|
|
6502
|
+
"stroke-dasharray": (transformedStrokeWidth * 3).toString()
|
|
6503
|
+
},
|
|
6504
|
+
...schRect.rotation !== 0 && {
|
|
6505
|
+
transform: `rotate(${schRect.rotation} ${center.x} ${center.y})`
|
|
6506
|
+
},
|
|
6507
|
+
"data-schematic-rect-id": schRect.schematic_rect_id,
|
|
6508
|
+
...schRect.schematic_component_id && {
|
|
6509
|
+
"data-schematic-component-id": schRect.schematic_component_id
|
|
6510
|
+
}
|
|
6511
|
+
},
|
|
6512
|
+
children: [],
|
|
6513
|
+
value: ""
|
|
6514
|
+
};
|
|
6515
|
+
return [svgRect];
|
|
6516
|
+
}
|
|
6517
|
+
|
|
6518
|
+
// lib/sch/svg-object-fns/create-svg-objects-from-sch-arc.ts
|
|
6519
|
+
import { applyToPoint as applyToPoint49 } from "transformation-matrix";
|
|
6520
|
+
function createSvgObjectsFromSchematicArc({
|
|
6521
|
+
schArc,
|
|
6522
|
+
transform,
|
|
6523
|
+
colorMap: colorMap2
|
|
6524
|
+
}) {
|
|
6525
|
+
const center = applyToPoint49(transform, schArc.center);
|
|
6526
|
+
const transformedRadius = Math.abs(transform.a) * schArc.radius;
|
|
6527
|
+
const strokeWidth = schArc.stroke_width ?? 0.02;
|
|
6528
|
+
const transformedStrokeWidth = Math.abs(transform.a) * strokeWidth;
|
|
6529
|
+
const startAngleRad = schArc.start_angle_degrees * Math.PI / 180;
|
|
6530
|
+
const endAngleRad = schArc.end_angle_degrees * Math.PI / 180;
|
|
6531
|
+
const startX = center.x + transformedRadius * Math.cos(startAngleRad);
|
|
6532
|
+
const startY = center.y + transformedRadius * Math.sin(startAngleRad);
|
|
6533
|
+
const endX = center.x + transformedRadius * Math.cos(endAngleRad);
|
|
6534
|
+
const endY = center.y + transformedRadius * Math.sin(endAngleRad);
|
|
6535
|
+
let angleDiff = schArc.end_angle_degrees - schArc.start_angle_degrees;
|
|
6536
|
+
if (schArc.direction === "clockwise") {
|
|
6537
|
+
angleDiff = -angleDiff;
|
|
6538
|
+
}
|
|
6539
|
+
if (angleDiff < 0) {
|
|
6540
|
+
angleDiff += 360;
|
|
6541
|
+
}
|
|
6542
|
+
const largeArcFlag = angleDiff > 180 ? 1 : 0;
|
|
6543
|
+
const sweepFlag = schArc.direction === "clockwise" ? 1 : 0;
|
|
6544
|
+
const pathData = `M ${startX} ${startY} A ${transformedRadius} ${transformedRadius} 0 ${largeArcFlag} ${sweepFlag} ${endX} ${endY}`;
|
|
6545
|
+
return [
|
|
6546
|
+
{
|
|
6547
|
+
name: "path",
|
|
6548
|
+
type: "element",
|
|
6549
|
+
attributes: {
|
|
6550
|
+
d: pathData,
|
|
6551
|
+
fill: "none",
|
|
6552
|
+
stroke: schArc.color,
|
|
6553
|
+
"stroke-width": transformedStrokeWidth.toString(),
|
|
6554
|
+
...schArc.is_dashed && {
|
|
6555
|
+
"stroke-dasharray": (transformedStrokeWidth * 3).toString()
|
|
6556
|
+
},
|
|
6557
|
+
"data-schematic-arc-id": schArc.schematic_arc_id,
|
|
6558
|
+
...schArc.schematic_component_id && {
|
|
6559
|
+
"data-schematic-component-id": schArc.schematic_component_id
|
|
6560
|
+
}
|
|
6561
|
+
},
|
|
6562
|
+
children: [],
|
|
6563
|
+
value: ""
|
|
6564
|
+
}
|
|
6565
|
+
];
|
|
6566
|
+
}
|
|
6567
|
+
|
|
6383
6568
|
// lib/sch/convert-circuit-json-to-schematic-svg.ts
|
|
6384
6569
|
function buildNetHoverStyles(connectivityKeys) {
|
|
6385
6570
|
const rules = [];
|
|
@@ -6470,6 +6655,10 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
6470
6655
|
const schBoxSvgs = [];
|
|
6471
6656
|
const schTableSvgs = [];
|
|
6472
6657
|
const schPortHoverSvgs = [];
|
|
6658
|
+
const schLineSvgs = [];
|
|
6659
|
+
const schCircleSvgs = [];
|
|
6660
|
+
const schRectSvgs = [];
|
|
6661
|
+
const schArcSvgs = [];
|
|
6473
6662
|
for (const elm of circuitJson) {
|
|
6474
6663
|
if (elm.type === "schematic_debug_object") {
|
|
6475
6664
|
schDebugObjectSvgs.push(
|
|
@@ -6544,6 +6733,38 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
6544
6733
|
circuitJson
|
|
6545
6734
|
})
|
|
6546
6735
|
);
|
|
6736
|
+
} else if (elm.type === "schematic_line") {
|
|
6737
|
+
schLineSvgs.push(
|
|
6738
|
+
...createSvgObjectsFromSchematicLine({
|
|
6739
|
+
schLine: elm,
|
|
6740
|
+
transform,
|
|
6741
|
+
colorMap: colorMap2
|
|
6742
|
+
})
|
|
6743
|
+
);
|
|
6744
|
+
} else if (elm.type === "schematic_circle") {
|
|
6745
|
+
schCircleSvgs.push(
|
|
6746
|
+
...createSvgObjectsFromSchematicCircle({
|
|
6747
|
+
schCircle: elm,
|
|
6748
|
+
transform,
|
|
6749
|
+
colorMap: colorMap2
|
|
6750
|
+
})
|
|
6751
|
+
);
|
|
6752
|
+
} else if (elm.type === "schematic_rect") {
|
|
6753
|
+
schRectSvgs.push(
|
|
6754
|
+
...createSvgObjectsFromSchematicRect({
|
|
6755
|
+
schRect: elm,
|
|
6756
|
+
transform,
|
|
6757
|
+
colorMap: colorMap2
|
|
6758
|
+
})
|
|
6759
|
+
);
|
|
6760
|
+
} else if (elm.type === "schematic_arc") {
|
|
6761
|
+
schArcSvgs.push(
|
|
6762
|
+
...createSvgObjectsFromSchematicArc({
|
|
6763
|
+
schArc: elm,
|
|
6764
|
+
transform,
|
|
6765
|
+
colorMap: colorMap2
|
|
6766
|
+
})
|
|
6767
|
+
);
|
|
6547
6768
|
}
|
|
6548
6769
|
}
|
|
6549
6770
|
const schTraceBaseSvgs = schTraceSvgs.filter(
|
|
@@ -6556,6 +6777,10 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
6556
6777
|
...schDebugObjectSvgs,
|
|
6557
6778
|
...schTraceBaseSvgs,
|
|
6558
6779
|
...schTraceOverlaySvgs,
|
|
6780
|
+
...schLineSvgs,
|
|
6781
|
+
...schCircleSvgs,
|
|
6782
|
+
...schRectSvgs,
|
|
6783
|
+
...schArcSvgs,
|
|
6559
6784
|
...schComponentSvgs,
|
|
6560
6785
|
...schPortHoverSvgs,
|
|
6561
6786
|
...schNetLabel,
|
|
@@ -6644,18 +6869,18 @@ var circuitJsonToSchematicSvg = convertCircuitJsonToSchematicSvg;
|
|
|
6644
6869
|
// lib/pcb/convert-circuit-json-to-solder-paste-mask.ts
|
|
6645
6870
|
import { stringify as stringify4 } from "svgson";
|
|
6646
6871
|
import {
|
|
6647
|
-
applyToPoint as
|
|
6648
|
-
compose as
|
|
6872
|
+
applyToPoint as applyToPoint52,
|
|
6873
|
+
compose as compose13,
|
|
6649
6874
|
scale as scale8,
|
|
6650
|
-
translate as
|
|
6875
|
+
translate as translate13
|
|
6651
6876
|
} from "transformation-matrix";
|
|
6652
6877
|
|
|
6653
6878
|
// lib/pcb/svg-object-fns/convert-circuit-json-to-solder-paste-mask.ts
|
|
6654
|
-
import { applyToPoint as
|
|
6879
|
+
import { applyToPoint as applyToPoint51 } from "transformation-matrix";
|
|
6655
6880
|
function createSvgObjectsFromSolderPaste(solderPaste, ctx) {
|
|
6656
6881
|
const { transform, layer: layerFilter } = ctx;
|
|
6657
6882
|
if (layerFilter && solderPaste.layer !== layerFilter) return [];
|
|
6658
|
-
const [x, y] =
|
|
6883
|
+
const [x, y] = applyToPoint51(transform, [solderPaste.x, solderPaste.y]);
|
|
6659
6884
|
if (solderPaste.shape === "rect" || solderPaste.shape === "rotated_rect") {
|
|
6660
6885
|
const width = solderPaste.width * Math.abs(transform.a);
|
|
6661
6886
|
const height = solderPaste.height * Math.abs(transform.d);
|
|
@@ -6763,8 +6988,8 @@ function convertCircuitJsonToSolderPasteMask(circuitJson, options) {
|
|
|
6763
6988
|
const scaleFactor = Math.min(scaleX, scaleY);
|
|
6764
6989
|
const offsetX = (svgWidth - circuitWidth * scaleFactor) / 2;
|
|
6765
6990
|
const offsetY = (svgHeight - circuitHeight * scaleFactor) / 2;
|
|
6766
|
-
const transform =
|
|
6767
|
-
|
|
6991
|
+
const transform = compose13(
|
|
6992
|
+
translate13(
|
|
6768
6993
|
offsetX - minX * scaleFactor + padding * scaleFactor,
|
|
6769
6994
|
svgHeight - offsetY + minY * scaleFactor - padding * scaleFactor
|
|
6770
6995
|
),
|
|
@@ -6858,8 +7083,8 @@ function createSvgObjects3({ elm, ctx }) {
|
|
|
6858
7083
|
}
|
|
6859
7084
|
}
|
|
6860
7085
|
function createSvgObjectFromPcbBoundary2(transform, minX, minY, maxX, maxY) {
|
|
6861
|
-
const [x1, y1] =
|
|
6862
|
-
const [x2, y2] =
|
|
7086
|
+
const [x1, y1] = applyToPoint52(transform, [minX, minY]);
|
|
7087
|
+
const [x2, y2] = applyToPoint52(transform, [maxX, maxY]);
|
|
6863
7088
|
const width = Math.abs(x2 - x1);
|
|
6864
7089
|
const height = Math.abs(y2 - y1);
|
|
6865
7090
|
const x = Math.min(x1, x2);
|