circuit-json-to-tscircuit 0.0.13 → 0.0.14

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.
@@ -249,6 +249,10 @@ import { su as su2 } from "@tscircuit/soup-util";
249
249
  var generateSymbolTsx = (circuitJson) => {
250
250
  const schematicArcs = su2(circuitJson).schematic_arc.list();
251
251
  const schematicLines = su2(circuitJson).schematic_line.list();
252
+ const schematicPaths = su2(circuitJson).schematic_path.list();
253
+ const schematicTexts = su2(circuitJson).schematic_text.list();
254
+ const schematicCircles = su2(circuitJson).schematic_circle.list();
255
+ const schematicBoxes = su2(circuitJson).schematic_box.list();
252
256
  const elementStrings = [];
253
257
  for (const arc of schematicArcs) {
254
258
  const center = arc.center ?? { x: 0, y: 0 };
@@ -284,6 +288,49 @@ var generateSymbolTsx = (circuitJson) => {
284
288
  `<schematicline x1={${x1}} y1={${y1}} x2={${x2}} y2={${y2}} strokeWidth={${strokeWidth}} color="${color}" isDashed={${isDashed}}/>`
285
289
  );
286
290
  }
291
+ for (const box of schematicBoxes) {
292
+ const x = box.x ?? 0;
293
+ const y = box.y ?? 0;
294
+ const width = box.width ?? 0;
295
+ const height = box.height ?? 0;
296
+ const isDashed = box.is_dashed ?? false;
297
+ elementStrings.push(
298
+ `<schematicbox center={{ x: ${x}, y: ${y} }} width={${width}} height={${height}} isDashed={${isDashed}}/>`
299
+ );
300
+ }
301
+ for (const path of schematicPaths) {
302
+ const points = path.points ?? [];
303
+ const fillColor = path.fill_color ?? "red";
304
+ const isFilled = path.is_filled ?? false;
305
+ elementStrings.push(
306
+ `<schematicpath points={${JSON.stringify(points)}} strokeColor="${fillColor}" fillColor="${fillColor}" isFilled={${isFilled}}/>`
307
+ );
308
+ }
309
+ for (const text of schematicTexts) {
310
+ const x = text.position?.x ?? 0;
311
+ const y = text.position?.y ?? 0;
312
+ const rawText = String(text.text ?? "");
313
+ const escapedText = rawText.replace(/"/g, '\\"');
314
+ const anchorAlignment = text.anchor ?? "center";
315
+ const fontSize = text.font_size ?? 0.1;
316
+ const color = text.color ?? "black";
317
+ const rotation = text.rotation ?? 0;
318
+ elementStrings.push(
319
+ `<schematictext text="${escapedText}" x={${x}} y={${y}} anchorAlignment="${anchorAlignment}" fontSize={${fontSize}} color="${color}" rotation={${rotation}} />`
320
+ );
321
+ }
322
+ for (const circle of schematicCircles) {
323
+ const x = circle.center?.x ?? 0;
324
+ const y = circle.center?.y ?? 0;
325
+ const radius = circle.radius ?? 0;
326
+ const strokeWidth = circle.stroke_width ?? 0.05;
327
+ const color = circle.color ?? "black";
328
+ const isFilled = circle.is_filled ?? false;
329
+ const isDashed = circle.is_dashed ?? false;
330
+ elementStrings.push(
331
+ `<schematiccircle center={{ x: ${x}, y: ${y} }} radius={${radius}} strokeWidth={${strokeWidth}} color="${color}" isFilled={${isFilled}} isDashed={${isDashed}} />`
332
+ );
333
+ }
287
334
  if (elementStrings.length === 0) {
288
335
  return null;
289
336
  }
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-YX563LGB.js";
4
+ } from "../chunk-544RXIHZ.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.12",
19
+ version: "0.0.13",
20
20
  scripts: {
21
21
  build: "tsup-node lib/index.ts cli/main.ts --format esm --dts",
22
22
  test: "bun test",
package/dist/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  convertCircuitJsonToTscircuit
3
- } from "../chunk-YX563LGB.js";
3
+ } from "../chunk-544RXIHZ.js";
4
4
  export {
5
5
  convertCircuitJsonToTscircuit
6
6
  };
@@ -6,7 +6,10 @@ export const generateSymbolTsx = (
6
6
  ): string | null => {
7
7
  const schematicArcs = su(circuitJson).schematic_arc.list()
8
8
  const schematicLines = su(circuitJson).schematic_line.list()
9
-
9
+ const schematicPaths = su(circuitJson).schematic_path.list()
10
+ const schematicTexts = su(circuitJson).schematic_text.list()
11
+ const schematicCircles = su(circuitJson).schematic_circle.list()
12
+ const schematicBoxes = su(circuitJson).schematic_box.list()
10
13
  const elementStrings: string[] = []
11
14
 
12
15
  for (const arc of schematicArcs) {
@@ -47,6 +50,57 @@ export const generateSymbolTsx = (
47
50
  )
48
51
  }
49
52
 
53
+ for (const box of schematicBoxes) {
54
+ const x = box.x ?? 0
55
+ const y = box.y ?? 0
56
+ const width = box.width ?? 0
57
+ const height = box.height ?? 0
58
+ const isDashed = box.is_dashed ?? false
59
+
60
+ elementStrings.push(
61
+ `<schematicbox center={{ x: ${x}, y: ${y} }} width={${width}} height={${height}} isDashed={${isDashed}}/>`,
62
+ )
63
+ }
64
+
65
+ for (const path of schematicPaths) {
66
+ const points = path.points ?? []
67
+ const fillColor = path.fill_color ?? "red"
68
+ const isFilled = path.is_filled ?? false
69
+
70
+ elementStrings.push(
71
+ `<schematicpath points={${JSON.stringify(points)}} strokeColor="${fillColor}" fillColor="${fillColor}" isFilled={${isFilled}}/>`,
72
+ )
73
+ }
74
+
75
+ for (const text of schematicTexts) {
76
+ const x = text.position?.x ?? 0
77
+ const y = text.position?.y ?? 0
78
+ const rawText = String(text.text ?? "")
79
+ const escapedText = rawText.replace(/"/g, '\\"')
80
+ const anchorAlignment = text.anchor ?? "center"
81
+ const fontSize = text.font_size ?? 0.1
82
+ const color = text.color ?? "black"
83
+ const rotation = text.rotation ?? 0
84
+
85
+ elementStrings.push(
86
+ `<schematictext text="${escapedText}" x={${x}} y={${y}} anchorAlignment="${anchorAlignment}" fontSize={${fontSize}} color="${color}" rotation={${rotation}} />`,
87
+ )
88
+ }
89
+
90
+ for (const circle of schematicCircles) {
91
+ const x = circle.center?.x ?? 0
92
+ const y = circle.center?.y ?? 0
93
+ const radius = circle.radius ?? 0
94
+ const strokeWidth = circle.stroke_width ?? 0.05
95
+ const color = circle.color ?? "black"
96
+ const isFilled = circle.is_filled ?? false
97
+ const isDashed = circle.is_dashed ?? false
98
+
99
+ elementStrings.push(
100
+ `<schematiccircle center={{ x: ${x}, y: ${y} }} radius={${radius}} strokeWidth={${strokeWidth}} color="${color}" isFilled={${isFilled}} isDashed={${isDashed}} />`,
101
+ )
102
+ }
103
+
50
104
  if (elementStrings.length === 0) {
51
105
  return null
52
106
  }
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.13",
9
+ "version": "0.0.14",
10
10
  "scripts": {
11
11
  "build": "tsup-node lib/index.ts cli/main.ts --format esm --dts",
12
12
  "test": "bun test",
@@ -0,0 +1,25 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="1200" height="600" style="background-color: rgb(245, 241, 237)" data-real-to-screen-transform="matrix(70.5052878966,0,0,-70.5052878966,493.8895417156,317.9788484136)" data-software-used-string="@tscircuit/core@0.0.1090"><style>
2
+ .boundary { fill: rgb(245, 241, 237); }
3
+ .schematic-boundary { fill: none; stroke: #fff; }
4
+ .component { fill: none; stroke: rgb(132, 0, 0); }
5
+ .chip { fill: rgb(255, 255, 194); stroke: rgb(132, 0, 0); }
6
+ .component-pin { fill: none; stroke: rgb(132, 0, 0); }
7
+ /* Basic per-trace hover fallback */
8
+ .trace:hover {
9
+ filter: invert(1);
10
+ }
11
+ .trace:hover .trace-crossing-outline {
12
+ opacity: 0;
13
+ }
14
+ .trace:hover .trace-junction {
15
+ filter: invert(1);
16
+ }
17
+ /* Net-hover highlighting: when a trace or its overlays are hovered,
18
+ invert color for all traces (base + overlays) sharing the same
19
+ subcircuit connectivity key. Also hide crossing outline during hover. */
20
+
21
+ .text { font-family: sans-serif; fill: rgb(0, 150, 0); }
22
+ .pin-number { fill: rgb(169, 0, 0); }
23
+ .port-label { fill: rgb(0, 100, 100); }
24
+ .component-name { fill: rgb(0, 100, 100); }
25
+ </style><rect class="boundary" x="0" y="0" width="1200" height="600"/><line x1="634.9001175088" y1="317.9788484136" x2="775.910693302" y2="317.9788484136" stroke="black" stroke-width="3.5252643948299998" data-schematic-line-id="schematic_line_0" data-schematic-component-id="schematic_component_0"/><circle cx="705.4054054054" cy="529.4947121033999" r="35.2526439483" fill="green" stroke="green" stroke-width="3.5252643948299998" stroke-dasharray="10.57579318449" data-schematic-circle-id="schematic_circle_0" data-schematic-component-id="schematic_component_0"/><path d="M 564.3948296121999 317.9788484136 A 70.5052878966 70.5052878966 0 0 0 423.384253819 317.9788484136" fill="none" stroke="black" stroke-width="3.5252643948299998" data-schematic-arc-id="schematic_arc_0" data-schematic-component-id="schematic_component_0"/><path d="M 705.4054054054 106.46298472380005 L 775.910693302 35.95769682720004" stroke="blue" stroke-width="1.410105757932" fill="none" stroke-linecap="round" stroke-linejoin="round" data-schematic-component-id="schematic_component_0"/><text x="493.8895417156" y="317.9788484136" fill="red" text-anchor="middle" dominant-baseline="middle" font-family="sans-serif" font-size="14.101057579319999px" transform="rotate(0, 493.8895417156, 317.9788484136)">U1</text><rect class="schematic-box" x="423.384253819" y="247.473560517" width="141.01057579319996" height="141.01057579320002" stroke-width="1.410105757932px" stroke="rgb(132, 0, 0)" fill="transparent"/></svg>
@@ -0,0 +1,123 @@
1
+ import { test, expect } from "bun:test"
2
+ import { convertCircuitJsonToTscircuit } from "lib/index"
3
+ import type { AnyCircuitElement } from "circuit-json"
4
+ import { runTscircuitCode } from "tscircuit"
5
+ import { convertCircuitJsonToSchematicSvg } from "circuit-to-svg"
6
+
7
+ const circuitJson: AnyCircuitElement[] = [
8
+ {
9
+ type: "schematic_arc",
10
+ center: { x: 0, y: 0 },
11
+ schematic_arc_id: "schematic_arc_id_1",
12
+ radius: 1,
13
+ schematic_component_id: "schematic_component_id_1",
14
+ start_angle_degrees: 0,
15
+ end_angle_degrees: 180,
16
+ stroke_width: 0.05,
17
+ color: "black",
18
+ is_dashed: false,
19
+ direction: "counterclockwise",
20
+ },
21
+ {
22
+ type: "schematic_line",
23
+ x1: 2,
24
+ schematic_line_id: "schematic_line_id_1",
25
+ schematic_component_id: "schematic_component_id_1",
26
+ y1: 0,
27
+ x2: 4,
28
+ y2: 0,
29
+ stroke_width: 0.05,
30
+ color: "black",
31
+ is_dashed: false,
32
+ },
33
+ {
34
+ type: "schematic_box",
35
+ schematic_component_id: "schematic_component_id_1",
36
+ x: 0,
37
+ y: 3,
38
+ width: 2,
39
+ height: 2,
40
+ is_dashed: true,
41
+ },
42
+ {
43
+ type: "schematic_path",
44
+ schematic_path_id: "schematic_path_id_1",
45
+ points: [
46
+ { x: 3, y: 3 },
47
+ { x: 4, y: 4 },
48
+ ],
49
+ fill_color: "blue",
50
+ },
51
+ {
52
+ type: "schematic_text",
53
+ schematic_text_id: "schematic_text_id_1",
54
+ text: "U1",
55
+ position: { x: 0, y: -3 },
56
+ anchor: "center",
57
+ font_size: 0.2,
58
+ color: "red",
59
+ rotation: 45,
60
+ },
61
+ {
62
+ type: "schematic_circle",
63
+ center: { x: 3, y: -3 },
64
+ schematic_circle_id: "schematic_circle_id_1",
65
+ radius: 0.5,
66
+ stroke_width: 0.05,
67
+ color: "green",
68
+ is_filled: true,
69
+ is_dashed: true,
70
+ },
71
+ ]
72
+
73
+ test("test7 comprehensive schematic symbol support", async () => {
74
+ const tscircuit = convertCircuitJsonToTscircuit(circuitJson, {
75
+ componentName: "U1",
76
+ })
77
+
78
+ expect(tscircuit).toMatchInlineSnapshot(`
79
+ "import { type ChipProps } from "tscircuit"
80
+ export const U1 = (props: ChipProps) => (
81
+ <chip
82
+ symbol={<symbol>
83
+ <schematicarc
84
+ center={{ x: 0, y: 0 }}
85
+ radius={1}
86
+ startAngleDegrees={0}
87
+ endAngleDegrees={180}
88
+ strokeWidth={0.05}
89
+ color="black"
90
+ isDashed={false}
91
+ direction="counterclockwise"
92
+ />
93
+ <schematicline x1={2} y1={0} x2={4} y2={0} strokeWidth={0.05} color="black" isDashed={false}/>
94
+ <schematicbox center={{ x: 0, y: 3 }} width={2} height={2} isDashed={true}/>
95
+ <schematicpath points={[{"x":3,"y":3},{"x":4,"y":4}]} strokeColor="blue" fillColor="blue" isFilled={false}/>
96
+ <schematictext text="U1" x={0} y={-3} anchorAlignment="center" fontSize={0.2} color="red" rotation={45} />
97
+ <schematiccircle center={{ x: 3, y: -3 }} radius={0.5} strokeWidth={0.05} color="green" isFilled={true} isDashed={true} />
98
+ </symbol>}
99
+ {...props}
100
+ />
101
+ )"
102
+ `)
103
+ const result = await runTscircuitCode(tscircuit)
104
+
105
+ expect(Array.isArray(result)).toBe(true)
106
+ expect(result).not.toHaveLength(0)
107
+ }, 15000)
108
+
109
+ test("test7 comprehensive schematic symbol support svg", async () => {
110
+ const tscircuit = convertCircuitJsonToTscircuit(circuitJson, {
111
+ componentName: "U1",
112
+ })
113
+
114
+ const result = await runTscircuitCode(tscircuit)
115
+
116
+ const schematicSvg = convertCircuitJsonToSchematicSvg(
117
+ result as AnyCircuitElement[],
118
+ )
119
+ await expect(schematicSvg).toMatchSvgSnapshot(
120
+ import.meta.path,
121
+ "comprehensive-schematic-symbol",
122
+ )
123
+ })
@@ -1,59 +0,0 @@
1
- import { test, expect } from "bun:test"
2
- import { convertCircuitJsonToTscircuit } from "lib/index"
3
- import type { AnyCircuitElement } from "circuit-json"
4
-
5
- test("test7 schematic arc and line inline snapshot", async () => {
6
- const circuitJson: AnyCircuitElement[] = [
7
- {
8
- type: "schematic_arc",
9
- center: { x: 0, y: 0 },
10
- radius: 1,
11
- start_angle_degrees: 0,
12
- end_angle_degrees: 180,
13
- stroke_width: 0.05,
14
- color: "black",
15
- is_dashed: false,
16
- schematic_component_id: "schematic_component_id_1",
17
- direction: "counterclockwise",
18
- schematic_arc_id: "schematic_arc_id_1",
19
- },
20
- {
21
- type: "schematic_line",
22
- x1: -1,
23
- y1: 0,
24
- x2: 1,
25
- y2: 0,
26
- stroke_width: 0.05,
27
- schematic_line_id: "schematic_line_id_1",
28
- schematic_component_id: "schematic_component_id_1",
29
- color: "black",
30
- is_dashed: false,
31
- },
32
- ]
33
-
34
- const tscircuit = convertCircuitJsonToTscircuit(circuitJson, {
35
- componentName: "U1",
36
- })
37
-
38
- expect(tscircuit).toMatchInlineSnapshot(`
39
- "import { type ChipProps } from "tscircuit"
40
- export const U1 = (props: ChipProps) => (
41
- <chip
42
- symbol={<symbol>
43
- <schematicarc
44
- center={{ x: 0, y: 0 }}
45
- radius={1}
46
- startAngleDegrees={0}
47
- endAngleDegrees={180}
48
- strokeWidth={0.05}
49
- color="black"
50
- isDashed={false}
51
- direction="counterclockwise"
52
- />
53
- <schematicline x1={-1} y1={0} x2={1} y2={0} strokeWidth={0.05} color="black" isDashed={false}/>
54
- </symbol>}
55
- {...props}
56
- />
57
- )"
58
- `)
59
- })