@tscircuit/core 0.0.321 → 0.0.323

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 +70 -47
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1823,8 +1823,55 @@ var Hole = class extends PrimitiveComponent {
1823
1823
  }
1824
1824
  };
1825
1825
 
1826
+ // lib/components/primitive-components/SilkscreenText.ts
1827
+ import { silkscreenTextProps } from "@tscircuit/props";
1828
+ var SilkscreenText = class extends PrimitiveComponent {
1829
+ isPcbPrimitive = true;
1830
+ get config() {
1831
+ return {
1832
+ componentName: "SilkscreenText",
1833
+ zodProps: silkscreenTextProps
1834
+ };
1835
+ }
1836
+ doInitialPcbPrimitiveRender() {
1837
+ if (this.root?.pcbDisabled) return;
1838
+ const { db } = this.root;
1839
+ const { _parsedProps: props } = this;
1840
+ const container = this.getPrimitiveContainer();
1841
+ const position = this._getGlobalPcbPositionBeforeLayout();
1842
+ const { maybeFlipLayer } = this._getPcbPrimitiveFlippedHelpers();
1843
+ const subcircuit = this.getSubcircuit();
1844
+ db.pcb_silkscreen_text.insert({
1845
+ anchor_alignment: props.anchorAlignment,
1846
+ anchor_position: {
1847
+ x: position.x,
1848
+ y: position.y
1849
+ },
1850
+ font: props.font ?? "tscircuit2024",
1851
+ font_size: props.fontSize ?? 1,
1852
+ layer: maybeFlipLayer(props.layer ?? "top"),
1853
+ text: props.text ?? "",
1854
+ ccw_rotation: props.pcbRotation,
1855
+ pcb_component_id: container.pcb_component_id,
1856
+ subcircuit_id: subcircuit?.subcircuit_id ?? void 0,
1857
+ pcb_group_id: this.getGroup()?.pcb_group_id ?? void 0
1858
+ });
1859
+ }
1860
+ getPcbSize() {
1861
+ const { _parsedProps: props } = this;
1862
+ const fontSize = props.fontSize ?? 1;
1863
+ const text = props.text ?? "";
1864
+ const textWidth = text.length * fontSize;
1865
+ const textHeight = fontSize;
1866
+ return { width: textWidth * fontSize, height: textHeight * fontSize };
1867
+ }
1868
+ };
1869
+
1826
1870
  // lib/utils/createComponentsFromSoup.ts
1827
- var createComponentsFromSoup = (soup) => {
1871
+ var createComponentsFromSoup = ({
1872
+ componentName,
1873
+ componentRotation
1874
+ }, soup) => {
1828
1875
  const components = [];
1829
1876
  for (const elm of soup) {
1830
1877
  if (elm.type === "pcb_smtpad" && elm.shape === "rect") {
@@ -1898,6 +1945,21 @@ var createComponentsFromSoup = (soup) => {
1898
1945
  diameter: elm.hole_diameter
1899
1946
  })
1900
1947
  );
1948
+ } else if (elm.type === "pcb_silkscreen_text") {
1949
+ let readableRotation = componentRotation ? parseInt(componentRotation) : 0;
1950
+ const normalizedRotation = (readableRotation % 360 + 360) % 360;
1951
+ const isUpsideDown = normalizedRotation > 90 && normalizedRotation <= 270;
1952
+ readableRotation = isUpsideDown ? (normalizedRotation + 180) % 360 : normalizedRotation;
1953
+ components.push(
1954
+ new SilkscreenText({
1955
+ anchorAlignment: "center",
1956
+ text: componentName,
1957
+ fontSize: elm.font_size + 0.2,
1958
+ pcbX: isNaN(elm.anchor_position.x) ? 0 : elm.anchor_position.x,
1959
+ pcbY: elm.anchor_position.y,
1960
+ pcbRotation: readableRotation ?? 0
1961
+ })
1962
+ );
1901
1963
  }
1902
1964
  }
1903
1965
  return components;
@@ -1910,7 +1972,7 @@ function getBoundsOfPcbComponents(components) {
1910
1972
  let maxX = -Infinity;
1911
1973
  let maxY = -Infinity;
1912
1974
  for (const child of components) {
1913
- if (child.isPcbPrimitive) {
1975
+ if (child.isPcbPrimitive && child.componentName !== "SilkscreenText") {
1914
1976
  const { x, y } = child._getGlobalPcbPositionBeforeLayout();
1915
1977
  const { width: width2, height: height2 } = child.getPcbSize();
1916
1978
  minX = Math.min(minX, x - width2 / 2);
@@ -3078,12 +3140,16 @@ var NormalComponent = class extends PrimitiveComponent {
3078
3140
  return null;
3079
3141
  }
3080
3142
  _addChildrenFromStringFootprint() {
3143
+ const { name: componentName, pcbRotation: componentRotation } = this.props;
3081
3144
  let { footprint } = this.props;
3082
3145
  footprint ??= this._getImpliedFootprintString?.();
3083
3146
  if (!footprint) return;
3084
3147
  if (typeof footprint === "string") {
3085
3148
  const fpSoup = fp.string(footprint).soup();
3086
- const fpComponents = createComponentsFromSoup(fpSoup);
3149
+ const fpComponents = createComponentsFromSoup(
3150
+ { componentName, componentRotation },
3151
+ fpSoup
3152
+ );
3087
3153
  this.addAll(fpComponents);
3088
3154
  }
3089
3155
  }
@@ -3985,6 +4051,7 @@ var Group = class extends NormalComponent {
3985
4051
  if (!output_pcb_traces) return;
3986
4052
  const { db } = this.root;
3987
4053
  for (const pcb_trace of output_pcb_traces) {
4054
+ pcb_trace.subcircuit_id = this.subcircuit_id;
3988
4055
  db.pcb_trace.insert(pcb_trace);
3989
4056
  }
3990
4057
  }
@@ -6163,50 +6230,6 @@ var SilkscreenRect = class extends PrimitiveComponent {
6163
6230
  }
6164
6231
  };
6165
6232
 
6166
- // lib/components/primitive-components/SilkscreenText.ts
6167
- import { silkscreenTextProps } from "@tscircuit/props";
6168
- var SilkscreenText = class extends PrimitiveComponent {
6169
- isPcbPrimitive = true;
6170
- get config() {
6171
- return {
6172
- componentName: "SilkscreenText",
6173
- zodProps: silkscreenTextProps
6174
- };
6175
- }
6176
- doInitialPcbPrimitiveRender() {
6177
- if (this.root?.pcbDisabled) return;
6178
- const { db } = this.root;
6179
- const { _parsedProps: props } = this;
6180
- const container = this.getPrimitiveContainer();
6181
- const position = this._getGlobalPcbPositionBeforeLayout();
6182
- const { maybeFlipLayer } = this._getPcbPrimitiveFlippedHelpers();
6183
- const subcircuit = this.getSubcircuit();
6184
- db.pcb_silkscreen_text.insert({
6185
- anchor_alignment: props.anchorAlignment,
6186
- anchor_position: {
6187
- x: position.x,
6188
- y: position.y
6189
- },
6190
- font: props.font ?? "tscircuit2024",
6191
- font_size: props.fontSize ?? 1,
6192
- layer: maybeFlipLayer(props.layer ?? "top"),
6193
- text: props.text ?? "",
6194
- ccw_rotation: props.pcbRotation,
6195
- pcb_component_id: container.pcb_component_id,
6196
- subcircuit_id: subcircuit?.subcircuit_id ?? void 0,
6197
- pcb_group_id: this.getGroup()?.pcb_group_id ?? void 0
6198
- });
6199
- }
6200
- getPcbSize() {
6201
- const { _parsedProps: props } = this;
6202
- const fontSize = props.fontSize ?? 1;
6203
- const text = props.text ?? "";
6204
- const textWidth = text.length * fontSize;
6205
- const textHeight = fontSize;
6206
- return { width: textWidth * fontSize, height: textHeight * fontSize };
6207
- }
6208
- };
6209
-
6210
6233
  // lib/components/primitive-components/SilkscreenLine.ts
6211
6234
  import { silkscreenLineProps } from "@tscircuit/props";
6212
6235
  var SilkscreenLine = class extends PrimitiveComponent {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.321",
4
+ "version": "0.0.323",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -51,7 +51,7 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "@lume/kiwi": "^0.4.3",
54
- "@tscircuit/footprinter": "^0.0.124",
54
+ "@tscircuit/footprinter": "^0.0.128",
55
55
  "@tscircuit/infgrid-ijump-astar": "^0.0.33",
56
56
  "@tscircuit/math-utils": "^0.0.9",
57
57
  "@tscircuit/props": "^0.0.152",