@tscircuit/core 0.0.743 → 0.0.745

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 +42 -21
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -81,7 +81,7 @@ import {
81
81
  rotation as rotation2,
82
82
  schematic_manual_edit_conflict_warning
83
83
  } from "circuit-json";
84
- import { decomposeTSR as decomposeTSR4 } from "transformation-matrix";
84
+ import { decomposeTSR as decomposeTSR5 } from "transformation-matrix";
85
85
  import Debug4 from "debug";
86
86
 
87
87
  // lib/fiber/create-instance-from-react-element.ts
@@ -1850,16 +1850,18 @@ var SmtPad = class extends PrimitiveComponent2 {
1850
1850
  const { db } = this.root;
1851
1851
  const { _parsedProps: props } = this;
1852
1852
  if (!props.portHints) return;
1853
- const container = this.getPrimitiveContainer();
1854
1853
  const subcircuit = this.getSubcircuit();
1855
1854
  const position = this._getGlobalPcbPositionBeforeLayout();
1856
- const containerCenter = container?._getGlobalPcbPositionBeforeLayout();
1857
- const decomposedMat = decomposeTSR(
1855
+ const decomposedTransform = decomposeTSR(
1858
1856
  this._computePcbGlobalTransformBeforeLayout()
1859
1857
  );
1860
- const isRotated90 = Math.abs(decomposedMat.rotation.angle * (180 / Math.PI) - 90) % 180 < 0.01;
1858
+ const rotationDegrees = decomposedTransform.rotation.angle * 180 / Math.PI;
1859
+ const normalizedRotationDegrees = (rotationDegrees % 360 + 360) % 360;
1860
+ const rotationTolerance = 0.01;
1861
+ const isAxisAligned = Math.abs(normalizedRotationDegrees) < rotationTolerance || Math.abs(normalizedRotationDegrees - 180) < rotationTolerance || Math.abs(normalizedRotationDegrees - 360) < rotationTolerance;
1862
+ const isRotated90Degrees = Math.abs(normalizedRotationDegrees - 90) < rotationTolerance || Math.abs(normalizedRotationDegrees - 270) < rotationTolerance;
1863
+ const finalRotationDegrees = Math.abs(normalizedRotationDegrees - 360) < rotationTolerance ? 0 : normalizedRotationDegrees;
1861
1864
  const { maybeFlipLayer } = this._getPcbPrimitiveFlippedHelpers();
1862
- const parentRotation = container?._parsedProps.pcbRotation ?? 0;
1863
1865
  let pcb_smtpad = null;
1864
1866
  const pcb_component_id = this.parent?.pcb_component_id ?? this.getPrimitiveContainer()?.pcb_component_id;
1865
1867
  if (props.shape === "circle") {
@@ -1888,14 +1890,14 @@ var SmtPad = class extends PrimitiveComponent2 {
1888
1890
  pcb_group_id: this.getGroup()?.pcb_group_id ?? void 0
1889
1891
  });
1890
1892
  } else if (props.shape === "rect") {
1891
- pcb_smtpad = parentRotation === 0 || isRotated90 ? db.pcb_smtpad.insert({
1893
+ pcb_smtpad = isAxisAligned || isRotated90Degrees ? db.pcb_smtpad.insert({
1892
1894
  pcb_component_id,
1893
1895
  pcb_port_id: this.matchedPort?.pcb_port_id,
1894
1896
  // port likely isn't matched
1895
1897
  layer: maybeFlipLayer(props.layer ?? "top"),
1896
1898
  shape: "rect",
1897
- width: isRotated90 ? props.height : props.width,
1898
- height: isRotated90 ? props.width : props.height,
1899
+ width: isRotated90Degrees ? props.height : props.width,
1900
+ height: isRotated90Degrees ? props.width : props.height,
1899
1901
  port_hints: props.portHints.map((ph) => ph.toString()),
1900
1902
  is_covered_with_solder_mask: props.coveredWithSolderMask ?? false,
1901
1903
  x: position.x,
@@ -1910,7 +1912,7 @@ var SmtPad = class extends PrimitiveComponent2 {
1910
1912
  height: props.height,
1911
1913
  x: position.x,
1912
1914
  y: position.y,
1913
- ccw_rotation: parentRotation,
1915
+ ccw_rotation: finalRotationDegrees,
1914
1916
  port_hints: props.portHints.map((ph) => ph.toString()),
1915
1917
  is_covered_with_solder_mask: props.coveredWithSolderMask ?? false,
1916
1918
  subcircuit_id: subcircuit?.subcircuit_id ?? void 0,
@@ -1937,7 +1939,7 @@ var SmtPad = class extends PrimitiveComponent2 {
1937
1939
  height: pcb_smtpad.height * 0.7,
1938
1940
  x: pcb_smtpad.x,
1939
1941
  y: pcb_smtpad.y,
1940
- ccw_rotation: parentRotation,
1942
+ ccw_rotation: finalRotationDegrees,
1941
1943
  pcb_component_id: pcb_smtpad.pcb_component_id,
1942
1944
  pcb_smtpad_id: pcb_smtpad.pcb_smtpad_id,
1943
1945
  subcircuit_id: subcircuit?.subcircuit_id ?? void 0,
@@ -2607,6 +2609,7 @@ var Hole = class extends PrimitiveComponent2 {
2607
2609
 
2608
2610
  // lib/components/primitive-components/SilkscreenText.ts
2609
2611
  import { silkscreenTextProps } from "@tscircuit/props";
2612
+ import { decomposeTSR as decomposeTSR3 } from "transformation-matrix";
2610
2613
  var SilkscreenText = class extends PrimitiveComponent2 {
2611
2614
  isPcbPrimitive = true;
2612
2615
  get config() {
@@ -2621,8 +2624,19 @@ var SilkscreenText = class extends PrimitiveComponent2 {
2621
2624
  const { _parsedProps: props } = this;
2622
2625
  const container = this.getPrimitiveContainer();
2623
2626
  const position = this._getGlobalPcbPositionBeforeLayout();
2624
- const { maybeFlipLayer } = this._getPcbPrimitiveFlippedHelpers();
2627
+ const { maybeFlipLayer, isFlipped } = this._getPcbPrimitiveFlippedHelpers();
2625
2628
  const subcircuit = this.getSubcircuit();
2629
+ let rotation5 = 0;
2630
+ if (props.pcbRotation !== void 0 && props.pcbRotation !== 0) {
2631
+ rotation5 = props.pcbRotation;
2632
+ } else {
2633
+ const globalTransform = this._computePcbGlobalTransformBeforeLayout();
2634
+ const decomposedTransform = decomposeTSR3(globalTransform);
2635
+ rotation5 = decomposedTransform.rotation.angle * 180 / Math.PI;
2636
+ }
2637
+ if (isFlipped) {
2638
+ rotation5 = (rotation5 + 180) % 360;
2639
+ }
2626
2640
  const uniqueLayers = new Set(props.layers);
2627
2641
  if (props.layer) uniqueLayers.add(props.layer);
2628
2642
  const targetLayers = uniqueLayers.size > 0 ? Array.from(uniqueLayers) : ["top"];
@@ -2637,7 +2651,7 @@ var SilkscreenText = class extends PrimitiveComponent2 {
2637
2651
  font_size: props.fontSize ?? 1,
2638
2652
  layer: maybeFlipLayer(layer),
2639
2653
  text: props.text ?? "",
2640
- ccw_rotation: props.pcbRotation,
2654
+ ccw_rotation: rotation5,
2641
2655
  pcb_component_id: container.pcb_component_id,
2642
2656
  subcircuit_id: subcircuit?.subcircuit_id ?? void 0,
2643
2657
  pcb_group_id: this.getGroup()?.pcb_group_id ?? void 0
@@ -2839,8 +2853,12 @@ var createPinrowSilkscreenText = ({
2839
2853
  // lib/utils/createComponentsFromCircuitJson.ts
2840
2854
  var calculateCcwRotation = (componentRotationStr, elementCcwRotation) => {
2841
2855
  const componentAngle = parseInt(componentRotationStr || "0", 10);
2842
- const baseRotation = -componentAngle;
2843
- const totalRotation = baseRotation + (elementCcwRotation ?? 0);
2856
+ let totalRotation;
2857
+ if (elementCcwRotation !== void 0 && elementCcwRotation !== null) {
2858
+ totalRotation = elementCcwRotation - componentAngle;
2859
+ } else {
2860
+ totalRotation = componentAngle;
2861
+ }
2844
2862
  const normalizedRotation = (totalRotation % 360 + 360) % 360;
2845
2863
  return normalizedRotation;
2846
2864
  };
@@ -4232,7 +4250,7 @@ var Footprint = class extends PrimitiveComponent2 {
4232
4250
  // lib/components/primitive-components/CadModel.ts
4233
4251
  import { cadmodelProps, point3 } from "@tscircuit/props";
4234
4252
  import { z as z7 } from "zod";
4235
- import { decomposeTSR as decomposeTSR3 } from "transformation-matrix";
4253
+ import { decomposeTSR as decomposeTSR4 } from "transformation-matrix";
4236
4254
  var rotation = z7.union([z7.number(), z7.string()]);
4237
4255
  var rotation3 = z7.object({ x: rotation, y: rotation, z: rotation });
4238
4256
  var CadModel = class extends PrimitiveComponent2 {
@@ -4253,7 +4271,7 @@ var CadModel = class extends PrimitiveComponent2 {
4253
4271
  const props = this._parsedProps;
4254
4272
  if (!props || typeof props.modelUrl !== "string") return;
4255
4273
  const parentTransform = parent._computePcbGlobalTransformBeforeLayout();
4256
- const decomposedTransform = decomposeTSR3(parentTransform);
4274
+ const decomposedTransform = decomposeTSR4(parentTransform);
4257
4275
  const accumulatedRotation = decomposedTransform.rotation.angle * 180 / Math.PI;
4258
4276
  const rotationOffset = rotation3.parse({ x: 0, y: 0, z: 0 });
4259
4277
  if (typeof props.rotationOffset === "number") {
@@ -7640,13 +7658,16 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
7640
7658
  const { db } = this.root;
7641
7659
  const { _parsedProps: props } = this;
7642
7660
  const subcircuit = this.getSubcircuit();
7661
+ const globalTransform = this._computePcbGlobalTransformBeforeLayout();
7662
+ const decomposedTransform = decomposeTSR5(globalTransform);
7663
+ const accumulatedRotation = decomposedTransform.rotation.angle * 180 / Math.PI;
7643
7664
  const pcb_component = db.pcb_component.insert({
7644
7665
  center: this._getGlobalPcbPositionBeforeLayout(),
7645
7666
  // width/height are computed in the PcbComponentSizeCalculation phase
7646
7667
  width: 0,
7647
7668
  height: 0,
7648
7669
  layer: props.layer ?? "top",
7649
- rotation: props.pcbRotation ?? 0,
7670
+ rotation: props.pcbRotation ?? accumulatedRotation,
7650
7671
  source_component_id: this.source_component_id,
7651
7672
  subcircuit_id: subcircuit.subcircuit_id ?? void 0,
7652
7673
  do_not_place: props.doNotPlace ?? false
@@ -8033,7 +8054,7 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
8033
8054
  });
8034
8055
  const computedLayer = this.props.layer === "bottom" ? "bottom" : "top";
8035
8056
  const globalTransform = this._computePcbGlobalTransformBeforeLayout();
8036
- const decomposedTransform = decomposeTSR4(globalTransform);
8057
+ const decomposedTransform = decomposeTSR5(globalTransform);
8037
8058
  const accumulatedRotation = decomposedTransform.rotation.angle * 180 / Math.PI;
8038
8059
  const cad_model = db.cad_component.insert({
8039
8060
  // TODO z maybe depends on layer
@@ -15703,7 +15724,7 @@ import { identity as identity6 } from "transformation-matrix";
15703
15724
  var package_default = {
15704
15725
  name: "@tscircuit/core",
15705
15726
  type: "module",
15706
- version: "0.0.742",
15727
+ version: "0.0.744",
15707
15728
  types: "dist/index.d.ts",
15708
15729
  main: "dist/index.js",
15709
15730
  module: "dist/index.js",
@@ -15760,7 +15781,7 @@ var package_default = {
15760
15781
  "circuit-json-to-bpc": "^0.0.13",
15761
15782
  "circuit-json-to-connectivity-map": "^0.0.22",
15762
15783
  "circuit-json-to-simple-3d": "^0.0.9",
15763
- "circuit-to-svg": "^0.0.197",
15784
+ "circuit-to-svg": "^0.0.200",
15764
15785
  concurrently: "^9.1.2",
15765
15786
  "connectivity-map": "^1.0.0",
15766
15787
  debug: "^4.3.6",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.743",
4
+ "version": "0.0.745",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -58,7 +58,7 @@
58
58
  "circuit-json-to-bpc": "^0.0.13",
59
59
  "circuit-json-to-connectivity-map": "^0.0.22",
60
60
  "circuit-json-to-simple-3d": "^0.0.9",
61
- "circuit-to-svg": "^0.0.197",
61
+ "circuit-to-svg": "^0.0.200",
62
62
  "concurrently": "^9.1.2",
63
63
  "connectivity-map": "^1.0.0",
64
64
  "debug": "^4.3.6",