circuit-to-svg 0.0.312 → 0.0.313
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 +157 -42
- 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.312",
|
|
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",
|