@tscircuit/core 0.0.656 → 0.0.658

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> {
@@ -1684,6 +1716,7 @@ declare class Board extends Group<typeof boardProps> {
1684
1716
  }>>;
1685
1717
  schAutoLayoutEnabled: zod.ZodOptional<zod.ZodBoolean>;
1686
1718
  schTraceAutoLabelEnabled: zod.ZodOptional<zod.ZodBoolean>;
1719
+ schMaxTraceDistance: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
1687
1720
  routingDisabled: zod.ZodOptional<zod.ZodBoolean>;
1688
1721
  defaultTraceWidth: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
1689
1722
  minTraceWidth: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
@@ -1968,6 +2001,7 @@ declare class Board extends Group<typeof boardProps> {
1968
2001
  } | undefined;
1969
2002
  schAutoLayoutEnabled?: boolean | undefined;
1970
2003
  schTraceAutoLabelEnabled?: boolean | undefined;
2004
+ schMaxTraceDistance?: number | undefined;
1971
2005
  partsEngine?: _tscircuit_props.PartsEngine | undefined;
1972
2006
  square?: boolean | undefined;
1973
2007
  emptyArea?: string | undefined;
@@ -2205,6 +2239,7 @@ declare class Board extends Group<typeof boardProps> {
2205
2239
  } | undefined;
2206
2240
  schAutoLayoutEnabled?: boolean | undefined;
2207
2241
  schTraceAutoLabelEnabled?: boolean | undefined;
2242
+ schMaxTraceDistance?: string | number | undefined;
2208
2243
  partsEngine?: _tscircuit_props.PartsEngine | undefined;
2209
2244
  square?: boolean | undefined;
2210
2245
  emptyArea?: string | 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,15 @@ 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
9357
- });
9391
+ const pcbChildren = group.children.filter(
9392
+ (c) => c.pcb_component_id || c.pcb_group_id
9393
+ );
9358
9394
  const rawJustify = props.pcbJustifyContent ?? props.justifyContent;
9359
9395
  const rawAlign = props.pcbAlignItems ?? props.alignItems;
9360
9396
  const rawGap = props.pcbFlexGap ?? props.pcbGap ?? props.gap;
@@ -9402,7 +9438,7 @@ var Group_doInitialPcbLayoutFlex = (group) => {
9402
9438
  const isInline = Boolean(width === void 0 || height === void 0);
9403
9439
  if (isInline) {
9404
9440
  minFlexContainer = getMinimumFlexContainer2(
9405
- tree.childNodes.map((child) => getSizeOfTreeNodeChild2(db, child)).filter((size) => size !== null),
9441
+ pcbChildren.map((child) => child._getMinimumFlexContainerSize()).filter((size) => size !== null),
9406
9442
  {
9407
9443
  alignItems,
9408
9444
  justifyContent,
@@ -9421,8 +9457,8 @@ var Group_doInitialPcbLayoutFlex = (group) => {
9421
9457
  rowGap,
9422
9458
  columnGap
9423
9459
  });
9424
- for (const child of tree.childNodes) {
9425
- const size = getSizeOfTreeNodeChild2(db, child);
9460
+ for (const child of pcbChildren) {
9461
+ const size = child._getMinimumFlexContainerSize();
9426
9462
  flexBox.addChild({
9427
9463
  metadata: child,
9428
9464
  // TODO these should be minWidth/minHeight
@@ -9434,7 +9470,6 @@ var Group_doInitialPcbLayoutFlex = (group) => {
9434
9470
  });
9435
9471
  }
9436
9472
  flexBox.build();
9437
- const allCircuitJson = db.toArray();
9438
9473
  const bounds = {
9439
9474
  minX: Infinity,
9440
9475
  minY: Infinity,
@@ -9451,36 +9486,22 @@ var Group_doInitialPcbLayoutFlex = (group) => {
9451
9486
  }
9452
9487
  bounds.width = bounds.maxX - bounds.minX;
9453
9488
  bounds.height = bounds.maxY - bounds.minY;
9489
+ const groupCenter = group._getGlobalPcbPositionBeforeLayout();
9454
9490
  const offset = {
9455
- x: -(bounds.maxX + bounds.minX) / 2,
9456
- y: -(bounds.maxY + bounds.minY) / 2
9491
+ x: groupCenter.x - (bounds.maxX + bounds.minX) / 2,
9492
+ y: groupCenter.y - (bounds.maxY + bounds.minY) / 2
9457
9493
  };
9458
9494
  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
- }
9495
+ const childMetadata = child.metadata;
9496
+ childMetadata._repositionOnPcb({
9497
+ x: child.position.x + child.size.width / 2 + offset.x,
9498
+ y: child.position.y + child.size.height / 2 + offset.y
9499
+ });
9480
9500
  }
9481
9501
  db.pcb_group.update(group.pcb_group_id, {
9482
9502
  width: bounds.width,
9483
- height: bounds.height
9503
+ height: bounds.height,
9504
+ center: groupCenter
9484
9505
  });
9485
9506
  };
9486
9507
 
@@ -9645,7 +9666,7 @@ function createSchematicTraceSolverInputProblem(group) {
9645
9666
  directConnections,
9646
9667
  netConnections,
9647
9668
  availableNetLabelOrientations,
9648
- maxMspPairDistance: 5
9669
+ maxMspPairDistance: group._parsedProps.schMaxTraceDistance ?? 5
9649
9670
  };
9650
9671
  return {
9651
9672
  inputProblem,
@@ -11019,6 +11040,18 @@ var Group6 = class extends NormalComponent {
11019
11040
  }
11020
11041
  }
11021
11042
  }
11043
+ /**
11044
+ * Get the minimum flex container size for this group on PCB
11045
+ */
11046
+ _getMinimumFlexContainerSize() {
11047
+ return super._getMinimumFlexContainerSize();
11048
+ }
11049
+ /**
11050
+ * Reposition this group on the PCB to the specified coordinates
11051
+ */
11052
+ _repositionOnPcb(position) {
11053
+ return super._repositionOnPcb(position);
11054
+ }
11022
11055
  };
11023
11056
 
11024
11057
  // lib/components/normal-components/Board.ts
@@ -13729,7 +13762,7 @@ import { identity as identity5 } from "transformation-matrix";
13729
13762
  var package_default = {
13730
13763
  name: "@tscircuit/core",
13731
13764
  type: "module",
13732
- version: "0.0.655",
13765
+ version: "0.0.657",
13733
13766
  types: "dist/index.d.ts",
13734
13767
  main: "dist/index.js",
13735
13768
  module: "dist/index.js",
@@ -13768,7 +13801,7 @@ var package_default = {
13768
13801
  "@tscircuit/matchpack": "^0.0.9",
13769
13802
  "@tscircuit/math-utils": "^0.0.18",
13770
13803
  "@tscircuit/miniflex": "^0.0.4",
13771
- "@tscircuit/props": "^0.0.287",
13804
+ "@tscircuit/props": "0.0.288",
13772
13805
  "@tscircuit/schematic-autolayout": "^0.0.6",
13773
13806
  "@tscircuit/schematic-match-adapt": "^0.0.16",
13774
13807
  "@tscircuit/schematic-trace-solver": "^0.0.23",
@@ -13844,7 +13877,7 @@ var RootCircuit = class {
13844
13877
  schematicDisabled = false;
13845
13878
  pcbDisabled = false;
13846
13879
  pcbRoutingDisabled = false;
13847
- _featureMspSchematicTraceRouting = false;
13880
+ _featureMspSchematicTraceRouting = true;
13848
13881
  /**
13849
13882
  * The RootCircuit name is usually set by the platform, it's not required but
13850
13883
  * if supplied can identify the circuit in certain effects, e.g. it is passed
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.656",
4
+ "version": "0.0.658",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -40,7 +40,7 @@
40
40
  "@tscircuit/matchpack": "^0.0.9",
41
41
  "@tscircuit/math-utils": "^0.0.18",
42
42
  "@tscircuit/miniflex": "^0.0.4",
43
- "@tscircuit/props": "^0.0.287",
43
+ "@tscircuit/props": "0.0.288",
44
44
  "@tscircuit/schematic-autolayout": "^0.0.6",
45
45
  "@tscircuit/schematic-match-adapt": "^0.0.16",
46
46
  "@tscircuit/schematic-trace-solver": "^0.0.23",