@tscircuit/core 0.0.281 → 0.0.283
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.d.ts +425 -198
- package/dist/index.js +104 -20
- package/package.json +2 -2
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
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
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();
|
|
@@ -2839,7 +2906,7 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
2839
2906
|
if (this.root?.schematicDisabled) return;
|
|
2840
2907
|
const { config } = this;
|
|
2841
2908
|
const portsToCreate = [];
|
|
2842
|
-
const schPortArrangement = this.
|
|
2909
|
+
const schPortArrangement = this._getSchematicPortArrangement();
|
|
2843
2910
|
if (schPortArrangement && !this._parsedProps.pinLabels) {
|
|
2844
2911
|
for (const side in schPortArrangement) {
|
|
2845
2912
|
const pins = schPortArrangement[side].pins;
|
|
@@ -2931,7 +2998,7 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
2931
2998
|
}
|
|
2932
2999
|
this.addAll(portsToCreate);
|
|
2933
3000
|
}
|
|
2934
|
-
if (!this.
|
|
3001
|
+
if (!this._getSchematicPortArrangement()) {
|
|
2935
3002
|
const portsFromFootprint = this.getPortsFromFootprint(opts);
|
|
2936
3003
|
for (const port of portsFromFootprint) {
|
|
2937
3004
|
if (!portsToCreate.some(
|
|
@@ -2942,13 +3009,13 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
2942
3009
|
}
|
|
2943
3010
|
}
|
|
2944
3011
|
for (let pn = 1; pn <= (opts.pinCount ?? this._getPinCount()); pn++) {
|
|
2945
|
-
if (!
|
|
3012
|
+
if (!schPortArrangement) continue;
|
|
2946
3013
|
if (portsToCreate.find((p) => p._parsedProps.pinNumber === pn)) continue;
|
|
2947
3014
|
let explicitlyListedPinNumbersInSchPortArrangement = [
|
|
2948
|
-
...
|
|
2949
|
-
...
|
|
2950
|
-
...
|
|
2951
|
-
...
|
|
3015
|
+
...schPortArrangement.leftSide?.pins ?? [],
|
|
3016
|
+
...schPortArrangement.rightSide?.pins ?? [],
|
|
3017
|
+
...schPortArrangement.topSide?.pins ?? [],
|
|
3018
|
+
...schPortArrangement.bottomSide?.pins ?? []
|
|
2952
3019
|
].map(
|
|
2953
3020
|
(pn2) => parsePinNumberFromLabelsOrThrow(pn2, this._parsedProps.pinLabels)
|
|
2954
3021
|
);
|
|
@@ -2961,7 +3028,7 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
2961
3028
|
"rightPinCount",
|
|
2962
3029
|
"topPinCount",
|
|
2963
3030
|
"bottomPinCount"
|
|
2964
|
-
].some((key) => key in
|
|
3031
|
+
].some((key) => key in schPortArrangement)) {
|
|
2965
3032
|
explicitlyListedPinNumbersInSchPortArrangement = Array.from(
|
|
2966
3033
|
{ length: this._getPinCount() },
|
|
2967
3034
|
(_, i) => i + 1
|
|
@@ -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;
|
|
@@ -3092,6 +3171,7 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
3092
3171
|
}
|
|
3093
3172
|
}
|
|
3094
3173
|
const center = this._getGlobalSchematicPositionBeforeLayout();
|
|
3174
|
+
const schPortArrangement = this._getSchematicPortArrangement();
|
|
3095
3175
|
const schematic_component2 = db.schematic_component.insert({
|
|
3096
3176
|
center,
|
|
3097
3177
|
rotation: props.schRotation ?? 0,
|
|
@@ -3100,16 +3180,14 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
3100
3180
|
// uses the schematic_component size to draw boxes instead of the
|
|
3101
3181
|
// schematic_box size
|
|
3102
3182
|
// size: dimensions.getSizeIncludingPins(),
|
|
3103
|
-
port_arrangement: underscorifyPortArrangement(
|
|
3104
|
-
props.schPortArrangement
|
|
3105
|
-
),
|
|
3183
|
+
port_arrangement: underscorifyPortArrangement(schPortArrangement),
|
|
3106
3184
|
pin_spacing: props.schPinSpacing ?? 0.2,
|
|
3107
3185
|
// @ts-ignore soup needs to support distance for pin_styles
|
|
3108
3186
|
pin_styles: underscorifyPinStyles(props.schPinStyle, props.pinLabels),
|
|
3109
3187
|
port_labels: primaryPortLabels,
|
|
3110
3188
|
source_component_id: this.source_component_id
|
|
3111
3189
|
});
|
|
3112
|
-
const hasTopOrBottomPins =
|
|
3190
|
+
const hasTopOrBottomPins = schPortArrangement?.topSide !== void 0 || schPortArrangement?.bottomSide !== void 0;
|
|
3113
3191
|
const schematic_box_width = dimensions?.getSize().width;
|
|
3114
3192
|
const schematic_box_height = dimensions?.getSize().height;
|
|
3115
3193
|
const manufacturer_part_number_schematic_text = db.schematic_text.insert({
|
|
@@ -3357,7 +3435,7 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
3357
3435
|
* appear on a schematic box, e.g. for a pin header
|
|
3358
3436
|
*/
|
|
3359
3437
|
_getSchematicPortArrangement() {
|
|
3360
|
-
return this._parsedProps.schPortArrangement;
|
|
3438
|
+
return this._parsedProps.schPinArrangement ?? this._parsedProps.schPortArrangement;
|
|
3361
3439
|
}
|
|
3362
3440
|
_getSchematicBoxDimensions() {
|
|
3363
3441
|
if (this.getSchematicSymbol()) return null;
|
|
@@ -6311,6 +6389,12 @@ var PushButton = class extends NormalComponent {
|
|
|
6311
6389
|
sourceFtype: FTYPE.simple_push_button
|
|
6312
6390
|
};
|
|
6313
6391
|
}
|
|
6392
|
+
get defaultInternallyConnectedPortNames() {
|
|
6393
|
+
return [
|
|
6394
|
+
["pin1", "pin4"],
|
|
6395
|
+
["pin2", "pin3"]
|
|
6396
|
+
];
|
|
6397
|
+
}
|
|
6314
6398
|
initPorts() {
|
|
6315
6399
|
super.initPorts({
|
|
6316
6400
|
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.
|
|
4
|
+
"version": "0.0.283",
|
|
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.
|
|
58
|
+
"@tscircuit/props": "^0.0.136",
|
|
59
59
|
"@tscircuit/schematic-autolayout": "^0.0.6",
|
|
60
60
|
"@tscircuit/soup-util": "^0.0.41",
|
|
61
61
|
"circuit-json": "^0.0.134",
|