circuit-to-svg 0.0.158 → 0.0.160

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
@@ -3622,6 +3622,18 @@ var createSvgSchErrorText = ({
3622
3622
  };
3623
3623
  };
3624
3624
 
3625
+ // lib/utils/is-source-port-connected.ts
3626
+ var isSourcePortConnected = (circuitJson, sourcePortId) => {
3627
+ for (const elm of circuitJson) {
3628
+ if (elm.type !== "source_trace") continue;
3629
+ const trace = elm;
3630
+ if (Array.isArray(trace.connected_source_port_ids) && trace.connected_source_port_ids.includes(sourcePortId)) {
3631
+ return true;
3632
+ }
3633
+ }
3634
+ return false;
3635
+ };
3636
+
3625
3637
  // lib/sch/svg-object-fns/create-svg-objects-from-sch-component-with-symbol.ts
3626
3638
  var ninePointAnchorToTextAnchor2 = {
3627
3639
  top_left: "start",
@@ -3681,6 +3693,12 @@ var createSvgObjectsFromSchematicComponentWithSymbol = ({
3681
3693
  const texts = symbol.primitives.filter((p) => p.type === "text");
3682
3694
  const circles = symbol.primitives.filter((p) => p.type === "circle");
3683
3695
  const boxes = symbol.primitives.filter((p) => p.type === "box");
3696
+ const connectedSymbolPorts = /* @__PURE__ */ new Set();
3697
+ for (const match of schPortsWithSymbolPorts) {
3698
+ if (isSourcePortConnected(circuitJson, match.schPort.source_port_id)) {
3699
+ connectedSymbolPorts.add(match.symbolPort);
3700
+ }
3701
+ }
3684
3702
  const bounds = {
3685
3703
  minX: Math.min(...paths.flatMap((p) => p.points.map((pt) => pt.x))),
3686
3704
  maxX: Math.max(...paths.flatMap((p) => p.points.map((pt) => pt.x))),
@@ -3805,6 +3823,7 @@ var createSvgObjectsFromSchematicComponentWithSymbol = ({
3805
3823
  });
3806
3824
  }
3807
3825
  for (const port of symbol.ports) {
3826
+ if (connectedSymbolPorts.has(port)) continue;
3808
3827
  const screenPortPos = applyToPoint26(
3809
3828
  compose7(realToScreenTransform, transformFromSymbolToReal),
3810
3829
  port
@@ -3921,19 +3940,22 @@ var createSvgObjectsForSchPortBoxLine = ({
3921
3940
  value: "",
3922
3941
  children: []
3923
3942
  });
3924
- svgObjects.push({
3925
- name: "circle",
3926
- type: "element",
3927
- attributes: {
3928
- class: "component-pin",
3929
- cx: screenSchPortPos.x.toString(),
3930
- cy: screenSchPortPos.y.toString(),
3931
- r: (Math.abs(transform.a) * PIN_CIRCLE_RADIUS_MM).toString(),
3932
- "stroke-width": `${getSchStrokeSize(transform)}px`
3933
- },
3934
- value: "",
3935
- children: []
3936
- });
3943
+ const isConnected = isSourcePortConnected(circuitJson, schPort.source_port_id);
3944
+ if (!isConnected) {
3945
+ svgObjects.push({
3946
+ name: "circle",
3947
+ type: "element",
3948
+ attributes: {
3949
+ class: "component-pin",
3950
+ cx: screenSchPortPos.x.toString(),
3951
+ cy: screenSchPortPos.y.toString(),
3952
+ r: (Math.abs(transform.a) * PIN_CIRCLE_RADIUS_MM).toString(),
3953
+ "stroke-width": `${getSchStrokeSize(transform)}px`
3954
+ },
3955
+ value: "",
3956
+ children: []
3957
+ });
3958
+ }
3937
3959
  return svgObjects;
3938
3960
  };
3939
3961
 
@@ -4079,6 +4101,33 @@ var createSvgSchText = ({
4079
4101
  top_right: "hanging",
4080
4102
  center_left: "middle"
4081
4103
  };
4104
+ const lines = elm.text.split("\n");
4105
+ const children = lines.length === 1 ? [
4106
+ {
4107
+ type: "text",
4108
+ value: elm.text,
4109
+ name: elm.schematic_text_id,
4110
+ attributes: {},
4111
+ children: []
4112
+ }
4113
+ ] : lines.map((line, idx) => ({
4114
+ type: "element",
4115
+ name: "tspan",
4116
+ value: "",
4117
+ attributes: {
4118
+ x: center.x.toString(),
4119
+ ...idx > 0 ? { dy: "1em" } : {}
4120
+ },
4121
+ children: [
4122
+ {
4123
+ type: "text",
4124
+ value: line,
4125
+ name: idx === 0 ? elm.schematic_text_id : "",
4126
+ attributes: {},
4127
+ children: []
4128
+ }
4129
+ ]
4130
+ }));
4082
4131
  return {
4083
4132
  type: "element",
4084
4133
  name: "text",
@@ -4093,15 +4142,7 @@ var createSvgSchText = ({
4093
4142
  "font-size": `${getSchScreenFontSize(transform, "reference_designator", elm.font_size)}px`,
4094
4143
  transform: `rotate(${elm.rotation}, ${center.x}, ${center.y})`
4095
4144
  },
4096
- children: [
4097
- {
4098
- type: "text",
4099
- value: elm.text,
4100
- name: elm.schematic_text_id,
4101
- attributes: {},
4102
- children: []
4103
- }
4104
- ]
4145
+ children
4105
4146
  };
4106
4147
  };
4107
4148