@tscircuit/core 0.0.1203 → 0.0.1204

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
@@ -188,9 +188,9 @@ interface IIsolatedCircuit {
188
188
  interface IRootCircuit extends IIsolatedCircuit {
189
189
  }
190
190
 
191
- declare const orderedRenderPhases: readonly ["ReactSubtreesRender", "RenderIsolatedSubcircuits", "InflateSubcircuitCircuitJson", "SourceNameDuplicateComponentRemoval", "PcbFootprintStringRender", "FetchPartFootprint", "InitializePortsFromChildren", "CreateNetsFromProps", "AssignFallbackProps", "CreateTracesFromProps", "CreateTracesFromNetLabels", "CreateTraceHintsFromProps", "SourceGroupRender", "AssignNameToUnnamedComponents", "SourceRender", "SourceComponentPropertyValidation", "SourceParentAttachment", "PortMatching", "OptimizeSelectorCache", "SourceTraceRender", "SourceAddConnectivityMapKey", "SourceDesignRuleChecks", "SimulationRender", "SchematicComponentRender", "SchematicPortRender", "SymbolContainerRender", "SchematicPrimitiveRender", "SchematicSymbolResize", "SchematicComponentSizeCalculation", "SchematicLayout", "SchematicTraceRender", "SchematicReplaceNetLabelsWithSymbols", "PanelBoardLayout", "ValidatePcbCoordinates", "PcbComponentRender", "PcbPrimitiveRender", "PcbFootprintLayout", "PcbPortRender", "PcbPortAttachment", "PcbComponentSizeCalculation", "PcbComponentAnchorAlignment", "PcbCalcPlacementResolution", "PcbLayout", "PcbBoardAutoSize", "PanelLayout", "PcbTraceHintRender", "PcbManualTraceRender", "PcbTraceRender", "PcbRouteNetIslands", "PcbCopperPourRender", "PcbDesignRuleChecks", "SilkscreenOverlapAdjustment", "CadModelRender", "PartsEngineRender", "SimulationSpiceEngineRender"];
191
+ declare const orderedRenderPhases: readonly ["ReactSubtreesRender", "RenderIsolatedSubcircuits", "InflateSubcircuitCircuitJson", "SourceNameDuplicateComponentRemoval", "PcbFootprintStringRender", "FetchPartFootprint", "InitializePortsFromChildren", "CreateNetsFromProps", "AssignFallbackProps", "CreateTracesFromProps", "CreateTracesFromNetLabels", "CreateTraceHintsFromProps", "SourceGroupRender", "AssignNameToUnnamedComponents", "SourceRender", "SourceComponentPropertyValidation", "SourceParentAttachment", "PortMatching", "OptimizeSelectorCache", "SourceTraceRender", "SourceAddConnectivityMapKey", "SourceDesignRuleChecks", "SimulationRender", "SchematicComponentRender", "SchematicPortRender", "SymbolContainerRender", "SchematicPrimitiveRender", "SchematicSymbolResize", "SchematicComponentSizeCalculation", "SchematicLayout", "SchematicTraceRender", "SchematicReplaceNetLabelsWithSymbols", "PanelBoardLayout", "ValidatePcbCoordinates", "PcbComponentRender", "PcbPrimitiveRender", "PcbFootprintLayout", "PcbPortRender", "PcbPortAttachment", "PcbComponentSizeCalculation", "PcbComponentAnchorAlignment", "PcbCalcPlacementResolution", "PcbLayout", "PcbBoardAutoSize", "PanelLayout", "PcbTraceHintRender", "PcbManualTraceRender", "PcbTraceRender", "PcbRouteNetIslands", "PcbCopperPourRender", "PcbDesignRuleChecks", "SilkscreenOverlapAdjustment", "CadModelRender", "PartsEngineRender", "SupplierFootprintMismatchWarning", "SimulationSpiceEngineRender"];
192
192
  type RenderPhase = (typeof orderedRenderPhases)[number];
193
- declare const renderPhaseIndexMap: Map<"ReactSubtreesRender" | "RenderIsolatedSubcircuits" | "InflateSubcircuitCircuitJson" | "SourceNameDuplicateComponentRemoval" | "PcbFootprintStringRender" | "FetchPartFootprint" | "InitializePortsFromChildren" | "CreateNetsFromProps" | "AssignFallbackProps" | "CreateTracesFromProps" | "CreateTracesFromNetLabels" | "CreateTraceHintsFromProps" | "SourceGroupRender" | "AssignNameToUnnamedComponents" | "SourceRender" | "SourceComponentPropertyValidation" | "SourceParentAttachment" | "PortMatching" | "OptimizeSelectorCache" | "SourceTraceRender" | "SourceAddConnectivityMapKey" | "SourceDesignRuleChecks" | "SimulationRender" | "SchematicComponentRender" | "SchematicPortRender" | "SymbolContainerRender" | "SchematicPrimitiveRender" | "SchematicSymbolResize" | "SchematicComponentSizeCalculation" | "SchematicLayout" | "SchematicTraceRender" | "SchematicReplaceNetLabelsWithSymbols" | "PanelBoardLayout" | "ValidatePcbCoordinates" | "PcbComponentRender" | "PcbPrimitiveRender" | "PcbFootprintLayout" | "PcbPortRender" | "PcbPortAttachment" | "PcbComponentSizeCalculation" | "PcbComponentAnchorAlignment" | "PcbCalcPlacementResolution" | "PcbLayout" | "PcbBoardAutoSize" | "PanelLayout" | "PcbTraceHintRender" | "PcbManualTraceRender" | "PcbTraceRender" | "PcbRouteNetIslands" | "PcbCopperPourRender" | "PcbDesignRuleChecks" | "SilkscreenOverlapAdjustment" | "CadModelRender" | "PartsEngineRender" | "SimulationSpiceEngineRender", number>;
193
+ declare const renderPhaseIndexMap: Map<"ReactSubtreesRender" | "RenderIsolatedSubcircuits" | "InflateSubcircuitCircuitJson" | "SourceNameDuplicateComponentRemoval" | "PcbFootprintStringRender" | "FetchPartFootprint" | "InitializePortsFromChildren" | "CreateNetsFromProps" | "AssignFallbackProps" | "CreateTracesFromProps" | "CreateTracesFromNetLabels" | "CreateTraceHintsFromProps" | "SourceGroupRender" | "AssignNameToUnnamedComponents" | "SourceRender" | "SourceComponentPropertyValidation" | "SourceParentAttachment" | "PortMatching" | "OptimizeSelectorCache" | "SourceTraceRender" | "SourceAddConnectivityMapKey" | "SourceDesignRuleChecks" | "SimulationRender" | "SchematicComponentRender" | "SchematicPortRender" | "SymbolContainerRender" | "SchematicPrimitiveRender" | "SchematicSymbolResize" | "SchematicComponentSizeCalculation" | "SchematicLayout" | "SchematicTraceRender" | "SchematicReplaceNetLabelsWithSymbols" | "PanelBoardLayout" | "ValidatePcbCoordinates" | "PcbComponentRender" | "PcbPrimitiveRender" | "PcbFootprintLayout" | "PcbPortRender" | "PcbPortAttachment" | "PcbComponentSizeCalculation" | "PcbComponentAnchorAlignment" | "PcbCalcPlacementResolution" | "PcbLayout" | "PcbBoardAutoSize" | "PanelLayout" | "PcbTraceHintRender" | "PcbManualTraceRender" | "PcbTraceRender" | "PcbRouteNetIslands" | "PcbCopperPourRender" | "PcbDesignRuleChecks" | "SilkscreenOverlapAdjustment" | "CadModelRender" | "PartsEngineRender" | "SupplierFootprintMismatchWarning" | "SimulationSpiceEngineRender", number>;
194
194
  type RenderPhaseFn<K extends RenderPhase = RenderPhase> = `doInitial${K}` | `update${K}` | `remove${K}`;
195
195
  type RenderPhaseStates = Record<RenderPhase, {
196
196
  initialized: boolean;
@@ -1888,6 +1888,7 @@ declare class NormalComponent<ZodProps extends z.ZodType = any, PortNames extend
1888
1888
  _inferredInternallyConnectedPinNames: string[][];
1889
1889
  pcb_missing_footprint_error_id?: string;
1890
1890
  _hasStartedFootprintUrlLoad: boolean;
1891
+ _hasStartedSupplierFootprintMismatchWarningCheck: boolean;
1891
1892
  private _invalidFootprintPropMessages;
1892
1893
  private _invalidPinLabelMessages;
1893
1894
  /**
@@ -2023,6 +2024,8 @@ declare class NormalComponent<ZodProps extends z.ZodType = any, PortNames extend
2023
2024
  protected _getSupplierPartNumbers(partsEngine: any, source_component: any, footprinterString: string | undefined): Promise<any>;
2024
2025
  doInitialPartsEngineRender(): void;
2025
2026
  updatePartsEngineRender(): void;
2027
+ doInitialSupplierFootprintMismatchWarning(): void;
2028
+ updateSupplierFootprintMismatchWarning(): void;
2026
2029
  doInitialAssignFallbackProps(): void;
2027
2030
  doInitialCreateTracesFromProps(): void;
2028
2031
  _createTracesFromConnectionsProp(): void;
package/dist/index.js CHANGED
@@ -105,7 +105,7 @@ import {
105
105
  point3 as point32,
106
106
  rotation as rotation2,
107
107
  schematic_manual_edit_conflict_warning,
108
- unknown_error_finding_part
108
+ unknown_error_finding_part as unknown_error_finding_part2
109
109
  } from "circuit-json";
110
110
  import Debug5 from "debug";
111
111
 
@@ -353,6 +353,7 @@ var orderedRenderPhases = [
353
353
  "SilkscreenOverlapAdjustment",
354
354
  "CadModelRender",
355
355
  "PartsEngineRender",
356
+ "SupplierFootprintMismatchWarning",
356
357
  "SimulationSpiceEngineRender"
357
358
  ];
358
359
  var renderPhaseIndexMap = new Map(
@@ -399,6 +400,11 @@ var asyncPhaseDependencies = {
399
400
  ],
400
401
  CadModelRender: ["PcbFootprintStringRender", "FetchPartFootprint"],
401
402
  PartsEngineRender: ["PcbFootprintStringRender", "FetchPartFootprint"],
403
+ SupplierFootprintMismatchWarning: [
404
+ "PcbFootprintStringRender",
405
+ "FetchPartFootprint",
406
+ "PartsEngineRender"
407
+ ],
402
408
  PcbComponentAnchorAlignment: [
403
409
  "PcbFootprintStringRender",
404
410
  "FetchPartFootprint"
@@ -10786,6 +10792,133 @@ var shouldCheckPortForMissingTrace = (component, port) => {
10786
10792
  return true;
10787
10793
  };
10788
10794
 
10795
+ // lib/components/base-components/NormalComponent/NormalComponent_doInitialSupplierFootprintMismatchWarning.ts
10796
+ import { getBoundsOfPcbElements } from "@tscircuit/circuit-json-util";
10797
+ import {
10798
+ supplierProps
10799
+ } from "@tscircuit/props";
10800
+ import {
10801
+ supplier_footprint_mismatch_warning,
10802
+ unknown_error_finding_part
10803
+ } from "circuit-json";
10804
+ var SUPPLIER_FOOTPRINT_IOU_WARNING_THRESHOLD = 0.8;
10805
+ var supplierNames = supplierProps.shape.supplierPartNumbers.unwrap().keySchema.options;
10806
+ var isCopperElement = (elm) => elm.type === "pcb_smtpad" || elm.type === "pcb_plated_hole";
10807
+ var isValidBounds = (bounds) => Number.isFinite(bounds.minX) && Number.isFinite(bounds.minY) && Number.isFinite(bounds.maxX) && Number.isFinite(bounds.maxY) && bounds.maxX > bounds.minX && bounds.maxY > bounds.minY;
10808
+ var getCopperBounds = (elements) => {
10809
+ const copperElements = elements.filter(isCopperElement);
10810
+ if (copperElements.length === 0) return null;
10811
+ const bounds = getBoundsOfPcbElements(copperElements);
10812
+ if (!isValidBounds(bounds)) return null;
10813
+ return bounds;
10814
+ };
10815
+ var getBoundsSize = (bounds) => ({
10816
+ width: bounds.maxX - bounds.minX,
10817
+ height: bounds.maxY - bounds.minY
10818
+ });
10819
+ var getCenteredBoundsIou = (boundsA, boundsB, opts) => {
10820
+ const sizeA = getBoundsSize(boundsA);
10821
+ const sizeB = getBoundsSize(boundsB);
10822
+ const bWidth = opts?.rotateB ? sizeB.height : sizeB.width;
10823
+ const bHeight = opts?.rotateB ? sizeB.width : sizeB.height;
10824
+ const intersectionWidth = Math.min(sizeA.width, bWidth);
10825
+ const intersectionHeight = Math.min(sizeA.height, bHeight);
10826
+ const intersectionArea = intersectionWidth * intersectionHeight;
10827
+ const unionArea = sizeA.width * sizeA.height + bWidth * bHeight - intersectionArea;
10828
+ if (unionArea <= 0) return 0;
10829
+ return intersectionArea / unionArea;
10830
+ };
10831
+ var getBestBoundsIou = (localBounds, supplierBounds) => Math.max(
10832
+ getCenteredBoundsIou(localBounds, supplierBounds),
10833
+ getCenteredBoundsIou(localBounds, supplierBounds, { rotateB: true })
10834
+ );
10835
+ var getSupplierPartCandidates = (supplierPartNumbers) => {
10836
+ if (!supplierPartNumbers) return [];
10837
+ const candidates = [];
10838
+ for (const supplierName of supplierNames) {
10839
+ const partNumbers = supplierPartNumbers[supplierName];
10840
+ if (!Array.isArray(partNumbers)) continue;
10841
+ for (const supplierPartNumber of partNumbers) {
10842
+ if (!supplierPartNumber) continue;
10843
+ candidates.push({ supplierName, supplierPartNumber });
10844
+ }
10845
+ }
10846
+ return candidates;
10847
+ };
10848
+ function NormalComponent_doInitialSupplierFootprintMismatchWarning(component) {
10849
+ if (component.root?.pcbDisabled) return;
10850
+ if (component.props.doNotPlace) return;
10851
+ if (component.props.footprint === void 0) return;
10852
+ if (component.getInheritedProperty("bomDisabled")) return;
10853
+ if (component.getInheritedProperty("partsEngineDisabled")) return;
10854
+ const partsEngine = component.getInheritedProperty("partsEngine");
10855
+ if (!partsEngine?.fetchPartCircuitJson) return;
10856
+ const { db } = component.root;
10857
+ const sourceComponent = db.source_component.get(
10858
+ component.source_component_id
10859
+ );
10860
+ if (!sourceComponent?.supplier_part_numbers) return;
10861
+ if (!component.pcb_component_id) return;
10862
+ if (component._hasStartedSupplierFootprintMismatchWarningCheck) return;
10863
+ const supplierPartCandidates = getSupplierPartCandidates(
10864
+ sourceComponent.supplier_part_numbers
10865
+ );
10866
+ if (supplierPartCandidates.length === 0) return;
10867
+ const localCopperElements = [
10868
+ ...db.pcb_smtpad.list({ pcb_component_id: component.pcb_component_id }),
10869
+ ...db.pcb_plated_hole.list({
10870
+ pcb_component_id: component.pcb_component_id
10871
+ })
10872
+ ];
10873
+ const localBounds = getCopperBounds(localCopperElements);
10874
+ if (!localBounds) return;
10875
+ component._hasStartedSupplierFootprintMismatchWarningCheck = true;
10876
+ component._queueAsyncEffect("check-supplier-footprint-mismatch", async () => {
10877
+ const { db: db2 } = component.root;
10878
+ const fetchPartCircuitJson = partsEngine.fetchPartCircuitJson;
10879
+ for (const supplierPartCandidate of supplierPartCandidates) {
10880
+ const { supplierName, supplierPartNumber } = supplierPartCandidate;
10881
+ try {
10882
+ const supplierCircuitJson = await Promise.resolve(
10883
+ fetchPartCircuitJson({ supplierPartNumber })
10884
+ ) ?? null;
10885
+ if (!supplierCircuitJson?.length) continue;
10886
+ const supplierBounds = getCopperBounds(supplierCircuitJson);
10887
+ if (!supplierBounds) continue;
10888
+ const footprintCopperIou = getBestBoundsIou(localBounds, supplierBounds);
10889
+ if (footprintCopperIou >= SUPPLIER_FOOTPRINT_IOU_WARNING_THRESHOLD) {
10890
+ return;
10891
+ }
10892
+ const footprintLabel = typeof component.props.footprint === "string" ? `"${component.props.footprint}"` : "the provided footprint";
10893
+ const roundedIou = Number(footprintCopperIou.toFixed(4));
10894
+ const warning = supplier_footprint_mismatch_warning.parse({
10895
+ type: "supplier_footprint_mismatch_warning",
10896
+ message: `${component.getString()} footprint ${footprintLabel} does not match supplier footprint ${supplierName}:${supplierPartNumber} (copper IoU ${roundedIou}).`,
10897
+ source_component_id: component.source_component_id,
10898
+ pcb_component_id: component.pcb_component_id,
10899
+ pcb_group_id: component.getGroup()?.pcb_group_id ?? void 0,
10900
+ subcircuit_id: component.getSubcircuit()?.subcircuit_id ?? void 0,
10901
+ supplier_name: supplierName,
10902
+ supplier_part_number: supplierPartNumber,
10903
+ footprint_copper_intersection_over_union: roundedIou
10904
+ });
10905
+ db2.supplier_footprint_mismatch_warning.insert(warning);
10906
+ return;
10907
+ } catch (error) {
10908
+ const errorMessage = error instanceof Error ? error.message : String(error);
10909
+ const errorObj = unknown_error_finding_part.parse({
10910
+ type: "unknown_error_finding_part",
10911
+ message: `Failed to fetch supplier footprint for ${component.getString()} (${supplierName}:${supplierPartNumber}): ${errorMessage}`,
10912
+ source_component_id: component.source_component_id,
10913
+ subcircuit_id: component.getSubcircuit()?.subcircuit_id
10914
+ });
10915
+ db2.unknown_error_finding_part.insert(errorObj);
10916
+ return;
10917
+ }
10918
+ }
10919
+ });
10920
+ }
10921
+
10789
10922
  // lib/components/base-components/NormalComponent/utils/canMergePortDefinitions.ts
10790
10923
  var canMergePortDefinitions = (a, b) => {
10791
10924
  const aPinNumber = a._parsedProps.pinNumber;
@@ -10967,6 +11100,7 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
10967
11100
  _inferredInternallyConnectedPinNames = [];
10968
11101
  pcb_missing_footprint_error_id;
10969
11102
  _hasStartedFootprintUrlLoad = false;
11103
+ _hasStartedSupplierFootprintMismatchWarningCheck = false;
10970
11104
  _invalidFootprintPropMessages = [];
10971
11105
  _invalidPinLabelMessages = [];
10972
11106
  /**
@@ -12221,7 +12355,7 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
12221
12355
  this._markDirty("PartsEngineRender");
12222
12356
  }).catch((error) => {
12223
12357
  this._asyncSupplierPartNumbers = {};
12224
- const errorObj = unknown_error_finding_part.parse({
12358
+ const errorObj = unknown_error_finding_part2.parse({
12225
12359
  type: "unknown_error_finding_part",
12226
12360
  message: `Failed to fetch supplier part numbers for ${this.getString()}: ${error.message}`,
12227
12361
  source_component_id: this.source_component_id,
@@ -12247,6 +12381,12 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
12247
12381
  return;
12248
12382
  }
12249
12383
  }
12384
+ doInitialSupplierFootprintMismatchWarning() {
12385
+ NormalComponent_doInitialSupplierFootprintMismatchWarning(this);
12386
+ }
12387
+ updateSupplierFootprintMismatchWarning() {
12388
+ this.doInitialSupplierFootprintMismatchWarning();
12389
+ }
12250
12390
  doInitialAssignFallbackProps() {
12251
12391
  const { _parsedProps: props } = this;
12252
12392
  if (props.connections && !this.name) {
@@ -14268,7 +14408,7 @@ var TraceHint = class extends PrimitiveComponent2 {
14268
14408
  };
14269
14409
 
14270
14410
  // lib/components/primitive-components/Group/Group_doInitialPcbCalcPlacementResolution.ts
14271
- import { getBoundsOfPcbElements } from "@tscircuit/circuit-json-util";
14411
+ import { getBoundsOfPcbElements as getBoundsOfPcbElements2 } from "@tscircuit/circuit-json-util";
14272
14412
  var SUPPORTED_COMPONENT_FIELDS = /* @__PURE__ */ new Set([
14273
14413
  "x",
14274
14414
  "y",
@@ -14555,7 +14695,7 @@ function updateVarsForNamedComponent(component, vars) {
14555
14695
  });
14556
14696
  const padElementsByReference = collectPadElementsByReference(component);
14557
14697
  for (const [referencePath, elements] of padElementsByReference.entries()) {
14558
- const bounds = getBoundsOfPcbElements(elements);
14698
+ const bounds = getBoundsOfPcbElements2(elements);
14559
14699
  const minX = bounds.minX;
14560
14700
  const maxX = bounds.maxX;
14561
14701
  const minY = bounds.minY;
@@ -20074,7 +20214,7 @@ import { identity as identity5 } from "transformation-matrix";
20074
20214
  var package_default = {
20075
20215
  name: "@tscircuit/core",
20076
20216
  type: "module",
20077
- version: "0.0.1202",
20217
+ version: "0.0.1203",
20078
20218
  types: "dist/index.d.ts",
20079
20219
  main: "dist/index.js",
20080
20220
  module: "dist/index.js",
@@ -20134,7 +20274,7 @@ var package_default = {
20134
20274
  "bun-match-svg": "0.0.12",
20135
20275
  "calculate-elbow": "^0.0.12",
20136
20276
  "chokidar-cli": "^3.0.0",
20137
- "circuit-json": "^0.0.419",
20277
+ "circuit-json": "^0.0.421",
20138
20278
  "circuit-json-to-bpc": "^0.0.13",
20139
20279
  "circuit-json-to-connectivity-map": "^0.0.23",
20140
20280
  "circuit-json-to-gltf": "^0.0.96",
@@ -23890,7 +24030,7 @@ import { guessCableInsertCenter } from "@tscircuit/infer-cable-insertion-point";
23890
24030
  import {
23891
24031
  connectorProps
23892
24032
  } from "@tscircuit/props";
23893
- import { unknown_error_finding_part as unknown_error_finding_part2 } from "circuit-json";
24033
+ import { unknown_error_finding_part as unknown_error_finding_part3 } from "circuit-json";
23894
24034
 
23895
24035
  // lib/utils/connectors/convertCircuitJsonToUsbCStandardCircuitJson.ts
23896
24036
  var STANDARD_USB_C_PIN_LABELS = [
@@ -24137,7 +24277,7 @@ var Connector = class extends Chip {
24137
24277
  }
24138
24278
  _insertStandardConnectorCircuitJsonError(standard, message) {
24139
24279
  const { db } = this.root;
24140
- const errorObj = unknown_error_finding_part2.parse({
24280
+ const errorObj = unknown_error_finding_part3.parse({
24141
24281
  type: "unknown_error_finding_part",
24142
24282
  message: `Failed to fetch circuit JSON for ${this.getString()} (standard="${standard}"): ${message}`,
24143
24283
  source_component_id: this.source_component_id ?? void 0,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.1203",
4
+ "version": "0.0.1204",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -61,7 +61,7 @@
61
61
  "bun-match-svg": "0.0.12",
62
62
  "calculate-elbow": "^0.0.12",
63
63
  "chokidar-cli": "^3.0.0",
64
- "circuit-json": "^0.0.419",
64
+ "circuit-json": "^0.0.421",
65
65
  "circuit-json-to-bpc": "^0.0.13",
66
66
  "circuit-json-to-connectivity-map": "^0.0.23",
67
67
  "circuit-json-to-gltf": "^0.0.96",