@tscircuit/core 0.0.439 → 0.0.440
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 +131 -1
- 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
|
@@ -6991,6 +6991,117 @@ function Group_doInitialSchematicLayoutGrid(group) {
|
|
|
6991
6991
|
}
|
|
6992
6992
|
}
|
|
6993
6993
|
|
|
6994
|
+
// lib/components/primitive-components/Group/Group_doInitialPcbLayoutGrid.ts
|
|
6995
|
+
import { translate as translate5 } from "transformation-matrix";
|
|
6996
|
+
import {
|
|
6997
|
+
transformPCBElements,
|
|
6998
|
+
getPrimaryId
|
|
6999
|
+
} from "@tscircuit/circuit-json-util";
|
|
7000
|
+
function Group_doInitialPcbLayoutGrid(group) {
|
|
7001
|
+
const { db } = group.root;
|
|
7002
|
+
const props = group._parsedProps;
|
|
7003
|
+
const pcbChildren = group.children.filter(
|
|
7004
|
+
(child) => child.pcb_component_id
|
|
7005
|
+
);
|
|
7006
|
+
if (pcbChildren.length === 0) return;
|
|
7007
|
+
let maxCellWidth = 0;
|
|
7008
|
+
let maxCellHeight = 0;
|
|
7009
|
+
for (const child of pcbChildren) {
|
|
7010
|
+
const pcbComp = db.pcb_component.get(child.pcb_component_id);
|
|
7011
|
+
if (pcbComp) {
|
|
7012
|
+
maxCellWidth = Math.max(maxCellWidth, pcbComp.width);
|
|
7013
|
+
maxCellHeight = Math.max(maxCellHeight, pcbComp.height);
|
|
7014
|
+
}
|
|
7015
|
+
}
|
|
7016
|
+
if (maxCellWidth === 0 && pcbChildren.length > 0) maxCellWidth = 1;
|
|
7017
|
+
if (maxCellHeight === 0 && pcbChildren.length > 0) maxCellHeight = 1;
|
|
7018
|
+
let gridColsOption = props.gridCols;
|
|
7019
|
+
let gridRowsOption = void 0;
|
|
7020
|
+
let gridGapOption = props.gridGap;
|
|
7021
|
+
if (props.pcbLayout?.grid) {
|
|
7022
|
+
gridColsOption = props.pcbLayout.grid.cols ?? gridColsOption;
|
|
7023
|
+
gridRowsOption = props.pcbLayout.grid.rows;
|
|
7024
|
+
gridGapOption = props.pcbLayout.grid.gap ?? gridGapOption;
|
|
7025
|
+
}
|
|
7026
|
+
let numCols;
|
|
7027
|
+
let numRows;
|
|
7028
|
+
if (gridColsOption !== void 0 && gridRowsOption !== void 0) {
|
|
7029
|
+
numCols = gridColsOption;
|
|
7030
|
+
numRows = gridRowsOption;
|
|
7031
|
+
} else if (gridColsOption !== void 0) {
|
|
7032
|
+
numCols = gridColsOption;
|
|
7033
|
+
numRows = Math.ceil(pcbChildren.length / numCols);
|
|
7034
|
+
} else if (gridRowsOption !== void 0) {
|
|
7035
|
+
numRows = gridRowsOption;
|
|
7036
|
+
numCols = Math.ceil(pcbChildren.length / numRows);
|
|
7037
|
+
} else {
|
|
7038
|
+
numCols = Math.ceil(Math.sqrt(pcbChildren.length));
|
|
7039
|
+
numRows = Math.ceil(pcbChildren.length / numCols);
|
|
7040
|
+
}
|
|
7041
|
+
if (numCols === 0 && pcbChildren.length > 0) numCols = 1;
|
|
7042
|
+
if (numRows === 0 && pcbChildren.length > 0) numRows = pcbChildren.length;
|
|
7043
|
+
let gridGapX;
|
|
7044
|
+
let gridGapY;
|
|
7045
|
+
if (typeof gridGapOption === "number") {
|
|
7046
|
+
gridGapX = gridGapOption;
|
|
7047
|
+
gridGapY = gridGapOption;
|
|
7048
|
+
} else if (typeof gridGapOption === "object" && gridGapOption !== null) {
|
|
7049
|
+
gridGapX = gridGapOption.x;
|
|
7050
|
+
gridGapY = gridGapOption.y;
|
|
7051
|
+
} else {
|
|
7052
|
+
gridGapX = 1;
|
|
7053
|
+
gridGapY = 1;
|
|
7054
|
+
}
|
|
7055
|
+
const totalGridWidth = numCols * maxCellWidth + Math.max(0, numCols - 1) * gridGapX;
|
|
7056
|
+
const totalGridHeight = numRows * maxCellHeight + Math.max(0, numRows - 1) * gridGapY;
|
|
7057
|
+
const groupCenter = group._getGlobalPcbPositionBeforeLayout();
|
|
7058
|
+
const firstCellCenterX = groupCenter.x - totalGridWidth / 2 + maxCellWidth / 2;
|
|
7059
|
+
const firstCellCenterY = groupCenter.y + totalGridHeight / 2 - maxCellHeight / 2;
|
|
7060
|
+
for (let i = 0; i < pcbChildren.length; i++) {
|
|
7061
|
+
const child = pcbChildren[i];
|
|
7062
|
+
if (!child.pcb_component_id) continue;
|
|
7063
|
+
const row = Math.floor(i / numCols);
|
|
7064
|
+
const col = i % numCols;
|
|
7065
|
+
if (row >= numRows || col >= numCols) {
|
|
7066
|
+
console.warn(
|
|
7067
|
+
`PCB grid layout: Child ${child.getString()} at index ${i} (row ${row}, col ${col}) exceeds grid dimensions (${numRows}x${numCols}). Skipping placement.`
|
|
7068
|
+
);
|
|
7069
|
+
continue;
|
|
7070
|
+
}
|
|
7071
|
+
const targetCellCenterX = firstCellCenterX + col * (maxCellWidth + gridGapX);
|
|
7072
|
+
const targetCellCenterY = firstCellCenterY - row * (maxCellHeight + gridGapY);
|
|
7073
|
+
const pcbComp = db.pcb_component.get(child.pcb_component_id);
|
|
7074
|
+
if (pcbComp) {
|
|
7075
|
+
const oldCenter = pcbComp.center;
|
|
7076
|
+
const newCenter = { x: targetCellCenterX, y: targetCellCenterY };
|
|
7077
|
+
const deltaX = newCenter.x - oldCenter.x;
|
|
7078
|
+
const deltaY = newCenter.y - oldCenter.y;
|
|
7079
|
+
const mat = translate5(deltaX, deltaY);
|
|
7080
|
+
const related = db.toArray().filter((e) => e.pcb_component_id === child.pcb_component_id);
|
|
7081
|
+
const moved = transformPCBElements(related, mat);
|
|
7082
|
+
for (const elm of moved) {
|
|
7083
|
+
const idProp = getPrimaryId(elm);
|
|
7084
|
+
db[elm.type].update(elm[idProp], elm);
|
|
7085
|
+
}
|
|
7086
|
+
db.pcb_component.update(child.pcb_component_id, {
|
|
7087
|
+
center: newCenter
|
|
7088
|
+
});
|
|
7089
|
+
child.setProps({
|
|
7090
|
+
...child.props,
|
|
7091
|
+
pcbX: (child.props.pcbX ?? 0) + deltaX,
|
|
7092
|
+
pcbY: (child.props.pcbY ?? 0) + deltaY
|
|
7093
|
+
});
|
|
7094
|
+
}
|
|
7095
|
+
}
|
|
7096
|
+
if (group.pcb_group_id) {
|
|
7097
|
+
db.pcb_group.update(group.pcb_group_id, {
|
|
7098
|
+
width: totalGridWidth,
|
|
7099
|
+
height: totalGridHeight,
|
|
7100
|
+
center: groupCenter
|
|
7101
|
+
});
|
|
7102
|
+
}
|
|
7103
|
+
}
|
|
7104
|
+
|
|
6994
7105
|
// lib/components/primitive-components/Group/Group.ts
|
|
6995
7106
|
var Group = class extends NormalComponent {
|
|
6996
7107
|
pcb_group_id = null;
|
|
@@ -7462,6 +7573,25 @@ var Group = class extends NormalComponent {
|
|
|
7462
7573
|
_doInitialSchematicLayoutGrid() {
|
|
7463
7574
|
Group_doInitialSchematicLayoutGrid(this);
|
|
7464
7575
|
}
|
|
7576
|
+
_getPcbLayoutMode() {
|
|
7577
|
+
const props = this._parsedProps;
|
|
7578
|
+
if (props.pcbLayout?.matchAdapt) return "match-adapt";
|
|
7579
|
+
if (props.pcbLayout?.flex) return "flex";
|
|
7580
|
+
if (props.pcbLayout?.grid) return "grid";
|
|
7581
|
+
if (props.matchAdapt) return "match-adapt";
|
|
7582
|
+
if (props.flex) return "flex";
|
|
7583
|
+
if (props.grid) return "grid";
|
|
7584
|
+
return "none";
|
|
7585
|
+
}
|
|
7586
|
+
doInitialPcbLayout() {
|
|
7587
|
+
const pcbLayoutMode = this._getPcbLayoutMode();
|
|
7588
|
+
if (pcbLayoutMode === "grid") {
|
|
7589
|
+
this._doInitialPcbLayoutGrid();
|
|
7590
|
+
}
|
|
7591
|
+
}
|
|
7592
|
+
_doInitialPcbLayoutGrid() {
|
|
7593
|
+
Group_doInitialPcbLayoutGrid(this);
|
|
7594
|
+
}
|
|
7465
7595
|
_determineSideFromPosition(port, component) {
|
|
7466
7596
|
if (!port.center || !component.center) return "left";
|
|
7467
7597
|
const dx = port.center.x - component.center.x;
|
|
@@ -9251,7 +9381,7 @@ import { identity as identity4 } from "transformation-matrix";
|
|
|
9251
9381
|
var package_default = {
|
|
9252
9382
|
name: "@tscircuit/core",
|
|
9253
9383
|
type: "module",
|
|
9254
|
-
version: "0.0.
|
|
9384
|
+
version: "0.0.439",
|
|
9255
9385
|
types: "dist/index.d.ts",
|
|
9256
9386
|
main: "dist/index.js",
|
|
9257
9387
|
module: "dist/index.js",
|