@tscircuit/core 0.0.1029 → 0.0.1030
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 +91 -18
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11185,6 +11185,7 @@ var TraceHint = class extends PrimitiveComponent2 {
|
|
|
11185
11185
|
};
|
|
11186
11186
|
|
|
11187
11187
|
// lib/components/primitive-components/Group/Group_doInitialPcbCalcPlacementResolution.ts
|
|
11188
|
+
import { getBoundsOfPcbElements } from "@tscircuit/circuit-json-util";
|
|
11188
11189
|
var SUPPORTED_COMPONENT_FIELDS = /* @__PURE__ */ new Set([
|
|
11189
11190
|
"x",
|
|
11190
11191
|
"y",
|
|
@@ -11221,29 +11222,24 @@ function Group_doInitialPcbCalcPlacementResolution(group) {
|
|
|
11221
11222
|
}
|
|
11222
11223
|
for (const [candidateName, candidate] of candidatesByName.entries()) {
|
|
11223
11224
|
for (const token of candidate.refs) {
|
|
11224
|
-
const {
|
|
11225
|
+
const { referencePath, field } = parseComponentReferenceToken(token);
|
|
11225
11226
|
if (!SUPPORTED_COMPONENT_FIELDS.has(field)) {
|
|
11226
11227
|
throw new Error(
|
|
11227
11228
|
`Invalid pcb position expression for ${candidate.component.getString()}: unsupported component field "${field}" in "${token}"`
|
|
11228
11229
|
);
|
|
11229
11230
|
}
|
|
11230
|
-
const
|
|
11231
|
-
|
|
11232
|
-
|
|
11233
|
-
|
|
11234
|
-
|
|
11235
|
-
}
|
|
11236
|
-
if (
|
|
11237
|
-
throw new Error(
|
|
11238
|
-
`Invalid pcb position expression for ${candidate.component.getString()}: ambiguous component reference "${componentName}" in "${token}"`
|
|
11239
|
-
);
|
|
11240
|
-
}
|
|
11241
|
-
if (candidatesByName.has(componentName) && componentName !== candidateName) {
|
|
11231
|
+
const referencedComponentName = resolveReferencedComponentName({
|
|
11232
|
+
token,
|
|
11233
|
+
referencePath,
|
|
11234
|
+
candidate,
|
|
11235
|
+
normalComponentNameMap
|
|
11236
|
+
});
|
|
11237
|
+
if (candidatesByName.has(referencedComponentName) && referencedComponentName !== candidateName) {
|
|
11242
11238
|
inDegree.set(candidateName, (inDegree.get(candidateName) ?? 0) + 1);
|
|
11243
|
-
if (!dependents.has(
|
|
11244
|
-
dependents.set(
|
|
11239
|
+
if (!dependents.has(referencedComponentName)) {
|
|
11240
|
+
dependents.set(referencedComponentName, /* @__PURE__ */ new Set());
|
|
11245
11241
|
}
|
|
11246
|
-
dependents.get(
|
|
11242
|
+
dependents.get(referencedComponentName).add(candidateName);
|
|
11247
11243
|
}
|
|
11248
11244
|
}
|
|
11249
11245
|
}
|
|
@@ -11337,10 +11333,35 @@ function parseComponentReferenceToken(token) {
|
|
|
11337
11333
|
throw new Error(`Invalid component reference token: "${token}"`);
|
|
11338
11334
|
}
|
|
11339
11335
|
return {
|
|
11340
|
-
|
|
11336
|
+
referencePath: token.slice(0, dotIndex),
|
|
11341
11337
|
field: token.slice(dotIndex + 1).toLowerCase()
|
|
11342
11338
|
};
|
|
11343
11339
|
}
|
|
11340
|
+
function resolveReferencedComponentName(params) {
|
|
11341
|
+
const { token, referencePath, candidate, normalComponentNameMap } = params;
|
|
11342
|
+
const directComponents = normalComponentNameMap.get(referencePath);
|
|
11343
|
+
if (directComponents && directComponents.length > 0) {
|
|
11344
|
+
if (directComponents.length > 1) {
|
|
11345
|
+
throw new Error(
|
|
11346
|
+
`Invalid pcb position expression for ${candidate.component.getString()}: ambiguous component reference "${referencePath}" in "${token}"`
|
|
11347
|
+
);
|
|
11348
|
+
}
|
|
11349
|
+
return referencePath;
|
|
11350
|
+
}
|
|
11351
|
+
let bestMatch = null;
|
|
11352
|
+
for (const componentName of normalComponentNameMap.keys()) {
|
|
11353
|
+
if (!referencePath.startsWith(`${componentName}.`)) continue;
|
|
11354
|
+
if (!bestMatch || componentName.length > bestMatch.length) {
|
|
11355
|
+
bestMatch = componentName;
|
|
11356
|
+
}
|
|
11357
|
+
}
|
|
11358
|
+
if (!bestMatch) {
|
|
11359
|
+
throw new Error(
|
|
11360
|
+
`Invalid pcb position expression for ${candidate.component.getString()}: unknown component reference "${referencePath}" in "${token}"`
|
|
11361
|
+
);
|
|
11362
|
+
}
|
|
11363
|
+
return bestMatch;
|
|
11364
|
+
}
|
|
11344
11365
|
function updateVarsForNamedComponent(component, vars) {
|
|
11345
11366
|
if (!component.name || !component.pcb_component_id || !component.root) return;
|
|
11346
11367
|
const pcbComponent = component.root.db.pcb_component.get(
|
|
@@ -11359,6 +11380,58 @@ function updateVarsForNamedComponent(component, vars) {
|
|
|
11359
11380
|
vars[`${component.name}.maxx`] = x + width / 2;
|
|
11360
11381
|
vars[`${component.name}.miny`] = y - height / 2;
|
|
11361
11382
|
vars[`${component.name}.maxy`] = y + height / 2;
|
|
11383
|
+
const padElementsByReference = collectPadElementsByReference(component);
|
|
11384
|
+
for (const [referencePath, elements] of padElementsByReference.entries()) {
|
|
11385
|
+
const bounds = getBoundsOfPcbElements(elements);
|
|
11386
|
+
const minX = bounds.minX;
|
|
11387
|
+
const maxX = bounds.maxX;
|
|
11388
|
+
const minY = bounds.minY;
|
|
11389
|
+
const maxY = bounds.maxY;
|
|
11390
|
+
vars[`${referencePath}.x`] = (minX + maxX) / 2;
|
|
11391
|
+
vars[`${referencePath}.y`] = (minY + maxY) / 2;
|
|
11392
|
+
vars[`${referencePath}.width`] = maxX - minX;
|
|
11393
|
+
vars[`${referencePath}.height`] = maxY - minY;
|
|
11394
|
+
vars[`${referencePath}.minx`] = minX;
|
|
11395
|
+
vars[`${referencePath}.maxx`] = maxX;
|
|
11396
|
+
vars[`${referencePath}.miny`] = minY;
|
|
11397
|
+
vars[`${referencePath}.maxy`] = maxY;
|
|
11398
|
+
}
|
|
11399
|
+
}
|
|
11400
|
+
function collectPadElementsByReference(component) {
|
|
11401
|
+
const refsToElements = /* @__PURE__ */ new Map();
|
|
11402
|
+
if (!component.name || !component.pcb_component_id || !component.root) {
|
|
11403
|
+
return refsToElements;
|
|
11404
|
+
}
|
|
11405
|
+
const { db } = component.root;
|
|
11406
|
+
const padElements = [
|
|
11407
|
+
...db.pcb_smtpad.list({ pcb_component_id: component.pcb_component_id }),
|
|
11408
|
+
...db.pcb_plated_hole.list({
|
|
11409
|
+
pcb_component_id: component.pcb_component_id
|
|
11410
|
+
})
|
|
11411
|
+
];
|
|
11412
|
+
for (const pad of padElements) {
|
|
11413
|
+
const aliases = /* @__PURE__ */ new Set();
|
|
11414
|
+
for (const hint of pad.port_hints ?? []) {
|
|
11415
|
+
if (typeof hint === "string" && hint.length > 0) aliases.add(hint);
|
|
11416
|
+
}
|
|
11417
|
+
const pcbPortId = pad.pcb_port_id;
|
|
11418
|
+
if (pcbPortId) {
|
|
11419
|
+
const pcbPort = db.pcb_port.get(pcbPortId);
|
|
11420
|
+
const sourcePort = pcbPort?.source_port_id ? db.source_port.get(pcbPort.source_port_id) : null;
|
|
11421
|
+
if (sourcePort?.name) aliases.add(sourcePort.name);
|
|
11422
|
+
if (sourcePort?.pin_number != null) {
|
|
11423
|
+
aliases.add(`pin${sourcePort.pin_number}`);
|
|
11424
|
+
}
|
|
11425
|
+
}
|
|
11426
|
+
for (const alias of aliases) {
|
|
11427
|
+
const referencePath = `${component.name}.${alias}`;
|
|
11428
|
+
if (!refsToElements.has(referencePath)) {
|
|
11429
|
+
refsToElements.set(referencePath, []);
|
|
11430
|
+
}
|
|
11431
|
+
refsToElements.get(referencePath).push(pad);
|
|
11432
|
+
}
|
|
11433
|
+
}
|
|
11434
|
+
return refsToElements;
|
|
11362
11435
|
}
|
|
11363
11436
|
|
|
11364
11437
|
// lib/components/primitive-components/Group/Group_doInitialPcbComponentAnchorAlignment.ts
|
|
@@ -12351,7 +12424,7 @@ import { identity as identity4 } from "transformation-matrix";
|
|
|
12351
12424
|
var package_default = {
|
|
12352
12425
|
name: "@tscircuit/core",
|
|
12353
12426
|
type: "module",
|
|
12354
|
-
version: "0.0.
|
|
12427
|
+
version: "0.0.1029",
|
|
12355
12428
|
types: "dist/index.d.ts",
|
|
12356
12429
|
main: "dist/index.js",
|
|
12357
12430
|
module: "dist/index.js",
|