@tscircuit/core 0.0.281 → 0.0.282

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
@@ -50,7 +50,7 @@ __export(components_exports, {
50
50
  Via: () => Via
51
51
  });
52
52
 
53
- // lib/components/base-components/NormalComponent.ts
53
+ // lib/components/base-components/NormalComponent/NormalComponent.ts
54
54
  import { fp } from "@tscircuit/footprinter";
55
55
  import { point3, rotation } from "circuit-json";
56
56
  import Debug4 from "debug";
@@ -2050,14 +2050,67 @@ var Port = class extends PrimitiveComponent {
2050
2050
  _getGlobalPcbPositionAfterLayout() {
2051
2051
  return this._getPcbCircuitJsonBounds().center;
2052
2052
  }
2053
+ _getPortsInternallyConnectedToThisPort() {
2054
+ const parent = this.parent;
2055
+ if (!parent || !parent._getInternallyConnectedPorts) return [];
2056
+ const internallyConnectedPorts = parent._getInternallyConnectedPorts();
2057
+ for (const ports of internallyConnectedPorts) {
2058
+ if (ports.some((port) => port === this)) {
2059
+ return ports;
2060
+ }
2061
+ }
2062
+ return [];
2063
+ }
2064
+ /**
2065
+ * Return true if this port has a schematic representation and can be rendered
2066
+ * to the schematic.
2067
+ *
2068
+ * Sometimes things like mounting holes don't have a schematic representation
2069
+ * and aren't rendered to the schematic.
2070
+ *
2071
+ * It's common for a schematic symbol to not have a representation for all of
2072
+ * the pins on a footprint, e.g. a pushbutton has 4 pins but is typically
2073
+ * represented by a two-pin symbol. In these cases, it's best to use
2074
+ * internallyConnectedPorts or externallyConnectedPorts to ensure the things
2075
+ * are rendered properly.
2076
+ */
2077
+ _hasSchematicPort() {
2078
+ const symbol = this.parent?.getSchematicSymbol();
2079
+ if (symbol) {
2080
+ if (this.schematicSymbolPortDef) return true;
2081
+ const portsInternallyConnectedToThisPort = this._getPortsInternallyConnectedToThisPort();
2082
+ if (portsInternallyConnectedToThisPort.some((p) => p.schematicSymbolPortDef))
2083
+ return true;
2084
+ return false;
2085
+ }
2086
+ const parentBoxDim = this?.parent?._getSchematicBoxDimensions();
2087
+ if (parentBoxDim && this.props.pinNumber !== void 0) {
2088
+ const localPortPosition = parentBoxDim.getPortPositionByPinNumber(
2089
+ this.props.pinNumber
2090
+ );
2091
+ if (localPortPosition) return true;
2092
+ }
2093
+ return false;
2094
+ }
2053
2095
  _getGlobalSchematicPositionBeforeLayout() {
2054
2096
  const symbol = this.parent?.getSchematicSymbol();
2055
- if (symbol && this.schematicSymbolPortDef) {
2097
+ if (symbol) {
2098
+ let schematicSymbolPortDef = this.schematicSymbolPortDef;
2099
+ if (!schematicSymbolPortDef) {
2100
+ schematicSymbolPortDef = this._getPortsInternallyConnectedToThisPort().find(
2101
+ (p) => p.schematicSymbolPortDef
2102
+ )?.schematicSymbolPortDef ?? null;
2103
+ if (!schematicSymbolPortDef) {
2104
+ throw new Error(
2105
+ `Couldn't find schematicSymbolPortDef for port ${this.getString()}, searched internally connected ports and none had a schematicSymbolPortDef. Why are we trying to get the schematic position of this port?`
2106
+ );
2107
+ }
2108
+ }
2056
2109
  const transform = compose2(
2057
2110
  this.parent.computeSchematicGlobalTransform(),
2058
2111
  translate2(-symbol.center.x, -symbol.center.y)
2059
2112
  );
2060
- return applyToPoint3(transform, this.schematicSymbolPortDef);
2113
+ return applyToPoint3(transform, schematicSymbolPortDef);
2061
2114
  }
2062
2115
  const parentBoxDim = this?.parent?._getSchematicBoxDimensions();
2063
2116
  if (parentBoxDim && this.props.pinNumber !== void 0) {
@@ -2065,14 +2118,18 @@ var Port = class extends PrimitiveComponent {
2065
2118
  this.props.pinNumber
2066
2119
  );
2067
2120
  if (!localPortPosition) {
2068
- return { x: 0, y: 0 };
2121
+ throw new Error(
2122
+ `Couldn't find position for schematic_port for port ${this.getString()} inside of the schematic box`
2123
+ );
2069
2124
  }
2070
2125
  return applyToPoint3(
2071
2126
  this.parent.computeSchematicGlobalTransform(),
2072
2127
  localPortPosition
2073
2128
  );
2074
2129
  }
2075
- return { x: 0, y: 0 };
2130
+ throw new Error(
2131
+ `Couldn't find position for schematic_port for port ${this.getString()}`
2132
+ );
2076
2133
  }
2077
2134
  _getGlobalSchematicPositionAfterLayout() {
2078
2135
  const { db } = this.root;
@@ -2200,6 +2257,7 @@ var Port = class extends PrimitiveComponent {
2200
2257
  const { _parsedProps: props } = this;
2201
2258
  const container = this.getPrimitiveContainer();
2202
2259
  if (!container) return;
2260
+ if (!this._hasSchematicPort()) return;
2203
2261
  const containerCenter = container._getGlobalSchematicPositionBeforeLayout();
2204
2262
  const portCenter = this._getGlobalSchematicPositionBeforeLayout();
2205
2263
  let localPortInfo = null;
@@ -2571,7 +2629,7 @@ var getAllDimensionsForSchematicBox = (params) => {
2571
2629
  };
2572
2630
  };
2573
2631
 
2574
- // lib/components/base-components/NormalComponent.ts
2632
+ // lib/components/base-components/NormalComponent/NormalComponent.ts
2575
2633
  import {
2576
2634
  isValidElement as isReactElement,
2577
2635
  isValidElement
@@ -2803,7 +2861,7 @@ var getNumericSchPinStyle = (pinStyles, pinLabels) => {
2803
2861
  return numericPinStyles;
2804
2862
  };
2805
2863
 
2806
- // lib/components/base-components/NormalComponent.ts
2864
+ // lib/components/base-components/NormalComponent/NormalComponent.ts
2807
2865
  var debug3 = Debug4("tscircuit:core");
2808
2866
  var rotation3 = z5.object({
2809
2867
  x: rotation,
@@ -2816,6 +2874,15 @@ var NormalComponent = class extends PrimitiveComponent {
2816
2874
  isPrimitiveContainer = true;
2817
2875
  _asyncSupplierPartNumbers;
2818
2876
  pcb_missing_footprint_error_id;
2877
+ /**
2878
+ * Override this property for component defaults
2879
+ */
2880
+ get defaultInternallyConnectedPortNames() {
2881
+ return [];
2882
+ }
2883
+ get internallyConnectedPortNames() {
2884
+ return this._parsedProps.internallyConnectedPorts ?? this.defaultInternallyConnectedPortNames;
2885
+ }
2819
2886
  constructor(props) {
2820
2887
  super(props);
2821
2888
  this._addChildrenFromStringFootprint();
@@ -3057,6 +3124,18 @@ var NormalComponent = class extends PrimitiveComponent {
3057
3124
  _getSchematicSymbolDisplayValue() {
3058
3125
  return void 0;
3059
3126
  }
3127
+ _getInternallyConnectedPorts() {
3128
+ if (this.internallyConnectedPortNames.length === 0) return [];
3129
+ const internallyConnectedPorts = [];
3130
+ for (const netPortNames of this.internallyConnectedPortNames) {
3131
+ const ports = [];
3132
+ for (const portName of netPortNames) {
3133
+ ports.push(this.portMap[portName]);
3134
+ }
3135
+ internallyConnectedPorts.push(ports);
3136
+ }
3137
+ return internallyConnectedPorts;
3138
+ }
3060
3139
  _doInitialSchematicComponentRenderWithSymbol() {
3061
3140
  if (this.root?.schematicDisabled) return;
3062
3141
  const { db } = this.root;
@@ -6311,6 +6390,12 @@ var PushButton = class extends NormalComponent {
6311
6390
  sourceFtype: FTYPE.simple_push_button
6312
6391
  };
6313
6392
  }
6393
+ get defaultInternallyConnectedPortNames() {
6394
+ return [
6395
+ ["pin1", "pin4"],
6396
+ ["pin2", "pin3"]
6397
+ ];
6398
+ }
6314
6399
  initPorts() {
6315
6400
  super.initPorts({
6316
6401
  pinCount: 4,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.281",
4
+ "version": "0.0.282",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -55,7 +55,7 @@
55
55
  "@tscircuit/footprinter": "^0.0.97",
56
56
  "@tscircuit/infgrid-ijump-astar": "^0.0.33",
57
57
  "@tscircuit/math-utils": "^0.0.9",
58
- "@tscircuit/props": "^0.0.130",
58
+ "@tscircuit/props": "^0.0.134",
59
59
  "@tscircuit/schematic-autolayout": "^0.0.6",
60
60
  "@tscircuit/soup-util": "^0.0.41",
61
61
  "circuit-json": "^0.0.134",