circuit-json-to-tscircuit 0.0.76 → 0.0.78

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.
Files changed (22) hide show
  1. package/dist/{chunk-NQTXLCEN.js → chunk-35I53U4L.js} +3 -3
  2. package/dist/cli/main.js +2 -2
  3. package/dist/lib/index.js +1 -1
  4. package/lib/generate-board-schematic-tsx/convert-symbol-primitives.ts +5 -5
  5. package/package.json +1 -1
  6. package/tests/board-symbol-outline-width.test.ts +91 -0
  7. package/tests/fixtures/create-ti-evm-roundtrip.ts +9 -0
  8. package/tests/fixtures/ti-evms/README.md +5 -0
  9. package/tests/fixtures/ti-evms/lm251772evm-pd.circuit.json.gz +0 -0
  10. package/tests/fixtures/ti-evms/lm5155evm-fly.circuit.json.gz +0 -0
  11. package/tests/fixtures/ti-evms/lmg342x-bb-evm.circuit.json.gz +0 -0
  12. package/tests/ti-evms/__snapshots__/ti-drv8307evm-roundtrip-schematic-comparison.snap.svg +2 -2
  13. package/tests/ti-evms/__snapshots__/ti-drv8307evm-roundtrip.test.tsx.snap +376 -376
  14. package/tests/ti-evms/__snapshots__/ti-lm251772evm-pd-roundtrip-pcb-comparison.snap.svg +2 -2
  15. package/tests/ti-evms/__snapshots__/ti-lm251772evm-pd-roundtrip-schematic-comparison.snap.svg +1 -1
  16. package/tests/ti-evms/__snapshots__/ti-lm251772evm-pd-roundtrip.test.tsx.snap +554 -554
  17. package/tests/ti-evms/__snapshots__/ti-lm5155evm-fly-roundtrip-pcb-comparison.snap.svg +2 -2
  18. package/tests/ti-evms/__snapshots__/ti-lm5155evm-fly-roundtrip-schematic-comparison.snap.svg +2 -2
  19. package/tests/ti-evms/__snapshots__/ti-lmg342x-bb-evm-roundtrip-pcb-comparison.snap.svg +2 -2
  20. package/tests/ti-evms/__snapshots__/ti-lmg342x-bb-evm-roundtrip-schematic-comparison.snap.svg +2 -2
  21. package/tests/ti-evms/__snapshots__/ti-lmg342x-bb-evm-roundtrip.test.tsx.snap +408 -408
  22. package/tests/ti-evms/ti-lm5155evm-fly-roundtrip.test.tsx +370 -370
@@ -493,7 +493,7 @@ var isNonCollinear = ({
493
493
  // lib/generate-board-schematic-tsx/convert-symbol-primitives.ts
494
494
  import { schematic_text as schematic_text2 } from "circuit-json";
495
495
  import { applyToPoint as applyToPoint4 } from "transformation-matrix";
496
- var DEFAULT_SYMBOL_CIRCLE_STROKE_WIDTH = 0.02;
496
+ var SYMBOL_OUTLINE_STROKE_WIDTH = 0.02;
497
497
  var anchors = {
498
498
  middle_top: "top_center",
499
499
  middle_bottom: "bottom_center",
@@ -518,7 +518,7 @@ var convertSymbolPrimitives = ({
518
518
  if (primitive.closed && points[0]) points.push(points[0]);
519
519
  return formatElement("schematicpath", {
520
520
  points,
521
- strokeWidth: primitive.strokeWidth,
521
+ strokeWidth: SYMBOL_OUTLINE_STROKE_WIDTH,
522
522
  isFilled: primitive.fill
523
523
  });
524
524
  }
@@ -546,7 +546,7 @@ var convertSymbolPrimitives = ({
546
546
  return formatElement("schematiccircle", {
547
547
  center,
548
548
  radius: Math.hypot(radiusVector.x, radiusVector.y),
549
- strokeWidth: DEFAULT_SYMBOL_CIRCLE_STROKE_WIDTH,
549
+ strokeWidth: SYMBOL_OUTLINE_STROKE_WIDTH,
550
550
  isFilled: primitive.fill
551
551
  });
552
552
  }
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-NQTXLCEN.js";
4
+ } from "../chunk-35I53U4L.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.75",
19
+ version: "0.0.77",
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-NQTXLCEN.js";
3
+ } from "../chunk-35I53U4L.js";
4
4
  export {
5
5
  convertCircuitJsonToTscircuit
6
6
  };
@@ -3,9 +3,9 @@ import type { SchSymbol } from "schematic-symbols"
3
3
  import { applyToPoint, type Matrix } from "transformation-matrix"
4
4
  import { formatElement } from "./format-attributes"
5
5
 
6
- // Circuit JSON symbol primitives do not encode a stroke width. This matches
7
- // the component outline width used by circuit-to-svg.
8
- const DEFAULT_SYMBOL_CIRCLE_STROKE_WIDTH = 0.02
6
+ // circuit-to-svg renders library symbol paths and circles with a fixed
7
+ // component outline width, independent of library strokeWidth and symbol scale.
8
+ const SYMBOL_OUTLINE_STROKE_WIDTH = 0.02
9
9
 
10
10
  const anchors = {
11
11
  middle_top: "top_center",
@@ -38,7 +38,7 @@ export const convertSymbolPrimitives = ({
38
38
  if (primitive.closed && points[0]) points.push(points[0])
39
39
  return formatElement("schematicpath", {
40
40
  points,
41
- strokeWidth: primitive.strokeWidth,
41
+ strokeWidth: SYMBOL_OUTLINE_STROKE_WIDTH,
42
42
  isFilled: primitive.fill,
43
43
  })
44
44
  }
@@ -72,7 +72,7 @@ export const convertSymbolPrimitives = ({
72
72
  return formatElement("schematiccircle", {
73
73
  center,
74
74
  radius: Math.hypot(radiusVector.x, radiusVector.y),
75
- strokeWidth: DEFAULT_SYMBOL_CIRCLE_STROKE_WIDTH,
75
+ strokeWidth: SYMBOL_OUTLINE_STROKE_WIDTH,
76
76
  isFilled: primitive.fill,
77
77
  })
78
78
  }
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.76",
9
+ "version": "0.0.78",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "https://github.com/tscircuit/circuit-json-to-tscircuit.git"
@@ -0,0 +1,91 @@
1
+ import { expect, test } from "bun:test"
2
+ import { readFileSync } from "node:fs"
3
+ import { gunzipSync } from "node:zlib"
4
+ import type { CircuitJson } from "circuit-json"
5
+ import { convertCircuitJsonToSchematicSvg } from "circuit-to-svg"
6
+ import { convertCircuitJsonToTscircuit } from "lib"
7
+ import { runTscircuitCode } from "tscircuit"
8
+ import { applyToPoint, compose, scale, translate } from "transformation-matrix"
9
+
10
+ // Compare stroke/segment-length ratios so SVG auto-fit does not affect the test.
11
+ const firstPathStrokeRatio = (svg: string) => {
12
+ const path = svg.match(/<path\b[^>]*\bd="M ([^\"]+)"[^>]*>/)?.[0]
13
+ if (!path) throw new Error("Missing rendered symbol path")
14
+ const coordinates = path
15
+ .match(/\bd="M ([^\"]+)"/)![1]!
16
+ .split(/[MLZ\s,]+/)
17
+ .filter(Boolean)
18
+ .map(Number)
19
+ const width = Number.parseFloat(path.match(/\bstroke-width="([^\"]+)"/)![1]!)
20
+ return (
21
+ width /
22
+ Math.hypot(
23
+ coordinates[2]! - coordinates[0]!,
24
+ coordinates[3]! - coordinates[1]!,
25
+ )
26
+ )
27
+ }
28
+
29
+ for (const [fixture, symbolName, scaleFactor] of [
30
+ ["drv8307evm", "boxresistor_up", 1],
31
+ ["lm251772evm-pd", "boxresistor_right", 2],
32
+ ["lm5155evm-fly", "capacitor_down", 0.5],
33
+ ["lmg342x-bb-evm", "capacitor_polarized_down", 1],
34
+ ["drv8307evm", "diode_down", 1],
35
+ ] as const) {
36
+ test(`${fixture} ${symbolName} keeps rendered outline width at scale ${scaleFactor}`, async () => {
37
+ const source = JSON.parse(
38
+ gunzipSync(
39
+ readFileSync(
40
+ new URL(
41
+ `./fixtures/ti-evms/${fixture}.circuit.json.gz`,
42
+ import.meta.url,
43
+ ),
44
+ ),
45
+ ).toString(),
46
+ ) as CircuitJson
47
+ const component = source.find(
48
+ (e) => e.type === "schematic_component" && e.symbol_name === symbolName,
49
+ )
50
+ if (component?.type !== "schematic_component")
51
+ throw new Error("Missing fixture symbol")
52
+ const subset = source.filter(
53
+ (e) =>
54
+ e.type === "pcb_board" ||
55
+ e === component ||
56
+ (e.type === "source_component" &&
57
+ e.source_component_id === component.source_component_id) ||
58
+ (e.type === "source_port" &&
59
+ e.source_component_id === component.source_component_id) ||
60
+ (e.type === "schematic_port" &&
61
+ e.schematic_component_id === component.schematic_component_id),
62
+ )
63
+ const schematicToScaledSchematicTransform = compose(
64
+ translate(component.center.x, component.center.y),
65
+ scale(scaleFactor),
66
+ translate(-component.center.x, -component.center.y),
67
+ )
68
+ const scaledSize = applyToPoint(scale(scaleFactor), {
69
+ x: component.size.width,
70
+ y: component.size.height,
71
+ })
72
+ component.size = { width: scaledSize.x, height: scaledSize.y }
73
+ for (const element of subset) {
74
+ if (element.type === "schematic_port") {
75
+ element.center = applyToPoint(
76
+ schematicToScaledSchematicTransform,
77
+ element.center,
78
+ )
79
+ }
80
+ }
81
+ const output = await runTscircuitCode(
82
+ convertCircuitJsonToTscircuit(subset, { componentName: "SymbolOutline" }),
83
+ )
84
+ expect(
85
+ firstPathStrokeRatio(convertCircuitJsonToSchematicSvg(output)),
86
+ ).toBeCloseTo(
87
+ firstPathStrokeRatio(convertCircuitJsonToSchematicSvg(subset)),
88
+ 8,
89
+ )
90
+ })
91
+ }
@@ -58,6 +58,15 @@ export async function createTiEvmRoundtrip({
58
58
  sourceCircuitJson.filter((element) => element.type === "pcb_via").length,
59
59
  )
60
60
 
61
+ for (const circuitJson of [sourceCircuitJson, renderedCircuitJson]) {
62
+ const unresolvedProjectStrings = circuitJson.filter(
63
+ (element) =>
64
+ element.type === "pcb_silkscreen_text" &&
65
+ /\.(?:PRJ_[A-Za-z0-9_]+|PCB_Rev)\b/u.test(element.text),
66
+ )
67
+ expect(unresolvedProjectStrings).toEqual([])
68
+ }
69
+
61
70
  const sourcePcbSvg = convertCircuitJsonToPcbSvg(sourceCircuitJson, {
62
71
  matchBoardAspectRatio: true,
63
72
  })
@@ -5,6 +5,11 @@ Texas Instruments' published Altium design files. They were generated with
5
5
  `tscircuit/altium-to-circuit-json` at commit
6
6
  `9a578b5762e1dcca06e6d3f84f1d2950d0acc301`.
7
7
 
8
+ Project special strings in the LM251772EVM-PD, LM5155EVM-FLY, and
9
+ LMG342X-BB-EVM PCB fixtures were resolved from their matching `.PrjPcb` files using
10
+ `tscircuit/altium-to-circuit-json` commit
11
+ `c630289c2cae01c8a4d4dc9b896b33f8a3d90f34`.
12
+
8
13
  The upstream files and checksums are maintained in that repository's
9
14
  `scripts/references/reference-manifest.ts`. The gzip files only avoid committing
10
15
  several megabytes of repetitive JSON; tests expand them before conversion.