@tscircuit/core 0.0.799 → 0.0.801

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 +80 -51
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -6841,8 +6841,8 @@ var NormalComponent__getMinimumFlexContainerSize = (component) => {
6841
6841
  );
6842
6842
  if (!pcbGroup) return null;
6843
6843
  return {
6844
- width: pcbGroup.width,
6845
- height: pcbGroup.height
6844
+ width: pcbGroup.width ?? 0,
6845
+ height: pcbGroup.height ?? 0
6846
6846
  };
6847
6847
  }
6848
6848
  return null;
@@ -7398,6 +7398,7 @@ function NormalComponent_doInitialPcbComponentAnchorAlignment(component) {
7398
7398
  }
7399
7399
 
7400
7400
  // lib/components/base-components/NormalComponent/NormalComponent.ts
7401
+ import { normalizeDegrees } from "@tscircuit/math-utils";
7401
7402
  var debug3 = Debug4("tscircuit:core");
7402
7403
  var rotation32 = z9.object({
7403
7404
  x: rotation2,
@@ -8326,6 +8327,9 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
8326
8327
  const globalTransform = this._computePcbGlobalTransformBeforeLayout();
8327
8328
  const decomposedTransform = decomposeTSR5(globalTransform);
8328
8329
  const accumulatedRotation = decomposedTransform.rotation.angle * 180 / Math.PI;
8330
+ const pcbRotation = pcb_component?.rotation ?? 0;
8331
+ const rotationWithOffset = pcbRotation + accumulatedRotation + (rotationOffset.z ?? 0);
8332
+ const cadRotationZ = computedLayer === "bottom" ? normalizeDegrees(-rotationWithOffset + 180) : normalizeDegrees(rotationWithOffset);
8329
8333
  const cad_model = db.cad_component.insert({
8330
8334
  // TODO z maybe depends on layer
8331
8335
  position: {
@@ -8336,7 +8340,7 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
8336
8340
  rotation: {
8337
8341
  x: rotationOffset.x,
8338
8342
  y: (computedLayer === "top" ? 0 : 180) + rotationOffset.y,
8339
- z: computedLayer === "bottom" ? -(accumulatedRotation + rotationOffset.z) + 180 : accumulatedRotation + rotationOffset.z
8343
+ z: cadRotationZ
8340
8344
  },
8341
8345
  pcb_component_id: this.pcb_component_id,
8342
8346
  source_component_id: this.source_component_id,
@@ -9050,7 +9054,7 @@ var getSimpleRouteJsonFromCircuitJson = ({
9050
9054
  }
9051
9055
  if (subcircuit_id) {
9052
9056
  const group = db.pcb_group.getWhere({ subcircuit_id });
9053
- if (group) {
9057
+ if (group?.width && group.height) {
9054
9058
  const groupBounds = {
9055
9059
  minX: group.center.x - group.width / 2,
9056
9060
  maxX: group.center.x + group.width / 2,
@@ -10999,7 +11003,33 @@ var applyComponentConstraintClusters = (group, packInput) => {
10999
11003
 
11000
11004
  // lib/components/primitive-components/Group/Group_doInitialPcbLayoutPack/applyPackOutput.ts
11001
11005
  import { translate as translate5, rotate as rotate2, compose as compose4 } from "transformation-matrix";
11002
- import { transformPCBElements } from "@tscircuit/circuit-json-util";
11006
+ import {
11007
+ transformPCBElements
11008
+ } from "@tscircuit/circuit-json-util";
11009
+ import { normalizeDegrees as normalizeDegrees2 } from "@tscircuit/math-utils";
11010
+ var updateCadRotation = ({
11011
+ db,
11012
+ pcbComponentId,
11013
+ rotationDegrees,
11014
+ layer
11015
+ }) => {
11016
+ if (rotationDegrees == null) return;
11017
+ if (!db?.cad_component?.list) return;
11018
+ const cadComponent = db.cad_component.getWhere({
11019
+ pcb_component_id: pcbComponentId
11020
+ });
11021
+ if (!cadComponent) return;
11022
+ const delta = layer?.toLowerCase?.() === "bottom" ? -rotationDegrees : rotationDegrees;
11023
+ const currentRotationZ = cadComponent.rotation?.z ?? 0;
11024
+ const nextRotation = {
11025
+ ...cadComponent.rotation ?? { x: 0, y: 0, z: 0 },
11026
+ z: normalizeDegrees2(currentRotationZ + delta)
11027
+ };
11028
+ db.cad_component.update(cadComponent.cad_component_id, {
11029
+ rotation: nextRotation
11030
+ });
11031
+ cadComponent.rotation = nextRotation;
11032
+ };
11003
11033
  var isDescendantGroup = (db, groupId, ancestorId) => {
11004
11034
  if (groupId === ancestorId) return true;
11005
11035
  const group = db.source_group.get(groupId);
@@ -11034,6 +11064,12 @@ var applyPackOutput = (group, packOutput, clusterMap) => {
11034
11064
  (elm) => "pcb_component_id" in elm && elm.pcb_component_id === memberId
11035
11065
  );
11036
11066
  transformPCBElements(related, transformMatrix2);
11067
+ updateCadRotation({
11068
+ db,
11069
+ pcbComponentId: memberId,
11070
+ rotationDegrees: rotationDegrees2,
11071
+ layer: member.layer
11072
+ });
11037
11073
  }
11038
11074
  continue;
11039
11075
  }
@@ -11059,6 +11095,12 @@ var applyPackOutput = (group, packOutput, clusterMap) => {
11059
11095
  (elm) => "pcb_component_id" in elm && elm.pcb_component_id === componentId
11060
11096
  );
11061
11097
  transformPCBElements(related, transformMatrix2);
11098
+ updateCadRotation({
11099
+ db,
11100
+ pcbComponentId: componentId,
11101
+ rotationDegrees: rotationDegrees2,
11102
+ layer: pcbComponent.layer
11103
+ });
11062
11104
  continue;
11063
11105
  }
11064
11106
  const pcbGroup = db.pcb_group.list().find((g) => g.source_group_id === componentId);
@@ -12424,7 +12466,7 @@ function Group_doInitialPcbComponentAnchorAlignment(group) {
12424
12466
  const pcbGroup = db.pcb_group.get(group.pcb_group_id);
12425
12467
  if (!pcbGroup) return;
12426
12468
  const { width, height, center } = pcbGroup;
12427
- if (width === 0 || height === 0) return;
12469
+ if (!width || !height) return;
12428
12470
  const bounds = {
12429
12471
  left: center.x - width / 2,
12430
12472
  right: center.x + width / 2,
@@ -13400,7 +13442,7 @@ var Board = class extends Group6 {
13400
13442
  updateBounds(pcbComponent.center, pcbComponent.width, pcbComponent.height);
13401
13443
  }
13402
13444
  for (const pcbGroup of allPcbGroups) {
13403
- updateBounds(pcbGroup.center, pcbGroup.width, pcbGroup.height);
13445
+ updateBounds(pcbGroup.center, pcbGroup.width ?? 0, pcbGroup.height ?? 0);
13404
13446
  }
13405
13447
  if (props.boardAnchorPosition) {
13406
13448
  const { x, y } = props.boardAnchorPosition;
@@ -15024,8 +15066,8 @@ var Breakout = class extends Group6 {
15024
15066
  const padTop = props.paddingTop ?? props.padding ?? 0;
15025
15067
  const padBottom = props.paddingBottom ?? props.padding ?? 0;
15026
15068
  db.pcb_group.update(this.pcb_group_id, {
15027
- width: pcb_group.width + padLeft + padRight,
15028
- height: pcb_group.height + padTop + padBottom,
15069
+ width: (pcb_group.width ?? 0) + padLeft + padRight,
15070
+ height: (pcb_group.height ?? 0) + padTop + padBottom,
15029
15071
  center: {
15030
15072
  x: pcb_group.center.x + (padRight - padLeft) / 2,
15031
15073
  y: pcb_group.center.y + (padTop - padBottom) / 2
@@ -16223,26 +16265,11 @@ var Mosfet = class extends NormalComponent3 {
16223
16265
  };
16224
16266
 
16225
16267
  // lib/components/normal-components/Switch.ts
16226
- import {
16227
- switchProps
16228
- } from "@tscircuit/props";
16229
- var hasSimulationValues = (values) => {
16230
- if (!values) return false;
16231
- return values.closesAt !== void 0 || values.opensAt !== void 0 || values.startsClosed !== void 0 || values.switchingFrequency !== void 0;
16232
- };
16233
- var isSpiceContainer = (simulation) => {
16234
- if (!simulation || typeof simulation !== "object") {
16235
- return false;
16236
- }
16237
- return Object.prototype.hasOwnProperty.call(simulation, "spice");
16238
- };
16239
- var getSimulationValues = (simulation) => {
16240
- if (!simulation || typeof simulation !== "object") {
16241
- return null;
16242
- }
16243
- const maybeValues = isSpiceContainer(simulation) ? simulation.spice ?? null : simulation;
16244
- return hasSimulationValues(maybeValues) ? { ...maybeValues } : null;
16245
- };
16268
+ import { switchProps } from "@tscircuit/props";
16269
+ import { frequency as frequency2, ms } from "circuit-json";
16270
+ function hasSimProps(props) {
16271
+ return props.simSwitchFrequency !== void 0 || props.simCloseAt !== void 0 || props.simOpenAt !== void 0 || props.simStartClosed !== void 0 || props.simStartOpen !== void 0;
16272
+ }
16246
16273
  var Switch = class extends NormalComponent3 {
16247
16274
  _getSwitchType() {
16248
16275
  const props = this._parsedProps;
@@ -16275,35 +16302,37 @@ var Switch = class extends NormalComponent3 {
16275
16302
  const source_component = db.source_component.insert({
16276
16303
  ftype: "simple_switch",
16277
16304
  name: this.name,
16278
- switch_type: props.type,
16279
- is_normally_closed: props.isNormallyClosed ?? false,
16280
16305
  are_pins_interchangeable: this._getSwitchType() === "spst"
16281
16306
  });
16282
16307
  this.source_component_id = source_component.source_component_id;
16283
16308
  }
16284
16309
  doInitialSimulationRender() {
16285
- const props = this.props;
16286
- const simulationValues = getSimulationValues(props.simulation);
16287
- if (!simulationValues) {
16310
+ const { _parsedProps: props } = this;
16311
+ if (!hasSimProps(props)) {
16288
16312
  return;
16289
16313
  }
16290
16314
  const { db } = this.root;
16291
16315
  const simulationSwitch = {
16292
- type: "simulation_switch"
16316
+ type: "simulation_switch",
16317
+ source_component_id: this.source_component_id || ""
16293
16318
  };
16294
- if (simulationValues.closesAt !== void 0) {
16295
- simulationSwitch.closes_at = simulationValues.closesAt;
16319
+ if (props.simSwitchFrequency !== void 0) {
16320
+ simulationSwitch.switching_frequency = frequency2.parse(
16321
+ props.simSwitchFrequency
16322
+ );
16296
16323
  }
16297
- if (simulationValues.opensAt !== void 0) {
16298
- simulationSwitch.opens_at = simulationValues.opensAt;
16324
+ if (props.simCloseAt !== void 0) {
16325
+ simulationSwitch.closes_at = ms.parse(props.simCloseAt);
16299
16326
  }
16300
- if (simulationValues.startsClosed !== void 0) {
16301
- simulationSwitch.starts_closed = simulationValues.startsClosed;
16327
+ if (props.simOpenAt !== void 0) {
16328
+ simulationSwitch.opens_at = ms.parse(props.simOpenAt);
16302
16329
  }
16303
- if (simulationValues.switchingFrequency !== void 0) {
16304
- simulationSwitch.switching_frequency = simulationValues.switchingFrequency;
16330
+ if (props.simStartOpen !== void 0) {
16331
+ simulationSwitch.starts_closed = !props.simStartOpen;
16332
+ }
16333
+ if (props.simStartClosed !== void 0) {
16334
+ simulationSwitch.starts_closed = props.simStartClosed;
16305
16335
  }
16306
- ;
16307
16336
  db.simulation_switch.insert(simulationSwitch);
16308
16337
  }
16309
16338
  };
@@ -17024,7 +17053,7 @@ import { identity as identity6 } from "transformation-matrix";
17024
17053
  var package_default = {
17025
17054
  name: "@tscircuit/core",
17026
17055
  type: "module",
17027
- version: "0.0.798",
17056
+ version: "0.0.800",
17028
17057
  types: "dist/index.d.ts",
17029
17058
  main: "dist/index.js",
17030
17059
  module: "dist/index.js",
@@ -17056,13 +17085,13 @@ var package_default = {
17056
17085
  "@tscircuit/capacity-autorouter": "^0.0.132",
17057
17086
  "@tscircuit/checks": "^0.0.85",
17058
17087
  "@tscircuit/circuit-json-util": "^0.0.72",
17059
- "@tscircuit/common": "^0.0.11",
17088
+ "@tscircuit/common": "^0.0.14",
17060
17089
  "@tscircuit/footprinter": "^0.0.236",
17061
17090
  "@tscircuit/import-snippet": "^0.0.4",
17062
17091
  "@tscircuit/infgrid-ijump-astar": "^0.0.33",
17063
17092
  "@tscircuit/log-soup": "^1.0.2",
17064
17093
  "@tscircuit/matchpack": "^0.0.16",
17065
- "@tscircuit/math-utils": "^0.0.21",
17094
+ "@tscircuit/math-utils": "^0.0.28",
17066
17095
  "@tscircuit/miniflex": "^0.0.4",
17067
17096
  "@tscircuit/props": "0.0.369",
17068
17097
  "@tscircuit/schematic-autolayout": "^0.0.6",
@@ -17077,13 +17106,13 @@ var package_default = {
17077
17106
  "bun-match-svg": "0.0.12",
17078
17107
  "calculate-elbow": "^0.0.12",
17079
17108
  "chokidar-cli": "^3.0.0",
17080
- "circuit-json": "^0.0.283",
17109
+ "circuit-json": "^0.0.288",
17081
17110
  "circuit-json-to-bpc": "^0.0.13",
17082
17111
  "circuit-json-to-connectivity-map": "^0.0.22",
17083
- "circuit-json-to-gltf": "^0.0.7",
17112
+ "circuit-json-to-gltf": "^0.0.26",
17084
17113
  "circuit-json-to-simple-3d": "^0.0.9",
17085
17114
  "circuit-to-svg": "^0.0.245",
17086
- "circuit-json-to-spice": "^0.0.14",
17115
+ "circuit-json-to-spice": "^0.0.15",
17087
17116
  concurrently: "^9.1.2",
17088
17117
  "connectivity-map": "^1.0.0",
17089
17118
  debug: "^4.3.6",
@@ -17098,7 +17127,7 @@ var package_default = {
17098
17127
  react: "^19.1.0",
17099
17128
  "react-dom": "^19.1.0",
17100
17129
  "schematic-symbols": "^0.0.202",
17101
- spicey: "^0.0.8",
17130
+ spicey: "^0.0.10",
17102
17131
  "ts-expect": "^1.3.0",
17103
17132
  tsup: "^8.2.4"
17104
17133
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.799",
4
+ "version": "0.0.801",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -33,13 +33,13 @@
33
33
  "@tscircuit/capacity-autorouter": "^0.0.132",
34
34
  "@tscircuit/checks": "^0.0.85",
35
35
  "@tscircuit/circuit-json-util": "^0.0.72",
36
- "@tscircuit/common": "^0.0.11",
36
+ "@tscircuit/common": "^0.0.14",
37
37
  "@tscircuit/footprinter": "^0.0.236",
38
38
  "@tscircuit/import-snippet": "^0.0.4",
39
39
  "@tscircuit/infgrid-ijump-astar": "^0.0.33",
40
40
  "@tscircuit/log-soup": "^1.0.2",
41
41
  "@tscircuit/matchpack": "^0.0.16",
42
- "@tscircuit/math-utils": "^0.0.21",
42
+ "@tscircuit/math-utils": "^0.0.28",
43
43
  "@tscircuit/miniflex": "^0.0.4",
44
44
  "@tscircuit/props": "0.0.369",
45
45
  "@tscircuit/schematic-autolayout": "^0.0.6",
@@ -54,13 +54,13 @@
54
54
  "bun-match-svg": "0.0.12",
55
55
  "calculate-elbow": "^0.0.12",
56
56
  "chokidar-cli": "^3.0.0",
57
- "circuit-json": "^0.0.283",
57
+ "circuit-json": "^0.0.288",
58
58
  "circuit-json-to-bpc": "^0.0.13",
59
59
  "circuit-json-to-connectivity-map": "^0.0.22",
60
- "circuit-json-to-gltf": "^0.0.7",
60
+ "circuit-json-to-gltf": "^0.0.26",
61
61
  "circuit-json-to-simple-3d": "^0.0.9",
62
62
  "circuit-to-svg": "^0.0.245",
63
- "circuit-json-to-spice": "^0.0.14",
63
+ "circuit-json-to-spice": "^0.0.15",
64
64
  "concurrently": "^9.1.2",
65
65
  "connectivity-map": "^1.0.0",
66
66
  "debug": "^4.3.6",
@@ -75,7 +75,7 @@
75
75
  "react": "^19.1.0",
76
76
  "react-dom": "^19.1.0",
77
77
  "schematic-symbols": "^0.0.202",
78
- "spicey": "^0.0.8",
78
+ "spicey": "^0.0.10",
79
79
  "ts-expect": "^1.3.0",
80
80
  "tsup": "^8.2.4"
81
81
  },