@tscircuit/core 0.0.462 → 0.0.464

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 +122 -11
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -3026,7 +3026,8 @@ var getSizeOfSidesFromPortArrangement = (pa) => {
3026
3026
 
3027
3027
  // lib/utils/schematic/getAllDimensionsForSchematicBox.ts
3028
3028
  function isExplicitPinMappingArrangement(arrangement) {
3029
- return arrangement.leftSide !== void 0;
3029
+ const a = arrangement;
3030
+ return a.leftSide !== void 0 || a.rightSide !== void 0;
3030
3031
  }
3031
3032
  var getAllDimensionsForSchematicBox = (params) => {
3032
3033
  const portDistanceFromEdge = params.portDistanceFromEdge ?? 0.4;
@@ -9526,6 +9527,81 @@ var SchematicText = class extends PrimitiveComponent2 {
9526
9527
 
9527
9528
  // lib/components/primitive-components/SchematicBox.ts
9528
9529
  import { schematicBoxProps } from "@tscircuit/props";
9530
+
9531
+ // lib/components/primitive-components/getTitleAnchorAndPosition.ts
9532
+ function getTitleAnchorAndPosition({
9533
+ anchor,
9534
+ x,
9535
+ y,
9536
+ width,
9537
+ height,
9538
+ isInside
9539
+ }) {
9540
+ switch (anchor) {
9541
+ case "top_left":
9542
+ return {
9543
+ x,
9544
+ y: y + height,
9545
+ textAnchor: isInside ? "top_left" : "bottom_left"
9546
+ };
9547
+ case "top_center":
9548
+ return {
9549
+ x: x + width / 2,
9550
+ y: y + height,
9551
+ textAnchor: isInside ? "top_center" : "bottom_center"
9552
+ };
9553
+ case "top_right":
9554
+ return {
9555
+ x: x + width,
9556
+ y: y + height,
9557
+ textAnchor: isInside ? "top_right" : "bottom_right"
9558
+ };
9559
+ case "center_left":
9560
+ return {
9561
+ x,
9562
+ y: y + height / 2,
9563
+ textAnchor: isInside ? "center_left" : "center_right"
9564
+ };
9565
+ case "center":
9566
+ return {
9567
+ x: x + width / 2,
9568
+ y: y + height / 2,
9569
+ textAnchor: "center"
9570
+ };
9571
+ case "center_right":
9572
+ return {
9573
+ x: x + width,
9574
+ y: y + height / 2,
9575
+ textAnchor: isInside ? "center_right" : "center_left"
9576
+ };
9577
+ case "bottom_left":
9578
+ return {
9579
+ x,
9580
+ y,
9581
+ textAnchor: isInside ? "bottom_left" : "top_left"
9582
+ };
9583
+ case "bottom_center":
9584
+ return {
9585
+ x: x + width / 2,
9586
+ y,
9587
+ textAnchor: isInside ? "bottom_center" : "top_center"
9588
+ };
9589
+ case "bottom_right":
9590
+ return {
9591
+ x: x + width,
9592
+ y,
9593
+ textAnchor: isInside ? "bottom_right" : "top_right"
9594
+ };
9595
+ default:
9596
+ return {
9597
+ x: x + width / 2,
9598
+ y: y + height,
9599
+ textAnchor: "center"
9600
+ };
9601
+ }
9602
+ }
9603
+
9604
+ // lib/components/primitive-components/SchematicBox.ts
9529
9605
  var SchematicBox = class extends PrimitiveComponent2 {
9530
9606
  isSchematicPrimitive = true;
9531
9607
  get config() {
@@ -9539,11 +9615,6 @@ var SchematicBox = class extends PrimitiveComponent2 {
9539
9615
  if (this.root?.schematicDisabled) return;
9540
9616
  const { db } = this.root;
9541
9617
  const { _parsedProps: props } = this;
9542
- const result = schematicBoxProps.safeParse(props);
9543
- if (!result.success) {
9544
- console.error("Validation failed:", result.error.format());
9545
- throw result.error;
9546
- }
9547
9618
  const basePadding = 0.6;
9548
9619
  const generalPadding = typeof props.padding === "number" ? props.padding : 0;
9549
9620
  const paddingTop = typeof props.paddingTop === "number" ? props.paddingTop : generalPadding;
@@ -9556,6 +9627,8 @@ var SchematicBox = class extends PrimitiveComponent2 {
9556
9627
  let height;
9557
9628
  let x;
9558
9629
  let y;
9630
+ let centerX;
9631
+ let centerY;
9559
9632
  if (hasOverlay) {
9560
9633
  const portsWithSelectors = props.overlay.map((selector) => ({
9561
9634
  selector,
@@ -9589,11 +9662,13 @@ var SchematicBox = class extends PrimitiveComponent2 {
9589
9662
  height = bottom - top;
9590
9663
  x = left + (props.schX ?? 0);
9591
9664
  y = top + (props.schY ?? 0);
9665
+ centerX = x + width / 2;
9666
+ centerY = y + height / 2;
9592
9667
  } else if (hasFixedSize) {
9593
9668
  width = props.width;
9594
9669
  height = props.height;
9595
- const centerX = typeof props.schX === "number" ? props.schX : 0;
9596
- const centerY = typeof props.schY === "number" ? props.schY : 0;
9670
+ centerX = typeof props.schX === "number" ? props.schX : 0;
9671
+ centerY = typeof props.schY === "number" ? props.schY : 0;
9597
9672
  x = centerX - width / 2;
9598
9673
  y = centerY - height / 2;
9599
9674
  } else {
@@ -9607,6 +9682,42 @@ var SchematicBox = class extends PrimitiveComponent2 {
9607
9682
  is_dashed: props.strokeStyle === "dashed",
9608
9683
  schematic_component_id: ""
9609
9684
  });
9685
+ if (props.title) {
9686
+ const isInside = props.titleInside ?? false;
9687
+ const TITLE_PADDING = 0.1;
9688
+ const anchor = props.titleAlignment ?? "bottom_center";
9689
+ const anchorPos = getTitleAnchorAndPosition({
9690
+ anchor,
9691
+ x,
9692
+ y,
9693
+ width,
9694
+ height,
9695
+ isInside
9696
+ });
9697
+ let titleOffsetY;
9698
+ let titleOffsetX;
9699
+ const textAnchor = anchorPos.textAnchor;
9700
+ if (isInside) {
9701
+ titleOffsetY = anchor.includes("top") ? -TITLE_PADDING : anchor.includes("bottom") ? TITLE_PADDING : 0;
9702
+ titleOffsetX = anchor.includes("left") ? TITLE_PADDING : anchor.includes("right") ? -TITLE_PADDING : 0;
9703
+ } else {
9704
+ titleOffsetY = anchor.includes("top") ? TITLE_PADDING : anchor.includes("bottom") ? -TITLE_PADDING : 0;
9705
+ titleOffsetX = anchor.includes("center_left") ? -TITLE_PADDING : anchor.includes("center_right") ? TITLE_PADDING : 0;
9706
+ }
9707
+ const titleX = anchorPos.x + titleOffsetX;
9708
+ const titleY = anchorPos.y + titleOffsetY;
9709
+ db.schematic_text.insert({
9710
+ anchor: textAnchor,
9711
+ text: props.title,
9712
+ font_size: props.titleFontSize ?? 0.18,
9713
+ color: props.titleColor ?? "#000000",
9714
+ position: {
9715
+ x: titleX,
9716
+ y: titleY
9717
+ },
9718
+ rotation: 0
9719
+ });
9720
+ }
9610
9721
  }
9611
9722
  };
9612
9723
 
@@ -9619,7 +9730,7 @@ import { identity as identity4 } from "transformation-matrix";
9619
9730
  var package_default = {
9620
9731
  name: "@tscircuit/core",
9621
9732
  type: "module",
9622
- version: "0.0.461",
9733
+ version: "0.0.463",
9623
9734
  types: "dist/index.d.ts",
9624
9735
  main: "dist/index.js",
9625
9736
  module: "dist/index.js",
@@ -9651,7 +9762,7 @@ var package_default = {
9651
9762
  "@tscircuit/layout": "^0.0.28",
9652
9763
  "@tscircuit/log-soup": "^1.0.2",
9653
9764
  "@tscircuit/math-utils": "^0.0.18",
9654
- "@tscircuit/props": "^0.0.218",
9765
+ "@tscircuit/props": "^0.0.219",
9655
9766
  "@tscircuit/schematic-autolayout": "^0.0.6",
9656
9767
  "@tscircuit/schematic-match-adapt": "^0.0.16",
9657
9768
  "@tscircuit/simple-3d-svg": "^0.0.6",
@@ -9662,7 +9773,7 @@ var package_default = {
9662
9773
  "@types/react-reconciler": "^0.28.9",
9663
9774
  "bun-match-svg": "0.0.8",
9664
9775
  "chokidar-cli": "^3.0.0",
9665
- "circuit-json": "^0.0.201",
9776
+ "circuit-json": "^0.0.204",
9666
9777
  "circuit-json-to-connectivity-map": "^0.0.22",
9667
9778
  "circuit-json-to-simple-3d": "^0.0.2",
9668
9779
  "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.462",
4
+ "version": "0.0.464",
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",