@tscircuit/core 0.0.523 → 0.0.525

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
@@ -7407,7 +7407,9 @@ declare class NetLabel extends PrimitiveComponent<typeof netLabelProps> {
7407
7407
  anchorSide?: "left" | "right" | "top" | "bottom" | undefined;
7408
7408
  }>;
7409
7409
  };
7410
- doInitialSchematicComponentRender(): void;
7410
+ _getAnchorSide(): "top" | "bottom" | "left" | "right";
7411
+ _getConnectedPorts(): Port[];
7412
+ doInitialSchematicPrimitiveRender(): void;
7411
7413
  _resolveConnectsTo(): string[] | undefined;
7412
7414
  _getNetName(): string;
7413
7415
  doInitialCreateNetsFromProps(): void;
package/dist/index.js CHANGED
@@ -9408,18 +9408,53 @@ var NetLabel = class extends PrimitiveComponent2 {
9408
9408
  zodProps: netLabelProps
9409
9409
  };
9410
9410
  }
9411
- doInitialSchematicComponentRender() {
9411
+ _getAnchorSide() {
9412
+ const { _parsedProps: props } = this;
9413
+ if (props.anchorSide) return props.anchorSide;
9414
+ const connectsTo = this._resolveConnectsTo();
9415
+ if (!connectsTo) return "right";
9416
+ const anchorPos = this._getGlobalSchematicPositionBeforeLayout();
9417
+ const connectedPorts = this._getConnectedPorts();
9418
+ if (connectedPorts.length === 0) return "right";
9419
+ const connectedPortPosition = connectedPorts[0]._getGlobalSchematicPositionBeforeLayout();
9420
+ const dx = connectedPortPosition.x - anchorPos.x;
9421
+ const dy = connectedPortPosition.y - anchorPos.y;
9422
+ if (Math.abs(dx) > Math.abs(dy)) {
9423
+ if (dx > 0) return "right";
9424
+ if (dx < 0) return "left";
9425
+ } else {
9426
+ if (dy > 0) return "top";
9427
+ if (dy < 0) return "bottom";
9428
+ }
9429
+ return "right";
9430
+ }
9431
+ _getConnectedPorts() {
9432
+ const connectsTo = this._resolveConnectsTo();
9433
+ if (!connectsTo) return [];
9434
+ const connectedPorts = [];
9435
+ for (const connection of connectsTo) {
9436
+ const port = this.getSubcircuit().selectOne(connection);
9437
+ if (port) {
9438
+ connectedPorts.push(port);
9439
+ }
9440
+ }
9441
+ return connectedPorts;
9442
+ }
9443
+ doInitialSchematicPrimitiveRender() {
9412
9444
  if (this.root?.schematicDisabled) return;
9413
9445
  const { db } = this.root;
9414
9446
  const { _parsedProps: props } = this;
9415
- const anchorPos = { x: props.schX ?? 0, y: props.schY ?? 0 };
9447
+ const anchorPos = this._getGlobalSchematicPositionBeforeLayout();
9448
+ const net = this.getSubcircuit().selectOne(
9449
+ `net.${this._getNetName()}`
9450
+ );
9416
9451
  const netLabel = db.schematic_net_label.insert({
9417
9452
  text: props.net,
9418
- source_net_id: props.net,
9453
+ source_net_id: net.source_net_id,
9419
9454
  anchor_position: anchorPos,
9420
9455
  // TODO compute the center based on the text size
9421
9456
  center: anchorPos,
9422
- anchor_side: props.anchorSide ?? "right"
9457
+ anchor_side: this._getAnchorSide()
9423
9458
  });
9424
9459
  this.source_net_label_id = netLabel.source_net_id;
9425
9460
  }
@@ -10563,7 +10598,7 @@ import { identity as identity4 } from "transformation-matrix";
10563
10598
  var package_default = {
10564
10599
  name: "@tscircuit/core",
10565
10600
  type: "module",
10566
- version: "0.0.522",
10601
+ version: "0.0.524",
10567
10602
  types: "dist/index.d.ts",
10568
10603
  main: "dist/index.js",
10569
10604
  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.523",
4
+ "version": "0.0.525",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",