circuit-to-svg 0.0.312 → 0.0.314
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 +214 -47
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5270,12 +5270,86 @@ import {
|
|
|
5270
5270
|
translate as translate5,
|
|
5271
5271
|
toString as matrixToString8
|
|
5272
5272
|
} from "transformation-matrix";
|
|
5273
|
+
var KEEPOUT_PATTERN_ID = "pcb-keepout-pattern";
|
|
5274
|
+
var KEEPOUT_PATTERN_SIZE = 20;
|
|
5275
|
+
var KEEPOUT_LINE_SPACING = 5;
|
|
5276
|
+
var KEEPOUT_BACKGROUND_COLOR = "rgba(255, 107, 107, 0.2)";
|
|
5277
|
+
function createKeepoutPatternLines(keepoutColor) {
|
|
5278
|
+
const patternLines = [];
|
|
5279
|
+
for (let i = -KEEPOUT_PATTERN_SIZE; i <= KEEPOUT_PATTERN_SIZE; i += KEEPOUT_LINE_SPACING) {
|
|
5280
|
+
patternLines.push({
|
|
5281
|
+
name: "line",
|
|
5282
|
+
type: "element",
|
|
5283
|
+
value: "",
|
|
5284
|
+
attributes: {
|
|
5285
|
+
x1: i.toString(),
|
|
5286
|
+
y1: "0",
|
|
5287
|
+
x2: (i + KEEPOUT_PATTERN_SIZE).toString(),
|
|
5288
|
+
y2: KEEPOUT_PATTERN_SIZE.toString(),
|
|
5289
|
+
stroke: keepoutColor,
|
|
5290
|
+
"stroke-width": "1"
|
|
5291
|
+
},
|
|
5292
|
+
children: []
|
|
5293
|
+
});
|
|
5294
|
+
}
|
|
5295
|
+
return patternLines;
|
|
5296
|
+
}
|
|
5297
|
+
function createKeepoutPatternDefs(keepoutColor) {
|
|
5298
|
+
return {
|
|
5299
|
+
name: "defs",
|
|
5300
|
+
type: "element",
|
|
5301
|
+
value: "",
|
|
5302
|
+
attributes: {},
|
|
5303
|
+
children: [
|
|
5304
|
+
{
|
|
5305
|
+
name: "pattern",
|
|
5306
|
+
type: "element",
|
|
5307
|
+
value: "",
|
|
5308
|
+
attributes: {
|
|
5309
|
+
id: KEEPOUT_PATTERN_ID,
|
|
5310
|
+
width: KEEPOUT_PATTERN_SIZE.toString(),
|
|
5311
|
+
height: KEEPOUT_PATTERN_SIZE.toString(),
|
|
5312
|
+
patternUnits: "userSpaceOnUse"
|
|
5313
|
+
},
|
|
5314
|
+
children: createKeepoutPatternLines(keepoutColor)
|
|
5315
|
+
}
|
|
5316
|
+
]
|
|
5317
|
+
};
|
|
5318
|
+
}
|
|
5319
|
+
function createKeepoutBaseAttributes(keepoutId, layer, shapeClass, description) {
|
|
5320
|
+
const attributes = {
|
|
5321
|
+
class: `pcb-keepout ${shapeClass} pcb-keepout-background`,
|
|
5322
|
+
"data-type": "pcb_keepout",
|
|
5323
|
+
"data-pcb-layer": layer,
|
|
5324
|
+
"data-pcb-keepout-id": keepoutId,
|
|
5325
|
+
stroke: "none"
|
|
5326
|
+
};
|
|
5327
|
+
if (description) {
|
|
5328
|
+
attributes["data-description"] = description;
|
|
5329
|
+
}
|
|
5330
|
+
return attributes;
|
|
5331
|
+
}
|
|
5332
|
+
function createKeepoutPatternAttributes(keepoutId, layer, shapeClass, description) {
|
|
5333
|
+
const attributes = {
|
|
5334
|
+
class: `pcb-keepout ${shapeClass} pcb-keepout-pattern`,
|
|
5335
|
+
fill: `url(#${KEEPOUT_PATTERN_ID})`,
|
|
5336
|
+
"data-type": "pcb_keepout",
|
|
5337
|
+
"data-pcb-layer": layer,
|
|
5338
|
+
"data-pcb-keepout-id": keepoutId,
|
|
5339
|
+
stroke: "none"
|
|
5340
|
+
};
|
|
5341
|
+
if (description) {
|
|
5342
|
+
attributes["data-description"] = description;
|
|
5343
|
+
}
|
|
5344
|
+
return attributes;
|
|
5345
|
+
}
|
|
5273
5346
|
function createSvgObjectsFromPcbKeepout(keepout, ctx) {
|
|
5274
5347
|
const { transform, layer: layerFilter, colorMap: colorMap2 } = ctx;
|
|
5275
5348
|
if (layerFilter && !keepout.layers.includes(layerFilter)) {
|
|
5276
5349
|
return [];
|
|
5277
5350
|
}
|
|
5278
5351
|
const svgObjects = [];
|
|
5352
|
+
const keepoutColor = colorMap2.keepout;
|
|
5279
5353
|
for (const layer of keepout.layers) {
|
|
5280
5354
|
if (layerFilter && layer !== layerFilter) {
|
|
5281
5355
|
continue;
|
|
@@ -5288,32 +5362,50 @@ function createSvgObjectsFromPcbKeepout(keepout, ctx) {
|
|
|
5288
5362
|
]);
|
|
5289
5363
|
const scaledWidth = rectKeepout.width * Math.abs(transform.a);
|
|
5290
5364
|
const scaledHeight = rectKeepout.height * Math.abs(transform.d);
|
|
5291
|
-
const
|
|
5292
|
-
const
|
|
5293
|
-
|
|
5365
|
+
const baseTransform = matrixToString8(compose5(translate5(cx, cy)));
|
|
5366
|
+
const backgroundAttributes = {
|
|
5367
|
+
...createKeepoutBaseAttributes(
|
|
5368
|
+
rectKeepout.pcb_keepout_id,
|
|
5369
|
+
layer,
|
|
5370
|
+
"pcb-keepout-rect",
|
|
5371
|
+
rectKeepout.description
|
|
5372
|
+
),
|
|
5294
5373
|
x: (-scaledWidth / 2).toString(),
|
|
5295
5374
|
y: (-scaledHeight / 2).toString(),
|
|
5296
5375
|
width: scaledWidth.toString(),
|
|
5297
5376
|
height: scaledHeight.toString(),
|
|
5298
|
-
fill:
|
|
5299
|
-
|
|
5300
|
-
"stroke-width": transformedStrokeWidth.toString(),
|
|
5301
|
-
"stroke-dasharray": `${transformedStrokeWidth * 3} ${transformedStrokeWidth * 2}`,
|
|
5302
|
-
transform: matrixToString8(compose5(translate5(cx, cy))),
|
|
5303
|
-
"data-type": "pcb_keepout",
|
|
5304
|
-
"data-pcb-layer": layer,
|
|
5305
|
-
"data-pcb-keepout-id": rectKeepout.pcb_keepout_id
|
|
5377
|
+
fill: KEEPOUT_BACKGROUND_COLOR,
|
|
5378
|
+
transform: baseTransform
|
|
5306
5379
|
};
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5380
|
+
const patternAttributes = {
|
|
5381
|
+
...createKeepoutPatternAttributes(
|
|
5382
|
+
rectKeepout.pcb_keepout_id,
|
|
5383
|
+
layer,
|
|
5384
|
+
"pcb-keepout-rect",
|
|
5385
|
+
rectKeepout.description
|
|
5386
|
+
),
|
|
5387
|
+
x: (-scaledWidth / 2).toString(),
|
|
5388
|
+
y: (-scaledHeight / 2).toString(),
|
|
5389
|
+
width: scaledWidth.toString(),
|
|
5390
|
+
height: scaledHeight.toString(),
|
|
5391
|
+
transform: baseTransform
|
|
5392
|
+
};
|
|
5393
|
+
svgObjects.push(
|
|
5394
|
+
{
|
|
5395
|
+
name: "rect",
|
|
5396
|
+
type: "element",
|
|
5397
|
+
attributes: backgroundAttributes,
|
|
5398
|
+
children: [],
|
|
5399
|
+
value: ""
|
|
5400
|
+
},
|
|
5401
|
+
{
|
|
5402
|
+
name: "rect",
|
|
5403
|
+
type: "element",
|
|
5404
|
+
attributes: patternAttributes,
|
|
5405
|
+
children: [],
|
|
5406
|
+
value: ""
|
|
5407
|
+
}
|
|
5408
|
+
);
|
|
5317
5409
|
} else if (keepout.shape === "circle") {
|
|
5318
5410
|
const circleKeepout = keepout;
|
|
5319
5411
|
const [cx, cy] = applyToPoint33(transform, [
|
|
@@ -5321,30 +5413,45 @@ function createSvgObjectsFromPcbKeepout(keepout, ctx) {
|
|
|
5321
5413
|
circleKeepout.center.y
|
|
5322
5414
|
]);
|
|
5323
5415
|
const scaledRadius = circleKeepout.radius * Math.abs(transform.a);
|
|
5324
|
-
const
|
|
5325
|
-
|
|
5326
|
-
|
|
5416
|
+
const backgroundAttributes = {
|
|
5417
|
+
...createKeepoutBaseAttributes(
|
|
5418
|
+
circleKeepout.pcb_keepout_id,
|
|
5419
|
+
layer,
|
|
5420
|
+
"pcb-keepout-circle",
|
|
5421
|
+
circleKeepout.description
|
|
5422
|
+
),
|
|
5327
5423
|
cx: cx.toString(),
|
|
5328
5424
|
cy: cy.toString(),
|
|
5329
5425
|
r: scaledRadius.toString(),
|
|
5330
|
-
fill:
|
|
5331
|
-
stroke: colorMap2.keepout ?? "#FF6B6B",
|
|
5332
|
-
"stroke-width": transformedStrokeWidth.toString(),
|
|
5333
|
-
"stroke-dasharray": `${transformedStrokeWidth * 3} ${transformedStrokeWidth * 2}`,
|
|
5334
|
-
"data-type": "pcb_keepout",
|
|
5335
|
-
"data-pcb-layer": layer,
|
|
5336
|
-
"data-pcb-keepout-id": circleKeepout.pcb_keepout_id
|
|
5426
|
+
fill: KEEPOUT_BACKGROUND_COLOR
|
|
5337
5427
|
};
|
|
5338
|
-
|
|
5339
|
-
|
|
5340
|
-
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
5428
|
+
const patternAttributes = {
|
|
5429
|
+
...createKeepoutPatternAttributes(
|
|
5430
|
+
circleKeepout.pcb_keepout_id,
|
|
5431
|
+
layer,
|
|
5432
|
+
"pcb-keepout-circle",
|
|
5433
|
+
circleKeepout.description
|
|
5434
|
+
),
|
|
5435
|
+
cx: cx.toString(),
|
|
5436
|
+
cy: cy.toString(),
|
|
5437
|
+
r: scaledRadius.toString()
|
|
5438
|
+
};
|
|
5439
|
+
svgObjects.push(
|
|
5440
|
+
{
|
|
5441
|
+
name: "circle",
|
|
5442
|
+
type: "element",
|
|
5443
|
+
attributes: backgroundAttributes,
|
|
5444
|
+
children: [],
|
|
5445
|
+
value: ""
|
|
5446
|
+
},
|
|
5447
|
+
{
|
|
5448
|
+
name: "circle",
|
|
5449
|
+
type: "element",
|
|
5450
|
+
attributes: patternAttributes,
|
|
5451
|
+
children: [],
|
|
5452
|
+
value: ""
|
|
5453
|
+
}
|
|
5454
|
+
);
|
|
5348
5455
|
}
|
|
5349
5456
|
}
|
|
5350
5457
|
return svgObjects;
|
|
@@ -5927,7 +6034,7 @@ function getSoftwareUsedString(circuitJson) {
|
|
|
5927
6034
|
var package_default = {
|
|
5928
6035
|
name: "circuit-to-svg",
|
|
5929
6036
|
type: "module",
|
|
5930
|
-
version: "0.0.
|
|
6037
|
+
version: "0.0.313",
|
|
5931
6038
|
description: "Convert Circuit JSON to SVG",
|
|
5932
6039
|
main: "dist/index.js",
|
|
5933
6040
|
files: [
|
|
@@ -6785,6 +6892,14 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
|
|
|
6785
6892
|
if (gridObjects.defs) {
|
|
6786
6893
|
children.push(gridObjects.defs);
|
|
6787
6894
|
}
|
|
6895
|
+
const hasKeepouts = circuitJson.some((elm) => elm.type === "pcb_keepout");
|
|
6896
|
+
if (hasKeepouts) {
|
|
6897
|
+
children.push(
|
|
6898
|
+
createKeepoutPatternDefs(
|
|
6899
|
+
colorMap2.keepout ?? DEFAULT_PCB_COLOR_MAP.keepout
|
|
6900
|
+
)
|
|
6901
|
+
);
|
|
6902
|
+
}
|
|
6788
6903
|
children.push({
|
|
6789
6904
|
name: "rect",
|
|
6790
6905
|
type: "element",
|
|
@@ -10372,6 +10487,10 @@ function getSchematicBoundsFromCircuitJson(soup, padding = 0.5) {
|
|
|
10372
10487
|
{ width: item.radius * 2, height: item.radius * 2 },
|
|
10373
10488
|
0
|
|
10374
10489
|
);
|
|
10490
|
+
} else if (item.type === "schematic_path") {
|
|
10491
|
+
for (const point of item.points) {
|
|
10492
|
+
updateBounds(point, { width: 0.02, height: 0.02 }, 0);
|
|
10493
|
+
}
|
|
10375
10494
|
}
|
|
10376
10495
|
}
|
|
10377
10496
|
minX -= padding;
|
|
@@ -12568,6 +12687,44 @@ function createSvgObjectsFromSchematicArc({
|
|
|
12568
12687
|
];
|
|
12569
12688
|
}
|
|
12570
12689
|
|
|
12690
|
+
// lib/sch/svg-object-fns/create-svg-objects-from-sch-path.ts
|
|
12691
|
+
import { applyToPoint as applyToPoint75 } from "transformation-matrix";
|
|
12692
|
+
function createSvgObjectsFromSchematicPath({
|
|
12693
|
+
schPath,
|
|
12694
|
+
transform,
|
|
12695
|
+
colorMap: colorMap2
|
|
12696
|
+
}) {
|
|
12697
|
+
if (!schPath.points || schPath.points.length < 2) {
|
|
12698
|
+
return [];
|
|
12699
|
+
}
|
|
12700
|
+
const transformedPoints = schPath.points.map(
|
|
12701
|
+
(p) => applyToPoint75(transform, { x: p.x, y: p.y })
|
|
12702
|
+
);
|
|
12703
|
+
const pathD = transformedPoints.map((p, i) => `${i === 0 ? "M" : "L"} ${p.x} ${p.y}`).join(" ");
|
|
12704
|
+
const strokeColor = colorMap2.schematic.component_outline;
|
|
12705
|
+
const fillColor = schPath.fill_color ?? "none";
|
|
12706
|
+
const strokeWidth = Math.abs(transform.a) * 0.02;
|
|
12707
|
+
return [
|
|
12708
|
+
{
|
|
12709
|
+
name: "path",
|
|
12710
|
+
type: "element",
|
|
12711
|
+
attributes: {
|
|
12712
|
+
d: pathD,
|
|
12713
|
+
stroke: strokeColor,
|
|
12714
|
+
"stroke-width": strokeWidth.toString(),
|
|
12715
|
+
fill: schPath.is_filled ? fillColor : "none",
|
|
12716
|
+
"stroke-linecap": "round",
|
|
12717
|
+
"stroke-linejoin": "round",
|
|
12718
|
+
...schPath.schematic_component_id && {
|
|
12719
|
+
"data-schematic-component-id": schPath.schematic_component_id
|
|
12720
|
+
}
|
|
12721
|
+
},
|
|
12722
|
+
children: [],
|
|
12723
|
+
value: ""
|
|
12724
|
+
}
|
|
12725
|
+
];
|
|
12726
|
+
}
|
|
12727
|
+
|
|
12571
12728
|
// lib/sch/convert-circuit-json-to-schematic-svg.ts
|
|
12572
12729
|
function buildNetHoverStyles(connectivityKeys) {
|
|
12573
12730
|
const rules = [];
|
|
@@ -12662,6 +12819,7 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
12662
12819
|
const schCircleSvgs = [];
|
|
12663
12820
|
const schRectSvgs = [];
|
|
12664
12821
|
const schArcSvgs = [];
|
|
12822
|
+
const schPathSvgs = [];
|
|
12665
12823
|
for (const elm of circuitJson) {
|
|
12666
12824
|
if (elm.type === "schematic_debug_object") {
|
|
12667
12825
|
schDebugObjectSvgs.push(
|
|
@@ -12768,6 +12926,14 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
12768
12926
|
colorMap: colorMap2
|
|
12769
12927
|
})
|
|
12770
12928
|
);
|
|
12929
|
+
} else if (elm.type === "schematic_path") {
|
|
12930
|
+
schPathSvgs.push(
|
|
12931
|
+
...createSvgObjectsFromSchematicPath({
|
|
12932
|
+
schPath: elm,
|
|
12933
|
+
transform,
|
|
12934
|
+
colorMap: colorMap2
|
|
12935
|
+
})
|
|
12936
|
+
);
|
|
12771
12937
|
}
|
|
12772
12938
|
}
|
|
12773
12939
|
const schTraceBaseSvgs = schTraceSvgs.filter(
|
|
@@ -12784,6 +12950,7 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
12784
12950
|
...schCircleSvgs,
|
|
12785
12951
|
...schRectSvgs,
|
|
12786
12952
|
...schArcSvgs,
|
|
12953
|
+
...schPathSvgs,
|
|
12787
12954
|
...schComponentSvgs,
|
|
12788
12955
|
...schPortHoverSvgs,
|
|
12789
12956
|
...schNetLabel,
|
|
@@ -13645,18 +13812,18 @@ function formatNumber2(value) {
|
|
|
13645
13812
|
import { distance as distance5 } from "circuit-json";
|
|
13646
13813
|
import { stringify as stringify7 } from "svgson";
|
|
13647
13814
|
import {
|
|
13648
|
-
applyToPoint as
|
|
13815
|
+
applyToPoint as applyToPoint78,
|
|
13649
13816
|
compose as compose16,
|
|
13650
13817
|
scale as scale9,
|
|
13651
13818
|
translate as translate16
|
|
13652
13819
|
} from "transformation-matrix";
|
|
13653
13820
|
|
|
13654
13821
|
// lib/pcb/svg-object-fns/convert-circuit-json-to-solder-paste-mask.ts
|
|
13655
|
-
import { applyToPoint as
|
|
13822
|
+
import { applyToPoint as applyToPoint77 } from "transformation-matrix";
|
|
13656
13823
|
function createSvgObjectsFromSolderPaste(solderPaste, ctx) {
|
|
13657
13824
|
const { transform, layer: layerFilter } = ctx;
|
|
13658
13825
|
if (layerFilter && solderPaste.layer !== layerFilter) return [];
|
|
13659
|
-
const [x, y] =
|
|
13826
|
+
const [x, y] = applyToPoint77(transform, [solderPaste.x, solderPaste.y]);
|
|
13660
13827
|
if (solderPaste.shape === "rect" || solderPaste.shape === "rotated_rect") {
|
|
13661
13828
|
const width = solderPaste.width * Math.abs(transform.a);
|
|
13662
13829
|
const height = solderPaste.height * Math.abs(transform.d);
|
|
@@ -13882,8 +14049,8 @@ function createSvgObjects4({ elm, ctx }) {
|
|
|
13882
14049
|
}
|
|
13883
14050
|
}
|
|
13884
14051
|
function createSvgObjectFromPcbBoundary2(transform, minX, minY, maxX, maxY) {
|
|
13885
|
-
const [x1, y1] =
|
|
13886
|
-
const [x2, y2] =
|
|
14052
|
+
const [x1, y1] = applyToPoint78(transform, [minX, minY]);
|
|
14053
|
+
const [x2, y2] = applyToPoint78(transform, [maxX, maxY]);
|
|
13887
14054
|
const width = Math.abs(x2 - x1);
|
|
13888
14055
|
const height = Math.abs(y2 - y1);
|
|
13889
14056
|
const x = Math.min(x1, x2);
|