@tscircuit/core 0.0.606 → 0.0.608

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
@@ -3447,6 +3447,7 @@ declare class Chip<PinLabels extends string = never> extends NormalComponent<typ
3447
3447
  }>;
3448
3448
  shouldRenderAsSchematicBox: boolean;
3449
3449
  };
3450
+ initPorts(opts?: {}): void;
3450
3451
  doInitialSchematicComponentRender(): void;
3451
3452
  doInitialSourceRender(): void;
3452
3453
  doInitialPcbComponentRender(): void;
package/dist/index.js CHANGED
@@ -4154,7 +4154,7 @@ var getMaxLengthFromConnectedCapacitors = (ports, { db }) => {
4154
4154
  return sourceComponent.max_decoupling_trace_length;
4155
4155
  }
4156
4156
  return null;
4157
- }).filter((length4) => length4 !== null);
4157
+ }).filter((length5) => length5 !== null);
4158
4158
  if (capacitorMaxLengths.length === 0) return void 0;
4159
4159
  return Math.min(...capacitorMaxLengths);
4160
4160
  };
@@ -5081,7 +5081,7 @@ var Trace_doInitialSchematicTraceRender = (trace) => {
5081
5081
  pointsToConnect: []
5082
5082
  };
5083
5083
  const obstacles = getSchematicObstaclesForTrace(trace);
5084
- const portsWithPosition = connectedPorts.map(({ port }) => ({
5084
+ const portsWithPosition = connectedPorts.filter(({ port }) => port.schematic_port_id !== null).map(({ port }) => ({
5085
5085
  port,
5086
5086
  position: port._getGlobalSchematicPositionAfterLayout(),
5087
5087
  schematic_port_id: port.schematic_port_id ?? void 0,
@@ -8284,44 +8284,172 @@ var Group_doInitialPcbLayoutPack = (group) => {
8284
8284
  };
8285
8285
 
8286
8286
  // lib/components/primitive-components/Group/Group_doInitialPcbLayoutFlex.ts
8287
- import { buildSubtree as buildSubtree3 } from "@tscircuit/circuit-json-util";
8288
- import { layoutCircuitJsonWithFlex } from "@tscircuit/circuit-json-flex";
8287
+ import "@tscircuit/circuit-json-flex";
8288
+ import {
8289
+ getCircuitJsonTree,
8290
+ repositionPcbComponentTo,
8291
+ repositionPcbGroupTo
8292
+ } from "@tscircuit/circuit-json-util";
8293
+ import { RootFlexBox } from "@tscircuit/miniflex";
8294
+ import { getMinimumFlexContainer } from "@tscircuit/circuit-json-flex";
8295
+ import { length as length4 } from "circuit-json";
8296
+ var getSizeOfTreeNodeChild = (db, child) => {
8297
+ const { sourceComponent, sourceGroup } = child;
8298
+ if (child.nodeType === "component") {
8299
+ const pcbComponent = db.pcb_component.getWhere({
8300
+ source_component_id: sourceComponent?.source_component_id
8301
+ });
8302
+ if (!pcbComponent) return null;
8303
+ return {
8304
+ width: pcbComponent.width,
8305
+ height: pcbComponent.height
8306
+ };
8307
+ }
8308
+ if (child.nodeType === "group") {
8309
+ const pcbGroup = db.pcb_group.getWhere({
8310
+ source_group_id: sourceGroup?.source_group_id
8311
+ });
8312
+ if (!pcbGroup) return null;
8313
+ return {
8314
+ width: pcbGroup.width,
8315
+ height: pcbGroup.height
8316
+ };
8317
+ }
8318
+ return null;
8319
+ };
8289
8320
  var Group_doInitialPcbLayoutFlex = (group) => {
8290
8321
  const { db } = group.root;
8291
8322
  const { _parsedProps: props } = group;
8292
- const circuitJson = group.lowercaseComponentName === "board" ? db.toArray() : buildSubtree3(db.toArray(), {
8323
+ const tree = getCircuitJsonTree(db.toArray(), {
8293
8324
  source_group_id: group.source_group_id
8294
8325
  });
8295
- const justify = props.pcbJustifyContent ?? props.justifyContent;
8296
- const align = props.pcbAlignItems ?? props.alignItems;
8297
- const gap = props.pcbFlexGap ?? props.pcbGap ?? props.gap;
8326
+ const rawJustify = props.pcbJustifyContent ?? props.justifyContent;
8327
+ const rawAlign = props.pcbAlignItems ?? props.alignItems;
8328
+ const rawGap = props.pcbFlexGap ?? props.pcbGap ?? props.gap;
8298
8329
  const direction = props.pcbFlexDirection ?? "row";
8299
- const modifiedCircuitJson = layoutCircuitJsonWithFlex(circuitJson, {
8300
- justifyContent: justify === "start" ? "flex-start" : justify === "end" ? "flex-end" : justify === "stretch" ? "space-between" : justify ?? "space-between",
8301
- alignItems: align === "start" ? "flex-start" : align === "end" ? "flex-end" : align ?? "center",
8302
- direction,
8303
- columnGap: typeof gap === "number" ? gap : 0,
8304
- rowGap: typeof gap === "number" ? gap : 0
8305
- });
8306
- const pcbSmtPads = db.pcb_smtpad.list();
8307
- for (const smtpad of pcbSmtPads) {
8308
- const modifiedElm = modifiedCircuitJson.find(
8309
- (elm) => elm.type === "pcb_smtpad" && elm.pcb_smtpad_id === smtpad.pcb_smtpad_id
8330
+ const justifyContent = {
8331
+ start: "flex-start",
8332
+ end: "flex-end",
8333
+ "flex-start": "flex-start",
8334
+ "flex-end": "flex-end",
8335
+ stretch: "space-between",
8336
+ "space-between": "space-between",
8337
+ "space-around": "space-around",
8338
+ "space-evenly": "space-evenly",
8339
+ center: "center"
8340
+ }[rawJustify ?? "space-between"];
8341
+ const alignItems = {
8342
+ start: "flex-start",
8343
+ end: "flex-end",
8344
+ "flex-start": "flex-start",
8345
+ "flex-end": "flex-end",
8346
+ stretch: "stretch",
8347
+ center: "center"
8348
+ }[rawAlign ?? "center"];
8349
+ if (!justifyContent) {
8350
+ throw new Error(`Invalid justifyContent value: "${rawJustify}"`);
8351
+ }
8352
+ if (!alignItems) {
8353
+ throw new Error(`Invalid alignItems value: "${rawAlign}"`);
8354
+ }
8355
+ let rowGap = 0;
8356
+ let columnGap = 0;
8357
+ if (typeof rawGap === "object") {
8358
+ rowGap = rawGap.y ?? 0;
8359
+ columnGap = rawGap.x ?? 0;
8360
+ } else if (typeof rawGap === "number") {
8361
+ rowGap = rawGap;
8362
+ columnGap = rawGap;
8363
+ } else if (typeof rawGap === "string") {
8364
+ rowGap = length4.parse(rawGap);
8365
+ columnGap = length4.parse(rawGap);
8366
+ }
8367
+ let minFlexContainer;
8368
+ let width = props.width ?? props.pcbWidth ?? void 0;
8369
+ let height = props.height ?? props.pcbHeight ?? void 0;
8370
+ const isInline = Boolean(width === void 0 || height === void 0);
8371
+ if (isInline) {
8372
+ minFlexContainer = getMinimumFlexContainer(
8373
+ tree.childNodes.map((child) => getSizeOfTreeNodeChild(db, child)).filter((size) => size !== null),
8374
+ {
8375
+ alignItems,
8376
+ justifyContent,
8377
+ direction,
8378
+ rowGap,
8379
+ columnGap
8380
+ }
8310
8381
  );
8311
- if (!modifiedElm) continue;
8312
- db.pcb_smtpad.update(smtpad.pcb_smtpad_id, modifiedElm);
8382
+ width = minFlexContainer.width;
8383
+ height = minFlexContainer.height;
8313
8384
  }
8314
- const pcbSilkScreenTexts = db.pcb_silkscreen_text.list();
8315
- for (const silkscreenText of pcbSilkScreenTexts) {
8316
- const modifiedElm = modifiedCircuitJson.find(
8317
- (elm) => elm.type === "pcb_silkscreen_text" && elm.pcb_silkscreen_text_id === silkscreenText.pcb_silkscreen_text_id
8318
- );
8319
- if (!modifiedElm) continue;
8320
- db.pcb_silkscreen_text.update(
8321
- silkscreenText.pcb_silkscreen_text_id,
8322
- modifiedElm
8323
- );
8385
+ const flexBox = new RootFlexBox(width, height, {
8386
+ alignItems,
8387
+ justifyContent,
8388
+ direction,
8389
+ rowGap,
8390
+ columnGap
8391
+ });
8392
+ for (const child of tree.childNodes) {
8393
+ const size = getSizeOfTreeNodeChild(db, child);
8394
+ flexBox.addChild({
8395
+ metadata: child,
8396
+ // TODO these should be minWidth/minHeight
8397
+ width: size?.width ?? 0,
8398
+ height: size?.height ?? 0,
8399
+ // TODO allow overriding flexBasis
8400
+ flexBasis: !size ? void 0 : direction === "row" ? size.width : size.height
8401
+ // TODO alignSelf, flexGrow, flexShrink etc.
8402
+ });
8403
+ }
8404
+ flexBox.build();
8405
+ const allCircuitJson = db.toArray();
8406
+ const bounds = {
8407
+ minX: Infinity,
8408
+ minY: Infinity,
8409
+ maxX: -Infinity,
8410
+ maxY: -Infinity,
8411
+ width: 0,
8412
+ height: 0
8413
+ };
8414
+ for (const child of flexBox.children) {
8415
+ bounds.minX = Math.min(bounds.minX, child.position.x);
8416
+ bounds.minY = Math.min(bounds.minY, child.position.y);
8417
+ bounds.maxX = Math.max(bounds.maxX, child.position.x + child.size.width);
8418
+ bounds.maxY = Math.max(bounds.maxY, child.position.y + child.size.height);
8419
+ }
8420
+ bounds.width = bounds.maxX - bounds.minX;
8421
+ bounds.height = bounds.maxY - bounds.minY;
8422
+ const offset = {
8423
+ x: -(bounds.maxX + bounds.minX) / 2,
8424
+ y: -(bounds.maxY + bounds.minY) / 2
8425
+ };
8426
+ for (const child of flexBox.children) {
8427
+ const { sourceComponent, sourceGroup } = child.metadata;
8428
+ if (sourceComponent) {
8429
+ const pcbComponent = db.pcb_component.getWhere({
8430
+ source_component_id: sourceComponent.source_component_id
8431
+ });
8432
+ if (!pcbComponent) continue;
8433
+ repositionPcbComponentTo(allCircuitJson, pcbComponent.pcb_component_id, {
8434
+ x: child.position.x + child.size.width / 2 + offset.x,
8435
+ y: child.position.y + child.size.height / 2 + offset.y
8436
+ });
8437
+ }
8438
+ if (sourceGroup) {
8439
+ const pcbGroup = db.pcb_group.getWhere({
8440
+ source_group_id: sourceGroup.source_group_id
8441
+ });
8442
+ if (!pcbGroup) continue;
8443
+ repositionPcbGroupTo(allCircuitJson, sourceGroup.source_group_id, {
8444
+ x: child.position.x + child.size.width / 2 + offset.x,
8445
+ y: child.position.y + child.size.height / 2 + offset.y
8446
+ });
8447
+ }
8324
8448
  }
8449
+ db.pcb_group.update(group.pcb_group_id, {
8450
+ width: bounds.width,
8451
+ height: bounds.height
8452
+ });
8325
8453
  };
8326
8454
 
8327
8455
  // lib/components/primitive-components/Group/Group.ts
@@ -8381,7 +8509,7 @@ var Group = class extends NormalComponent {
8381
8509
  const { _parsedProps: props } = this;
8382
8510
  const pcb_group = db.pcb_group.insert({
8383
8511
  is_subcircuit: this.isSubcircuit,
8384
- subcircuit_id: this.subcircuit_id,
8512
+ subcircuit_id: this.subcircuit_id ?? this.getSubcircuit()?.subcircuit_id,
8385
8513
  name: this.name,
8386
8514
  center: this._getGlobalPcbPositionBeforeLayout(),
8387
8515
  width: 0,
@@ -9089,6 +9217,7 @@ var Board = class extends Group {
9089
9217
  let maxY = -Infinity;
9090
9218
  const descendantIds = getDescendantSubcircuitIds(db, this.subcircuit_id);
9091
9219
  const allowedSubcircuitIds = /* @__PURE__ */ new Set([this.subcircuit_id, ...descendantIds]);
9220
+ console.log({ allowedSubcircuitIds });
9092
9221
  const allPcbComponents = db.pcb_component.list().filter(
9093
9222
  (c) => c.subcircuit_id && allowedSubcircuitIds.has(c.subcircuit_id)
9094
9223
  );
@@ -9318,6 +9447,41 @@ var Chip = class extends NormalComponent {
9318
9447
  shouldRenderAsSchematicBox: true
9319
9448
  };
9320
9449
  }
9450
+ initPorts(opts = {}) {
9451
+ super.initPorts(opts);
9452
+ const { _parsedProps: props } = this;
9453
+ if (props.externallyConnectedPins) {
9454
+ const requiredPorts = /* @__PURE__ */ new Set();
9455
+ for (const [pin1, pin2] of props.externallyConnectedPins) {
9456
+ requiredPorts.add(pin1);
9457
+ requiredPorts.add(pin2);
9458
+ }
9459
+ for (const pinIdentifier of requiredPorts) {
9460
+ const existingPort = this.children.find(
9461
+ (child) => child instanceof Port && child.isMatchingAnyOf([pinIdentifier])
9462
+ );
9463
+ if (!existingPort) {
9464
+ const pinMatch = pinIdentifier.match(/^pin(\d+)$/);
9465
+ if (pinMatch) {
9466
+ const pinNumber = parseInt(pinMatch[1]);
9467
+ this.add(
9468
+ new Port({
9469
+ pinNumber,
9470
+ aliases: [pinIdentifier]
9471
+ })
9472
+ );
9473
+ } else {
9474
+ this.add(
9475
+ new Port({
9476
+ name: pinIdentifier,
9477
+ aliases: [pinIdentifier]
9478
+ })
9479
+ );
9480
+ }
9481
+ }
9482
+ }
9483
+ }
9484
+ }
9321
9485
  doInitialSchematicComponentRender() {
9322
9486
  const { _parsedProps: props } = this;
9323
9487
  if (props?.noSchematicRepresentation === true) return;
@@ -11375,7 +11539,7 @@ import { identity as identity5 } from "transformation-matrix";
11375
11539
  var package_default = {
11376
11540
  name: "@tscircuit/core",
11377
11541
  type: "module",
11378
- version: "0.0.605",
11542
+ version: "0.0.607",
11379
11543
  types: "dist/index.d.ts",
11380
11544
  main: "dist/index.js",
11381
11545
  module: "dist/index.js",
@@ -11400,12 +11564,13 @@ var package_default = {
11400
11564
  "@biomejs/biome": "^1.8.3",
11401
11565
  "@tscircuit/capacity-autorouter": "^0.0.100",
11402
11566
  "@tscircuit/checks": "^0.0.64",
11403
- "@tscircuit/circuit-json-util": "^0.0.61",
11567
+ "@tscircuit/circuit-json-util": "^0.0.62",
11404
11568
  "@tscircuit/footprinter": "^0.0.208",
11405
11569
  "@tscircuit/import-snippet": "^0.0.4",
11406
11570
  "@tscircuit/infgrid-ijump-astar": "^0.0.33",
11407
11571
  "@tscircuit/log-soup": "^1.0.2",
11408
11572
  "@tscircuit/math-utils": "^0.0.18",
11573
+ "@tscircuit/miniflex": "^0.0.4",
11409
11574
  "@tscircuit/props": "^0.0.276",
11410
11575
  "@tscircuit/schematic-autolayout": "^0.0.6",
11411
11576
  "@tscircuit/schematic-corpus": "^0.0.110",
@@ -11436,6 +11601,7 @@ var package_default = {
11436
11601
  "react-dom": "^19.1.0",
11437
11602
  "schematic-symbols": "^0.0.180",
11438
11603
  "ts-expect": "^1.3.0",
11604
+ "@tscircuit/circuit-json-flex": "^0.0.3",
11439
11605
  tsup: "^8.2.4"
11440
11606
  },
11441
11607
  peerDependencies: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.606",
4
+ "version": "0.0.608",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -26,12 +26,13 @@
26
26
  "@biomejs/biome": "^1.8.3",
27
27
  "@tscircuit/capacity-autorouter": "^0.0.100",
28
28
  "@tscircuit/checks": "^0.0.64",
29
- "@tscircuit/circuit-json-util": "^0.0.61",
29
+ "@tscircuit/circuit-json-util": "^0.0.62",
30
30
  "@tscircuit/footprinter": "^0.0.208",
31
31
  "@tscircuit/import-snippet": "^0.0.4",
32
32
  "@tscircuit/infgrid-ijump-astar": "^0.0.33",
33
33
  "@tscircuit/log-soup": "^1.0.2",
34
34
  "@tscircuit/math-utils": "^0.0.18",
35
+ "@tscircuit/miniflex": "^0.0.4",
35
36
  "@tscircuit/props": "^0.0.276",
36
37
  "@tscircuit/schematic-autolayout": "^0.0.6",
37
38
  "@tscircuit/schematic-corpus": "^0.0.110",
@@ -62,6 +63,7 @@
62
63
  "react-dom": "^19.1.0",
63
64
  "schematic-symbols": "^0.0.180",
64
65
  "ts-expect": "^1.3.0",
66
+ "@tscircuit/circuit-json-flex": "^0.0.3",
65
67
  "tsup": "^8.2.4"
66
68
  },
67
69
  "peerDependencies": {