@tscircuit/core 0.0.439 → 0.0.441
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 +3 -0
- package/dist/index.js +138 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1056,6 +1056,9 @@ declare class Group<Props extends z.ZodType<any, any, any> = typeof groupProps>
|
|
|
1056
1056
|
doInitialSchematicLayout(): void;
|
|
1057
1057
|
_doInitialSchematicLayoutMatchAdapt(): void;
|
|
1058
1058
|
_doInitialSchematicLayoutGrid(): void;
|
|
1059
|
+
_getPcbLayoutMode(): "grid" | "flex" | "match-adapt" | "none";
|
|
1060
|
+
doInitialPcbLayout(): void;
|
|
1061
|
+
_doInitialPcbLayoutGrid(): void;
|
|
1059
1062
|
_determineSideFromPosition(port: SchematicPort, component: SchematicComponent): "left" | "right" | "top" | "bottom";
|
|
1060
1063
|
_calculateSchematicBounds(boxes: Array<{
|
|
1061
1064
|
centerX: number;
|
package/dist/index.js
CHANGED
|
@@ -476,7 +476,13 @@ var cssSelectPrimitiveComponentAdapterOnlySubcircuits = {
|
|
|
476
476
|
|
|
477
477
|
// lib/components/base-components/PrimitiveComponent/preprocessSelector.ts
|
|
478
478
|
var preprocessSelector = (selector) => {
|
|
479
|
-
return selector.replace(/ pin/g, " port").replace(/ subcircuit\./g, " group[isSubcircuit=true]").replace(/([^ ])\>([^ ])/g, "$1 > $2").
|
|
479
|
+
return selector.replace(/ pin/g, " port").replace(/ subcircuit\./g, " group[isSubcircuit=true]").replace(/([^ ])\>([^ ])/g, "$1 > $2").replace(
|
|
480
|
+
/(^|[ >])(?!pin\.)(?!port\.)(?!net\.)([A-Z][A-Za-z0-9_-]*)\.([A-Za-z0-9_-]+)/g,
|
|
481
|
+
(_, sep, name, pin) => {
|
|
482
|
+
const pinPart = /^\d+$/.test(pin) ? `pin${pin}` : pin;
|
|
483
|
+
return `${sep}.${name} > .${pinPart}`;
|
|
484
|
+
}
|
|
485
|
+
).trim();
|
|
480
486
|
};
|
|
481
487
|
|
|
482
488
|
// lib/components/base-components/PrimitiveComponent/PrimitiveComponent.ts
|
|
@@ -6991,6 +6997,117 @@ function Group_doInitialSchematicLayoutGrid(group) {
|
|
|
6991
6997
|
}
|
|
6992
6998
|
}
|
|
6993
6999
|
|
|
7000
|
+
// lib/components/primitive-components/Group/Group_doInitialPcbLayoutGrid.ts
|
|
7001
|
+
import { translate as translate5 } from "transformation-matrix";
|
|
7002
|
+
import {
|
|
7003
|
+
transformPCBElements,
|
|
7004
|
+
getPrimaryId
|
|
7005
|
+
} from "@tscircuit/circuit-json-util";
|
|
7006
|
+
function Group_doInitialPcbLayoutGrid(group) {
|
|
7007
|
+
const { db } = group.root;
|
|
7008
|
+
const props = group._parsedProps;
|
|
7009
|
+
const pcbChildren = group.children.filter(
|
|
7010
|
+
(child) => child.pcb_component_id
|
|
7011
|
+
);
|
|
7012
|
+
if (pcbChildren.length === 0) return;
|
|
7013
|
+
let maxCellWidth = 0;
|
|
7014
|
+
let maxCellHeight = 0;
|
|
7015
|
+
for (const child of pcbChildren) {
|
|
7016
|
+
const pcbComp = db.pcb_component.get(child.pcb_component_id);
|
|
7017
|
+
if (pcbComp) {
|
|
7018
|
+
maxCellWidth = Math.max(maxCellWidth, pcbComp.width);
|
|
7019
|
+
maxCellHeight = Math.max(maxCellHeight, pcbComp.height);
|
|
7020
|
+
}
|
|
7021
|
+
}
|
|
7022
|
+
if (maxCellWidth === 0 && pcbChildren.length > 0) maxCellWidth = 1;
|
|
7023
|
+
if (maxCellHeight === 0 && pcbChildren.length > 0) maxCellHeight = 1;
|
|
7024
|
+
let gridColsOption = props.gridCols;
|
|
7025
|
+
let gridRowsOption = void 0;
|
|
7026
|
+
let gridGapOption = props.gridGap;
|
|
7027
|
+
if (props.pcbLayout?.grid) {
|
|
7028
|
+
gridColsOption = props.pcbLayout.grid.cols ?? gridColsOption;
|
|
7029
|
+
gridRowsOption = props.pcbLayout.grid.rows;
|
|
7030
|
+
gridGapOption = props.pcbLayout.grid.gap ?? gridGapOption;
|
|
7031
|
+
}
|
|
7032
|
+
let numCols;
|
|
7033
|
+
let numRows;
|
|
7034
|
+
if (gridColsOption !== void 0 && gridRowsOption !== void 0) {
|
|
7035
|
+
numCols = gridColsOption;
|
|
7036
|
+
numRows = gridRowsOption;
|
|
7037
|
+
} else if (gridColsOption !== void 0) {
|
|
7038
|
+
numCols = gridColsOption;
|
|
7039
|
+
numRows = Math.ceil(pcbChildren.length / numCols);
|
|
7040
|
+
} else if (gridRowsOption !== void 0) {
|
|
7041
|
+
numRows = gridRowsOption;
|
|
7042
|
+
numCols = Math.ceil(pcbChildren.length / numRows);
|
|
7043
|
+
} else {
|
|
7044
|
+
numCols = Math.ceil(Math.sqrt(pcbChildren.length));
|
|
7045
|
+
numRows = Math.ceil(pcbChildren.length / numCols);
|
|
7046
|
+
}
|
|
7047
|
+
if (numCols === 0 && pcbChildren.length > 0) numCols = 1;
|
|
7048
|
+
if (numRows === 0 && pcbChildren.length > 0) numRows = pcbChildren.length;
|
|
7049
|
+
let gridGapX;
|
|
7050
|
+
let gridGapY;
|
|
7051
|
+
if (typeof gridGapOption === "number") {
|
|
7052
|
+
gridGapX = gridGapOption;
|
|
7053
|
+
gridGapY = gridGapOption;
|
|
7054
|
+
} else if (typeof gridGapOption === "object" && gridGapOption !== null) {
|
|
7055
|
+
gridGapX = gridGapOption.x;
|
|
7056
|
+
gridGapY = gridGapOption.y;
|
|
7057
|
+
} else {
|
|
7058
|
+
gridGapX = 1;
|
|
7059
|
+
gridGapY = 1;
|
|
7060
|
+
}
|
|
7061
|
+
const totalGridWidth = numCols * maxCellWidth + Math.max(0, numCols - 1) * gridGapX;
|
|
7062
|
+
const totalGridHeight = numRows * maxCellHeight + Math.max(0, numRows - 1) * gridGapY;
|
|
7063
|
+
const groupCenter = group._getGlobalPcbPositionBeforeLayout();
|
|
7064
|
+
const firstCellCenterX = groupCenter.x - totalGridWidth / 2 + maxCellWidth / 2;
|
|
7065
|
+
const firstCellCenterY = groupCenter.y + totalGridHeight / 2 - maxCellHeight / 2;
|
|
7066
|
+
for (let i = 0; i < pcbChildren.length; i++) {
|
|
7067
|
+
const child = pcbChildren[i];
|
|
7068
|
+
if (!child.pcb_component_id) continue;
|
|
7069
|
+
const row = Math.floor(i / numCols);
|
|
7070
|
+
const col = i % numCols;
|
|
7071
|
+
if (row >= numRows || col >= numCols) {
|
|
7072
|
+
console.warn(
|
|
7073
|
+
`PCB grid layout: Child ${child.getString()} at index ${i} (row ${row}, col ${col}) exceeds grid dimensions (${numRows}x${numCols}). Skipping placement.`
|
|
7074
|
+
);
|
|
7075
|
+
continue;
|
|
7076
|
+
}
|
|
7077
|
+
const targetCellCenterX = firstCellCenterX + col * (maxCellWidth + gridGapX);
|
|
7078
|
+
const targetCellCenterY = firstCellCenterY - row * (maxCellHeight + gridGapY);
|
|
7079
|
+
const pcbComp = db.pcb_component.get(child.pcb_component_id);
|
|
7080
|
+
if (pcbComp) {
|
|
7081
|
+
const oldCenter = pcbComp.center;
|
|
7082
|
+
const newCenter = { x: targetCellCenterX, y: targetCellCenterY };
|
|
7083
|
+
const deltaX = newCenter.x - oldCenter.x;
|
|
7084
|
+
const deltaY = newCenter.y - oldCenter.y;
|
|
7085
|
+
const mat = translate5(deltaX, deltaY);
|
|
7086
|
+
const related = db.toArray().filter((e) => e.pcb_component_id === child.pcb_component_id);
|
|
7087
|
+
const moved = transformPCBElements(related, mat);
|
|
7088
|
+
for (const elm of moved) {
|
|
7089
|
+
const idProp = getPrimaryId(elm);
|
|
7090
|
+
db[elm.type].update(elm[idProp], elm);
|
|
7091
|
+
}
|
|
7092
|
+
db.pcb_component.update(child.pcb_component_id, {
|
|
7093
|
+
center: newCenter
|
|
7094
|
+
});
|
|
7095
|
+
child.setProps({
|
|
7096
|
+
...child.props,
|
|
7097
|
+
pcbX: (child.props.pcbX ?? 0) + deltaX,
|
|
7098
|
+
pcbY: (child.props.pcbY ?? 0) + deltaY
|
|
7099
|
+
});
|
|
7100
|
+
}
|
|
7101
|
+
}
|
|
7102
|
+
if (group.pcb_group_id) {
|
|
7103
|
+
db.pcb_group.update(group.pcb_group_id, {
|
|
7104
|
+
width: totalGridWidth,
|
|
7105
|
+
height: totalGridHeight,
|
|
7106
|
+
center: groupCenter
|
|
7107
|
+
});
|
|
7108
|
+
}
|
|
7109
|
+
}
|
|
7110
|
+
|
|
6994
7111
|
// lib/components/primitive-components/Group/Group.ts
|
|
6995
7112
|
var Group = class extends NormalComponent {
|
|
6996
7113
|
pcb_group_id = null;
|
|
@@ -7462,6 +7579,25 @@ var Group = class extends NormalComponent {
|
|
|
7462
7579
|
_doInitialSchematicLayoutGrid() {
|
|
7463
7580
|
Group_doInitialSchematicLayoutGrid(this);
|
|
7464
7581
|
}
|
|
7582
|
+
_getPcbLayoutMode() {
|
|
7583
|
+
const props = this._parsedProps;
|
|
7584
|
+
if (props.pcbLayout?.matchAdapt) return "match-adapt";
|
|
7585
|
+
if (props.pcbLayout?.flex) return "flex";
|
|
7586
|
+
if (props.pcbLayout?.grid) return "grid";
|
|
7587
|
+
if (props.matchAdapt) return "match-adapt";
|
|
7588
|
+
if (props.flex) return "flex";
|
|
7589
|
+
if (props.grid) return "grid";
|
|
7590
|
+
return "none";
|
|
7591
|
+
}
|
|
7592
|
+
doInitialPcbLayout() {
|
|
7593
|
+
const pcbLayoutMode = this._getPcbLayoutMode();
|
|
7594
|
+
if (pcbLayoutMode === "grid") {
|
|
7595
|
+
this._doInitialPcbLayoutGrid();
|
|
7596
|
+
}
|
|
7597
|
+
}
|
|
7598
|
+
_doInitialPcbLayoutGrid() {
|
|
7599
|
+
Group_doInitialPcbLayoutGrid(this);
|
|
7600
|
+
}
|
|
7465
7601
|
_determineSideFromPosition(port, component) {
|
|
7466
7602
|
if (!port.center || !component.center) return "left";
|
|
7467
7603
|
const dx = port.center.x - component.center.x;
|
|
@@ -9251,7 +9387,7 @@ import { identity as identity4 } from "transformation-matrix";
|
|
|
9251
9387
|
var package_default = {
|
|
9252
9388
|
name: "@tscircuit/core",
|
|
9253
9389
|
type: "module",
|
|
9254
|
-
version: "0.0.
|
|
9390
|
+
version: "0.0.440",
|
|
9255
9391
|
types: "dist/index.d.ts",
|
|
9256
9392
|
main: "dist/index.js",
|
|
9257
9393
|
module: "dist/index.js",
|