circuit-json-to-tscircuit 0.0.55 → 0.0.57

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.
@@ -1,6 +1,6 @@
1
1
  // lib/get-board-using-template.ts
2
2
  import { mmStr as mmStr8 } from "@tscircuit/mm";
3
- import { su as su13 } from "@tscircuit/soup-util";
3
+ import { su as su14 } from "@tscircuit/soup-util";
4
4
 
5
5
  // lib/generate-footprint-tsx/convert-copper-text.ts
6
6
  import { su } from "@tscircuit/soup-util";
@@ -385,8 +385,12 @@ var convertNotes = (circuitJson) => {
385
385
  return elementStrings;
386
386
  };
387
387
 
388
- // lib/generate-footprint-tsx/convert-plated-holes.ts
388
+ // lib/generate-footprint-tsx/convert-pcb-traces.ts
389
389
  import { su as su8 } from "@tscircuit/soup-util";
390
+ var convertPcbTraces = (circuitJson) => su8(circuitJson).pcb_trace.list().map((trace) => `<pcbtrace route={${JSON.stringify(trace.route)}} />`);
391
+
392
+ // lib/generate-footprint-tsx/convert-plated-holes.ts
393
+ import { su as su9 } from "@tscircuit/soup-util";
390
394
  import { mmStr as mmStr4 } from "@tscircuit/mm";
391
395
 
392
396
  // lib/generate-footprint-tsx/footprint-tsx-attribute-formatters/format-optional-mm-attr.ts
@@ -407,7 +411,7 @@ var formatSolderMaskAttrs = (platedHole) => {
407
411
 
408
412
  // lib/generate-footprint-tsx/convert-plated-holes.ts
409
413
  var convertPlatedHoles = (circuitJson) => {
410
- const platedHoles = su8(circuitJson).pcb_plated_hole.list();
414
+ const platedHoles = su9(circuitJson).pcb_plated_hole.list();
411
415
  const elementStrings = [];
412
416
  for (const platedHole of platedHoles) {
413
417
  if (platedHole.shape === "oval" || platedHole.shape === "pill") {
@@ -439,12 +443,12 @@ var convertPlatedHoles = (circuitJson) => {
439
443
  };
440
444
 
441
445
  // lib/generate-footprint-tsx/convert-silkscreen.ts
442
- import { su as su9 } from "@tscircuit/soup-util";
446
+ import { su as su10 } from "@tscircuit/soup-util";
443
447
  var convertSilkscreen = (circuitJson) => {
444
- const silkscreenLines = su9(circuitJson).pcb_silkscreen_line.list();
445
- const silkscreenPaths = su9(circuitJson).pcb_silkscreen_path.list();
446
- const silkscreenRects = su9(circuitJson).pcb_silkscreen_rect.list();
447
- const silkscreenCircles = su9(circuitJson).pcb_silkscreen_circle.list();
448
+ const silkscreenLines = su10(circuitJson).pcb_silkscreen_line.list();
449
+ const silkscreenPaths = su10(circuitJson).pcb_silkscreen_path.list();
450
+ const silkscreenRects = su10(circuitJson).pcb_silkscreen_rect.list();
451
+ const silkscreenCircles = su10(circuitJson).pcb_silkscreen_circle.list();
448
452
  const elementStrings = [];
449
453
  for (const silkscreenPath of silkscreenPaths) {
450
454
  const attrs = [`route={${JSON.stringify(silkscreenPath.route)}}`];
@@ -465,7 +469,9 @@ var convertSilkscreen = (circuitJson) => {
465
469
  `height={${silkscreenRect.height ?? 0}}`,
466
470
  `layer="${silkscreenRect.layer}"`
467
471
  ];
468
- if (silkscreenRect.stroke_width !== void 0) {
472
+ if (silkscreenRect.has_stroke === false) {
473
+ attrs.push("strokeWidth={0}");
474
+ } else if (silkscreenRect.stroke_width !== void 0) {
469
475
  attrs.push(`strokeWidth={${silkscreenRect.stroke_width}}`);
470
476
  }
471
477
  if (silkscreenRect.is_filled !== void 0) {
@@ -474,7 +480,9 @@ var convertSilkscreen = (circuitJson) => {
474
480
  if (silkscreenRect.corner_radius !== void 0) {
475
481
  attrs.push(`cornerRadius={${silkscreenRect.corner_radius}}`);
476
482
  }
477
- elementStrings.push(`<silkscreenrect ${attrs.join(" ")} />`);
483
+ elementStrings.push(
484
+ `<silkscreenrect ${attrs.join(" ")}${formatPcbRotationAttr(silkscreenRect.ccw_rotation)} />`
485
+ );
478
486
  }
479
487
  for (const silkscreenCircle of silkscreenCircles) {
480
488
  const center = silkscreenCircle.center ?? { x: 0, y: 0 };
@@ -511,10 +519,10 @@ var convertSilkscreen = (circuitJson) => {
511
519
  };
512
520
 
513
521
  // lib/generate-footprint-tsx/convert-silkscreen-text.ts
514
- import { su as su10 } from "@tscircuit/soup-util";
522
+ import { su as su11 } from "@tscircuit/soup-util";
515
523
  import { mmStr as mmStr5 } from "@tscircuit/mm";
516
524
  var convertSilkscreenText = (circuitJson) => {
517
- const silkscreenTexts = su10(circuitJson).pcb_silkscreen_text.list();
525
+ const silkscreenTexts = su11(circuitJson).pcb_silkscreen_text.list();
518
526
  const elementStrings = [];
519
527
  for (const silkscreenText of silkscreenTexts) {
520
528
  const pcbX = silkscreenText.anchor_position?.x ?? 0;
@@ -529,10 +537,10 @@ var convertSilkscreenText = (circuitJson) => {
529
537
  };
530
538
 
531
539
  // lib/generate-footprint-tsx/convert-smt-pads.ts
532
- import { su as su11 } from "@tscircuit/soup-util";
540
+ import { su as su12 } from "@tscircuit/soup-util";
533
541
  import { mmStr as mmStr6 } from "@tscircuit/mm";
534
542
  var convertSmtPads = (circuitJson) => {
535
- const smtPads = su11(circuitJson).pcb_smtpad.list();
543
+ const smtPads = su12(circuitJson).pcb_smtpad.list();
536
544
  const elementStrings = [];
537
545
  for (const smtPad of smtPads) {
538
546
  const commonAttrs = [];
@@ -581,9 +589,9 @@ var convertSmtPads = (circuitJson) => {
581
589
 
582
590
  // lib/generate-footprint-tsx/convert-vias.ts
583
591
  import { mmStr as mmStr7 } from "@tscircuit/mm";
584
- import { su as su12 } from "@tscircuit/soup-util";
592
+ import { su as su13 } from "@tscircuit/soup-util";
585
593
  var convertVias = (circuitJson) => {
586
- return su12(circuitJson).pcb_via.list().map((via) => {
594
+ return su13(circuitJson).pcb_via.list().map((via) => {
587
595
  const fromLayer = via.from_layer ?? via.layers[0];
588
596
  const toLayer = via.to_layer ?? via.layers[via.layers.length - 1];
589
597
  if (!fromLayer || !toLayer) {
@@ -605,6 +613,7 @@ var generateFootprintTsx = (circuitJson) => {
605
613
  convertPlatedHoles,
606
614
  convertVias,
607
615
  convertSmtPads,
616
+ convertPcbTraces,
608
617
  convertSilkscreen,
609
618
  convertFabrication,
610
619
  convertSilkscreenText,
@@ -630,7 +639,7 @@ var getBoardUsingTemplate = ({
630
639
  circuitJson,
631
640
  componentName
632
641
  }) => {
633
- const pcbBoard = su13(circuitJson).pcb_board.list()[0];
642
+ const pcbBoard = su14(circuitJson).pcb_board.list()[0];
634
643
  const boardProps = [];
635
644
  if (pcbBoard) {
636
645
  if (pcbBoard.width !== void 0) {
@@ -682,18 +691,18 @@ ${componentName ? `export default ${componentName}` : ""}
682
691
  };
683
692
 
684
693
  // lib/generate-symbol-tsx.ts
685
- import { su as su14 } from "@tscircuit/soup-util";
694
+ import { su as su15 } from "@tscircuit/soup-util";
686
695
  var escapeJsxText2 = (text) => text.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
687
696
  var generateSymbolTsx = (circuitJson) => {
688
- const schematicArcs = su14(circuitJson).schematic_arc.list();
689
- const schematicLines = su14(circuitJson).schematic_line.list();
690
- const schematicPaths = su14(circuitJson).schematic_path.list();
691
- const schematicTexts = su14(circuitJson).schematic_text.list();
692
- const schematicCircles = su14(circuitJson).schematic_circle.list();
693
- const schematicBoxes = su14(circuitJson).schematic_box.list();
694
- const schematicRects = su14(circuitJson).schematic_rect.list();
695
- const schematicTables = su14(circuitJson).schematic_table.list();
696
- const schematicTableCells = su14(circuitJson).schematic_table_cell.list();
697
+ const schematicArcs = su15(circuitJson).schematic_arc.list();
698
+ const schematicLines = su15(circuitJson).schematic_line.list();
699
+ const schematicPaths = su15(circuitJson).schematic_path.list();
700
+ const schematicTexts = su15(circuitJson).schematic_text.list();
701
+ const schematicCircles = su15(circuitJson).schematic_circle.list();
702
+ const schematicBoxes = su15(circuitJson).schematic_box.list();
703
+ const schematicRects = su15(circuitJson).schematic_rect.list();
704
+ const schematicTables = su15(circuitJson).schematic_table.list();
705
+ const schematicTableCells = su15(circuitJson).schematic_table_cell.list();
697
706
  const elementStrings = [];
698
707
  for (const arc of schematicArcs) {
699
708
  const center = arc.center ?? { x: 0, y: 0 };
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-NOSIW5HF.js";
4
+ } from "../chunk-U24G34W6.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.54",
19
+ version: "0.0.56",
20
20
  repository: {
21
21
  type: "git",
22
22
  url: "https://github.com/tscircuit/circuit-json-to-tscircuit.git"
package/dist/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  convertCircuitJsonToTscircuit
3
- } from "../chunk-NOSIW5HF.js";
3
+ } from "../chunk-U24G34W6.js";
4
4
  export {
5
5
  convertCircuitJsonToTscircuit
6
6
  };
@@ -0,0 +1,7 @@
1
+ import { su } from "@tscircuit/soup-util"
2
+ import type { FootprintElementConverter } from "./converter-types"
3
+
4
+ export const convertPcbTraces: FootprintElementConverter = (circuitJson) =>
5
+ su(circuitJson)
6
+ .pcb_trace.list()
7
+ .map((trace) => `<pcbtrace route={${JSON.stringify(trace.route)}} />`)
@@ -1,5 +1,6 @@
1
1
  import { su } from "@tscircuit/soup-util"
2
2
  import type { FootprintElementConverter } from "./converter-types"
3
+ import { formatPcbRotationAttr } from "./footprint-tsx-attribute-formatters/format-pcb-rotation-attr"
3
4
 
4
5
  export const convertSilkscreen: FootprintElementConverter = (circuitJson) => {
5
6
  const silkscreenLines = su(circuitJson).pcb_silkscreen_line.list()
@@ -31,7 +32,9 @@ export const convertSilkscreen: FootprintElementConverter = (circuitJson) => {
31
32
  `layer="${silkscreenRect.layer}"`,
32
33
  ]
33
34
 
34
- if (silkscreenRect.stroke_width !== undefined) {
35
+ if (silkscreenRect.has_stroke === false) {
36
+ attrs.push("strokeWidth={0}")
37
+ } else if (silkscreenRect.stroke_width !== undefined) {
35
38
  attrs.push(`strokeWidth={${silkscreenRect.stroke_width}}`)
36
39
  }
37
40
  if (silkscreenRect.is_filled !== undefined) {
@@ -41,7 +44,9 @@ export const convertSilkscreen: FootprintElementConverter = (circuitJson) => {
41
44
  attrs.push(`cornerRadius={${silkscreenRect.corner_radius}}`)
42
45
  }
43
46
 
44
- elementStrings.push(`<silkscreenrect ${attrs.join(" ")} />`)
47
+ elementStrings.push(
48
+ `<silkscreenrect ${attrs.join(" ")}${formatPcbRotationAttr(silkscreenRect.ccw_rotation)} />`,
49
+ )
45
50
  }
46
51
 
47
52
  for (const silkscreenCircle of silkscreenCircles) {
@@ -1,5 +1,4 @@
1
1
  import type { AnyCircuitElement } from "circuit-json"
2
- import type { FootprintElementConverter } from "./generate-footprint-tsx/converter-types"
3
2
  import { convertCopperText } from "./generate-footprint-tsx/convert-copper-text"
4
3
  import { convertCourtyard } from "./generate-footprint-tsx/convert-courtyard"
5
4
  import { convertCutouts } from "./generate-footprint-tsx/convert-cutouts"
@@ -7,11 +6,13 @@ import { convertFabrication } from "./generate-footprint-tsx/convert-fabrication
7
6
  import { convertHoles } from "./generate-footprint-tsx/convert-holes"
8
7
  import { convertKeepouts } from "./generate-footprint-tsx/convert-keepouts"
9
8
  import { convertNotes } from "./generate-footprint-tsx/convert-notes"
9
+ import { convertPcbTraces } from "./generate-footprint-tsx/convert-pcb-traces"
10
10
  import { convertPlatedHoles } from "./generate-footprint-tsx/convert-plated-holes"
11
11
  import { convertSilkscreen } from "./generate-footprint-tsx/convert-silkscreen"
12
12
  import { convertSilkscreenText } from "./generate-footprint-tsx/convert-silkscreen-text"
13
13
  import { convertSmtPads } from "./generate-footprint-tsx/convert-smt-pads"
14
14
  import { convertVias } from "./generate-footprint-tsx/convert-vias"
15
+ import type { FootprintElementConverter } from "./generate-footprint-tsx/converter-types"
15
16
 
16
17
  export const generateFootprintTsx = (
17
18
  circuitJson: AnyCircuitElement[],
@@ -21,6 +22,7 @@ export const generateFootprintTsx = (
21
22
  convertPlatedHoles,
22
23
  convertVias,
23
24
  convertSmtPads,
25
+ convertPcbTraces,
24
26
  convertSilkscreen,
25
27
  convertFabrication,
26
28
  convertSilkscreenText,
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.55",
9
+ "version": "0.0.57",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "https://github.com/tscircuit/circuit-json-to-tscircuit.git"
@@ -0,0 +1,39 @@
1
+ import { expect, test } from "bun:test"
2
+ import type { CircuitJson } from "circuit-json"
3
+ import { convertCircuitJsonToTscircuit } from "lib"
4
+ import { runTscircuitCode } from "tscircuit"
5
+
6
+ for (const ccwRotationDegrees of [0, 90, 180, 270]) {
7
+ test(`preserves silkscreen rectangle orientation at ${ccwRotationDegrees} degrees`, async () => {
8
+ const circuitJson: CircuitJson = [
9
+ {
10
+ type: "pcb_silkscreen_rect",
11
+ pcb_silkscreen_rect_id: "polarity_bar",
12
+ pcb_component_id: "diode",
13
+ center: { x: 0, y: 0 },
14
+ width: 0.5,
15
+ height: 3,
16
+ layer: "top",
17
+ is_filled: true,
18
+ stroke_width: 0.1,
19
+ has_stroke: false,
20
+ ccw_rotation: ccwRotationDegrees,
21
+ },
22
+ ]
23
+ const generatedTscircuit = convertCircuitJsonToTscircuit(circuitJson, {
24
+ componentName: "PolarityBar",
25
+ })
26
+ const renderedCircuitJson = (await runTscircuitCode(`
27
+ ${generatedTscircuit}
28
+ circuit.add(<board width="10mm" height="10mm"><PolarityBar /></board>)
29
+ `)) as CircuitJson
30
+ const rectangle = renderedCircuitJson.find(
31
+ (element) => element.type === "pcb_silkscreen_rect",
32
+ )
33
+ const isQuarterTurn = ccwRotationDegrees % 180 === 90
34
+ expect(rectangle?.width).toBe(isQuarterTurn ? 3 : 0.5)
35
+ expect(rectangle?.height).toBe(isQuarterTurn ? 0.5 : 3)
36
+ expect(rectangle?.is_filled).toBe(true)
37
+ expect(rectangle?.stroke_width).toBe(0)
38
+ })
39
+ }
@@ -0,0 +1,38 @@
1
+ import { expect, test } from "bun:test"
2
+ import type { CircuitJson, PcbTrace } from "circuit-json"
3
+ import { convertCircuitJsonToTscircuit } from "lib"
4
+ import { runTscircuitCode } from "tscircuit"
5
+
6
+ test("preserves routed PCB trace geometry", async () => {
7
+ const route: PcbTrace["route"] = [
8
+ { route_type: "wire", x: -4, y: 1, width: 0.3, layer: "top" },
9
+ { route_type: "wire", x: 4, y: 1, width: 0.3, layer: "top" },
10
+ ]
11
+ const circuitJson: CircuitJson = [
12
+ {
13
+ type: "pcb_board",
14
+ pcb_board_id: "pcb_board_0",
15
+ center: { x: 0, y: 0 },
16
+ width: 10,
17
+ height: 10,
18
+ thickness: 1.6,
19
+ num_layers: 2,
20
+ material: "fr4",
21
+ },
22
+ {
23
+ type: "pcb_trace",
24
+ pcb_trace_id: "pcb_trace_0",
25
+ route,
26
+ },
27
+ ]
28
+
29
+ const generatedTscircuit = convertCircuitJsonToTscircuit(circuitJson, {
30
+ componentName: "TraceBoard",
31
+ })
32
+ const renderedCircuitJson = await runTscircuitCode(generatedTscircuit)
33
+ const trace = renderedCircuitJson.find(
34
+ (element) => element.type === "pcb_trace",
35
+ )
36
+
37
+ expect(trace).toMatchObject({ route })
38
+ })