@tscircuit/core 0.0.131 → 0.0.133

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
@@ -1218,6 +1218,14 @@ declare class Capacitor extends NormalComponent<typeof capacitorProps, PassivePo
1218
1218
  doInitialSourceRender(): void;
1219
1219
  }
1220
1220
 
1221
+ type PortInfo = {
1222
+ trueIndex: number;
1223
+ pinNumber: number;
1224
+ side: "left" | "right" | "top" | "bottom" | "center";
1225
+ distanceFromEdge: number;
1226
+ x: number;
1227
+ y: number;
1228
+ };
1221
1229
  /**
1222
1230
  * Get the dimensions of a schematic box based on the provided parameters.
1223
1231
  *
@@ -1234,10 +1242,7 @@ declare class Capacitor extends NormalComponent<typeof capacitorProps, PassivePo
1234
1242
  */
1235
1243
  interface SchematicBoxDimensions {
1236
1244
  pinCount: number;
1237
- getPortPositionByPinNumber(pinNumber: number): {
1238
- x: number;
1239
- y: number;
1240
- };
1245
+ getPortPositionByPinNumber(pinNumber: number): PortInfo;
1241
1246
  getSize(): {
1242
1247
  width: number;
1243
1248
  height: number;
package/dist/index.js CHANGED
@@ -1543,9 +1543,10 @@ var Port = class extends PrimitiveComponent {
1543
1543
  console.warn(`Could not find parent symbol for ${this}`);
1544
1544
  return { x: 0, y: 0 };
1545
1545
  }
1546
+ const offsetY = -0.045;
1546
1547
  const transform = compose3(
1547
1548
  this.parent.computeSchematicGlobalTransform(),
1548
- translate3(-symbol.center.x, -symbol.center.y)
1549
+ translate3(-symbol.center.x, -symbol.center.y + offsetY)
1549
1550
  );
1550
1551
  return applyToPoint4(transform, this.schematicSymbolPortDef);
1551
1552
  }
@@ -2554,11 +2555,49 @@ var stringProxy = new Proxy(
2554
2555
  var FTYPE = stringProxy;
2555
2556
 
2556
2557
  // lib/components/primitive-components/Trace.ts
2557
- import { traceProps } from "@tscircuit/props";
2558
2558
  import {
2559
2559
  MultilayerIjump,
2560
2560
  getObstaclesFromSoup
2561
2561
  } from "@tscircuit/infgrid-ijump-astar";
2562
+ import { traceProps } from "@tscircuit/props";
2563
+ import { getFullConnectivityMapFromCircuitJson } from "circuit-json-to-connectivity-map";
2564
+
2565
+ // lib/utils/autorouting/DirectLineRouter.ts
2566
+ var DirectLineRouter = class {
2567
+ input;
2568
+ constructor({ input }) {
2569
+ this.input = input;
2570
+ }
2571
+ solveAndMapToTraces() {
2572
+ const traces = [];
2573
+ for (const connection of this.input.connections) {
2574
+ if (connection.pointsToConnect.length !== 2) continue;
2575
+ const [start, end] = connection.pointsToConnect;
2576
+ const trace = {
2577
+ type: "pcb_trace",
2578
+ pcb_trace_id: "",
2579
+ route: [
2580
+ {
2581
+ route_type: "wire",
2582
+ x: start.x,
2583
+ y: start.y,
2584
+ layer: "top",
2585
+ width: 0.1
2586
+ },
2587
+ {
2588
+ route_type: "wire",
2589
+ x: end.x,
2590
+ y: end.y,
2591
+ layer: "top",
2592
+ width: 0.1
2593
+ }
2594
+ ]
2595
+ };
2596
+ traces.push(trace);
2597
+ }
2598
+ return traces;
2599
+ }
2600
+ };
2562
2601
 
2563
2602
  // lib/utils/autorouting/computeObstacleBounds.ts
2564
2603
  var computeObstacleBounds = (obstacles) => {
@@ -2569,22 +2608,6 @@ var computeObstacleBounds = (obstacles) => {
2569
2608
  return { minX, maxX, minY, maxY };
2570
2609
  };
2571
2610
 
2572
- // lib/utils/projectPointInDirection.ts
2573
- var projectPointInDirection = (point, direction, distance) => {
2574
- switch (direction) {
2575
- case "up":
2576
- return { x: point.x, y: point.y - distance };
2577
- case "down":
2578
- return { x: point.x, y: point.y + distance };
2579
- case "left":
2580
- return { x: point.x - distance, y: point.y };
2581
- case "right":
2582
- return { x: point.x + distance, y: point.y };
2583
- default:
2584
- throw new Error(`Unknown direction "${direction}"`);
2585
- }
2586
- };
2587
-
2588
2611
  // lib/utils/autorouting/findPossibleTraceLayerCombinations.ts
2589
2612
  var LAYER_SELECTION_PREFERENCE = ["top", "bottom", "inner1", "inner2"];
2590
2613
  var findPossibleTraceLayerCombinations = (hints, layer_path = []) => {
@@ -2718,8 +2741,37 @@ function getClosest(point, candidates) {
2718
2741
  return closest;
2719
2742
  }
2720
2743
 
2721
- // lib/components/primitive-components/Trace.ts
2722
- import "zod";
2744
+ // lib/utils/projectPointInDirection.ts
2745
+ var projectPointInDirection = (point, direction, distance) => {
2746
+ switch (direction) {
2747
+ case "up":
2748
+ return { x: point.x, y: point.y + distance };
2749
+ case "down":
2750
+ return { x: point.x, y: point.y - distance };
2751
+ case "left":
2752
+ return { x: point.x + distance, y: point.y };
2753
+ case "right":
2754
+ return { x: point.x - distance, y: point.y };
2755
+ default:
2756
+ throw new Error(`Unknown direction "${direction}"`);
2757
+ }
2758
+ };
2759
+
2760
+ // lib/utils/projectPointInOppositeDirection.ts
2761
+ var projectPointInOppositeDirection = (point, direction, distance) => {
2762
+ switch (direction) {
2763
+ case "up":
2764
+ return { x: point.x, y: point.y + distance };
2765
+ case "down":
2766
+ return { x: point.x, y: point.y - distance };
2767
+ case "left":
2768
+ return { x: point.x + distance, y: point.y };
2769
+ case "right":
2770
+ return { x: point.x - distance, y: point.y };
2771
+ default:
2772
+ throw new Error(`Unknown direction "${direction}"`);
2773
+ }
2774
+ };
2723
2775
 
2724
2776
  // lib/utils/try-now.ts
2725
2777
  function tryNow(fn) {
@@ -2731,46 +2783,7 @@ function tryNow(fn) {
2731
2783
  }
2732
2784
 
2733
2785
  // lib/components/primitive-components/Trace.ts
2734
- import { getFullConnectivityMapFromCircuitJson } from "circuit-json-to-connectivity-map";
2735
-
2736
- // lib/utils/autorouting/DirectLineRouter.ts
2737
- var DirectLineRouter = class {
2738
- input;
2739
- constructor({ input }) {
2740
- this.input = input;
2741
- }
2742
- solveAndMapToTraces() {
2743
- const traces = [];
2744
- for (const connection of this.input.connections) {
2745
- if (connection.pointsToConnect.length !== 2) continue;
2746
- const [start, end] = connection.pointsToConnect;
2747
- const trace = {
2748
- type: "pcb_trace",
2749
- pcb_trace_id: "",
2750
- route: [
2751
- {
2752
- route_type: "wire",
2753
- x: start.x,
2754
- y: start.y,
2755
- layer: "top",
2756
- width: 0.1
2757
- },
2758
- {
2759
- route_type: "wire",
2760
- x: end.x,
2761
- y: end.y,
2762
- layer: "top",
2763
- width: 0.1
2764
- }
2765
- ]
2766
- };
2767
- traces.push(trace);
2768
- }
2769
- return traces;
2770
- }
2771
- };
2772
-
2773
- // lib/components/primitive-components/Trace.ts
2786
+ import "zod";
2774
2787
  var portToObjective = (port) => {
2775
2788
  const portPosition = port._getGlobalPcbPositionAfterLayout();
2776
2789
  return {
@@ -3204,17 +3217,19 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
3204
3217
  });
3205
3218
  }
3206
3219
  }
3207
- for (const { port } of ports) {
3208
- connection.pointsToConnect.push({
3209
- ...port._getGlobalSchematicPositionAfterLayout(),
3210
- ...projectPointInDirection(
3211
- port._getGlobalSchematicPositionAfterLayout(),
3212
- port.facingDirection,
3213
- 0.1501
3214
- ),
3215
- layer: "top"
3216
- });
3220
+ const portsWithPosition = ports.map(({ port }) => ({
3221
+ port,
3222
+ position: port._getGlobalSchematicPositionAfterLayout(),
3223
+ schematic_port_id: port.schematic_port_id ?? void 0,
3224
+ facingDirection: port.facingDirection
3225
+ }));
3226
+ if (portsWithPosition.length < 2) {
3227
+ return;
3217
3228
  }
3229
+ connection.pointsToConnect = portsWithPosition.map(({ position }) => ({
3230
+ ...position,
3231
+ layer: "top"
3232
+ }));
3218
3233
  const bounds = computeObstacleBounds(obstacles);
3219
3234
  const simpleRouteJsonInput = {
3220
3235
  minTraceWidth: 0.1,
@@ -3223,19 +3238,6 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
3223
3238
  bounds,
3224
3239
  layerCount: 1
3225
3240
  };
3226
- if (this.getSubcircuit().props._schDebugObjectsEnabled) {
3227
- for (const obstacle of obstacles) {
3228
- db.schematic_debug_object.insert({
3229
- shape: "rect",
3230
- center: obstacle.center,
3231
- size: {
3232
- width: obstacle.width,
3233
- height: obstacle.height
3234
- },
3235
- label: "obstacle"
3236
- });
3237
- }
3238
- }
3239
3241
  let Autorouter = MultilayerIjump;
3240
3242
  if (this.getSubcircuit().props._schDirectLineRoutingEnabled) {
3241
3243
  Autorouter = DirectLineRouter;
@@ -3250,14 +3252,34 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
3250
3252
  const { route } = result;
3251
3253
  const edges = [];
3252
3254
  for (let i = 0; i < route.length - 1; i++) {
3253
- const from = route[i];
3254
- const to = route[i + 1];
3255
3255
  edges.push({
3256
- from,
3257
- to
3258
- // TODO to_schematic_port_id and from_schematic_port_id
3256
+ from: route[i],
3257
+ to: route[i + 1]
3259
3258
  });
3260
3259
  }
3260
+ const STUB_LENGTH = 0.15;
3261
+ edges.unshift({
3262
+ from: {
3263
+ ...projectPointInDirection(
3264
+ route[0],
3265
+ portsWithPosition[0].facingDirection,
3266
+ STUB_LENGTH
3267
+ )
3268
+ },
3269
+ to: route[0],
3270
+ from_schematic_port_id: portsWithPosition[0].schematic_port_id
3271
+ });
3272
+ edges.push({
3273
+ from: route[route.length - 1],
3274
+ to: {
3275
+ ...projectPointInOppositeDirection(
3276
+ route[route.length - 1],
3277
+ portsWithPosition[1].facingDirection,
3278
+ STUB_LENGTH
3279
+ )
3280
+ },
3281
+ from_schematic_port_id: portsWithPosition[1].schematic_port_id
3282
+ });
3261
3283
  const trace = db.schematic_trace.insert({
3262
3284
  source_trace_id: this.source_trace_id,
3263
3285
  edges
@@ -3484,7 +3506,9 @@ var getAllDimensionsForSchematicBox = (params) => {
3484
3506
  trueIndex: truePinIndex,
3485
3507
  pinNumber,
3486
3508
  side,
3487
- distanceFromEdge: currentDistanceFromEdge
3509
+ distanceFromEdge: currentDistanceFromEdge,
3510
+ x: 0,
3511
+ y: 0
3488
3512
  });
3489
3513
  if (pinStyle) {
3490
3514
  if (isVertical) {
@@ -3573,12 +3597,19 @@ var getAllDimensionsForSchematicBox = (params) => {
3573
3597
  };
3574
3598
  const truePortsWithPositions = orderedTruePorts.map((p) => {
3575
3599
  const { distanceFromEdge, side } = p;
3600
+ if (side === "center") {
3601
+ return {
3602
+ ...p,
3603
+ x: 0,
3604
+ y: 0
3605
+ };
3606
+ }
3576
3607
  const edgePos = trueEdgePositions[side];
3577
3608
  const edgeDir = trueEdgeTraversalDirections[side];
3578
3609
  return {
3610
+ ...p,
3579
3611
  x: edgePos.x + distanceFromEdge * edgeDir.x,
3580
- y: edgePos.y + distanceFromEdge * edgeDir.y,
3581
- ...p
3612
+ y: edgePos.y + distanceFromEdge * edgeDir.y
3582
3613
  };
3583
3614
  });
3584
3615
  return {
@@ -3587,7 +3618,15 @@ var getAllDimensionsForSchematicBox = (params) => {
3587
3618
  (p) => p.pinNumber.toString() === pinNumber.toString()
3588
3619
  );
3589
3620
  if (!port) {
3590
- return { x: 0, y: 0 };
3621
+ return {
3622
+ trueIndex: -1,
3623
+ // Use -1 for non-existent ports
3624
+ pinNumber,
3625
+ side: "center",
3626
+ distanceFromEdge: 0,
3627
+ x: 0,
3628
+ y: 0
3629
+ };
3591
3630
  }
3592
3631
  return port;
3593
3632
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.131",
4
+ "version": "0.0.133",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -44,7 +44,7 @@
44
44
  "@tscircuit/soup-util": "^0.0.33",
45
45
  "circuit-json": "^0.0.91",
46
46
  "circuit-json-to-connectivity-map": "^0.0.17",
47
- "circuit-to-svg": "^0.0.54",
47
+ "circuit-to-svg": "^0.0.55",
48
48
  "nanoid": "^5.0.7",
49
49
  "performance-now": "^2.1.0",
50
50
  "react": "^18.3.1",