circuit-json-to-tscircuit 0.0.59 → 0.0.60
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/{chunk-QMIS5SJZ.js → chunk-76BQ2MMR.js} +34 -24
- package/dist/cli/main.js +3 -3
- package/dist/lib/index.js +1 -1
- package/lib/generate-footprint-tsx/convert-notes.ts +2 -28
- package/lib/generate-footprint-tsx/convert-pcb-note-dimension.ts +39 -0
- package/package.json +2 -2
- package/tests/__snapshots__/pcb-note-dimension-offset-comparison.snap.svg +8 -0
- package/tests/pcb-note-dimension-offset.test.tsx +72 -0
- package/tests/ti-evms/__snapshots__/ti-drv8307evm-roundtrip-pcb-comparison.snap.svg +3 -3
- package/tests/ti-evms/__snapshots__/ti-lm251772evm-pd-roundtrip-pcb-comparison.snap.svg +3 -3
- package/tests/ti-evms/__snapshots__/ti-lm5155evm-fly-roundtrip-pcb-comparison.snap.svg +3 -3
- package/tests/ti-evms/__snapshots__/ti-lmg342x-bb-evm-roundtrip-pcb-comparison.snap.svg +3 -3
|
@@ -499,6 +499,39 @@ var convertKeepouts = (circuitJson) => {
|
|
|
499
499
|
|
|
500
500
|
// lib/generate-footprint-tsx/convert-notes.ts
|
|
501
501
|
import { su as su8 } from "@tscircuit/soup-util";
|
|
502
|
+
|
|
503
|
+
// lib/generate-footprint-tsx/convert-pcb-note-dimension.ts
|
|
504
|
+
var convertPcbNoteDimension = (dimension) => {
|
|
505
|
+
const from = dimension.from ?? { x: 0, y: 0 };
|
|
506
|
+
const to = dimension.to ?? { x: 0, y: 0 };
|
|
507
|
+
const legacyOffset = "offset" in dimension && typeof dimension.offset === "number" ? dimension.offset : void 0;
|
|
508
|
+
const offsetDistance = dimension.offset_distance ?? legacyOffset;
|
|
509
|
+
const attrs = [
|
|
510
|
+
`from={{ x: ${from.x}, y: ${from.y} }}`,
|
|
511
|
+
`to={{ x: ${to.x}, y: ${to.y} }}`,
|
|
512
|
+
`font="${dimension.font ?? "tscircuit2024"}"`,
|
|
513
|
+
`fontSize={${dimension.font_size ?? 0}}`
|
|
514
|
+
];
|
|
515
|
+
if (dimension.arrow_size !== void 0) {
|
|
516
|
+
attrs.push(`arrowSize={${dimension.arrow_size}}`);
|
|
517
|
+
}
|
|
518
|
+
if (offsetDistance !== void 0) {
|
|
519
|
+
attrs.push(`offset={${offsetDistance}}`);
|
|
520
|
+
}
|
|
521
|
+
if (dimension.offset_direction !== void 0) {
|
|
522
|
+
attrs.push(
|
|
523
|
+
`offsetDirection={${JSON.stringify(dimension.offset_direction)}}`
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
if (dimension.text !== void 0) {
|
|
527
|
+
attrs.push(`text="${escapeJsxText(dimension.text)}"`);
|
|
528
|
+
}
|
|
529
|
+
if (dimension.color !== void 0) attrs.push(`color="${dimension.color}"`);
|
|
530
|
+
if (dimension.layer === "bottom") attrs.push(`layer="bottom"`);
|
|
531
|
+
return [`<pcbnotedimension ${attrs.join(" ")} />`];
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
// lib/generate-footprint-tsx/convert-notes.ts
|
|
502
535
|
var convertNotes = (circuitJson) => {
|
|
503
536
|
const noteTexts = su8(circuitJson).pcb_note_text.list();
|
|
504
537
|
const noteRects = su8(circuitJson).pcb_note_rect.list();
|
|
@@ -565,30 +598,7 @@ var convertNotes = (circuitJson) => {
|
|
|
565
598
|
elementStrings.push(`<pcbnoteline ${attrs.join(" ")} />`);
|
|
566
599
|
}
|
|
567
600
|
for (const noteDimension of noteDimensions) {
|
|
568
|
-
|
|
569
|
-
const toPoint2 = noteDimension.to ?? { x: 0, y: 0 };
|
|
570
|
-
const attrs = [
|
|
571
|
-
`from={{ x: ${fromPoint.x}, y: ${fromPoint.y} }}`,
|
|
572
|
-
`to={{ x: ${toPoint2.x}, y: ${toPoint2.y} }}`,
|
|
573
|
-
`font="${noteDimension.font ?? "tscircuit2024"}"`,
|
|
574
|
-
`fontSize={${noteDimension.font_size ?? 0}}`
|
|
575
|
-
];
|
|
576
|
-
if (noteDimension.arrow_size !== void 0) {
|
|
577
|
-
attrs.push(`arrowSize={${noteDimension.arrow_size}}`);
|
|
578
|
-
}
|
|
579
|
-
if ("offset" in noteDimension) {
|
|
580
|
-
const offsetValue = noteDimension.offset;
|
|
581
|
-
if (offsetValue !== void 0) {
|
|
582
|
-
attrs.push(`offset={${offsetValue}}`);
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
if (noteDimension.text !== void 0) {
|
|
586
|
-
attrs.push(`text="${escapeJsxText(noteDimension.text)}"`);
|
|
587
|
-
}
|
|
588
|
-
if (noteDimension.color !== void 0) {
|
|
589
|
-
attrs.push(`color="${noteDimension.color}"`);
|
|
590
|
-
}
|
|
591
|
-
elementStrings.push(`<pcbnotedimension ${attrs.join(" ")} />`);
|
|
601
|
+
elementStrings.push(...convertPcbNoteDimension(noteDimension));
|
|
592
602
|
}
|
|
593
603
|
return elementStrings;
|
|
594
604
|
};
|
package/dist/cli/main.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
convertCircuitJsonToTscircuit
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-76BQ2MMR.js";
|
|
5
5
|
|
|
6
6
|
// cli/main.ts
|
|
7
7
|
import { Command } from "commander";
|
|
@@ -16,7 +16,7 @@ var package_default = {
|
|
|
16
16
|
"./cli": "./dist/cli/main.js"
|
|
17
17
|
},
|
|
18
18
|
type: "module",
|
|
19
|
-
version: "0.0.
|
|
19
|
+
version: "0.0.59",
|
|
20
20
|
repository: {
|
|
21
21
|
type: "git",
|
|
22
22
|
url: "https://github.com/tscircuit/circuit-json-to-tscircuit.git"
|
|
@@ -43,7 +43,7 @@ var package_default = {
|
|
|
43
43
|
prettier: "^3.9.5",
|
|
44
44
|
shiki: "^4.3.1",
|
|
45
45
|
"stack-svgs": "^0.0.1",
|
|
46
|
-
tscircuit: "
|
|
46
|
+
tscircuit: "0.0.2703-libonly",
|
|
47
47
|
tsup: "^8.3.5",
|
|
48
48
|
zod: "^3.25.76"
|
|
49
49
|
},
|
package/dist/lib/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { su } from "@tscircuit/soup-util"
|
|
2
2
|
import type { FootprintElementConverter } from "./converter-types"
|
|
3
3
|
import { escapeJsxText } from "./footprint-tsx-attribute-formatters/escape-jsx-text"
|
|
4
|
+
import { convertPcbNoteDimension } from "./convert-pcb-note-dimension"
|
|
4
5
|
|
|
5
6
|
export const convertNotes: FootprintElementConverter = (circuitJson) => {
|
|
6
7
|
const noteTexts = su(circuitJson).pcb_note_text.list()
|
|
@@ -80,34 +81,7 @@ export const convertNotes: FootprintElementConverter = (circuitJson) => {
|
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
for (const noteDimension of noteDimensions) {
|
|
83
|
-
|
|
84
|
-
const toPoint = noteDimension.to ?? { x: 0, y: 0 }
|
|
85
|
-
const attrs = [
|
|
86
|
-
`from={{ x: ${fromPoint.x}, y: ${fromPoint.y} }}`,
|
|
87
|
-
`to={{ x: ${toPoint.x}, y: ${toPoint.y} }}`,
|
|
88
|
-
`font="${noteDimension.font ?? "tscircuit2024"}"`,
|
|
89
|
-
`fontSize={${noteDimension.font_size ?? 0}}`,
|
|
90
|
-
]
|
|
91
|
-
|
|
92
|
-
if (noteDimension.arrow_size !== undefined) {
|
|
93
|
-
attrs.push(`arrowSize={${noteDimension.arrow_size}}`)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if ("offset" in noteDimension) {
|
|
97
|
-
const offsetValue = (noteDimension as { offset?: number }).offset
|
|
98
|
-
if (offsetValue !== undefined) {
|
|
99
|
-
attrs.push(`offset={${offsetValue}}`)
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (noteDimension.text !== undefined) {
|
|
104
|
-
attrs.push(`text="${escapeJsxText(noteDimension.text)}"`)
|
|
105
|
-
}
|
|
106
|
-
if (noteDimension.color !== undefined) {
|
|
107
|
-
attrs.push(`color="${noteDimension.color}"`)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
elementStrings.push(`<pcbnotedimension ${attrs.join(" ")} />`)
|
|
84
|
+
elementStrings.push(...convertPcbNoteDimension(noteDimension))
|
|
111
85
|
}
|
|
112
86
|
|
|
113
87
|
return elementStrings
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { PcbNoteDimension } from "circuit-json"
|
|
2
|
+
import { escapeJsxText } from "./footprint-tsx-attribute-formatters/escape-jsx-text"
|
|
3
|
+
|
|
4
|
+
export const convertPcbNoteDimension = (
|
|
5
|
+
dimension: PcbNoteDimension,
|
|
6
|
+
): string[] => {
|
|
7
|
+
const from = dimension.from ?? { x: 0, y: 0 }
|
|
8
|
+
const to = dimension.to ?? { x: 0, y: 0 }
|
|
9
|
+
const legacyOffset =
|
|
10
|
+
"offset" in dimension && typeof dimension.offset === "number"
|
|
11
|
+
? dimension.offset
|
|
12
|
+
: undefined
|
|
13
|
+
const offsetDistance = dimension.offset_distance ?? legacyOffset
|
|
14
|
+
const attrs = [
|
|
15
|
+
`from={{ x: ${from.x}, y: ${from.y} }}`,
|
|
16
|
+
`to={{ x: ${to.x}, y: ${to.y} }}`,
|
|
17
|
+
`font="${dimension.font ?? "tscircuit2024"}"`,
|
|
18
|
+
`fontSize={${dimension.font_size ?? 0}}`,
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
if (dimension.arrow_size !== undefined) {
|
|
22
|
+
attrs.push(`arrowSize={${dimension.arrow_size}}`)
|
|
23
|
+
}
|
|
24
|
+
if (offsetDistance !== undefined) {
|
|
25
|
+
attrs.push(`offset={${offsetDistance}}`)
|
|
26
|
+
}
|
|
27
|
+
if (dimension.offset_direction !== undefined) {
|
|
28
|
+
attrs.push(
|
|
29
|
+
`offsetDirection={${JSON.stringify(dimension.offset_direction)}}`,
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
if (dimension.text !== undefined) {
|
|
33
|
+
attrs.push(`text="${escapeJsxText(dimension.text)}"`)
|
|
34
|
+
}
|
|
35
|
+
if (dimension.color !== undefined) attrs.push(`color="${dimension.color}"`)
|
|
36
|
+
if (dimension.layer === "bottom") attrs.push(`layer="bottom"`)
|
|
37
|
+
|
|
38
|
+
return [`<pcbnotedimension ${attrs.join(" ")} />`]
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"./cli": "./dist/cli/main.js"
|
|
7
7
|
},
|
|
8
8
|
"type": "module",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.60",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "https://github.com/tscircuit/circuit-json-to-tscircuit.git"
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"prettier": "^3.9.5",
|
|
34
34
|
"shiki": "^4.3.1",
|
|
35
35
|
"stack-svgs": "^0.0.1",
|
|
36
|
-
"tscircuit": "
|
|
36
|
+
"tscircuit": "0.0.2703-libonly",
|
|
37
37
|
"tsup": "^8.3.5",
|
|
38
38
|
"zod": "^3.25.76"
|
|
39
39
|
},
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<svg width="1624" height="600" viewBox="0 0 1624 600" xmlns="http://www.w3.org/2000/svg" aria-label="PCB note dimension source on left, generated tscircuit render on right" role="img">
|
|
2
|
+
<g transform="translate(0, 0)">
|
|
3
|
+
<style></style><rect class="boundary" x="0" y="0" fill="#000" width="800" height="600" data-type="pcb_background" data-pcb-layer="global"/><rect class="pcb-boundary" fill="none" stroke="#fff" stroke-width="0.3" x="100" y="50" width="600" height="500" data-type="pcb_boundary" data-pcb-layer="global"/><path class="pcb-board" d="M 100 550 L 700 550 L 700 50 L 100 50 Z" fill="none" stroke="rgba(255, 255, 255, 0.5)" stroke-width="5" data-type="pcb_board" data-pcb-layer="board"/><g class="pcb-note-dimension" data-type="pcb_note_dimension" data-pcb-note-dimension-id="pcb_note_dimension_0" data-pcb-layer="overlay"><path d="M 250 300 L 276.5165042944955 326.5165042944955" stroke="#facc15" fill="none" stroke-width="5" stroke-linecap="round" class="pcb-note-dimension-extension"/><path d="M 550 300 L 576.5165042944955 326.5165042944955" stroke="#facc15" fill="none" stroke-width="5" stroke-linecap="round" class="pcb-note-dimension-extension"/><path d="M 283.83883476483186 308.83883476483186 L 533.8388347648319 308.83883476483186" stroke="#facc15" fill="none" stroke-width="5" stroke-linecap="round" class="pcb-note-dimension-line"/><path d="M 258.83883476483186 308.83883476483186 L 283.83883476483186 296.33883476483186 L 283.83883476483186 321.33883476483186 Z" fill="#facc15" class="pcb-note-dimension-arrow"/><path d="M 558.8388347648319 308.83883476483186 L 533.8388347648319 296.33883476483186 L 533.8388347648319 321.33883476483186 Z" fill="#facc15" class="pcb-note-dimension-arrow"/><text x="408.83883476483186" y="271.33883476483186" fill="#facc15" font-size="40" font-family="Arial, sans-serif" text-anchor="middle" dominant-baseline="central" class="pcb-note-dimension-text" transform="rotate(0 408.83883476483186 271.33883476483186)">6 mm</text></g>
|
|
4
|
+
</g>
|
|
5
|
+
<g transform="translate(824, 0)">
|
|
6
|
+
<style></style><rect class="boundary" x="0" y="0" fill="#000" width="800" height="600" data-type="pcb_background" data-pcb-layer="global"/><rect class="pcb-boundary" fill="none" stroke="#fff" stroke-width="0.3" x="100" y="50" width="600" height="500" data-type="pcb_boundary" data-pcb-layer="global"/><path class="pcb-board" d="M 100 550 L 700 550 L 700 50 L 100 50 Z" fill="none" stroke="rgba(255, 255, 255, 0.5)" stroke-width="5" data-type="pcb_board" data-pcb-layer="board"/><g class="pcb-note-dimension" data-type="pcb_note_dimension" data-pcb-note-dimension-id="pcb_note_dimension_0__stack1" data-pcb-layer="overlay"><path d="M 250 300 L 276.5165042944955 326.5165042944955" stroke="#facc15" fill="none" stroke-width="5" stroke-linecap="round" class="pcb-note-dimension-extension"/><path d="M 550 300 L 576.5165042944955 326.5165042944955" stroke="#facc15" fill="none" stroke-width="5" stroke-linecap="round" class="pcb-note-dimension-extension"/><path d="M 283.83883476483186 308.83883476483186 L 533.8388347648319 308.83883476483186" stroke="#facc15" fill="none" stroke-width="5" stroke-linecap="round" class="pcb-note-dimension-line"/><path d="M 258.83883476483186 308.83883476483186 L 283.83883476483186 296.33883476483186 L 283.83883476483186 321.33883476483186 Z" fill="#facc15" class="pcb-note-dimension-arrow"/><path d="M 558.8388347648319 308.83883476483186 L 533.8388347648319 296.33883476483186 L 533.8388347648319 321.33883476483186 Z" fill="#facc15" class="pcb-note-dimension-arrow"/><text x="408.83883476483186" y="271.33883476483186" fill="#facc15" font-size="40" font-family="Arial, sans-serif" text-anchor="middle" dominant-baseline="central" class="pcb-note-dimension-text" transform="rotate(0 408.83883476483186 271.33883476483186)">6 mm</text></g>
|
|
7
|
+
</g>
|
|
8
|
+
</svg>
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import type { CircuitJson } from "circuit-json"
|
|
3
|
+
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
|
|
4
|
+
import { convertCircuitJsonToTscircuit } from "lib"
|
|
5
|
+
import { stackSvgsHorizontally } from "stack-svgs"
|
|
6
|
+
import { runTscircuitCode } from "tscircuit"
|
|
7
|
+
|
|
8
|
+
test("preserves PCB note dimension offset direction", async () => {
|
|
9
|
+
const generatedTscircuit = convertCircuitJsonToTscircuit(sourceCircuitJson, {
|
|
10
|
+
componentName: "PcbNoteDimensionBoard",
|
|
11
|
+
})
|
|
12
|
+
const renderedCircuitJson = (await runTscircuitCode(
|
|
13
|
+
generatedTscircuit,
|
|
14
|
+
)) as CircuitJson
|
|
15
|
+
const renderedDimension = renderedCircuitJson.find(
|
|
16
|
+
(element) => element.type === "pcb_note_dimension",
|
|
17
|
+
)
|
|
18
|
+
expect(renderedDimension).toMatchObject({
|
|
19
|
+
from: { x: -3, y: 0 },
|
|
20
|
+
to: { x: 3, y: 0 },
|
|
21
|
+
layer: "bottom",
|
|
22
|
+
offset_distance: 0.25,
|
|
23
|
+
offset_direction: { x: 1, y: -1 },
|
|
24
|
+
})
|
|
25
|
+
expect(
|
|
26
|
+
renderedCircuitJson.filter((element) => element.type === "pcb_note_path"),
|
|
27
|
+
).toHaveLength(0)
|
|
28
|
+
|
|
29
|
+
const comparisonSvg = stackSvgsHorizontally(
|
|
30
|
+
[
|
|
31
|
+
convertCircuitJsonToPcbSvg(sourceCircuitJson),
|
|
32
|
+
convertCircuitJsonToPcbSvg(renderedCircuitJson),
|
|
33
|
+
],
|
|
34
|
+
{
|
|
35
|
+
gap: 24,
|
|
36
|
+
targetSize: 800,
|
|
37
|
+
rootAttributes: {
|
|
38
|
+
"aria-label":
|
|
39
|
+
"PCB note dimension source on left, generated tscircuit render on right",
|
|
40
|
+
role: "img",
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
)
|
|
44
|
+
await expect(comparisonSvg).toMatchSvgSnapshot(import.meta.path, "comparison")
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const sourceCircuitJson: CircuitJson = [
|
|
48
|
+
{
|
|
49
|
+
type: "pcb_board",
|
|
50
|
+
pcb_board_id: "pcb_board_0",
|
|
51
|
+
center: { x: 0, y: 0 },
|
|
52
|
+
width: 12,
|
|
53
|
+
height: 10,
|
|
54
|
+
thickness: 1.6,
|
|
55
|
+
num_layers: 2,
|
|
56
|
+
material: "fr4",
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
type: "pcb_note_dimension",
|
|
60
|
+
pcb_note_dimension_id: "pcb_note_dimension_0",
|
|
61
|
+
layer: "bottom",
|
|
62
|
+
from: { x: -3, y: 0 },
|
|
63
|
+
to: { x: 3, y: 0 },
|
|
64
|
+
text: "6 mm",
|
|
65
|
+
font: "tscircuit2024",
|
|
66
|
+
font_size: 0.8,
|
|
67
|
+
color: "#facc15",
|
|
68
|
+
arrow_size: 0.5,
|
|
69
|
+
offset_distance: 0.25,
|
|
70
|
+
offset_direction: { x: 1, y: -1 },
|
|
71
|
+
},
|
|
72
|
+
]
|