@tscircuit/core 0.0.589 → 0.0.591

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 CHANGED
@@ -271,6 +271,7 @@ interface ISubcircuit extends PrimitiveComponent {
271
271
  _shouldUseTraceByTraceRouting(): boolean;
272
272
  _parsedProps: z.infer<typeof subcircuitGroupProps>;
273
273
  _getAutorouterConfig(): AutorouterConfig;
274
+ getNextAvailableName(elm: PrimitiveComponent): string;
274
275
  _getSubcircuitLayerCount(): number;
275
276
  subcircuit_id: string | null;
276
277
  }
@@ -1053,6 +1054,8 @@ declare class Group<Props extends z.ZodType<any, any, any> = typeof groupProps>
1053
1054
  doInitialSourceParentAttachment(): void;
1054
1055
  doInitialPcbComponentRender(): void;
1055
1056
  doInitialPcbPrimitiveRender(): void;
1057
+ unnamedElementCounter: Record<string, number>;
1058
+ getNextAvailableName(elm: PrimitiveComponent): string;
1056
1059
  _resolvePcbPadding(): {
1057
1060
  padLeft: number;
1058
1061
  padRight: number;
package/dist/index.js CHANGED
@@ -977,7 +977,7 @@ var PrimitiveComponent2 = class extends Renderable {
977
977
  }
978
978
  doInitialAssignNameToUnnamedComponents() {
979
979
  if (!this._parsedProps.name) {
980
- this.fallbackUnassignedName = `UNNAMED_${this.getSubcircuit().subcircuit_id}`;
980
+ this.fallbackUnassignedName = this.getSubcircuit().getNextAvailableName(this);
981
981
  }
982
982
  }
983
983
  doInitialOptimizeSelectorCache() {
@@ -7826,7 +7826,7 @@ function Group_doInitialSchematicLayoutGrid(group) {
7826
7826
  if (props.schLayout?.grid) {
7827
7827
  gridColsOption = props.schLayout.grid.cols ?? gridColsOption;
7828
7828
  gridRowsOption = props.schLayout.grid.rows;
7829
- gridGapOption = props.schLayout.grid.gap ?? gridGapOption;
7829
+ gridGapOption = props.schLayout.gridGap ?? gridGapOption;
7830
7830
  }
7831
7831
  let numCols;
7832
7832
  let numRows;
@@ -7939,10 +7939,15 @@ function Group_doInitialPcbLayoutGrid(group) {
7939
7939
  let maxCellHeight = 0;
7940
7940
  for (const child of pcbChildren) {
7941
7941
  const pcbComp = db.pcb_component.get(child.pcb_component_id);
7942
- if (pcbComp) {
7943
- maxCellWidth = Math.max(maxCellWidth, pcbComp.width);
7944
- maxCellHeight = Math.max(maxCellHeight, pcbComp.height);
7942
+ let width = pcbComp?.width ?? 0;
7943
+ let height = pcbComp?.height ?? 0;
7944
+ if (width === 0 || height === 0) {
7945
+ const bounds = getBoundsOfPcbComponents(child.children);
7946
+ width = Math.max(width, bounds.width);
7947
+ height = Math.max(height, bounds.height);
7945
7948
  }
7949
+ maxCellWidth = Math.max(maxCellWidth, width);
7950
+ maxCellHeight = Math.max(maxCellHeight, height);
7946
7951
  }
7947
7952
  if (maxCellWidth === 0 && pcbChildren.length > 0) maxCellWidth = 1;
7948
7953
  if (maxCellHeight === 0 && pcbChildren.length > 0) maxCellHeight = 1;
@@ -7952,7 +7957,7 @@ function Group_doInitialPcbLayoutGrid(group) {
7952
7957
  if (props.pcbLayout?.grid) {
7953
7958
  gridColsOption = props.pcbLayout.grid.cols ?? gridColsOption;
7954
7959
  gridRowsOption = props.pcbLayout.grid.rows;
7955
- gridGapOption = props.pcbLayout.grid.gap ?? gridGapOption;
7960
+ gridGapOption = props.pcbLayout.gridGap ?? gridGapOption;
7956
7961
  }
7957
7962
  let numCols;
7958
7963
  let numRows;
@@ -8087,7 +8092,7 @@ function getPresetAutoroutingConfig(autorouterConfig) {
8087
8092
  }
8088
8093
 
8089
8094
  // lib/components/primitive-components/Group/Group_doInitialPcbLayoutPack.ts
8090
- import { buildSubtree as buildSubtree2 } from "@tscircuit/circuit-json-util";
8095
+ import "@tscircuit/circuit-json-util";
8091
8096
  import {
8092
8097
  pack,
8093
8098
  convertCircuitJsonToPackOutput,
@@ -8095,7 +8100,9 @@ import {
8095
8100
  getGraphicsFromPackOutput
8096
8101
  } from "calculate-packing";
8097
8102
  import { length as length3 } from "circuit-json";
8098
- import { transformPCBElements as transformPCBElements2 } from "@tscircuit/circuit-json-util";
8103
+ import {
8104
+ transformPCBElements as transformPCBElements2
8105
+ } from "@tscircuit/circuit-json-util";
8099
8106
  import { translate as translate6, rotate as rotate2, compose as compose4 } from "transformation-matrix";
8100
8107
  import Debug6 from "debug";
8101
8108
  var debug5 = Debug6("Group_doInitialPcbLayoutPack");
@@ -8103,13 +8110,12 @@ var Group_doInitialPcbLayoutPack = (group) => {
8103
8110
  const { db } = group.root;
8104
8111
  const { _parsedProps: props } = group;
8105
8112
  const { packOrderStrategy, packPlacementStrategy, gap } = props;
8106
- const subtreeCircuitJson = buildSubtree2(db.toArray(), {
8107
- source_group_id: group.source_group_id
8108
- });
8109
8113
  const gapMm = length3.parse(gap ?? "0mm");
8110
8114
  const packInput = {
8111
8115
  ...convertPackOutputToPackInput(
8112
- convertCircuitJsonToPackOutput(subtreeCircuitJson)
8116
+ convertCircuitJsonToPackOutput(db.toArray(), {
8117
+ source_group_id: group.source_group_id
8118
+ })
8113
8119
  ),
8114
8120
  orderStrategy: packOrderStrategy ?? "largest_to_smallest",
8115
8121
  placementStrategy: packPlacementStrategy ?? "shortest_connection_along_outline",
@@ -8118,21 +8124,22 @@ var Group_doInitialPcbLayoutPack = (group) => {
8118
8124
  const packOutput = pack(packInput);
8119
8125
  if (debug5.enabled) {
8120
8126
  const graphics = getGraphicsFromPackOutput(packOutput);
8121
- graphics.title = "packOutput";
8127
+ graphics.title = `packOutput-${group.name}`;
8122
8128
  global.debugGraphics?.push(graphics);
8123
8129
  }
8124
8130
  for (const packedComponent of packOutput.components) {
8125
8131
  const { center, componentId, ccwRotationOffset } = packedComponent;
8126
- const component = db.pcb_component.get(componentId);
8127
- if (!component) continue;
8128
- const originalCenter = component.center;
8132
+ const pcbComponent = db.pcb_component.get(componentId);
8133
+ if (!pcbComponent) continue;
8134
+ const originalCenter = pcbComponent.center;
8129
8135
  const transformMatrix = compose4(
8136
+ group._computePcbGlobalTransformBeforeLayout(),
8130
8137
  translate6(center.x, center.y),
8131
8138
  rotate2(ccwRotationOffset || 0),
8132
8139
  translate6(-originalCenter.x, -originalCenter.y)
8133
8140
  );
8134
8141
  transformPCBElements2(
8135
- subtreeCircuitJson.filter(
8142
+ db.toArray().filter(
8136
8143
  (elm) => "pcb_component_id" in elm && elm.pcb_component_id === componentId
8137
8144
  ),
8138
8145
  transformMatrix
@@ -8275,6 +8282,11 @@ var Group = class extends NormalComponent {
8275
8282
  });
8276
8283
  }
8277
8284
  }
8285
+ unnamedElementCounter = {};
8286
+ getNextAvailableName(elm) {
8287
+ this.unnamedElementCounter[elm.lowercaseComponentName] ??= 1;
8288
+ return `unnamed_${elm.lowercaseComponentName}${this.unnamedElementCounter[elm.lowercaseComponentName]++}`;
8289
+ }
8278
8290
  _resolvePcbPadding() {
8279
8291
  const props = this._parsedProps;
8280
8292
  const layout = props.pcbLayout;
@@ -11195,7 +11207,7 @@ import { identity as identity5 } from "transformation-matrix";
11195
11207
  var package_default = {
11196
11208
  name: "@tscircuit/core",
11197
11209
  type: "module",
11198
- version: "0.0.588",
11210
+ version: "0.0.590",
11199
11211
  types: "dist/index.d.ts",
11200
11212
  main: "dist/index.js",
11201
11213
  module: "dist/index.js",
@@ -11221,7 +11233,7 @@ var package_default = {
11221
11233
  "@tscircuit/capacity-autorouter": "^0.0.100",
11222
11234
  "@tscircuit/checks": "^0.0.56",
11223
11235
  "@tscircuit/circuit-json-flex": "^0.0.1",
11224
- "@tscircuit/circuit-json-util": "^0.0.57",
11236
+ "@tscircuit/circuit-json-util": "^0.0.59",
11225
11237
  "@tscircuit/footprinter": "^0.0.204",
11226
11238
  "@tscircuit/import-snippet": "^0.0.4",
11227
11239
  "@tscircuit/infgrid-ijump-astar": "^0.0.33",
@@ -11281,7 +11293,7 @@ var package_default = {
11281
11293
  dependencies: {
11282
11294
  "@flatten-js/core": "^1.6.2",
11283
11295
  "@lume/kiwi": "^0.4.3",
11284
- "calculate-packing": "0.0.7",
11296
+ "calculate-packing": "0.0.9",
11285
11297
  "css-select": "5.1.0",
11286
11298
  "format-si-unit": "^0.0.3",
11287
11299
  nanoid: "^5.0.7",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.589",
4
+ "version": "0.0.591",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -27,7 +27,7 @@
27
27
  "@tscircuit/capacity-autorouter": "^0.0.100",
28
28
  "@tscircuit/checks": "^0.0.56",
29
29
  "@tscircuit/circuit-json-flex": "^0.0.1",
30
- "@tscircuit/circuit-json-util": "^0.0.57",
30
+ "@tscircuit/circuit-json-util": "^0.0.59",
31
31
  "@tscircuit/footprinter": "^0.0.204",
32
32
  "@tscircuit/import-snippet": "^0.0.4",
33
33
  "@tscircuit/infgrid-ijump-astar": "^0.0.33",
@@ -87,7 +87,7 @@
87
87
  "dependencies": {
88
88
  "@flatten-js/core": "^1.6.2",
89
89
  "@lume/kiwi": "^0.4.3",
90
- "calculate-packing": "0.0.7",
90
+ "calculate-packing": "0.0.9",
91
91
  "css-select": "5.1.0",
92
92
  "format-si-unit": "^0.0.3",
93
93
  "nanoid": "^5.0.7",