@tscircuit/core 0.0.1156 → 0.0.1157
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 +66 -72
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -19296,7 +19296,7 @@ import { identity as identity5 } from "transformation-matrix";
|
|
|
19296
19296
|
var package_default = {
|
|
19297
19297
|
name: "@tscircuit/core",
|
|
19298
19298
|
type: "module",
|
|
19299
|
-
version: "0.0.
|
|
19299
|
+
version: "0.0.1156",
|
|
19300
19300
|
types: "dist/index.d.ts",
|
|
19301
19301
|
main: "dist/index.js",
|
|
19302
19302
|
module: "dist/index.js",
|
|
@@ -23094,83 +23094,77 @@ import {
|
|
|
23094
23094
|
} from "@tscircuit/props";
|
|
23095
23095
|
import { unknown_error_finding_part as unknown_error_finding_part2 } from "circuit-json";
|
|
23096
23096
|
|
|
23097
|
-
// lib/utils/connectors/
|
|
23098
|
-
var
|
|
23099
|
-
|
|
23100
|
-
|
|
23101
|
-
|
|
23102
|
-
|
|
23103
|
-
|
|
23104
|
-
|
|
23105
|
-
|
|
23106
|
-
|
|
23107
|
-
DP2: [],
|
|
23108
|
-
|
|
23109
|
-
|
|
23110
|
-
|
|
23111
|
-
|
|
23112
|
-
|
|
23113
|
-
|
|
23114
|
-
|
|
23115
|
-
|
|
23116
|
-
|
|
23117
|
-
var
|
|
23118
|
-
var
|
|
23119
|
-
const
|
|
23120
|
-
for (const
|
|
23121
|
-
|
|
23122
|
-
|
|
23123
|
-
|
|
23124
|
-
|
|
23125
|
-
|
|
23126
|
-
|
|
23127
|
-
|
|
23128
|
-
|
|
23129
|
-
|
|
23130
|
-
|
|
23131
|
-
|
|
23132
|
-
|
|
23133
|
-
|
|
23134
|
-
|
|
23135
|
-
|
|
23136
|
-
|
|
23137
|
-
|
|
23138
|
-
if (
|
|
23139
|
-
|
|
23097
|
+
// lib/utils/connectors/convertCircuitJsonToUsbCStandardCircuitJson.ts
|
|
23098
|
+
var STANDARD_USB_C_PIN_LABELS = [
|
|
23099
|
+
{ label: "GND1", aliases: [] },
|
|
23100
|
+
{ label: "VBUS1", aliases: [] },
|
|
23101
|
+
{ label: "CC1", aliases: [] },
|
|
23102
|
+
{ label: "DP1", aliases: [] },
|
|
23103
|
+
{ label: "DM1", aliases: ["DN1"] },
|
|
23104
|
+
{ label: "SBU1", aliases: [] },
|
|
23105
|
+
{ label: "SBU2", aliases: [] },
|
|
23106
|
+
{ label: "DM2", aliases: ["DN2"] },
|
|
23107
|
+
{ label: "DP2", aliases: [] },
|
|
23108
|
+
{ label: "CC2", aliases: [] },
|
|
23109
|
+
{ label: "VBUS2", aliases: [] },
|
|
23110
|
+
{ label: "GND2", aliases: [] },
|
|
23111
|
+
{ label: "SHELL1", aliases: ["MH1", "EH1", "MOUNT1"] },
|
|
23112
|
+
{ label: "SHELL2", aliases: ["MH2", "EH2", "MOUNT2"] },
|
|
23113
|
+
{ label: "SHELL3", aliases: ["MH3", "EH3", "MOUNT3"] },
|
|
23114
|
+
{ label: "SHELL4", aliases: ["MH4", "EH4", "MOUNT4"] }
|
|
23115
|
+
];
|
|
23116
|
+
var PIN_NUMBER_HINT_PATTERN = /^(?:pin)?(\d+)$/i;
|
|
23117
|
+
var dedupeHintsPreservingOrder = (hints) => Array.from(new Set(hints));
|
|
23118
|
+
var convertCircuitJsonToUsbCStandardCircuitJson = (partCircuitJson) => {
|
|
23119
|
+
const unassignedPorts = [];
|
|
23120
|
+
for (const elm of partCircuitJson) {
|
|
23121
|
+
if (elm.type !== "source_port") continue;
|
|
23122
|
+
const pinNumber = elm.pin_number;
|
|
23123
|
+
if (typeof pinNumber !== "number") continue;
|
|
23124
|
+
const upperCaseHints = /* @__PURE__ */ new Set();
|
|
23125
|
+
for (const hint of elm.port_hints ?? []) {
|
|
23126
|
+
upperCaseHints.add(hint.trim().toUpperCase());
|
|
23127
|
+
}
|
|
23128
|
+
unassignedPorts.push({ pinKey: `pin${pinNumber}`, upperCaseHints });
|
|
23129
|
+
}
|
|
23130
|
+
const canonicalHintsByPin = {};
|
|
23131
|
+
for (const { label, aliases } of STANDARD_USB_C_PIN_LABELS) {
|
|
23132
|
+
const canonicalAndAliasHintsUpper = [label, ...aliases].map(
|
|
23133
|
+
(s) => s.toUpperCase()
|
|
23134
|
+
);
|
|
23135
|
+
const matchIndex = unassignedPorts.findIndex(
|
|
23136
|
+
(port) => canonicalAndAliasHintsUpper.some((hint) => port.upperCaseHints.has(hint))
|
|
23137
|
+
);
|
|
23138
|
+
if (matchIndex === -1) continue;
|
|
23139
|
+
const { pinKey } = unassignedPorts[matchIndex];
|
|
23140
|
+
canonicalHintsByPin[pinKey] = [label];
|
|
23141
|
+
unassignedPorts.splice(matchIndex, 1);
|
|
23142
|
+
}
|
|
23143
|
+
if (Object.keys(canonicalHintsByPin).length === 0) return partCircuitJson;
|
|
23144
|
+
return partCircuitJson.map((elm) => {
|
|
23145
|
+
if (!("port_hints" in elm) || !Array.isArray(elm.port_hints)) return elm;
|
|
23140
23146
|
const originalHints = elm.port_hints.filter((h) => typeof h === "string").map((h) => h.trim()).filter((h) => h.length > 0);
|
|
23141
23147
|
if (originalHints.length === 0) return elm;
|
|
23142
|
-
const
|
|
23148
|
+
const pinKeys = /* @__PURE__ */ new Set();
|
|
23143
23149
|
if (elm.type === "source_port" && typeof elm.pin_number === "number") {
|
|
23144
|
-
|
|
23150
|
+
pinKeys.add(`pin${elm.pin_number}`);
|
|
23145
23151
|
}
|
|
23146
23152
|
for (const hint of originalHints) {
|
|
23147
|
-
const
|
|
23148
|
-
if (
|
|
23149
|
-
|
|
23150
|
-
const sourceAliases = [];
|
|
23151
|
-
for (const pin of pinNumbers) {
|
|
23152
|
-
sourceAliases.push(...sourceAliasesByPin.get(pin) ?? []);
|
|
23153
|
-
}
|
|
23154
|
-
const standardHints = /* @__PURE__ */ new Set();
|
|
23155
|
-
for (const hint of [...originalHints, ...sourceAliases]) {
|
|
23156
|
-
const standard = aliasToStandardHint[hint.toUpperCase()];
|
|
23157
|
-
if (standard) standardHints.add(standard);
|
|
23158
|
-
}
|
|
23159
|
-
const addedHints = [];
|
|
23160
|
-
for (const standardHint of standardHints) {
|
|
23161
|
-
addedHints.push(
|
|
23162
|
-
standardHint,
|
|
23163
|
-
...USB_C_STANDARD_PORT_HINT_ALIASES[standardHint]
|
|
23164
|
-
);
|
|
23153
|
+
const matchedPin = hint.match(PIN_NUMBER_HINT_PATTERN);
|
|
23154
|
+
if (!matchedPin) continue;
|
|
23155
|
+
pinKeys.add(`pin${Number.parseInt(matchedPin[1], 10)}`);
|
|
23165
23156
|
}
|
|
23166
|
-
const
|
|
23167
|
-
|
|
23168
|
-
...
|
|
23169
|
-
|
|
23170
|
-
|
|
23157
|
+
const canonicalHintsToAdd = [];
|
|
23158
|
+
for (const pinKey of pinKeys) {
|
|
23159
|
+
canonicalHintsToAdd.push(...canonicalHintsByPin[pinKey] ?? []);
|
|
23160
|
+
}
|
|
23161
|
+
if (canonicalHintsToAdd.length === 0) return elm;
|
|
23171
23162
|
return {
|
|
23172
23163
|
...elm,
|
|
23173
|
-
port_hints:
|
|
23164
|
+
port_hints: dedupeHintsPreservingOrder([
|
|
23165
|
+
...originalHints,
|
|
23166
|
+
...canonicalHintsToAdd
|
|
23167
|
+
])
|
|
23174
23168
|
};
|
|
23175
23169
|
});
|
|
23176
23170
|
};
|
|
@@ -23316,8 +23310,8 @@ var Connector = class extends Chip {
|
|
|
23316
23310
|
});
|
|
23317
23311
|
}
|
|
23318
23312
|
_addConnectorFootprintFromCircuitJson(standard, circuitJson) {
|
|
23319
|
-
const rewrittenCircuitJson = standard === "usb_c" ? rewriteToStandardUsbCPortHints(circuitJson) : circuitJson;
|
|
23320
23313
|
const props = this._getConnectorProps();
|
|
23314
|
+
const standardizedCircuitJson = standard === "usb_c" ? convertCircuitJsonToUsbCStandardCircuitJson(circuitJson) : circuitJson;
|
|
23321
23315
|
const fpComponents = createComponentsFromCircuitJson(
|
|
23322
23316
|
{
|
|
23323
23317
|
componentName: this.name,
|
|
@@ -23326,7 +23320,7 @@ var Connector = class extends Chip {
|
|
|
23326
23320
|
pinLabels: props.pinLabels,
|
|
23327
23321
|
pcbPinLabels: props.pcbPinLabels
|
|
23328
23322
|
},
|
|
23329
|
-
|
|
23323
|
+
standardizedCircuitJson
|
|
23330
23324
|
);
|
|
23331
23325
|
this.addAll(fpComponents);
|
|
23332
23326
|
this._markDirty("InitializePortsFromChildren");
|