circuit-to-svg 0.0.297 → 0.0.299
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 +48 -42
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -2751,7 +2751,6 @@ var CHAR_WIDTH = 1;
|
|
|
2751
2751
|
var CHAR_SPACING = 0.2;
|
|
2752
2752
|
var LINE_HEIGHT = 1.4;
|
|
2753
2753
|
var FONT_SCALE = 0.53;
|
|
2754
|
-
var BASELINE_Y = 0.241;
|
|
2755
2754
|
function linesToPathData(lines, offsetX, offsetY, charScale, baselineAdjust = 0) {
|
|
2756
2755
|
return lines.map((line) => {
|
|
2757
2756
|
const x1 = offsetX + line.x1 * charScale;
|
|
@@ -2772,9 +2771,7 @@ function textToAlphabetPath(text, fontSize) {
|
|
|
2772
2771
|
}
|
|
2773
2772
|
const lines = lineAlphabet[char];
|
|
2774
2773
|
if (lines) {
|
|
2775
|
-
|
|
2776
|
-
const baselineAdjust = isLowercase ? BASELINE_Y : 0;
|
|
2777
|
-
paths.push(linesToPathData(lines, x, 0, fontSize, baselineAdjust));
|
|
2774
|
+
paths.push(linesToPathData(lines, x, 0, fontSize));
|
|
2778
2775
|
}
|
|
2779
2776
|
x += charAdvance;
|
|
2780
2777
|
}
|
|
@@ -2807,9 +2804,7 @@ function textToCenteredAlphabetPaths(text, fontSize) {
|
|
|
2807
2804
|
}
|
|
2808
2805
|
const charLines = lineAlphabet[char];
|
|
2809
2806
|
if (charLines) {
|
|
2810
|
-
|
|
2811
|
-
const baselineAdjust = isLowercase ? BASELINE_Y : 0;
|
|
2812
|
-
paths.push(linesToPathData(charLines, x, y, fontSize, baselineAdjust));
|
|
2807
|
+
paths.push(linesToPathData(charLines, x, y, fontSize));
|
|
2813
2808
|
}
|
|
2814
2809
|
x += charAdvance;
|
|
2815
2810
|
}
|
|
@@ -4133,10 +4128,28 @@ function formatOffsetLabel(axis, offsetMm, displayOffset) {
|
|
|
4133
4128
|
return `${axis}: ${valueStr}${unitSuffix}`;
|
|
4134
4129
|
}
|
|
4135
4130
|
|
|
4131
|
+
// lib/utils/get-point-from-elm.ts
|
|
4132
|
+
function getPointFromElm(elm) {
|
|
4133
|
+
const candidate = elm?.anchor_position ?? elm?.center;
|
|
4134
|
+
if (candidate && typeof candidate.x === "number" && typeof candidate.y === "number") {
|
|
4135
|
+
return { x: candidate.x, y: candidate.y };
|
|
4136
|
+
}
|
|
4137
|
+
return void 0;
|
|
4138
|
+
}
|
|
4139
|
+
|
|
4136
4140
|
// lib/pcb/svg-object-fns/create-svg-objects-from-pcb-board.ts
|
|
4137
4141
|
function createSvgObjectsFromPcbBoard(pcbBoard, ctx) {
|
|
4138
4142
|
const { transform, colorMap: colorMap2, showSolderMask, circuitJson } = ctx;
|
|
4139
|
-
const {
|
|
4143
|
+
const {
|
|
4144
|
+
width,
|
|
4145
|
+
height,
|
|
4146
|
+
center,
|
|
4147
|
+
outline,
|
|
4148
|
+
position_mode,
|
|
4149
|
+
anchor_position: boardAnchorPosition,
|
|
4150
|
+
display_offset_x,
|
|
4151
|
+
display_offset_y
|
|
4152
|
+
} = pcbBoard;
|
|
4140
4153
|
let path;
|
|
4141
4154
|
if (outline && Array.isArray(outline) && outline.length >= 3) {
|
|
4142
4155
|
path = outline.map((point, index) => {
|
|
@@ -4200,21 +4213,25 @@ function createSvgObjectsFromPcbBoard(pcbBoard, ctx) {
|
|
|
4200
4213
|
"data-pcb-layer": "board"
|
|
4201
4214
|
}
|
|
4202
4215
|
});
|
|
4203
|
-
if (ctx.showAnchorOffsets && circuitJson) {
|
|
4216
|
+
if (ctx.showAnchorOffsets && circuitJson && position_mode === "relative_to_panel_anchor") {
|
|
4204
4217
|
const panel = circuitJson.find(
|
|
4205
4218
|
(elm) => elm.type === "pcb_panel"
|
|
4206
4219
|
);
|
|
4207
4220
|
if (panel) {
|
|
4208
|
-
const
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4221
|
+
const panelAnchorPosition = getPointFromElm(panel);
|
|
4222
|
+
if (panelAnchorPosition) {
|
|
4223
|
+
svgObjects.push(
|
|
4224
|
+
...createAnchorOffsetIndicators({
|
|
4225
|
+
groupAnchorPosition: panelAnchorPosition,
|
|
4226
|
+
componentPosition: boardAnchorPosition ?? center,
|
|
4227
|
+
transform,
|
|
4228
|
+
componentWidth: width,
|
|
4229
|
+
componentHeight: height,
|
|
4230
|
+
displayXOffset: display_offset_x,
|
|
4231
|
+
displayYOffset: display_offset_y
|
|
4232
|
+
})
|
|
4233
|
+
);
|
|
4234
|
+
}
|
|
4218
4235
|
}
|
|
4219
4236
|
}
|
|
4220
4237
|
return svgObjects;
|
|
@@ -5412,17 +5429,6 @@ function createMajorGridPatternChildren(cellSize, majorCellSize, lineColor, majo
|
|
|
5412
5429
|
|
|
5413
5430
|
// lib/pcb/svg-object-fns/create-svg-objects-from-pcb-component.ts
|
|
5414
5431
|
import { applyToPoint as applyToPoint31 } from "transformation-matrix";
|
|
5415
|
-
|
|
5416
|
-
// lib/utils/get-point-from-elm.ts
|
|
5417
|
-
function getPointFromElm(elm) {
|
|
5418
|
-
const candidate = elm?.anchor_position ?? elm?.center;
|
|
5419
|
-
if (candidate && typeof candidate.x === "number" && typeof candidate.y === "number") {
|
|
5420
|
-
return { x: candidate.x, y: candidate.y };
|
|
5421
|
-
}
|
|
5422
|
-
return void 0;
|
|
5423
|
-
}
|
|
5424
|
-
|
|
5425
|
-
// lib/pcb/svg-object-fns/create-svg-objects-from-pcb-component.ts
|
|
5426
5432
|
function createSvgObjectsFromPcbComponent(component, ctx) {
|
|
5427
5433
|
const { transform, circuitJson } = ctx;
|
|
5428
5434
|
const { center, width, height, rotation = 0 } = component;
|
|
@@ -5432,11 +5438,11 @@ function createSvgObjectsFromPcbComponent(component, ctx) {
|
|
|
5432
5438
|
const transformStr = `translate(${x}, ${y}) rotate(${-rotation}) scale(1, -1)`;
|
|
5433
5439
|
const svgObjects = [];
|
|
5434
5440
|
if (ctx.showAnchorOffsets && circuitJson && component.position_mode === "relative_to_group_anchor" && (component.positioned_relative_to_pcb_group_id || component.positioned_relative_to_pcb_board_id)) {
|
|
5435
|
-
const
|
|
5436
|
-
if (
|
|
5441
|
+
const parentAnchorPosition = getParentAnchorPosition(component, circuitJson);
|
|
5442
|
+
if (parentAnchorPosition) {
|
|
5437
5443
|
svgObjects.push(
|
|
5438
5444
|
...createAnchorOffsetIndicators({
|
|
5439
|
-
groupAnchorPosition:
|
|
5445
|
+
groupAnchorPosition: parentAnchorPosition,
|
|
5440
5446
|
componentPosition: center,
|
|
5441
5447
|
transform,
|
|
5442
5448
|
componentWidth: width,
|
|
@@ -5479,7 +5485,7 @@ function createSvgObjectsFromPcbComponent(component, ctx) {
|
|
|
5479
5485
|
});
|
|
5480
5486
|
return svgObjects;
|
|
5481
5487
|
}
|
|
5482
|
-
function
|
|
5488
|
+
function getParentAnchorPosition(component, circuitJson) {
|
|
5483
5489
|
if (component.positioned_relative_to_pcb_group_id) {
|
|
5484
5490
|
const pcbGroup = circuitJson.find(
|
|
5485
5491
|
(elm) => elm.type === "pcb_group" && elm.pcb_group_id === component.positioned_relative_to_pcb_group_id
|
|
@@ -5506,11 +5512,11 @@ function createSvgObjectsFromPcbGroup(pcbGroup, ctx) {
|
|
|
5506
5512
|
const { center, width, height } = pcbGroup;
|
|
5507
5513
|
const svgObjects = [];
|
|
5508
5514
|
if (ctx.showAnchorOffsets && pcbGroup.position_mode === "relative_to_group_anchor" && circuitJson) {
|
|
5509
|
-
const
|
|
5510
|
-
if (
|
|
5515
|
+
const parentAnchorPosition = getParentAnchorPosition2(pcbGroup, circuitJson);
|
|
5516
|
+
if (parentAnchorPosition) {
|
|
5511
5517
|
svgObjects.push(
|
|
5512
5518
|
...createAnchorOffsetIndicators({
|
|
5513
|
-
groupAnchorPosition:
|
|
5519
|
+
groupAnchorPosition: parentAnchorPosition,
|
|
5514
5520
|
componentPosition: pcbGroup.anchor_position ?? pcbGroup.center,
|
|
5515
5521
|
transform,
|
|
5516
5522
|
componentWidth: pcbGroup.width,
|
|
@@ -5591,7 +5597,7 @@ function createSvgObjectsFromPcbGroup(pcbGroup, ctx) {
|
|
|
5591
5597
|
svgObjects.push(svgObject);
|
|
5592
5598
|
return svgObjects;
|
|
5593
5599
|
}
|
|
5594
|
-
function
|
|
5600
|
+
function getParentAnchorPosition2(group, circuitJson) {
|
|
5595
5601
|
if (group.positioned_relative_to_pcb_group_id) {
|
|
5596
5602
|
const pcbGroup = circuitJson.find(
|
|
5597
5603
|
(elm) => elm.type === "pcb_group" && elm.pcb_group_id === group.positioned_relative_to_pcb_group_id
|
|
@@ -5621,7 +5627,7 @@ function getSoftwareUsedString(circuitJson) {
|
|
|
5621
5627
|
var package_default = {
|
|
5622
5628
|
name: "circuit-to-svg",
|
|
5623
5629
|
type: "module",
|
|
5624
|
-
version: "0.0.
|
|
5630
|
+
version: "0.0.298",
|
|
5625
5631
|
description: "Convert Circuit JSON to SVG",
|
|
5626
5632
|
main: "dist/index.js",
|
|
5627
5633
|
files: [
|
|
@@ -5639,19 +5645,19 @@ var package_default = {
|
|
|
5639
5645
|
license: "ISC",
|
|
5640
5646
|
devDependencies: {
|
|
5641
5647
|
"@biomejs/biome": "^1.9.4",
|
|
5642
|
-
"@tscircuit/alphabet": "^0.0.
|
|
5648
|
+
"@tscircuit/alphabet": "^0.0.9",
|
|
5643
5649
|
"@types/bun": "^1.2.8",
|
|
5644
5650
|
"@vitejs/plugin-react": "5.0.0",
|
|
5645
5651
|
biome: "^0.3.3",
|
|
5646
5652
|
"bun-match-svg": "^0.0.12",
|
|
5647
|
-
"circuit-json": "^0.0.
|
|
5653
|
+
"circuit-json": "^0.0.342",
|
|
5648
5654
|
esbuild: "^0.20.2",
|
|
5649
5655
|
"performance-now": "^2.1.0",
|
|
5650
5656
|
react: "19.1.0",
|
|
5651
5657
|
"react-cosmos": "7.0.0",
|
|
5652
5658
|
"react-cosmos-plugin-vite": "7.0.0",
|
|
5653
5659
|
"react-dom": "19.1.0",
|
|
5654
|
-
tscircuit: "^0.0.
|
|
5660
|
+
tscircuit: "^0.0.1059",
|
|
5655
5661
|
tsup: "^8.0.2",
|
|
5656
5662
|
typescript: "^5.4.5",
|
|
5657
5663
|
"vite-tsconfig-paths": "^5.0.1"
|