@tscircuit/core 0.0.461 → 0.0.463

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.
Files changed (2) hide show
  1. package/dist/index.js +125 -12
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -486,8 +486,10 @@ var preprocessSelector = (selector) => {
486
486
  );
487
487
  }
488
488
  if (/net\.[0-9]/.test(selector)) {
489
+ const match = selector.match(/net\.([^ >]+)/);
490
+ const netName = match ? match[1] : "";
489
491
  throw new Error(
490
- 'Net names cannot start with a number, try using a prefix like "VBUS1"'
492
+ `Net name "${netName}" cannot start with a number, try using a prefix like "VBUS1"`
491
493
  );
492
494
  }
493
495
  return selector.replace(/ pin/g, " port").replace(/ subcircuit\./g, " group[isSubcircuit=true]").replace(/([^ ])\>([^ ])/g, "$1 > $2").replace(
@@ -1621,8 +1623,9 @@ var createNetsFromProps = (component, props) => {
1621
1623
  );
1622
1624
  }
1623
1625
  if (/net\.[0-9]/.test(prop)) {
1626
+ const netName = prop.split("net.")[1];
1624
1627
  throw new Error(
1625
- 'Net names cannot start with a number, try using a prefix like "VBUS1"'
1628
+ `Net name "${netName}" cannot start with a number, try using a prefix like "VBUS1"`
1626
1629
  );
1627
1630
  }
1628
1631
  const subcircuit = component.getSubcircuit();
@@ -9523,6 +9526,81 @@ var SchematicText = class extends PrimitiveComponent2 {
9523
9526
 
9524
9527
  // lib/components/primitive-components/SchematicBox.ts
9525
9528
  import { schematicBoxProps } from "@tscircuit/props";
9529
+
9530
+ // lib/components/primitive-components/getTitleAnchorAndPosition.ts
9531
+ function getTitleAnchorAndPosition({
9532
+ anchor,
9533
+ x,
9534
+ y,
9535
+ width,
9536
+ height,
9537
+ isInside
9538
+ }) {
9539
+ switch (anchor) {
9540
+ case "top_left":
9541
+ return {
9542
+ x,
9543
+ y: y + height,
9544
+ textAnchor: isInside ? "top_left" : "bottom_left"
9545
+ };
9546
+ case "top_center":
9547
+ return {
9548
+ x: x + width / 2,
9549
+ y: y + height,
9550
+ textAnchor: isInside ? "top_center" : "bottom_center"
9551
+ };
9552
+ case "top_right":
9553
+ return {
9554
+ x: x + width,
9555
+ y: y + height,
9556
+ textAnchor: isInside ? "top_right" : "bottom_right"
9557
+ };
9558
+ case "center_left":
9559
+ return {
9560
+ x,
9561
+ y: y + height / 2,
9562
+ textAnchor: isInside ? "center_left" : "center_right"
9563
+ };
9564
+ case "center":
9565
+ return {
9566
+ x: x + width / 2,
9567
+ y: y + height / 2,
9568
+ textAnchor: "center"
9569
+ };
9570
+ case "center_right":
9571
+ return {
9572
+ x: x + width,
9573
+ y: y + height / 2,
9574
+ textAnchor: isInside ? "center_right" : "center_left"
9575
+ };
9576
+ case "bottom_left":
9577
+ return {
9578
+ x,
9579
+ y,
9580
+ textAnchor: isInside ? "bottom_left" : "top_left"
9581
+ };
9582
+ case "bottom_center":
9583
+ return {
9584
+ x: x + width / 2,
9585
+ y,
9586
+ textAnchor: isInside ? "bottom_center" : "top_center"
9587
+ };
9588
+ case "bottom_right":
9589
+ return {
9590
+ x: x + width,
9591
+ y,
9592
+ textAnchor: isInside ? "bottom_right" : "top_right"
9593
+ };
9594
+ default:
9595
+ return {
9596
+ x: x + width / 2,
9597
+ y: y + height,
9598
+ textAnchor: "center"
9599
+ };
9600
+ }
9601
+ }
9602
+
9603
+ // lib/components/primitive-components/SchematicBox.ts
9526
9604
  var SchematicBox = class extends PrimitiveComponent2 {
9527
9605
  isSchematicPrimitive = true;
9528
9606
  get config() {
@@ -9536,11 +9614,6 @@ var SchematicBox = class extends PrimitiveComponent2 {
9536
9614
  if (this.root?.schematicDisabled) return;
9537
9615
  const { db } = this.root;
9538
9616
  const { _parsedProps: props } = this;
9539
- const result = schematicBoxProps.safeParse(props);
9540
- if (!result.success) {
9541
- console.error("Validation failed:", result.error.format());
9542
- throw result.error;
9543
- }
9544
9617
  const basePadding = 0.6;
9545
9618
  const generalPadding = typeof props.padding === "number" ? props.padding : 0;
9546
9619
  const paddingTop = typeof props.paddingTop === "number" ? props.paddingTop : generalPadding;
@@ -9553,6 +9626,8 @@ var SchematicBox = class extends PrimitiveComponent2 {
9553
9626
  let height;
9554
9627
  let x;
9555
9628
  let y;
9629
+ let centerX;
9630
+ let centerY;
9556
9631
  if (hasOverlay) {
9557
9632
  const portsWithSelectors = props.overlay.map((selector) => ({
9558
9633
  selector,
@@ -9586,11 +9661,13 @@ var SchematicBox = class extends PrimitiveComponent2 {
9586
9661
  height = bottom - top;
9587
9662
  x = left + (props.schX ?? 0);
9588
9663
  y = top + (props.schY ?? 0);
9664
+ centerX = x + width / 2;
9665
+ centerY = y + height / 2;
9589
9666
  } else if (hasFixedSize) {
9590
9667
  width = props.width;
9591
9668
  height = props.height;
9592
- const centerX = typeof props.schX === "number" ? props.schX : 0;
9593
- const centerY = typeof props.schY === "number" ? props.schY : 0;
9669
+ centerX = typeof props.schX === "number" ? props.schX : 0;
9670
+ centerY = typeof props.schY === "number" ? props.schY : 0;
9594
9671
  x = centerX - width / 2;
9595
9672
  y = centerY - height / 2;
9596
9673
  } else {
@@ -9604,6 +9681,42 @@ var SchematicBox = class extends PrimitiveComponent2 {
9604
9681
  is_dashed: props.strokeStyle === "dashed",
9605
9682
  schematic_component_id: ""
9606
9683
  });
9684
+ if (props.title) {
9685
+ const isInside = props.titleInside ?? false;
9686
+ const TITLE_PADDING = 0.1;
9687
+ const anchor = props.titleAlignment ?? "bottom_center";
9688
+ const anchorPos = getTitleAnchorAndPosition({
9689
+ anchor,
9690
+ x,
9691
+ y,
9692
+ width,
9693
+ height,
9694
+ isInside
9695
+ });
9696
+ let titleOffsetY;
9697
+ let titleOffsetX;
9698
+ const textAnchor = anchorPos.textAnchor;
9699
+ if (isInside) {
9700
+ titleOffsetY = anchor.includes("top") ? -TITLE_PADDING : anchor.includes("bottom") ? TITLE_PADDING : 0;
9701
+ titleOffsetX = anchor.includes("left") ? TITLE_PADDING : anchor.includes("right") ? -TITLE_PADDING : 0;
9702
+ } else {
9703
+ titleOffsetY = anchor.includes("top") ? TITLE_PADDING : anchor.includes("bottom") ? -TITLE_PADDING : 0;
9704
+ titleOffsetX = anchor.includes("center_left") ? -TITLE_PADDING : anchor.includes("center_right") ? TITLE_PADDING : 0;
9705
+ }
9706
+ const titleX = anchorPos.x + titleOffsetX;
9707
+ const titleY = anchorPos.y + titleOffsetY;
9708
+ db.schematic_text.insert({
9709
+ anchor: textAnchor,
9710
+ text: props.title,
9711
+ font_size: props.titleFontSize ?? 0.18,
9712
+ color: props.titleColor ?? "#000000",
9713
+ position: {
9714
+ x: titleX,
9715
+ y: titleY
9716
+ },
9717
+ rotation: 0
9718
+ });
9719
+ }
9607
9720
  }
9608
9721
  };
9609
9722
 
@@ -9616,7 +9729,7 @@ import { identity as identity4 } from "transformation-matrix";
9616
9729
  var package_default = {
9617
9730
  name: "@tscircuit/core",
9618
9731
  type: "module",
9619
- version: "0.0.460",
9732
+ version: "0.0.462",
9620
9733
  types: "dist/index.d.ts",
9621
9734
  main: "dist/index.js",
9622
9735
  module: "dist/index.js",
@@ -9648,7 +9761,7 @@ var package_default = {
9648
9761
  "@tscircuit/layout": "^0.0.28",
9649
9762
  "@tscircuit/log-soup": "^1.0.2",
9650
9763
  "@tscircuit/math-utils": "^0.0.18",
9651
- "@tscircuit/props": "^0.0.218",
9764
+ "@tscircuit/props": "^0.0.219",
9652
9765
  "@tscircuit/schematic-autolayout": "^0.0.6",
9653
9766
  "@tscircuit/schematic-match-adapt": "^0.0.16",
9654
9767
  "@tscircuit/simple-3d-svg": "^0.0.6",
@@ -9659,7 +9772,7 @@ var package_default = {
9659
9772
  "@types/react-reconciler": "^0.28.9",
9660
9773
  "bun-match-svg": "0.0.8",
9661
9774
  "chokidar-cli": "^3.0.0",
9662
- "circuit-json": "^0.0.201",
9775
+ "circuit-json": "^0.0.204",
9663
9776
  "circuit-json-to-connectivity-map": "^0.0.22",
9664
9777
  "circuit-json-to-simple-3d": "^0.0.2",
9665
9778
  "circuit-to-svg": "^0.0.151",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.461",
4
+ "version": "0.0.463",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -33,7 +33,7 @@
33
33
  "@tscircuit/layout": "^0.0.28",
34
34
  "@tscircuit/log-soup": "^1.0.2",
35
35
  "@tscircuit/math-utils": "^0.0.18",
36
- "@tscircuit/props": "^0.0.218",
36
+ "@tscircuit/props": "^0.0.219",
37
37
  "@tscircuit/schematic-autolayout": "^0.0.6",
38
38
  "@tscircuit/schematic-match-adapt": "^0.0.16",
39
39
  "@tscircuit/simple-3d-svg": "^0.0.6",
@@ -44,7 +44,7 @@
44
44
  "@types/react-reconciler": "^0.28.9",
45
45
  "bun-match-svg": "0.0.8",
46
46
  "chokidar-cli": "^3.0.0",
47
- "circuit-json": "^0.0.201",
47
+ "circuit-json": "^0.0.204",
48
48
  "circuit-json-to-connectivity-map": "^0.0.22",
49
49
  "circuit-json-to-simple-3d": "^0.0.2",
50
50
  "circuit-to-svg": "^0.0.151",