circuit-to-svg 0.0.317 → 0.0.319

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/index.js CHANGED
@@ -6042,7 +6042,7 @@ function getSoftwareUsedString(circuitJson) {
6042
6042
  var package_default = {
6043
6043
  name: "circuit-to-svg",
6044
6044
  type: "module",
6045
- version: "0.0.316",
6045
+ version: "0.0.318",
6046
6046
  description: "Convert Circuit JSON to SVG",
6047
6047
  main: "dist/index.js",
6048
6048
  files: [
@@ -6065,7 +6065,7 @@ var package_default = {
6065
6065
  "@vitejs/plugin-react": "5.0.0",
6066
6066
  biome: "^0.3.3",
6067
6067
  "bun-match-svg": "^0.0.12",
6068
- "circuit-json": "^0.0.359",
6068
+ "circuit-json": "^0.0.363",
6069
6069
  esbuild: "^0.20.2",
6070
6070
  "performance-now": "^2.1.0",
6071
6071
  react: "19.1.0",
@@ -6084,6 +6084,7 @@ var package_default = {
6084
6084
  "@types/node": "^22.5.5",
6085
6085
  "bun-types": "^1.1.40",
6086
6086
  "calculate-elbow": "0.0.12",
6087
+ "svg-path-commander": "^2.1.11",
6087
6088
  svgson: "^5.3.1",
6088
6089
  "transformation-matrix": "^2.16.1"
6089
6090
  }
@@ -10366,6 +10367,42 @@ function calculateAnchorPosition(schNetLabel, fontSizeMm, textWidthFSR) {
10366
10367
  };
10367
10368
  }
10368
10369
 
10370
+ // lib/utils/extract-points-from-svg-path.ts
10371
+ import SVGPathCommander from "svg-path-commander";
10372
+ function extractPointsFromSvgPath(svgPath) {
10373
+ const points = [];
10374
+ try {
10375
+ const parsed = SVGPathCommander.normalizePath(svgPath);
10376
+ for (const segment of parsed) {
10377
+ const command = segment[0];
10378
+ switch (command) {
10379
+ case "M":
10380
+ // MoveTo: x, y
10381
+ case "L":
10382
+ points.push({ x: segment[1], y: segment[2] });
10383
+ break;
10384
+ case "C":
10385
+ points.push({ x: segment[1], y: segment[2] });
10386
+ points.push({ x: segment[3], y: segment[4] });
10387
+ points.push({ x: segment[5], y: segment[6] });
10388
+ break;
10389
+ case "Q":
10390
+ points.push({ x: segment[1], y: segment[2] });
10391
+ points.push({ x: segment[3], y: segment[4] });
10392
+ break;
10393
+ case "A":
10394
+ points.push({ x: segment[6], y: segment[7] });
10395
+ break;
10396
+ case "Z":
10397
+ break;
10398
+ }
10399
+ }
10400
+ } catch {
10401
+ return [];
10402
+ }
10403
+ return points;
10404
+ }
10405
+
10369
10406
  // lib/sch/get-schematic-bounds-from-circuit-json.ts
10370
10407
  function getSchematicBoundsFromCircuitJson(soup, padding = 0.5) {
10371
10408
  let minX = Number.POSITIVE_INFINITY;
@@ -10496,8 +10533,15 @@ function getSchematicBoundsFromCircuitJson(soup, padding = 0.5) {
10496
10533
  0
10497
10534
  );
10498
10535
  } else if (item.type === "schematic_path") {
10499
- for (const point of item.points) {
10500
- updateBounds(point, { width: 0.02, height: 0.02 }, 0);
10536
+ if (item.points && item.points.length > 0) {
10537
+ for (const point of item.points) {
10538
+ updateBounds(point, { width: 0.02, height: 0.02 }, 0);
10539
+ }
10540
+ } else if (item.svg_path) {
10541
+ const points = extractPointsFromSvgPath(item.svg_path);
10542
+ for (const point of points) {
10543
+ updateBounds(point, { width: 0.02, height: 0.02 }, 0);
10544
+ }
10501
10545
  }
10502
10546
  }
10503
10547
  }
@@ -12736,12 +12780,46 @@ function createSvgObjectsFromSchematicArc({
12736
12780
  }
12737
12781
 
12738
12782
  // lib/sch/svg-object-fns/create-svg-objects-from-sch-path.ts
12739
- import { applyToPoint as applyToPoint75 } from "transformation-matrix";
12783
+ import { applyToPoint as applyToPoint75, toString as matrixToString10 } from "transformation-matrix";
12740
12784
  function createSvgObjectsFromSchematicPath({
12741
12785
  schPath,
12742
12786
  transform,
12743
12787
  colorMap: colorMap2
12744
12788
  }) {
12789
+ const strokeColor = schPath.stroke_color ?? colorMap2.schematic.component_outline;
12790
+ const fillColor = schPath.fill_color ?? "none";
12791
+ const strokeWidth = schPath.stroke_width ? Math.abs(transform.a) * schPath.stroke_width : Math.abs(transform.a) * 0.02;
12792
+ if (schPath.svg_path) {
12793
+ return [
12794
+ {
12795
+ name: "g",
12796
+ type: "element",
12797
+ attributes: {
12798
+ transform: matrixToString10(transform),
12799
+ ...schPath.schematic_component_id && {
12800
+ "data-schematic-component-id": schPath.schematic_component_id
12801
+ }
12802
+ },
12803
+ children: [
12804
+ {
12805
+ name: "path",
12806
+ type: "element",
12807
+ attributes: {
12808
+ d: schPath.svg_path,
12809
+ stroke: strokeColor,
12810
+ "stroke-width": (schPath.stroke_width ?? 0.02).toString(),
12811
+ fill: schPath.is_filled ? fillColor : "none",
12812
+ "stroke-linecap": "round",
12813
+ "stroke-linejoin": "round"
12814
+ },
12815
+ children: [],
12816
+ value: ""
12817
+ }
12818
+ ],
12819
+ value: ""
12820
+ }
12821
+ ];
12822
+ }
12745
12823
  if (!schPath.points || schPath.points.length < 2) {
12746
12824
  return [];
12747
12825
  }
@@ -12749,9 +12827,6 @@ function createSvgObjectsFromSchematicPath({
12749
12827
  (p) => applyToPoint75(transform, { x: p.x, y: p.y })
12750
12828
  );
12751
12829
  const pathD = transformedPoints.map((p, i) => `${i === 0 ? "M" : "L"} ${p.x} ${p.y}`).join(" ");
12752
- const strokeColor = colorMap2.schematic.component_outline;
12753
- const fillColor = schPath.fill_color ?? "none";
12754
- const strokeWidth = Math.abs(transform.a) * 0.02;
12755
12830
  return [
12756
12831
  {
12757
12832
  name: "path",