circuit-to-svg 0.0.165 → 0.0.167

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/README.md CHANGED
@@ -72,6 +72,11 @@ writeFileSync('board.svg', pcbSvg)
72
72
 
73
73
  Converts a schematic circuit description to an SVG string.
74
74
 
75
+ #### Options
76
+
77
+ - `includeVersion` – if `true`, add a `data-circuit-to-svg-version` attribute to
78
+ the root `<svg>`.
79
+
75
80
  ### convertCircuitJsonToPcbSvg
76
81
 
77
82
  `convertCircuitJsonToPcbSvg(circuitJson: AnyCircuitElement[], options?): string`
@@ -87,6 +92,8 @@ Converts a PCB layout description to an SVG string.
87
92
  `"#000"`.
88
93
  - `drawPaddingOutsideBoard` – if `false`, omit the board outline and extra
89
94
  padding around it. Defaults to `true`.
95
+ - `includeVersion` – if `true`, add a `data-circuit-to-svg-version` attribute to
96
+ the root `<svg>`.
90
97
 
91
98
  ### convertCircuitJsonToAssemblySvg
92
99
 
@@ -97,6 +104,8 @@ Converts circuit JSON into an assembly view of the board and components.
97
104
  #### Options
98
105
 
99
106
  - `width` and `height` – dimensions of the output SVG. Defaults to `800x600`.
107
+ - `includeVersion` – if `true`, add a `data-circuit-to-svg-version` attribute to
108
+ the root `<svg>`.
100
109
 
101
110
  ## Contributing
102
111
 
package/dist/index.d.ts CHANGED
@@ -40,6 +40,7 @@ interface Options$3 {
40
40
  matchBoardAspectRatio?: boolean;
41
41
  backgroundColor?: string;
42
42
  drawPaddingOutsideBoard?: boolean;
43
+ includeVersion?: boolean;
43
44
  }
44
45
  interface PcbContext {
45
46
  transform: Matrix;
@@ -57,6 +58,7 @@ declare const circuitJsonToPcbSvg: typeof convertCircuitJsonToPcbSvg;
57
58
  interface Options$2 {
58
59
  width?: number;
59
60
  height?: number;
61
+ includeVersion?: boolean;
60
62
  }
61
63
  interface AssemblySvgContext {
62
64
  transform: Matrix;
@@ -239,6 +241,7 @@ interface Options$1 {
239
241
  y: number;
240
242
  label: string;
241
243
  }>;
244
+ includeVersion?: boolean;
242
245
  }
243
246
  declare function convertCircuitJsonToSchematicSvg(circuitJson: AnyCircuitElement[], options?: Options$1): string;
244
247
  /**
@@ -250,9 +253,12 @@ interface Options {
250
253
  layer: "top" | "bottom";
251
254
  width?: number;
252
255
  height?: number;
256
+ includeVersion?: boolean;
253
257
  }
254
258
  declare function convertCircuitJsonToSolderPasteMask(circuitJson: AnyCircuitElement[], options: Options): string;
255
259
 
256
260
  declare function getSoftwareUsedString(circuitJson: AnyCircuitElement[]): string | undefined;
257
261
 
258
- export { type AssemblySvgContext, type ColorMap, type ColorOverrides, type PcbColorMap, type PcbColorOverrides, type PcbContext, circuitJsonToPcbSvg, circuitJsonToSchematicSvg, convertCircuitJsonToAssemblySvg, convertCircuitJsonToPcbSvg, convertCircuitJsonToSchematicSvg, convertCircuitJsonToSolderPasteMask, getSoftwareUsedString };
262
+ declare const CIRCUIT_TO_SVG_VERSION: string;
263
+
264
+ export { type AssemblySvgContext, CIRCUIT_TO_SVG_VERSION, type ColorMap, type ColorOverrides, type PcbColorMap, type PcbColorOverrides, type PcbContext, circuitJsonToPcbSvg, circuitJsonToSchematicSvg, convertCircuitJsonToAssemblySvg, convertCircuitJsonToPcbSvg, convertCircuitJsonToSchematicSvg, convertCircuitJsonToSolderPasteMask, getSoftwareUsedString };
package/dist/index.js CHANGED
@@ -1442,6 +1442,72 @@ function getSoftwareUsedString(circuitJson) {
1442
1442
  return metadata?.software_used_string;
1443
1443
  }
1444
1444
 
1445
+ // package.json
1446
+ var package_default = {
1447
+ name: "circuit-to-svg",
1448
+ type: "module",
1449
+ version: "0.0.166",
1450
+ description: "Convert Circuit JSON to SVG",
1451
+ main: "dist/index.js",
1452
+ files: [
1453
+ "dist"
1454
+ ],
1455
+ scripts: {
1456
+ start: "storybook dev -p 6006",
1457
+ prepublish: "npm run build",
1458
+ build: "tsup-node ./lib/index.ts --format esm --dts --sourcemap",
1459
+ format: "biome format . --write",
1460
+ "format:check": "biome format .",
1461
+ storybook: "storybook dev -p 6006",
1462
+ "build-storybook": "storybook build"
1463
+ },
1464
+ license: "ISC",
1465
+ devDependencies: {
1466
+ "@biomejs/biome": "^1.9.4",
1467
+ "@chromatic-com/storybook": "^1.6.1",
1468
+ "@storybook/addon-essentials": "^8.2.5",
1469
+ "@storybook/addon-interactions": "^8.2.5",
1470
+ "@storybook/addon-links": "^8.2.5",
1471
+ "@storybook/addon-onboarding": "^8.2.5",
1472
+ "@storybook/blocks": "^8.2.5",
1473
+ "@storybook/react": "^8.2.5",
1474
+ "@storybook/react-vite": "^8.2.5",
1475
+ "@storybook/test": "^8.2.5",
1476
+ "@tscircuit/core": "0.0.477",
1477
+ "@tscircuit/plop": "^0.0.10",
1478
+ "@types/bun": "^1.2.8",
1479
+ biome: "^0.3.3",
1480
+ "bun-match-svg": "^0.0.12",
1481
+ "circuit-json": "^0.0.218",
1482
+ esbuild: "^0.20.2",
1483
+ "performance-now": "^2.1.0",
1484
+ react: "^18.3.1",
1485
+ "schematic-symbols": "^0.0.153",
1486
+ storybook: "^8.2.5",
1487
+ tsup: "^8.0.2",
1488
+ typescript: "^5.4.5",
1489
+ "vite-tsconfig-paths": "^5.0.1",
1490
+ "@tscircuit/checks": "^0.0.44",
1491
+ "@tscircuit/circuit-json-util": "^0.0.47",
1492
+ "@tscircuit/footprinter": "^0.0.91"
1493
+ },
1494
+ peerDependencies: {
1495
+ "circuit-json": "*",
1496
+ "@tscircuit/circuit-json-util": "*",
1497
+ "@tscircuit/footprinter": "*",
1498
+ "schematic-symbols": "*"
1499
+ },
1500
+ dependencies: {
1501
+ "@types/node": "^22.5.5",
1502
+ "bun-types": "^1.1.40",
1503
+ svgson: "^5.3.1",
1504
+ "transformation-matrix": "^2.16.1"
1505
+ }
1506
+ };
1507
+
1508
+ // lib/package-version.ts
1509
+ var CIRCUIT_TO_SVG_VERSION = package_default.version;
1510
+
1445
1511
  // lib/pcb/convert-circuit-json-to-pcb-svg.ts
1446
1512
  var OBJECT_ORDER = [
1447
1513
  "pcb_trace_error",
@@ -1641,6 +1707,7 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
1641
1707
  }
1642
1708
  children.push(...svgObjects);
1643
1709
  const softwareUsedString = getSoftwareUsedString(circuitJson);
1710
+ const version = CIRCUIT_TO_SVG_VERSION;
1644
1711
  const svgObject = {
1645
1712
  name: "svg",
1646
1713
  type: "element",
@@ -1650,6 +1717,9 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
1650
1717
  height: svgHeight.toString(),
1651
1718
  ...softwareUsedString && {
1652
1719
  "data-software-used-string": softwareUsedString
1720
+ },
1721
+ ...options?.includeVersion && {
1722
+ "data-circuit-to-svg-version": version
1653
1723
  }
1654
1724
  },
1655
1725
  value: "",
@@ -2470,6 +2540,7 @@ function convertCircuitJsonToAssemblySvg(soup, options) {
2470
2540
  (a, b) => (OBJECT_ORDER2.indexOf(b.type) ?? 9999) - (OBJECT_ORDER2.indexOf(a.type) ?? 9999)
2471
2541
  ).flatMap((item) => createSvgObjects2(item, ctx, soup));
2472
2542
  const softwareUsedString = getSoftwareUsedString(soup);
2543
+ const version = CIRCUIT_TO_SVG_VERSION;
2473
2544
  const svgObject = {
2474
2545
  name: "svg",
2475
2546
  type: "element",
@@ -2479,6 +2550,9 @@ function convertCircuitJsonToAssemblySvg(soup, options) {
2479
2550
  height: svgHeight.toString(),
2480
2551
  ...softwareUsedString && {
2481
2552
  "data-software-used-string": softwareUsedString
2553
+ },
2554
+ ...options?.includeVersion && {
2555
+ "data-circuit-to-svg-version": version
2482
2556
  }
2483
2557
  },
2484
2558
  value: "",
@@ -4458,21 +4532,45 @@ var createSvgObjectsForSchPortBoxLine = ({
4458
4532
  children: []
4459
4533
  });
4460
4534
  const isConnected = isSourcePortConnected(circuitJson, schPort.source_port_id);
4535
+ const pinRadiusPx = Math.abs(transform.a) * PIN_CIRCLE_RADIUS_MM;
4536
+ const pinChildren = [];
4461
4537
  if (!isConnected) {
4462
- svgObjects.push({
4538
+ pinChildren.push({
4463
4539
  name: "circle",
4464
4540
  type: "element",
4465
4541
  attributes: {
4466
4542
  class: "component-pin",
4467
4543
  cx: screenSchPortPos.x.toString(),
4468
4544
  cy: screenSchPortPos.y.toString(),
4469
- r: (Math.abs(transform.a) * PIN_CIRCLE_RADIUS_MM).toString(),
4545
+ r: pinRadiusPx.toString(),
4470
4546
  "stroke-width": `${getSchStrokeSize(transform)}px`
4471
4547
  },
4472
4548
  value: "",
4473
4549
  children: []
4474
4550
  });
4475
4551
  }
4552
+ pinChildren.push({
4553
+ name: "rect",
4554
+ type: "element",
4555
+ attributes: {
4556
+ x: (screenSchPortPos.x - pinRadiusPx).toString(),
4557
+ y: (screenSchPortPos.y - pinRadiusPx).toString(),
4558
+ width: (pinRadiusPx * 2).toString(),
4559
+ height: (pinRadiusPx * 2).toString(),
4560
+ opacity: "0"
4561
+ },
4562
+ value: "",
4563
+ children: []
4564
+ });
4565
+ svgObjects.push({
4566
+ name: "g",
4567
+ type: "element",
4568
+ value: "",
4569
+ attributes: {
4570
+ "data-schematic-port-id": schPort.source_port_id
4571
+ },
4572
+ children: pinChildren
4573
+ });
4476
4574
  return svgObjects;
4477
4575
  };
4478
4576
 
@@ -5874,6 +5972,7 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
5874
5972
  );
5875
5973
  }
5876
5974
  const softwareUsedString = getSoftwareUsedString(circuitJson);
5975
+ const version = CIRCUIT_TO_SVG_VERSION;
5877
5976
  const svgObject = {
5878
5977
  name: "svg",
5879
5978
  type: "element",
@@ -5885,6 +5984,9 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
5885
5984
  "data-real-to-screen-transform": toSVG(transform),
5886
5985
  ...softwareUsedString && {
5887
5986
  "data-software-used-string": softwareUsedString
5987
+ },
5988
+ ...options?.includeVersion && {
5989
+ "data-circuit-to-svg-version": version
5888
5990
  }
5889
5991
  },
5890
5992
  children: [
@@ -6072,6 +6174,7 @@ function convertCircuitJsonToSolderPasteMask(circuitJson, options) {
6072
6174
  (a, b) => (OBJECT_ORDER3.indexOf(b.type) ?? 9999) - (OBJECT_ORDER3.indexOf(a.type) ?? 9999)
6073
6175
  ).flatMap((item) => createSvgObjects3({ elm: item, ctx }));
6074
6176
  const softwareUsedString = getSoftwareUsedString(circuitJson);
6177
+ const version = CIRCUIT_TO_SVG_VERSION;
6075
6178
  const svgObject = {
6076
6179
  name: "svg",
6077
6180
  type: "element",
@@ -6081,6 +6184,9 @@ function convertCircuitJsonToSolderPasteMask(circuitJson, options) {
6081
6184
  height: svgHeight.toString(),
6082
6185
  ...softwareUsedString && {
6083
6186
  "data-software-used-string": softwareUsedString
6187
+ },
6188
+ ...options.includeVersion && {
6189
+ "data-circuit-to-svg-version": version
6084
6190
  }
6085
6191
  },
6086
6192
  value: "",
@@ -6170,6 +6276,7 @@ function createSvgObjectFromPcbBoundary2(transform, minX, minY, maxX, maxY) {
6170
6276
  };
6171
6277
  }
6172
6278
  export {
6279
+ CIRCUIT_TO_SVG_VERSION,
6173
6280
  circuitJsonToPcbSvg,
6174
6281
  circuitJsonToSchematicSvg,
6175
6282
  convertCircuitJsonToAssemblySvg,