@tscircuit/core 0.0.718 → 0.0.720

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 (3) hide show
  1. package/dist/index.d.ts +286 -138
  2. package/dist/index.js +161 -34
  3. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -11,6 +11,8 @@ __export(components_exports, {
11
11
  Board: () => Board,
12
12
  Breakout: () => Breakout,
13
13
  BreakoutPoint: () => BreakoutPoint,
14
+ CadAssembly: () => CadAssembly,
15
+ CadModel: () => CadModel,
14
16
  Capacitor: () => Capacitor,
15
17
  Chip: () => Chip,
16
18
  Constraint: () => Constraint3,
@@ -69,8 +71,8 @@ __export(components_exports, {
69
71
  import { fp } from "@tscircuit/footprinter";
70
72
  import {
71
73
  pcb_manual_edit_conflict_warning,
72
- point3,
73
- rotation,
74
+ point3 as point32,
75
+ rotation as rotation2,
74
76
  schematic_manual_edit_conflict_warning
75
77
  } from "circuit-json";
76
78
  import Debug4 from "debug";
@@ -127,8 +129,18 @@ var orderedRenderPhases = [
127
129
  "PartsEngineRender"
128
130
  ];
129
131
  var asyncPhaseDependencies = {
132
+ PcbFootprintLayout: ["PcbFootprintStringRender"],
133
+ PcbComponentSizeCalculation: ["PcbFootprintStringRender"],
134
+ PcbLayout: ["PcbFootprintStringRender"],
135
+ PcbBoardAutoSize: ["PcbFootprintStringRender"],
136
+ PcbTraceHintRender: ["PcbFootprintStringRender"],
137
+ PcbManualTraceRender: ["PcbFootprintStringRender"],
130
138
  PcbTraceRender: ["PcbFootprintStringRender"],
131
- CadModelRender: ["PcbFootprintStringRender"]
139
+ PcbRouteNetIslands: ["PcbFootprintStringRender"],
140
+ PcbDesignRuleChecks: ["PcbFootprintStringRender"],
141
+ SilkscreenOverlapAdjustment: ["PcbFootprintStringRender"],
142
+ CadModelRender: ["PcbFootprintStringRender"],
143
+ PartsEngineRender: ["PcbFootprintStringRender"]
132
144
  };
133
145
  var globalRenderCounter = 0;
134
146
  var Renderable = class {
@@ -699,10 +711,10 @@ var PrimitiveComponent2 = class extends Renderable {
699
711
  */
700
712
  computePcbPropsTransform() {
701
713
  const { _parsedProps: props } = this;
702
- const rotation4 = this._getPcbRotationBeforeLayout() ?? 0;
714
+ const rotation5 = this._getPcbRotationBeforeLayout() ?? 0;
703
715
  const matrix = compose(
704
716
  translate(props.pcbX ?? 0, props.pcbY ?? 0),
705
- rotate(rotation4 * Math.PI / 180)
717
+ rotate(rotation5 * Math.PI / 180)
706
718
  );
707
719
  return matrix;
708
720
  }
@@ -716,12 +728,12 @@ var PrimitiveComponent2 = class extends Renderable {
716
728
  _computePcbGlobalTransformBeforeLayout() {
717
729
  const manualPlacement = this.getSubcircuit()._getPcbManualPlacementForComponent(this);
718
730
  if (manualPlacement && this.props.pcbX === void 0 && this.props.pcbY === void 0) {
719
- const rotation4 = this._getPcbRotationBeforeLayout() ?? 0;
731
+ const rotation5 = this._getPcbRotationBeforeLayout() ?? 0;
720
732
  return compose(
721
733
  this.parent?._computePcbGlobalTransformBeforeLayout() ?? identity(),
722
734
  compose(
723
735
  translate(manualPlacement.x, manualPlacement.y),
724
- rotate(rotation4 * Math.PI / 180)
736
+ rotate(rotation5 * Math.PI / 180)
725
737
  )
726
738
  );
727
739
  }
@@ -3761,7 +3773,7 @@ import {
3761
3773
  isValidElement
3762
3774
  } from "react";
3763
3775
  import { symbols as symbols2 } from "schematic-symbols";
3764
- import { z as z8 } from "zod";
3776
+ import { z as z9 } from "zod";
3765
3777
 
3766
3778
  // lib/components/primitive-components/Footprint.ts
3767
3779
  import { footprintProps } from "@tscircuit/props";
@@ -3973,6 +3985,101 @@ var Footprint = class extends PrimitiveComponent2 {
3973
3985
  }
3974
3986
  };
3975
3987
 
3988
+ // lib/components/primitive-components/CadModel.ts
3989
+ import { cadmodelProps, point3 } from "@tscircuit/props";
3990
+ import { z as z7 } from "zod";
3991
+ var rotation = z7.union([z7.number(), z7.string()]);
3992
+ var rotation3 = z7.object({ x: rotation, y: rotation, z: rotation });
3993
+ var CadModel = class extends PrimitiveComponent2 {
3994
+ get config() {
3995
+ return {
3996
+ componentName: "CadModel",
3997
+ zodProps: cadmodelProps
3998
+ };
3999
+ }
4000
+ doInitialCadModelRender() {
4001
+ const parent = this._findParentWithPcbComponent();
4002
+ if (!parent) return;
4003
+ if (!parent.pcb_component_id) return;
4004
+ const { db } = this.root;
4005
+ const { boardThickness = 0 } = this.root?._getBoard() ?? {};
4006
+ const bounds = parent._getPcbCircuitJsonBounds();
4007
+ const pcb_component = db.pcb_component.get(parent.pcb_component_id);
4008
+ const props = this._parsedProps;
4009
+ if (!props || typeof props.modelUrl !== "string") return;
4010
+ const rotationOffset = rotation3.parse({ x: 0, y: 0, z: 0 });
4011
+ if (typeof props.rotationOffset === "number") {
4012
+ rotationOffset.z = Number(props.rotationOffset);
4013
+ } else if (typeof props.rotationOffset === "object") {
4014
+ const parsed = rotation3.parse(props.rotationOffset);
4015
+ rotationOffset.x = Number(parsed.x);
4016
+ rotationOffset.y = Number(parsed.y);
4017
+ rotationOffset.z = Number(parsed.z);
4018
+ }
4019
+ const positionOffset = point3.parse({
4020
+ x: props.pcbX ?? 0,
4021
+ y: props.pcbY ?? 0,
4022
+ z: props.pcbZ ?? 0,
4023
+ ...typeof props.positionOffset === "object" ? props.positionOffset : {}
4024
+ });
4025
+ const layer = parent.props.layer === "bottom" ? "bottom" : "top";
4026
+ const ext = new URL(props.modelUrl).pathname.split(".").pop()?.toLowerCase();
4027
+ const urlProps = {};
4028
+ if (ext === "stl")
4029
+ urlProps.model_stl_url = this._addCachebustToModelUrl(props.modelUrl);
4030
+ else if (ext === "obj")
4031
+ urlProps.model_obj_url = this._addCachebustToModelUrl(props.modelUrl);
4032
+ else if (ext === "gltf")
4033
+ urlProps.model_gltf_url = this._addCachebustToModelUrl(props.modelUrl);
4034
+ else if (ext === "glb")
4035
+ urlProps.model_glb_url = this._addCachebustToModelUrl(props.modelUrl);
4036
+ else if (ext === "step" || ext === "stp")
4037
+ urlProps.model_step_url = this._addCachebustToModelUrl(props.modelUrl);
4038
+ else if (ext === "wrl" || ext === "vrml")
4039
+ urlProps.model_wrl_url = this._addCachebustToModelUrl(props.modelUrl);
4040
+ else urlProps.model_stl_url = this._addCachebustToModelUrl(props.modelUrl);
4041
+ const cad = db.cad_component.insert({
4042
+ position: {
4043
+ x: bounds.center.x + Number(positionOffset.x),
4044
+ y: bounds.center.y + Number(positionOffset.y),
4045
+ z: (layer === "bottom" ? -boardThickness / 2 : boardThickness / 2) + Number(positionOffset.z)
4046
+ },
4047
+ rotation: {
4048
+ x: Number(rotationOffset.x),
4049
+ y: (layer === "top" ? 0 : 180) + Number(rotationOffset.y),
4050
+ z: layer === "bottom" ? -((pcb_component?.rotation ?? 0) + Number(rotationOffset.z)) + 180 : (pcb_component?.rotation ?? 0) + Number(rotationOffset.z)
4051
+ },
4052
+ pcb_component_id: parent.pcb_component_id,
4053
+ source_component_id: parent.source_component_id,
4054
+ model_unit_to_mm_scale_factor: typeof props.modelUnitToMmScale === "number" ? props.modelUnitToMmScale : void 0,
4055
+ ...urlProps
4056
+ });
4057
+ this.cad_component_id = cad.cad_component_id;
4058
+ }
4059
+ _findParentWithPcbComponent() {
4060
+ let p = this.parent;
4061
+ while (p && !p.pcb_component_id) p = p.parent;
4062
+ return p;
4063
+ }
4064
+ _addCachebustToModelUrl(url) {
4065
+ if (!url || !url.includes("modelcdn.tscircuit.com")) return url;
4066
+ const origin = this.root?.getClientOrigin() ?? "";
4067
+ return `${url}${url.includes("?") ? "&" : "?"}cachebust_origin=${encodeURIComponent(origin)}`;
4068
+ }
4069
+ };
4070
+
4071
+ // lib/components/primitive-components/CadAssembly.ts
4072
+ import { cadassemblyProps } from "@tscircuit/props";
4073
+ var CadAssembly = class extends PrimitiveComponent2 {
4074
+ isPrimitiveContainer = true;
4075
+ get config() {
4076
+ return {
4077
+ componentName: "CadAssembly",
4078
+ zodProps: cadassemblyProps
4079
+ };
4080
+ }
4081
+ };
4082
+
3976
4083
  // lib/utils/schematic/getNumericSchPinStyle.ts
3977
4084
  var getNumericSchPinStyle = (pinStyles, pinLabels) => {
3978
4085
  if (!pinStyles) return void 0;
@@ -4388,12 +4495,12 @@ var getObstaclesFromRoute = (route, source_trace_id, { viaDiameter = 0.5 } = {})
4388
4495
 
4389
4496
  // lib/utils/obstacles/generateApproximatingRects.ts
4390
4497
  function generateApproximatingRects(rotatedRect, numRects = 4) {
4391
- const { center, width, height, rotation: rotation4 } = rotatedRect;
4498
+ const { center, width, height, rotation: rotation5 } = rotatedRect;
4392
4499
  const rects = [];
4393
- const angleRad = rotation4 * Math.PI / 180;
4500
+ const angleRad = rotation5 * Math.PI / 180;
4394
4501
  const cosAngle = Math.cos(angleRad);
4395
4502
  const sinAngle = Math.sin(angleRad);
4396
- const normalizedRotation = (rotation4 % 360 + 360) % 360;
4503
+ const normalizedRotation = (rotation5 % 360 + 360) % 360;
4397
4504
  const sliceAlongWidth = height <= width ? normalizedRotation >= 45 && normalizedRotation < 135 || normalizedRotation >= 225 && normalizedRotation < 315 : normalizedRotation >= 135 && normalizedRotation < 225 || normalizedRotation >= 315 || normalizedRotation < 45;
4398
4505
  if (sliceAlongWidth) {
4399
4506
  const sliceWidth = width / numRects;
@@ -6705,13 +6812,6 @@ function NormalComponent_doInitialPcbFootprintStringRender(component, queueAsync
6705
6812
  });
6706
6813
  return;
6707
6814
  }
6708
- if (isReactElement(footprint)) {
6709
- if (component.reactSubtrees.some((rs) => rs.element === footprint)) return;
6710
- const subtree = component._renderReactSubtree(footprint);
6711
- component.reactSubtrees.push(subtree);
6712
- component.add(subtree.component);
6713
- return;
6714
- }
6715
6815
  if (!isReactElement(footprint) && footprint.componentName === "Footprint") {
6716
6816
  component.add(footprint);
6717
6817
  }
@@ -6719,10 +6819,10 @@ function NormalComponent_doInitialPcbFootprintStringRender(component, queueAsync
6719
6819
 
6720
6820
  // lib/components/base-components/NormalComponent/NormalComponent.ts
6721
6821
  var debug3 = Debug4("tscircuit:core");
6722
- var rotation3 = z8.object({
6723
- x: rotation,
6724
- y: rotation,
6725
- z: rotation
6822
+ var rotation32 = z9.object({
6823
+ x: rotation2,
6824
+ y: rotation2,
6825
+ z: rotation2
6726
6826
  });
6727
6827
  var NormalComponent2 = class extends PrimitiveComponent2 {
6728
6828
  reactSubtrees = [];
@@ -6737,6 +6837,7 @@ var NormalComponent2 = class extends PrimitiveComponent2 {
6737
6837
  };
6738
6838
  _asyncSupplierPartNumbers;
6739
6839
  _asyncFootprintCadModel;
6840
+ _isCadModelChild;
6740
6841
  pcb_missing_footprint_error_id;
6741
6842
  _hasStartedFootprintUrlLoad = false;
6742
6843
  _invalidPinLabelMessages = [];
@@ -7250,15 +7351,38 @@ var NormalComponent2 = class extends PrimitiveComponent2 {
7250
7351
  this.doInitialPcbComponentSizeCalculation();
7251
7352
  }
7252
7353
  _renderReactSubtree(element) {
7354
+ const component = createInstanceFromReactElement(element);
7253
7355
  return {
7254
7356
  element,
7255
- component: createInstanceFromReactElement(element)
7357
+ component
7256
7358
  };
7257
7359
  }
7258
7360
  doInitialInitializePortsFromChildren() {
7259
7361
  this.initPorts();
7260
7362
  }
7261
7363
  doInitialReactSubtreesRender() {
7364
+ const fpElm = this.props.footprint;
7365
+ if (isValidElement(fpElm)) {
7366
+ const hasFootprintChild = this.children.some(
7367
+ (c) => c.componentName === "Footprint"
7368
+ );
7369
+ if (!hasFootprintChild) {
7370
+ this.add(fpElm);
7371
+ }
7372
+ }
7373
+ const cmElm = this.props.cadModel;
7374
+ if (isValidElement(cmElm)) {
7375
+ this._isCadModelChild = true;
7376
+ const hasCadAssemblyChild = this.children.some(
7377
+ (c) => c.componentName === "CadAssembly"
7378
+ );
7379
+ const hasCadModelChild = this.children.some(
7380
+ (c) => c.componentName === "CadModel"
7381
+ );
7382
+ if (!hasCadAssemblyChild && !hasCadModelChild) {
7383
+ this.add(cmElm);
7384
+ }
7385
+ }
7262
7386
  }
7263
7387
  doInitialPcbFootprintStringRender() {
7264
7388
  NormalComponent_doInitialPcbFootprintStringRender(
@@ -7470,6 +7594,7 @@ var NormalComponent2 = class extends PrimitiveComponent2 {
7470
7594
  return dimensions;
7471
7595
  }
7472
7596
  doInitialCadModelRender() {
7597
+ if (this._isCadModelChild) return;
7473
7598
  const { db } = this.root;
7474
7599
  const { boardThickness = 0 } = this.root?._getBoard() ?? {};
7475
7600
  const cadModelProp = this._parsedProps.cadModel;
@@ -7483,13 +7608,13 @@ var NormalComponent2 = class extends PrimitiveComponent2 {
7483
7608
  if (typeof cadModel === "string") {
7484
7609
  throw new Error("String cadModel not yet implemented");
7485
7610
  }
7486
- const rotationOffset = rotation3.parse({
7611
+ const rotationOffset = rotation32.parse({
7487
7612
  x: 0,
7488
7613
  y: 0,
7489
7614
  z: typeof cadModel?.rotationOffset === "number" ? cadModel.rotationOffset : 0,
7490
7615
  ...typeof cadModel?.rotationOffset === "object" ? cadModel.rotationOffset ?? {} : {}
7491
7616
  });
7492
- const positionOffset = point3.parse({
7617
+ const positionOffset = point32.parse({
7493
7618
  x: 0,
7494
7619
  y: 0,
7495
7620
  z: 0,
@@ -12939,18 +13064,18 @@ var PowerSource = class extends NormalComponent2 {
12939
13064
  };
12940
13065
 
12941
13066
  // lib/components/normal-components/VoltageSource.ts
12942
- import { frequency, rotation as rotation2, voltage } from "circuit-json";
13067
+ import { frequency, rotation as rotation4, voltage } from "circuit-json";
12943
13068
  import {
12944
13069
  commonComponentProps
12945
13070
  } from "@tscircuit/props";
12946
- import { z as z12 } from "zod";
13071
+ import { z as z13 } from "zod";
12947
13072
  var voltageSourceProps = commonComponentProps.extend({
12948
13073
  voltage: voltage.optional(),
12949
13074
  frequency: frequency.optional(),
12950
13075
  peakToPeakVoltage: voltage.optional(),
12951
- waveShape: z12.enum(["sinewave", "square", "triangle", "sawtooth"]).optional(),
12952
- phase: rotation2.optional(),
12953
- dutyCycle: z12.number().optional()
13076
+ waveShape: z13.enum(["sinewave", "square", "triangle", "sawtooth"]).optional(),
13077
+ phase: rotation4.optional(),
13078
+ dutyCycle: z13.number().optional()
12954
13079
  });
12955
13080
  var VoltageSource = class extends NormalComponent2 {
12956
13081
  get config() {
@@ -14794,7 +14919,7 @@ import { identity as identity6 } from "transformation-matrix";
14794
14919
  var package_default = {
14795
14920
  name: "@tscircuit/core",
14796
14921
  type: "module",
14797
- version: "0.0.717",
14922
+ version: "0.0.719",
14798
14923
  types: "dist/index.d.ts",
14799
14924
  main: "dist/index.js",
14800
14925
  module: "dist/index.js",
@@ -14833,11 +14958,11 @@ var package_default = {
14833
14958
  "@tscircuit/matchpack": "^0.0.16",
14834
14959
  "@tscircuit/math-utils": "^0.0.21",
14835
14960
  "@tscircuit/miniflex": "^0.0.4",
14836
- "@tscircuit/props": "0.0.315",
14961
+ "@tscircuit/props": "0.0.319",
14837
14962
  "@tscircuit/schematic-autolayout": "^0.0.6",
14838
14963
  "@tscircuit/schematic-match-adapt": "^0.0.16",
14839
14964
  "@tscircuit/schematic-trace-solver": "^0.0.36",
14840
- "@tscircuit/simple-3d-svg": "^0.0.38",
14965
+ "@tscircuit/simple-3d-svg": "^0.0.41",
14841
14966
  "@types/bun": "^1.2.16",
14842
14967
  "@types/debug": "^4.1.12",
14843
14968
  "@types/react": "^19.1.8",
@@ -14850,7 +14975,7 @@ var package_default = {
14850
14975
  "circuit-json": "^0.0.250",
14851
14976
  "circuit-json-to-bpc": "^0.0.13",
14852
14977
  "circuit-json-to-connectivity-map": "^0.0.22",
14853
- "circuit-json-to-simple-3d": "^0.0.6",
14978
+ "circuit-json-to-simple-3d": "^0.0.8",
14854
14979
  "circuit-to-svg": "^0.0.189",
14855
14980
  concurrently: "^9.1.2",
14856
14981
  "connectivity-map": "^1.0.0",
@@ -15301,6 +15426,8 @@ export {
15301
15426
  Board,
15302
15427
  Breakout,
15303
15428
  BreakoutPoint,
15429
+ CadAssembly,
15430
+ CadModel,
15304
15431
  Capacitor,
15305
15432
  Chip,
15306
15433
  Circuit,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.718",
4
+ "version": "0.0.720",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -40,11 +40,11 @@
40
40
  "@tscircuit/matchpack": "^0.0.16",
41
41
  "@tscircuit/math-utils": "^0.0.21",
42
42
  "@tscircuit/miniflex": "^0.0.4",
43
- "@tscircuit/props": "0.0.315",
43
+ "@tscircuit/props": "0.0.319",
44
44
  "@tscircuit/schematic-autolayout": "^0.0.6",
45
45
  "@tscircuit/schematic-match-adapt": "^0.0.16",
46
46
  "@tscircuit/schematic-trace-solver": "^0.0.36",
47
- "@tscircuit/simple-3d-svg": "^0.0.38",
47
+ "@tscircuit/simple-3d-svg": "^0.0.41",
48
48
  "@types/bun": "^1.2.16",
49
49
  "@types/debug": "^4.1.12",
50
50
  "@types/react": "^19.1.8",
@@ -57,7 +57,7 @@
57
57
  "circuit-json": "^0.0.250",
58
58
  "circuit-json-to-bpc": "^0.0.13",
59
59
  "circuit-json-to-connectivity-map": "^0.0.22",
60
- "circuit-json-to-simple-3d": "^0.0.6",
60
+ "circuit-json-to-simple-3d": "^0.0.8",
61
61
  "circuit-to-svg": "^0.0.189",
62
62
  "concurrently": "^9.1.2",
63
63
  "connectivity-map": "^1.0.0",