@tscircuit/core 0.0.1105 → 0.0.1106

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.
package/dist/index.d.ts CHANGED
@@ -512,12 +512,13 @@ declare abstract class PrimitiveComponent<ZodProps extends ZodType = any> extend
512
512
  protected _validatePcbCoordinateReferences(params: {
513
513
  rawValue: unknown;
514
514
  axis: "pcbX" | "pcbY";
515
- propertyNameForError?: string;
515
+ propertyName?: string;
516
516
  }): void;
517
517
  protected _resolvePcbCoordinate(rawValue: unknown, axis: "pcbX" | "pcbY", options?: {
518
518
  allowBoardVariables?: boolean;
519
519
  allowComponentVariables?: boolean;
520
520
  componentVariables?: Record<string, number>;
521
+ propertyName?: string;
521
522
  }): number;
522
523
  private _shouldAllowBoardVariablesByDefault;
523
524
  private _isInsideFootprint;
@@ -527,10 +528,13 @@ declare abstract class PrimitiveComponent<ZodProps extends ZodType = any> extend
527
528
  * Position can be specified via pcbX/pcbY or edge-based props.
528
529
  */
529
530
  _hasUserDefinedPcbPosition(): boolean;
530
- resolvePcbCoordinate(rawValue: unknown, axis: "pcbX" | "pcbY", options?: {
531
+ resolvePcbCoordinate(params: {
532
+ rawValue: unknown;
533
+ axis: "pcbX" | "pcbY";
531
534
  allowBoardVariables?: boolean;
532
535
  allowComponentVariables?: boolean;
533
536
  componentVariables?: Record<string, number>;
537
+ propertyName?: string;
534
538
  }): number;
535
539
  /**
536
540
  * Computes a transformation matrix from the props of this component for PCB
package/dist/index.js CHANGED
@@ -1271,16 +1271,16 @@ var PrimitiveComponent2 = class extends Renderable {
1271
1271
  this._validatePcbCoordinateReferences({
1272
1272
  rawValue: rawPcbX,
1273
1273
  axis: "pcbX",
1274
- propertyNameForError: "pcbX"
1274
+ propertyName: "pcbX"
1275
1275
  });
1276
1276
  this._validatePcbCoordinateReferences({
1277
1277
  rawValue: rawPcbY,
1278
1278
  axis: "pcbY",
1279
- propertyNameForError: "pcbY"
1279
+ propertyName: "pcbY"
1280
1280
  });
1281
1281
  }
1282
1282
  _validatePcbCoordinateReferences(params) {
1283
- const { rawValue, axis, propertyNameForError = axis } = params;
1283
+ const { rawValue, axis, propertyName = axis } = params;
1284
1284
  if (typeof rawValue !== "string") return;
1285
1285
  const isNormalComponent = this._isNormalComponent === true;
1286
1286
  const allowComponentVariables = !isNormalComponent && !this._isInsideFootprint();
@@ -1289,8 +1289,8 @@ var PrimitiveComponent2 = class extends Renderable {
1289
1289
  calcIdentifiers = extractCalcIdentifiers(rawValue);
1290
1290
  } catch {
1291
1291
  this._reportInvalidComponentPropertyError(
1292
- propertyNameForError,
1293
- `Invalid ${propertyNameForError} value for ${this.componentName}: Invalid calc() expression. expression="${rawValue}"`
1292
+ propertyName,
1293
+ `Invalid ${propertyName} value for ${this.componentName}: Invalid calc() expression. expression="${rawValue}"`
1294
1294
  );
1295
1295
  return;
1296
1296
  }
@@ -1299,14 +1299,18 @@ var PrimitiveComponent2 = class extends Renderable {
1299
1299
  );
1300
1300
  if (includesComponentVariable && !allowComponentVariables) {
1301
1301
  this._reportInvalidComponentPropertyError(
1302
- propertyNameForError,
1303
- `Invalid ${propertyNameForError} value for ${this.componentName}: component-relative calc references are not supported for footprint elements (${this.componentName}); ${propertyNameForError} will be ignored. expression="${rawValue}"`
1302
+ propertyName,
1303
+ `Invalid ${propertyName} value for ${this.componentName}: component-relative calc references are not supported for footprint elements (${this.componentName}); ${propertyName} will be ignored. expression="${rawValue}"`
1304
1304
  );
1305
1305
  }
1306
1306
  }
1307
1307
  _resolvePcbCoordinate(rawValue, axis, options = {}) {
1308
1308
  if (rawValue == null) return 0;
1309
- if (typeof rawValue === "number") return rawValue;
1309
+ const propertyName = options.propertyName ?? axis;
1310
+ if (typeof rawValue === "number") {
1311
+ if (Number.isFinite(rawValue)) return rawValue;
1312
+ return 0;
1313
+ }
1310
1314
  if (typeof rawValue !== "string") {
1311
1315
  throw new Error(
1312
1316
  `Invalid ${axis} value for ${this.componentName}: ${String(rawValue)}`
@@ -1321,14 +1325,18 @@ var PrimitiveComponent2 = class extends Renderable {
1321
1325
  const board = this._getBoard();
1322
1326
  const boardVariables = board?._getBoardCalcVariables() ?? {};
1323
1327
  if (includesBoardVariable && !board) {
1324
- throw new Error(
1325
- `Cannot resolve ${axis} for ${this.componentName}: no board found for board.* variables`
1328
+ this._reportInvalidComponentPropertyError(
1329
+ propertyName,
1330
+ `Invalid ${propertyName} value for ${this.componentName}: no board found for board.* variables. expression="${rawValue}"`
1326
1331
  );
1332
+ return 0;
1327
1333
  }
1328
1334
  if (includesBoardVariable && board && Object.keys(boardVariables).length === 0) {
1329
- throw new Error(
1330
- "Cannot do calculations based on board size when the board is auto-sized"
1335
+ this._reportInvalidComponentPropertyError(
1336
+ propertyName,
1337
+ `Invalid ${propertyName} value for ${this.componentName}: Cannot do calculations based on board size when the board is auto-sized. expression="${rawValue}"`
1331
1338
  );
1339
+ return 0;
1332
1340
  }
1333
1341
  Object.assign(knownVariables, boardVariables);
1334
1342
  }
@@ -1359,9 +1367,11 @@ var PrimitiveComponent2 = class extends Renderable {
1359
1367
  return evaluateCalcString(rawValue, { knownVariables });
1360
1368
  } catch (error) {
1361
1369
  const message = error instanceof Error ? error.message : String(error);
1362
- throw new Error(
1363
- `Invalid ${axis} value for ${this.componentName}: ${message}`
1370
+ this._reportInvalidComponentPropertyError(
1371
+ propertyName,
1372
+ `Invalid ${propertyName} value for ${this.componentName}: ${message}. expression="${rawValue}"`
1364
1373
  );
1374
+ return 0;
1365
1375
  }
1366
1376
  }
1367
1377
  _shouldAllowBoardVariablesByDefault() {
@@ -1401,8 +1411,21 @@ var PrimitiveComponent2 = class extends Renderable {
1401
1411
  const props = this._parsedProps;
1402
1412
  return props.pcbX !== void 0 || props.pcbY !== void 0 || props.pcbLeftEdgeX !== void 0 || props.pcbRightEdgeX !== void 0 || props.pcbTopEdgeY !== void 0 || props.pcbBottomEdgeY !== void 0;
1403
1413
  }
1404
- resolvePcbCoordinate(rawValue, axis, options = {}) {
1405
- return this._resolvePcbCoordinate(rawValue, axis, options);
1414
+ resolvePcbCoordinate(params) {
1415
+ const {
1416
+ rawValue,
1417
+ axis,
1418
+ allowBoardVariables,
1419
+ allowComponentVariables,
1420
+ componentVariables,
1421
+ propertyName
1422
+ } = params;
1423
+ return this._resolvePcbCoordinate(rawValue, axis, {
1424
+ allowBoardVariables,
1425
+ allowComponentVariables,
1426
+ componentVariables,
1427
+ propertyName
1428
+ });
1406
1429
  }
1407
1430
  /**
1408
1431
  * Computes a transformation matrix from the props of this component for PCB
@@ -7001,14 +7024,14 @@ var SilkscreenText = class extends PrimitiveComponent2 {
7001
7024
  isFlipped ? flipY2() : identity4()
7002
7025
  ),
7003
7026
  {
7004
- x: this.resolvePcbCoordinate(
7005
- resolvedPcbSxPcbX ?? props.pcbX ?? 0,
7006
- "pcbX"
7007
- ),
7008
- y: this.resolvePcbCoordinate(
7009
- resolvedPcbSxPcbY ?? props.pcbY ?? 0,
7010
- "pcbY"
7011
- )
7027
+ x: this.resolvePcbCoordinate({
7028
+ rawValue: resolvedPcbSxPcbX ?? props.pcbX ?? 0,
7029
+ axis: "pcbX"
7030
+ }),
7031
+ y: this.resolvePcbCoordinate({
7032
+ rawValue: resolvedPcbSxPcbY ?? props.pcbY ?? 0,
7033
+ axis: "pcbY"
7034
+ })
7012
7035
  }
7013
7036
  ) : this._getGlobalPcbPositionBeforeLayout();
7014
7037
  const uniformPadding = props.knockoutPadding ?? 0;
@@ -11210,28 +11233,28 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
11210
11233
  this._validatePcbCoordinateReferences({
11211
11234
  rawValue: pcbLeftEdgeX,
11212
11235
  axis: "pcbX",
11213
- propertyNameForError: "pcbLeftEdgeX"
11236
+ propertyName: "pcbLeftEdgeX"
11214
11237
  });
11215
11238
  }
11216
11239
  if (pcbRightEdgeX !== void 0) {
11217
11240
  this._validatePcbCoordinateReferences({
11218
11241
  rawValue: pcbRightEdgeX,
11219
11242
  axis: "pcbX",
11220
- propertyNameForError: "pcbRightEdgeX"
11243
+ propertyName: "pcbRightEdgeX"
11221
11244
  });
11222
11245
  }
11223
11246
  if (pcbTopEdgeY !== void 0) {
11224
11247
  this._validatePcbCoordinateReferences({
11225
11248
  rawValue: pcbTopEdgeY,
11226
11249
  axis: "pcbY",
11227
- propertyNameForError: "pcbTopEdgeY"
11250
+ propertyName: "pcbTopEdgeY"
11228
11251
  });
11229
11252
  }
11230
11253
  if (pcbBottomEdgeY !== void 0) {
11231
11254
  this._validatePcbCoordinateReferences({
11232
11255
  rawValue: pcbBottomEdgeY,
11233
11256
  axis: "pcbY",
11234
- propertyNameForError: "pcbBottomEdgeY"
11257
+ propertyName: "pcbBottomEdgeY"
11235
11258
  });
11236
11259
  }
11237
11260
  }
@@ -11263,8 +11286,16 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
11263
11286
  const parentGroup = this.getGroup();
11264
11287
  const positionedRelativeToGroupId = parentGroup?.pcb_group_id ?? void 0;
11265
11288
  const positionedRelativeToBoardId = positionedRelativeToGroupId ? void 0 : this._getBoard()?.pcb_board_id ?? void 0;
11266
- const resolvedPcbX = this._resolvedPcbCalcOffsetX ?? (props.pcbX !== void 0 ? this._resolvePcbCoordinate(props.pcbX, "pcbX") : pcbLeftEdgeX !== void 0 ? this._resolvePcbCoordinate(pcbLeftEdgeX, "pcbX") + componentWidth / 2 : pcbRightEdgeX !== void 0 ? this._resolvePcbCoordinate(pcbRightEdgeX, "pcbX") - componentWidth / 2 : void 0);
11267
- const resolvedPcbY = this._resolvedPcbCalcOffsetY ?? (props.pcbY !== void 0 ? this._resolvePcbCoordinate(props.pcbY, "pcbY") : pcbTopEdgeY !== void 0 ? this._resolvePcbCoordinate(pcbTopEdgeY, "pcbY") - componentHeight / 2 : pcbBottomEdgeY !== void 0 ? this._resolvePcbCoordinate(pcbBottomEdgeY, "pcbY") + componentHeight / 2 : void 0);
11289
+ const resolvedPcbX = this._resolvedPcbCalcOffsetX ?? (props.pcbX !== void 0 ? this._resolvePcbCoordinate(props.pcbX, "pcbX") : pcbLeftEdgeX !== void 0 ? this._resolvePcbCoordinate(pcbLeftEdgeX, "pcbX", {
11290
+ propertyName: "pcbLeftEdgeX"
11291
+ }) + componentWidth / 2 : pcbRightEdgeX !== void 0 ? this._resolvePcbCoordinate(pcbRightEdgeX, "pcbX", {
11292
+ propertyName: "pcbRightEdgeX"
11293
+ }) - componentWidth / 2 : void 0);
11294
+ const resolvedPcbY = this._resolvedPcbCalcOffsetY ?? (props.pcbY !== void 0 ? this._resolvePcbCoordinate(props.pcbY, "pcbY") : pcbTopEdgeY !== void 0 ? this._resolvePcbCoordinate(pcbTopEdgeY, "pcbY", {
11295
+ propertyName: "pcbTopEdgeY"
11296
+ }) - componentHeight / 2 : pcbBottomEdgeY !== void 0 ? this._resolvePcbCoordinate(pcbBottomEdgeY, "pcbY", {
11297
+ propertyName: "pcbBottomEdgeY"
11298
+ }) + componentHeight / 2 : void 0);
11268
11299
  db.pcb_component.update(this.pcb_component_id, {
11269
11300
  position_mode: "relative_to_group_anchor",
11270
11301
  positioned_relative_to_pcb_group_id: positionedRelativeToGroupId,
@@ -13092,65 +13123,65 @@ function Group_doInitialPcbCalcPlacementResolution(group) {
13092
13123
  y: pcbComponent.center.y
13093
13124
  };
13094
13125
  if (rawPcbX !== void 0) {
13095
- const resolvedPcbX = component.resolvePcbCoordinate(rawPcbX, "pcbX", {
13126
+ const resolvedPcbX = component.resolvePcbCoordinate({
13127
+ rawValue: rawPcbX,
13128
+ axis: "pcbX",
13096
13129
  allowComponentVariables: true,
13097
13130
  componentVariables: componentVars
13098
13131
  });
13099
13132
  component._resolvedPcbCalcOffsetX = resolvedPcbX;
13100
13133
  nextCenter.x = resolvedPcbX;
13101
13134
  } else if (rawPcbLeftEdgeX !== void 0) {
13102
- const resolvedPcbLeftEdgeX = component.resolvePcbCoordinate(
13103
- rawPcbLeftEdgeX,
13104
- "pcbX",
13105
- {
13106
- allowComponentVariables: true,
13107
- componentVariables: componentVars
13108
- }
13109
- );
13135
+ const resolvedPcbLeftEdgeX = component.resolvePcbCoordinate({
13136
+ rawValue: rawPcbLeftEdgeX,
13137
+ axis: "pcbX",
13138
+ allowComponentVariables: true,
13139
+ componentVariables: componentVars,
13140
+ propertyName: "pcbLeftEdgeX"
13141
+ });
13110
13142
  const resolvedPcbX = resolvedPcbLeftEdgeX + componentWidth / 2;
13111
13143
  component._resolvedPcbCalcOffsetX = resolvedPcbX;
13112
13144
  nextCenter.x = resolvedPcbX;
13113
13145
  } else if (rawPcbRightEdgeX !== void 0) {
13114
- const resolvedPcbRightEdgeX = component.resolvePcbCoordinate(
13115
- rawPcbRightEdgeX,
13116
- "pcbX",
13117
- {
13118
- allowComponentVariables: true,
13119
- componentVariables: componentVars
13120
- }
13121
- );
13146
+ const resolvedPcbRightEdgeX = component.resolvePcbCoordinate({
13147
+ rawValue: rawPcbRightEdgeX,
13148
+ axis: "pcbX",
13149
+ allowComponentVariables: true,
13150
+ componentVariables: componentVars,
13151
+ propertyName: "pcbRightEdgeX"
13152
+ });
13122
13153
  const resolvedPcbX = resolvedPcbRightEdgeX - componentWidth / 2;
13123
13154
  component._resolvedPcbCalcOffsetX = resolvedPcbX;
13124
13155
  nextCenter.x = resolvedPcbX;
13125
13156
  }
13126
13157
  if (rawPcbY !== void 0) {
13127
- const resolvedPcbY = component.resolvePcbCoordinate(rawPcbY, "pcbY", {
13158
+ const resolvedPcbY = component.resolvePcbCoordinate({
13159
+ rawValue: rawPcbY,
13160
+ axis: "pcbY",
13128
13161
  allowComponentVariables: true,
13129
13162
  componentVariables: componentVars
13130
13163
  });
13131
13164
  component._resolvedPcbCalcOffsetY = resolvedPcbY;
13132
13165
  nextCenter.y = resolvedPcbY;
13133
13166
  } else if (rawPcbTopEdgeY !== void 0) {
13134
- const resolvedPcbTopEdgeY = component.resolvePcbCoordinate(
13135
- rawPcbTopEdgeY,
13136
- "pcbY",
13137
- {
13138
- allowComponentVariables: true,
13139
- componentVariables: componentVars
13140
- }
13141
- );
13167
+ const resolvedPcbTopEdgeY = component.resolvePcbCoordinate({
13168
+ rawValue: rawPcbTopEdgeY,
13169
+ axis: "pcbY",
13170
+ allowComponentVariables: true,
13171
+ componentVariables: componentVars,
13172
+ propertyName: "pcbTopEdgeY"
13173
+ });
13142
13174
  const resolvedPcbY = resolvedPcbTopEdgeY - componentHeight / 2;
13143
13175
  component._resolvedPcbCalcOffsetY = resolvedPcbY;
13144
13176
  nextCenter.y = resolvedPcbY;
13145
13177
  } else if (rawPcbBottomEdgeY !== void 0) {
13146
- const resolvedPcbBottomEdgeY = component.resolvePcbCoordinate(
13147
- rawPcbBottomEdgeY,
13148
- "pcbY",
13149
- {
13150
- allowComponentVariables: true,
13151
- componentVariables: componentVars
13152
- }
13153
- );
13178
+ const resolvedPcbBottomEdgeY = component.resolvePcbCoordinate({
13179
+ rawValue: rawPcbBottomEdgeY,
13180
+ axis: "pcbY",
13181
+ allowComponentVariables: true,
13182
+ componentVariables: componentVars,
13183
+ propertyName: "pcbBottomEdgeY"
13184
+ });
13154
13185
  const resolvedPcbY = resolvedPcbBottomEdgeY + componentHeight / 2;
13155
13186
  component._resolvedPcbCalcOffsetY = resolvedPcbY;
13156
13187
  nextCenter.y = resolvedPcbY;
@@ -18359,7 +18390,7 @@ import { identity as identity5 } from "transformation-matrix";
18359
18390
  var package_default = {
18360
18391
  name: "@tscircuit/core",
18361
18392
  type: "module",
18362
- version: "0.0.1104",
18393
+ version: "0.0.1105",
18363
18394
  types: "dist/index.d.ts",
18364
18395
  main: "dist/index.js",
18365
18396
  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.1105",
4
+ "version": "0.0.1106",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",