@tscircuit/core 0.0.657 → 0.0.659

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
@@ -1,3 +1,5 @@
1
+ import * as circuit_json from 'circuit-json';
2
+ import { PcbTraceError, PcbPlacementError, PcbManualEditConflictWarning, LayerRef, AnyCircuitElement, Size, AnySourceComponent, PcbTraceRoutePoint, PcbTrace as PcbTrace$1, PcbVia, SchematicPort, SchematicComponent, RouteHintPoint, CircuitJson } from 'circuit-json';
1
3
  import * as _tscircuit_props from '@tscircuit/props';
2
4
  import { PlatformConfig, subcircuitGroupProps, AutorouterConfig, traceProps, SupplierPartNumbers, SchematicPortArrangement, groupProps, boardProps, capacitorProps, chipProps, diodeProps, fuseProps, jumperProps, solderjumperProps, ledProps, powerSourceProps, CommonComponentProps, resistorProps, constraintProps, fabricationNotePathProps, fabricationNoteTextProps, footprintProps, subcircuitProps, breakoutProps, breakoutPointProps, holeProps, pcbKeepoutProps, netLabelProps, platedHoleProps, silkscreenCircleProps, silkscreenPathProps, silkscreenRectProps, silkscreenTextProps, silkscreenLineProps, smtPadProps, traceHintProps, viaProps, cutoutProps, batteryProps, pinHeaderProps, resonatorProps, inductorProps, potentiometerProps, pushButtonProps, crystalProps, transistorProps, mosfetProps, switchProps, testpointProps, schematicTextProps, schematicBoxProps, schematicTableProps, schematicRowProps, schematicCellProps, CapacitorProps, ChipProps, DiodeProps, ResistorProps, ManualEditEvent, ManualEditsFile, ChipConnections, manual_edits_file } from '@tscircuit/props';
3
5
  import React, { ReactElement, DetailedHTMLProps, SVGProps } from 'react';
@@ -5,7 +7,6 @@ export { createElement } from 'react';
5
7
  import * as zod from 'zod';
6
8
  import { z, ZodType } from 'zod';
7
9
  import { symbols, SchSymbol, BaseSymbolName } from 'schematic-symbols';
8
- import { PcbTraceError, PcbPlacementError, PcbManualEditConflictWarning, LayerRef, AnyCircuitElement, AnySourceComponent, PcbTraceRoutePoint, PcbTrace as PcbTrace$1, PcbVia, SchematicPort, SchematicComponent, RouteHintPoint, CircuitJson } from 'circuit-json';
9
10
  import { Matrix } from 'transformation-matrix';
10
11
  import { CircuitJsonUtilObjects } from '@tscircuit/circuit-json-util';
11
12
  import { ConnectivityMap } from 'circuit-json-to-connectivity-map';
@@ -281,6 +282,15 @@ interface IGroup extends PrimitiveComponent {
281
282
  source_group_id: string | null;
282
283
  pcb_group_id: string | null;
283
284
  _getSchematicLayoutMode(): "match-adapt" | "flex" | "grid" | "relative";
285
+ _getMinimumFlexContainerSize(): Size | null;
286
+ _repositionOnPcb(position: {
287
+ x: number;
288
+ y: number;
289
+ }): void;
290
+ _repositionOnSchematic(position: {
291
+ x: number;
292
+ y: number;
293
+ }): void;
284
294
  }
285
295
 
286
296
  type Ftype = Extract<AnySourceComponent, {
@@ -1094,6 +1104,17 @@ declare class NormalComponent<ZodProps extends z.ZodType = any, PortNames extend
1094
1104
  doInitialAssignFallbackProps(): void;
1095
1105
  doInitialCreateTracesFromProps(): void;
1096
1106
  _createTracesFromConnectionsProp(): void;
1107
+ /**
1108
+ * Get the minimum flex container size for this component on PCB
1109
+ */
1110
+ _getMinimumFlexContainerSize(): circuit_json.Size | null;
1111
+ /**
1112
+ * Reposition this component on the PCB to the specified coordinates
1113
+ */
1114
+ _repositionOnPcb(position: {
1115
+ x: number;
1116
+ y: number;
1117
+ }): void;
1097
1118
  }
1098
1119
 
1099
1120
  declare class Group<Props extends z.ZodType<any, any, any> = typeof groupProps> extends NormalComponent<Props> implements ISubcircuit {
@@ -1174,6 +1195,17 @@ declare class Group<Props extends z.ZodType<any, any, any> = typeof groupProps>
1174
1195
  _shouldUseTraceByTraceRouting(): boolean;
1175
1196
  doInitialPcbDesignRuleChecks(): void;
1176
1197
  doInitialSchematicReplaceNetLabelsWithSymbols(): void;
1198
+ /**
1199
+ * Get the minimum flex container size for this group on PCB
1200
+ */
1201
+ _getMinimumFlexContainerSize(): circuit_json.Size | null;
1202
+ /**
1203
+ * Reposition this group on the PCB to the specified coordinates
1204
+ */
1205
+ _repositionOnPcb(position: {
1206
+ x: number;
1207
+ y: number;
1208
+ }): void;
1177
1209
  }
1178
1210
 
1179
1211
  declare class Board extends Group<typeof boardProps> {
@@ -7834,9 +7866,9 @@ declare const voltageSourceProps: z.ZodObject<{
7834
7866
  relative?: boolean | undefined;
7835
7867
  layer?: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | undefined;
7836
7868
  phase?: number | undefined;
7869
+ pcbX?: number | undefined;
7837
7870
  voltage?: number | undefined;
7838
7871
  frequency?: number | undefined;
7839
- pcbX?: number | undefined;
7840
7872
  pcbY?: number | undefined;
7841
7873
  pcbRotation?: number | undefined;
7842
7874
  schX?: number | undefined;
@@ -7920,9 +7952,9 @@ declare const voltageSourceProps: z.ZodObject<{
7920
7952
  name: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
7921
7953
  } | undefined;
7922
7954
  phase?: string | number | undefined;
7955
+ pcbX?: string | number | undefined;
7923
7956
  voltage?: string | number | undefined;
7924
7957
  frequency?: string | number | undefined;
7925
- pcbX?: string | number | undefined;
7926
7958
  pcbY?: string | number | undefined;
7927
7959
  pcbRotation?: string | number | undefined;
7928
7960
  schX?: string | number | undefined;
@@ -8297,9 +8329,9 @@ declare class VoltageSource extends NormalComponent<typeof voltageSourceProps, "
8297
8329
  relative?: boolean | undefined;
8298
8330
  layer?: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | undefined;
8299
8331
  phase?: number | undefined;
8332
+ pcbX?: number | undefined;
8300
8333
  voltage?: number | undefined;
8301
8334
  frequency?: number | undefined;
8302
- pcbX?: number | undefined;
8303
8335
  pcbY?: number | undefined;
8304
8336
  pcbRotation?: number | undefined;
8305
8337
  schX?: number | undefined;
@@ -8383,9 +8415,9 @@ declare class VoltageSource extends NormalComponent<typeof voltageSourceProps, "
8383
8415
  name: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
8384
8416
  } | undefined;
8385
8417
  phase?: string | number | undefined;
8418
+ pcbX?: string | number | undefined;
8386
8419
  voltage?: string | number | undefined;
8387
8420
  frequency?: string | number | undefined;
8388
- pcbX?: string | number | undefined;
8389
8421
  pcbY?: string | number | undefined;
8390
8422
  pcbRotation?: string | number | undefined;
8391
8423
  schX?: string | number | undefined;
package/dist/index.js CHANGED
@@ -6178,6 +6178,59 @@ var Trace3 = class extends PrimitiveComponent2 {
6178
6178
  }
6179
6179
  };
6180
6180
 
6181
+ // lib/components/base-components/NormalComponent/NormalComponent__getMinimumFlexContainerSize.ts
6182
+ var NormalComponent__getMinimumFlexContainerSize = (component) => {
6183
+ const { db } = component.root;
6184
+ if (component.pcb_component_id) {
6185
+ const pcbComponent = db.pcb_component.get(component.pcb_component_id);
6186
+ if (!pcbComponent) return null;
6187
+ return {
6188
+ width: pcbComponent.width,
6189
+ height: pcbComponent.height
6190
+ };
6191
+ }
6192
+ if (component.pcb_group_id) {
6193
+ const pcbGroup = db.pcb_group.get(
6194
+ component.pcb_group_id
6195
+ );
6196
+ if (!pcbGroup) return null;
6197
+ return {
6198
+ width: pcbGroup.width,
6199
+ height: pcbGroup.height
6200
+ };
6201
+ }
6202
+ return null;
6203
+ };
6204
+
6205
+ // lib/components/base-components/NormalComponent/NormalComponent__repositionOnPcb.ts
6206
+ import {
6207
+ repositionPcbComponentTo,
6208
+ repositionPcbGroupTo
6209
+ } from "@tscircuit/circuit-json-util";
6210
+ var NormalComponent__repositionOnPcb = (component, position) => {
6211
+ const { db } = component.root;
6212
+ const allCircuitJson = db.toArray();
6213
+ if (component.pcb_component_id) {
6214
+ repositionPcbComponentTo(
6215
+ allCircuitJson,
6216
+ component.pcb_component_id,
6217
+ position
6218
+ );
6219
+ return;
6220
+ }
6221
+ if (component.source_group_id) {
6222
+ repositionPcbGroupTo(
6223
+ allCircuitJson,
6224
+ component.source_group_id,
6225
+ position
6226
+ );
6227
+ return;
6228
+ }
6229
+ throw new Error(
6230
+ `Cannot reposition component ${component.getString()}: no pcb_component_id or source_group_id`
6231
+ );
6232
+ };
6233
+
6181
6234
  // lib/components/base-components/NormalComponent/NormalComponent.ts
6182
6235
  var debug3 = Debug4("tscircuit:core");
6183
6236
  var rotation3 = z8.object({
@@ -7050,6 +7103,18 @@ var NormalComponent = class extends PrimitiveComponent2 {
7050
7103
  }
7051
7104
  }
7052
7105
  }
7106
+ /**
7107
+ * Get the minimum flex container size for this component on PCB
7108
+ */
7109
+ _getMinimumFlexContainerSize() {
7110
+ return NormalComponent__getMinimumFlexContainerSize(this);
7111
+ }
7112
+ /**
7113
+ * Reposition this component on the PCB to the specified coordinates
7114
+ */
7115
+ _repositionOnPcb(position) {
7116
+ return NormalComponent__repositionOnPcb(this, position);
7117
+ }
7053
7118
  };
7054
7119
 
7055
7120
  // lib/components/normal-components/Board.ts
@@ -8918,8 +8983,8 @@ var Group_doInitialSchematicLayoutFlex = (group) => {
8918
8983
 
8919
8984
  // lib/components/primitive-components/Group/Group_doInitialPcbLayoutGrid.ts
8920
8985
  import {
8921
- repositionPcbComponentTo,
8922
- repositionPcbGroupTo
8986
+ repositionPcbComponentTo as repositionPcbComponentTo2,
8987
+ repositionPcbGroupTo as repositionPcbGroupTo2
8923
8988
  } from "@tscircuit/circuit-json-util";
8924
8989
  import { length as length3 } from "circuit-json";
8925
8990
  import { CssGrid } from "minicssgrid";
@@ -9100,14 +9165,14 @@ function positionChildren(params) {
9100
9165
  const targetX = groupCenter.x - gridLayout.containerWidth / 2 + coordinates.x + coordinates.width / 2;
9101
9166
  const targetY = groupCenter.y + gridLayout.containerHeight / 2 - coordinates.y - coordinates.height / 2;
9102
9167
  if (child.pcb_component_id) {
9103
- repositionPcbComponentTo(allCircuitJson, child.pcb_component_id, {
9168
+ repositionPcbComponentTo2(allCircuitJson, child.pcb_component_id, {
9104
9169
  x: targetX,
9105
9170
  y: targetY
9106
9171
  });
9107
9172
  } else {
9108
9173
  const groupChild = child;
9109
9174
  if (groupChild.pcb_group_id && groupChild.source_group_id) {
9110
- repositionPcbGroupTo(allCircuitJson, groupChild.source_group_id, {
9175
+ repositionPcbGroupTo2(allCircuitJson, groupChild.source_group_id, {
9111
9176
  x: targetX,
9112
9177
  y: targetY
9113
9178
  });
@@ -9317,44 +9382,22 @@ var Group_doInitialPcbLayoutPack = (group) => {
9317
9382
  };
9318
9383
 
9319
9384
  // lib/components/primitive-components/Group/Group_doInitialPcbLayoutFlex.ts
9320
- import {
9321
- getCircuitJsonTree as getCircuitJsonTree3,
9322
- repositionPcbComponentTo as repositionPcbComponentTo2,
9323
- repositionPcbGroupTo as repositionPcbGroupTo2,
9324
- getMinimumFlexContainer as getMinimumFlexContainer2
9325
- } from "@tscircuit/circuit-json-util";
9385
+ import { getMinimumFlexContainer as getMinimumFlexContainer2 } from "@tscircuit/circuit-json-util";
9326
9386
  import { RootFlexBox as RootFlexBox2 } from "@tscircuit/miniflex";
9327
9387
  import { length as length5 } from "circuit-json";
9328
- var getSizeOfTreeNodeChild2 = (db, child) => {
9329
- const { sourceComponent, sourceGroup } = child;
9330
- if (child.nodeType === "component") {
9331
- const pcbComponent = db.pcb_component.getWhere({
9332
- source_component_id: sourceComponent?.source_component_id
9333
- });
9334
- if (!pcbComponent) return null;
9335
- return {
9336
- width: pcbComponent.width,
9337
- height: pcbComponent.height
9338
- };
9339
- }
9340
- if (child.nodeType === "group") {
9341
- const pcbGroup = db.pcb_group.getWhere({
9342
- source_group_id: sourceGroup?.source_group_id
9343
- });
9344
- if (!pcbGroup) return null;
9345
- return {
9346
- width: pcbGroup.width,
9347
- height: pcbGroup.height
9348
- };
9349
- }
9350
- return null;
9351
- };
9352
9388
  var Group_doInitialPcbLayoutFlex = (group) => {
9353
9389
  const { db } = group.root;
9354
9390
  const { _parsedProps: props } = group;
9355
- const tree = getCircuitJsonTree3(db.toArray(), {
9356
- source_group_id: group.source_group_id
9391
+ const pcbChildren = group.children.filter(
9392
+ (c) => c.pcb_component_id || c.pcb_group_id
9393
+ );
9394
+ const anyChildHasExplicitPcbPosition = pcbChildren.some((child) => {
9395
+ const childProps = child._parsedProps;
9396
+ return childProps?.pcbX !== void 0 || childProps?.pcbY !== void 0;
9357
9397
  });
9398
+ if (anyChildHasExplicitPcbPosition) {
9399
+ return;
9400
+ }
9358
9401
  const rawJustify = props.pcbJustifyContent ?? props.justifyContent;
9359
9402
  const rawAlign = props.pcbAlignItems ?? props.alignItems;
9360
9403
  const rawGap = props.pcbFlexGap ?? props.pcbGap ?? props.gap;
@@ -9402,7 +9445,7 @@ var Group_doInitialPcbLayoutFlex = (group) => {
9402
9445
  const isInline = Boolean(width === void 0 || height === void 0);
9403
9446
  if (isInline) {
9404
9447
  minFlexContainer = getMinimumFlexContainer2(
9405
- tree.childNodes.map((child) => getSizeOfTreeNodeChild2(db, child)).filter((size) => size !== null),
9448
+ pcbChildren.map((child) => child._getMinimumFlexContainerSize()).filter((size) => size !== null),
9406
9449
  {
9407
9450
  alignItems,
9408
9451
  justifyContent,
@@ -9421,8 +9464,8 @@ var Group_doInitialPcbLayoutFlex = (group) => {
9421
9464
  rowGap,
9422
9465
  columnGap
9423
9466
  });
9424
- for (const child of tree.childNodes) {
9425
- const size = getSizeOfTreeNodeChild2(db, child);
9467
+ for (const child of pcbChildren) {
9468
+ const size = child._getMinimumFlexContainerSize();
9426
9469
  flexBox.addChild({
9427
9470
  metadata: child,
9428
9471
  // TODO these should be minWidth/minHeight
@@ -9434,7 +9477,6 @@ var Group_doInitialPcbLayoutFlex = (group) => {
9434
9477
  });
9435
9478
  }
9436
9479
  flexBox.build();
9437
- const allCircuitJson = db.toArray();
9438
9480
  const bounds = {
9439
9481
  minX: Infinity,
9440
9482
  minY: Infinity,
@@ -9451,36 +9493,22 @@ var Group_doInitialPcbLayoutFlex = (group) => {
9451
9493
  }
9452
9494
  bounds.width = bounds.maxX - bounds.minX;
9453
9495
  bounds.height = bounds.maxY - bounds.minY;
9496
+ const groupCenter = group._getGlobalPcbPositionBeforeLayout();
9454
9497
  const offset = {
9455
- x: -(bounds.maxX + bounds.minX) / 2,
9456
- y: -(bounds.maxY + bounds.minY) / 2
9498
+ x: groupCenter.x - (bounds.maxX + bounds.minX) / 2,
9499
+ y: groupCenter.y - (bounds.maxY + bounds.minY) / 2
9457
9500
  };
9458
9501
  for (const child of flexBox.children) {
9459
- const { sourceComponent, sourceGroup } = child.metadata;
9460
- if (sourceComponent) {
9461
- const pcbComponent = db.pcb_component.getWhere({
9462
- source_component_id: sourceComponent.source_component_id
9463
- });
9464
- if (!pcbComponent) continue;
9465
- repositionPcbComponentTo2(allCircuitJson, pcbComponent.pcb_component_id, {
9466
- x: child.position.x + child.size.width / 2 + offset.x,
9467
- y: child.position.y + child.size.height / 2 + offset.y
9468
- });
9469
- }
9470
- if (sourceGroup) {
9471
- const pcbGroup = db.pcb_group.getWhere({
9472
- source_group_id: sourceGroup.source_group_id
9473
- });
9474
- if (!pcbGroup) continue;
9475
- repositionPcbGroupTo2(allCircuitJson, sourceGroup.source_group_id, {
9476
- x: child.position.x + child.size.width / 2 + offset.x,
9477
- y: child.position.y + child.size.height / 2 + offset.y
9478
- });
9479
- }
9502
+ const childMetadata = child.metadata;
9503
+ childMetadata._repositionOnPcb({
9504
+ x: child.position.x + child.size.width / 2 + offset.x,
9505
+ y: child.position.y + child.size.height / 2 + offset.y
9506
+ });
9480
9507
  }
9481
9508
  db.pcb_group.update(group.pcb_group_id, {
9482
9509
  width: bounds.width,
9483
- height: bounds.height
9510
+ height: bounds.height,
9511
+ center: groupCenter
9484
9512
  });
9485
9513
  };
9486
9514
 
@@ -11019,6 +11047,18 @@ var Group6 = class extends NormalComponent {
11019
11047
  }
11020
11048
  }
11021
11049
  }
11050
+ /**
11051
+ * Get the minimum flex container size for this group on PCB
11052
+ */
11053
+ _getMinimumFlexContainerSize() {
11054
+ return super._getMinimumFlexContainerSize();
11055
+ }
11056
+ /**
11057
+ * Reposition this group on the PCB to the specified coordinates
11058
+ */
11059
+ _repositionOnPcb(position) {
11060
+ return super._repositionOnPcb(position);
11061
+ }
11022
11062
  };
11023
11063
 
11024
11064
  // lib/components/normal-components/Board.ts
@@ -13729,7 +13769,7 @@ import { identity as identity5 } from "transformation-matrix";
13729
13769
  var package_default = {
13730
13770
  name: "@tscircuit/core",
13731
13771
  type: "module",
13732
- version: "0.0.656",
13772
+ version: "0.0.658",
13733
13773
  types: "dist/index.d.ts",
13734
13774
  main: "dist/index.js",
13735
13775
  module: "dist/index.js",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.657",
4
+ "version": "0.0.659",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",