@tscircuit/core 0.0.1099 → 0.0.1100

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 +49 -10
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -840,6 +840,42 @@ function parseExpression(tokens, vars) {
840
840
  return result;
841
841
  }
842
842
 
843
+ // lib/utils/getSubcircuitPcbCalcVariables.ts
844
+ function setSubcircuitPcbComponentCalcVariables(params) {
845
+ const { vars, componentName, position, size } = params;
846
+ vars[`${componentName}.x`] = position.x;
847
+ vars[`${componentName}.y`] = position.y;
848
+ vars[`${componentName}.width`] = size.width;
849
+ vars[`${componentName}.height`] = size.height;
850
+ vars[`${componentName}.minX`] = position.x - size.width / 2;
851
+ vars[`${componentName}.maxX`] = position.x + size.width / 2;
852
+ vars[`${componentName}.minY`] = position.y - size.height / 2;
853
+ vars[`${componentName}.maxY`] = position.y + size.height / 2;
854
+ }
855
+ function getSubcircuitPcbCalcVariables(db) {
856
+ const vars = {};
857
+ for (const sourceComponent of db.source_component.list()) {
858
+ if (!sourceComponent.name) continue;
859
+ const pcbComponent = db.pcb_component.getWhere({
860
+ source_component_id: sourceComponent.source_component_id
861
+ });
862
+ if (!pcbComponent) continue;
863
+ setSubcircuitPcbComponentCalcVariables({
864
+ vars,
865
+ componentName: sourceComponent.name,
866
+ position: {
867
+ x: pcbComponent.center.x,
868
+ y: pcbComponent.center.y
869
+ },
870
+ size: {
871
+ width: pcbComponent.width ?? 0,
872
+ height: pcbComponent.height ?? 0
873
+ }
874
+ });
875
+ }
876
+ return vars;
877
+ }
878
+
843
879
  // lib/utils/pcbSx/convert-pcb-style-to-pcb-sx.ts
844
880
  function convertPcbStyleToPcbSx(pcbStyle) {
845
881
  if (!pcbStyle) return void 0;
@@ -1221,7 +1257,8 @@ var PrimitiveComponent2 = class extends Renderable {
1221
1257
  );
1222
1258
  }
1223
1259
  const allowBoardVariables = options.allowBoardVariables ?? this._shouldAllowBoardVariablesByDefault();
1224
- const allowComponentVariables = options.allowComponentVariables ?? false;
1260
+ const isNormalComponent = this._isNormalComponent === true;
1261
+ const allowComponentVariables = options.allowComponentVariables ?? (!isNormalComponent && !this._isInsideFootprint());
1225
1262
  const includesBoardVariable = rawValue.includes("board.");
1226
1263
  const knownVariables = {};
1227
1264
  if (allowBoardVariables) {
@@ -1240,6 +1277,10 @@ var PrimitiveComponent2 = class extends Renderable {
1240
1277
  Object.assign(knownVariables, boardVariables);
1241
1278
  }
1242
1279
  if (allowComponentVariables) {
1280
+ const db = this.root?.db;
1281
+ if (db) {
1282
+ Object.assign(knownVariables, getSubcircuitPcbCalcVariables(db));
1283
+ }
1243
1284
  Object.assign(knownVariables, options.componentVariables ?? {});
1244
1285
  }
1245
1286
  try {
@@ -13109,14 +13150,12 @@ function updateVarsForNamedComponent(component, vars) {
13109
13150
  const height = pcbComponent.height ?? 0;
13110
13151
  const x = pcbComponent.center.x;
13111
13152
  const y = pcbComponent.center.y;
13112
- vars[`${component.name}.x`] = x;
13113
- vars[`${component.name}.y`] = y;
13114
- vars[`${component.name}.width`] = width;
13115
- vars[`${component.name}.height`] = height;
13116
- vars[`${component.name}.minX`] = x - width / 2;
13117
- vars[`${component.name}.maxX`] = x + width / 2;
13118
- vars[`${component.name}.minY`] = y - height / 2;
13119
- vars[`${component.name}.maxY`] = y + height / 2;
13153
+ setSubcircuitPcbComponentCalcVariables({
13154
+ vars,
13155
+ componentName: component.name,
13156
+ position: { x, y },
13157
+ size: { width, height }
13158
+ });
13120
13159
  const padElementsByReference = collectPadElementsByReference(component);
13121
13160
  for (const [referencePath, elements] of padElementsByReference.entries()) {
13122
13161
  const bounds = getBoundsOfPcbElements(elements);
@@ -18211,7 +18250,7 @@ import { identity as identity5 } from "transformation-matrix";
18211
18250
  var package_default = {
18212
18251
  name: "@tscircuit/core",
18213
18252
  type: "module",
18214
- version: "0.0.1098",
18253
+ version: "0.0.1099",
18215
18254
  types: "dist/index.d.ts",
18216
18255
  main: "dist/index.js",
18217
18256
  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.1099",
4
+ "version": "0.0.1100",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",