@tscircuit/cli 0.1.1289 → 0.1.1290

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/cli/main.js CHANGED
@@ -99964,7 +99964,7 @@ var import_perfect_cli = __toESM2(require_dist2(), 1);
99964
99964
  // lib/getVersion.ts
99965
99965
  import { createRequire as createRequire2 } from "node:module";
99966
99966
  // package.json
99967
- var version = "0.1.1288";
99967
+ var version = "0.1.1289";
99968
99968
  var package_default = {
99969
99969
  name: "@tscircuit/cli",
99970
99970
  version,
@@ -99978,6 +99978,7 @@ var package_default = {
99978
99978
  "@biomejs/biome": "^1.9.4",
99979
99979
  "@tscircuit/circuit-json-placement-analysis": "^0.0.6",
99980
99980
  "@tscircuit/circuit-json-routing-analysis": "^0.0.1",
99981
+ "@tscircuit/circuit-json-schematic-placement-analysis": "github:tscircuit/circuit-json-schematic-placement-analysis#d09c8d74f3085b29744bb0f1c9864c1154c69436",
99981
99982
  "@tscircuit/fake-snippets": "^0.0.182",
99982
99983
  "@tscircuit/file-server": "^0.0.32",
99983
99984
  "@tscircuit/image-utils": "^0.0.3",
@@ -240617,6 +240618,263 @@ var registerCheckRouting = (program2) => {
240617
240618
  });
240618
240619
  };
240619
240620
 
240621
+ // node_modules/@tscircuit/circuit-json-schematic-placement-analysis/lib/analyze-schematic-placement.ts
240622
+ import { cju as cju7 } from "@tscircuit/circuit-json-util";
240623
+
240624
+ // node_modules/@tscircuit/circuit-json-schematic-placement-analysis/lib/schematic-box-overlap.ts
240625
+ var getCenteredRectBounds = (box2) => {
240626
+ const halfWidth = box2.width / 2;
240627
+ const halfHeight = box2.height / 2;
240628
+ return {
240629
+ left: box2.schX - halfWidth,
240630
+ right: box2.schX + halfWidth,
240631
+ top: box2.schY - halfHeight,
240632
+ bottom: box2.schY + halfHeight
240633
+ };
240634
+ };
240635
+ var getComponentOverlap = (firstComponent, secondComponent) => {
240636
+ const firstBounds = getCenteredRectBounds(firstComponent);
240637
+ const secondBounds = getCenteredRectBounds(secondComponent);
240638
+ const left = Math.max(firstBounds.left, secondBounds.left);
240639
+ const right = Math.min(firstBounds.right, secondBounds.right);
240640
+ const top = Math.max(firstBounds.top, secondBounds.top);
240641
+ const bottom = Math.min(firstBounds.bottom, secondBounds.bottom);
240642
+ const overlapWidth = right - left;
240643
+ const overlapHeight = bottom - top;
240644
+ if (overlapWidth <= 0 || overlapHeight <= 0) {
240645
+ return null;
240646
+ }
240647
+ return {
240648
+ lineItemType: "ComponentOverlap",
240649
+ firstComponent,
240650
+ secondComponent,
240651
+ overlapWidth,
240652
+ overlapHeight,
240653
+ correctionSuggestions: getOverlapCorrectionSuggestions({
240654
+ firstComponent,
240655
+ secondComponent,
240656
+ overlapWidth,
240657
+ overlapHeight
240658
+ })
240659
+ };
240660
+ };
240661
+ var getOverlapCorrectionSuggestions = ({
240662
+ firstComponent,
240663
+ secondComponent,
240664
+ overlapWidth,
240665
+ overlapHeight
240666
+ }) => {
240667
+ const firstArea = firstComponent.width * firstComponent.height;
240668
+ const secondArea = secondComponent.width * secondComponent.height;
240669
+ const targetComponent = firstArea <= secondArea ? firstComponent : secondComponent;
240670
+ const otherComponent = targetComponent === firstComponent ? secondComponent : firstComponent;
240671
+ const deltaSchX = targetComponent.schX <= otherComponent.schX ? -overlapWidth : overlapWidth;
240672
+ const deltaSchY = targetComponent.schY <= otherComponent.schY ? -overlapHeight : overlapHeight;
240673
+ return [
240674
+ {
240675
+ targetComponentName: targetComponent.sourceComponentName,
240676
+ deltaSchX,
240677
+ deltaSchY: 0,
240678
+ newSchX: targetComponent.schX + deltaSchX,
240679
+ newSchY: targetComponent.schY
240680
+ },
240681
+ {
240682
+ targetComponentName: targetComponent.sourceComponentName,
240683
+ deltaSchX: 0,
240684
+ deltaSchY,
240685
+ newSchX: targetComponent.schX,
240686
+ newSchY: targetComponent.schY + deltaSchY
240687
+ }
240688
+ ];
240689
+ };
240690
+ var generateSchematicPlacementIssues = (componentPlacements) => {
240691
+ const issues = [];
240692
+ for (let firstIndex = 0;firstIndex < componentPlacements.length; firstIndex++) {
240693
+ for (let secondIndex = firstIndex + 1;secondIndex < componentPlacements.length; secondIndex++) {
240694
+ const overlap = getComponentOverlap(componentPlacements[firstIndex], componentPlacements[secondIndex]);
240695
+ if (overlap) {
240696
+ issues.push(overlap);
240697
+ }
240698
+ }
240699
+ }
240700
+ return issues;
240701
+ };
240702
+
240703
+ // node_modules/@tscircuit/circuit-json-schematic-placement-analysis/lib/analyze-schematic-placement.ts
240704
+ var fmtNumber5 = (value) => {
240705
+ if (Number.isInteger(value))
240706
+ return String(value);
240707
+ return value.toFixed(3).replace(/\.0+$/, "").replace(/(\.\d*?)0+$/, "$1");
240708
+ };
240709
+ var fmtDelta = (value) => {
240710
+ const formattedValue = fmtNumber5(value);
240711
+ return value > 0 ? `+${formattedValue}` : formattedValue;
240712
+ };
240713
+ var isSchematicBox = (element) => element.type === "schematic_box";
240714
+ var isSchematicComponent = (element) => element.type === "schematic_component";
240715
+ var getSourceComponentName = (circuitJson, sourceComponentId) => {
240716
+ if (!sourceComponentId)
240717
+ return;
240718
+ return cju7(circuitJson).source_component.get(sourceComponentId)?.name;
240719
+ };
240720
+ var schematicComponentToLineItem = (schematicComponent, circuitJson, schematicBox) => ({
240721
+ lineItemType: "SchematicBoxPlacement",
240722
+ positionAnchor: "center",
240723
+ schX: schematicComponent.center.x,
240724
+ schY: schematicComponent.center.y,
240725
+ width: schematicBox?.width ?? schematicComponent.size.width,
240726
+ height: schematicBox?.height ?? schematicComponent.size.height,
240727
+ sourceComponentId: schematicComponent.source_component_id,
240728
+ sourceComponentName: getSourceComponentName(circuitJson, schematicComponent.source_component_id),
240729
+ schematicComponentId: schematicComponent.schematic_component_id,
240730
+ schematicSymbolId: schematicBox?.schematic_symbol_id ?? schematicComponent.schematic_symbol_id,
240731
+ subcircuitId: schematicComponent.subcircuit_id ?? schematicBox?.subcircuit_id
240732
+ });
240733
+ var schematicBoxToLineItem = (schematicBox, circuitJson) => ({
240734
+ lineItemType: "SchematicBoxPlacement",
240735
+ positionAnchor: "center",
240736
+ schX: schematicBox.x,
240737
+ schY: schematicBox.y,
240738
+ width: schematicBox.width,
240739
+ height: schematicBox.height,
240740
+ ...getSourceComponentMetadata(schematicBox, circuitJson),
240741
+ schematicComponentId: schematicBox.schematic_component_id,
240742
+ schematicSymbolId: schematicBox.schematic_symbol_id,
240743
+ subcircuitId: schematicBox.subcircuit_id
240744
+ });
240745
+ var getSourceComponentMetadata = (schematicBox, circuitJson) => {
240746
+ if (!schematicBox.schematic_component_id)
240747
+ return {};
240748
+ const circuitJsonUtil = cju7(circuitJson);
240749
+ const schematicComponent = circuitJsonUtil.schematic_component.get(schematicBox.schematic_component_id);
240750
+ if (!schematicComponent?.source_component_id)
240751
+ return {};
240752
+ const sourceComponent = circuitJsonUtil.source_component.get(schematicComponent.source_component_id);
240753
+ return {
240754
+ sourceComponentId: schematicComponent.source_component_id,
240755
+ sourceComponentName: sourceComponent?.name
240756
+ };
240757
+ };
240758
+ var addAttr = (attrs, key, value, options) => {
240759
+ if (value === undefined)
240760
+ return;
240761
+ attrs.push(`${key}="${typeof value === "number" ? options?.formatDelta ? fmtDelta(value) : fmtNumber5(value) : escapeAttr3(value)}"`);
240762
+ };
240763
+ var lineItemToString3 = (lineItem) => {
240764
+ const attrs = [];
240765
+ addAttr(attrs, "componentName", lineItem.sourceComponentName);
240766
+ addAttr(attrs, "positionAnchor", lineItem.positionAnchor);
240767
+ addAttr(attrs, "schX", lineItem.schX);
240768
+ addAttr(attrs, "schY", lineItem.schY);
240769
+ addAttr(attrs, "width", lineItem.width);
240770
+ addAttr(attrs, "height", lineItem.height);
240771
+ return `<SchematicBoxPlacement ${attrs.join(" ")} />`;
240772
+ };
240773
+ var overlapIssueToString = (issue) => {
240774
+ const attrs = [];
240775
+ addAttr(attrs, "component1Name", issue.firstComponent.sourceComponentName);
240776
+ addAttr(attrs, "component2Name", issue.secondComponent.sourceComponentName);
240777
+ addAttr(attrs, "component1SchX", issue.firstComponent.schX);
240778
+ addAttr(attrs, "component1SchY", issue.firstComponent.schY);
240779
+ addAttr(attrs, "component2SchX", issue.secondComponent.schX);
240780
+ addAttr(attrs, "component2SchY", issue.secondComponent.schY);
240781
+ addAttr(attrs, "overlapWidth", issue.overlapWidth);
240782
+ addAttr(attrs, "overlapHeight", issue.overlapHeight);
240783
+ return [
240784
+ `<ComponentOverlap ${attrs.join(" ")}>`,
240785
+ ...issue.correctionSuggestions.map(correctionSuggestionToString),
240786
+ "</ComponentOverlap>"
240787
+ ].join(`
240788
+ `);
240789
+ };
240790
+ var correctionSuggestionToString = (suggestion) => {
240791
+ const attrs = [];
240792
+ addAttr(attrs, "target", suggestion.targetComponentName);
240793
+ if (suggestion.deltaSchX !== 0) {
240794
+ addAttr(attrs, "newSchX", suggestion.newSchX);
240795
+ addAttr(attrs, "deltaSchX", suggestion.deltaSchX, { formatDelta: true });
240796
+ }
240797
+ if (suggestion.deltaSchY !== 0) {
240798
+ addAttr(attrs, "newSchY", suggestion.newSchY);
240799
+ addAttr(attrs, "deltaSchY", suggestion.deltaSchY, { formatDelta: true });
240800
+ }
240801
+ return `<OverlapCorrectionSuggestion ${attrs.join(" ")} />`;
240802
+ };
240803
+ var escapeAttr3 = (value) => value.replaceAll("&", "&amp;").replaceAll('"', "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
240804
+
240805
+ class SchematicPlacementAnalysis {
240806
+ lineItems;
240807
+ constructor(lineItems) {
240808
+ this.lineItems = lineItems;
240809
+ }
240810
+ getLineItems() {
240811
+ return this.lineItems;
240812
+ }
240813
+ getString() {
240814
+ return this.toString();
240815
+ }
240816
+ toString() {
240817
+ const schematicBoxPlacements = this.lineItems.filter((lineItem) => lineItem.lineItemType === "SchematicBoxPlacement");
240818
+ const issues = this.lineItems.flatMap((lineItem) => lineItem.lineItemType === "SchematicPlacementIssues" ? lineItem.issues : []);
240819
+ return [
240820
+ "<SchematicBoxPositions>",
240821
+ ...schematicBoxPlacements.map(lineItemToString3),
240822
+ "</SchematicBoxPositions>",
240823
+ ...issues.length > 0 ? [
240824
+ "<SchematicPlacementIssues>",
240825
+ ...issues.map((issue) => {
240826
+ switch (issue.lineItemType) {
240827
+ case "ComponentOverlap":
240828
+ return overlapIssueToString(issue);
240829
+ default:
240830
+ return "";
240831
+ }
240832
+ }),
240833
+ "</SchematicPlacementIssues>"
240834
+ ] : []
240835
+ ].join(`
240836
+ `);
240837
+ }
240838
+ }
240839
+ var analyzeSchematicPlacement = (circuitJson) => {
240840
+ const schematicBoxes = circuitJson.filter(isSchematicBox);
240841
+ const schematicComponentIds = new Set(circuitJson.filter(isSchematicComponent).map((schematicComponent) => schematicComponent.schematic_component_id));
240842
+ const lineItems = [
240843
+ ...circuitJson.filter(isSchematicComponent).map((schematicComponent) => schematicComponentToLineItem(schematicComponent, circuitJson, schematicBoxes.find((schematicBox) => schematicBox.schematic_component_id === schematicComponent.schematic_component_id))),
240844
+ ...schematicBoxes.filter((schematicBox) => !schematicBox.schematic_component_id || !schematicComponentIds.has(schematicBox.schematic_component_id)).map((schematicBox) => schematicBoxToLineItem(schematicBox, circuitJson))
240845
+ ];
240846
+ const issues = generateSchematicPlacementIssues(lineItems);
240847
+ return new SchematicPlacementAnalysis([
240848
+ ...lineItems,
240849
+ ...issues.length > 0 ? [{ lineItemType: "SchematicPlacementIssues", issues }] : []
240850
+ ]);
240851
+ };
240852
+ // cli/check/schematic-placement/register.ts
240853
+ var checkSchematicPlacement = async (file) => {
240854
+ const resolvedInputFilePath = await resolveCheckInputFilePath(file);
240855
+ const circuitJson = await getCircuitJsonForCheck({
240856
+ filePath: resolvedInputFilePath,
240857
+ platformConfig: {
240858
+ pcbDisabled: true,
240859
+ routingDisabled: true,
240860
+ placementDrcChecksDisabled: true
240861
+ },
240862
+ allowPrebuiltCircuitJson: true
240863
+ });
240864
+ return analyzeSchematicPlacement(circuitJson).getString();
240865
+ };
240866
+ var registerCheckSchematicPlacement = (program2) => {
240867
+ program2.commands.find((c3) => c3.name() === "check").command("schematic-placement").description("Analyze schematic component placement").argument("[file]", "Path to the entry file").action(async (file) => {
240868
+ try {
240869
+ const output = await checkSchematicPlacement(file);
240870
+ console.log(output);
240871
+ } catch (error) {
240872
+ console.error(error instanceof Error ? error.message : String(error));
240873
+ process.exit(1);
240874
+ }
240875
+ });
240876
+ };
240877
+
240620
240878
  // node_modules/circuit-json-trace-length-analysis/lib/analyze-circuit-json-trace-length.ts
240621
240879
  class Trace {
240622
240880
  id;
@@ -246291,8 +246549,8 @@ var warnIfTsconfigMissingTscircuitType = (projectDir) => {
246291
246549
  }
246292
246550
  try {
246293
246551
  const tsconfig = JSON.parse(fs51.readFileSync(tsconfigPath, "utf-8"));
246294
- const types = tsconfig?.compilerOptions?.types;
246295
- if (!Array.isArray(types) || !types.includes("tscircuit")) {
246552
+ const types2 = tsconfig?.compilerOptions?.types;
246553
+ if (!Array.isArray(types2) || !types2.includes("tscircuit")) {
246296
246554
  console.warn(kleur_default.yellow('Warning: "tscircuit" is missing from tsconfig.json compilerOptions.types. Add it (e.g. "types": ["tscircuit"]) to ensure CLI-provided types work correctly.'));
246297
246555
  }
246298
246556
  } catch {}
@@ -255424,9 +255682,9 @@ var ZodUnion2 = class extends ZodType2 {
255424
255682
  return this._def.options;
255425
255683
  }
255426
255684
  };
255427
- ZodUnion2.create = (types, params2) => {
255685
+ ZodUnion2.create = (types2, params2) => {
255428
255686
  return new ZodUnion2({
255429
- options: types,
255687
+ options: types2,
255430
255688
  typeName: ZodFirstPartyTypeKind3.ZodUnion,
255431
255689
  ...processCreateParams2(params2)
255432
255690
  });
@@ -260055,7 +260313,7 @@ function buildSubtree2(soup, opts) {
260055
260313
  }
260056
260314
  return soup.filter((e4) => included.has(e4));
260057
260315
  }
260058
- var cju7 = (circuitJsonInput, options = {}) => {
260316
+ var cju8 = (circuitJsonInput, options = {}) => {
260059
260317
  const circuitJson = circuitJsonInput;
260060
260318
  let internalStore = circuitJson._internal_store;
260061
260319
  if (!internalStore) {
@@ -260087,7 +260345,7 @@ var cju7 = (circuitJsonInput, options = {}) => {
260087
260345
  return internalStore.editCount;
260088
260346
  }
260089
260347
  if (prop === "subtree") {
260090
- return (opts) => cju7(buildSubtree2(circuitJson, opts), options);
260348
+ return (opts) => cju8(buildSubtree2(circuitJson, opts), options);
260091
260349
  }
260092
260350
  if (prop === "insert") {
260093
260351
  return (elm) => {
@@ -260197,8 +260455,8 @@ var cju7 = (circuitJsonInput, options = {}) => {
260197
260455
  });
260198
260456
  return su24;
260199
260457
  };
260200
- cju7.unparsed = cju7;
260201
- var su9 = cju7;
260458
+ cju8.unparsed = cju8;
260459
+ var su9 = cju8;
260202
260460
  function createIdKey2(element) {
260203
260461
  const type = element.type;
260204
260462
  return `${type}:${element[`${type}_id`]}`;
@@ -266614,7 +266872,7 @@ function buildSubtree3(soup, opts) {
266614
266872
  }
266615
266873
  return soup.filter((e4) => included.has(e4));
266616
266874
  }
266617
- var cju8 = (circuitJsonInput, options = {}) => {
266875
+ var cju9 = (circuitJsonInput, options = {}) => {
266618
266876
  const circuitJson = circuitJsonInput;
266619
266877
  let internalStore = circuitJson._internal_store;
266620
266878
  if (!internalStore) {
@@ -266646,7 +266904,7 @@ var cju8 = (circuitJsonInput, options = {}) => {
266646
266904
  return internalStore.editCount;
266647
266905
  }
266648
266906
  if (prop === "subtree") {
266649
- return (opts) => cju8(buildSubtree3(circuitJson, opts), options);
266907
+ return (opts) => cju9(buildSubtree3(circuitJson, opts), options);
266650
266908
  }
266651
266909
  if (prop === "insert") {
266652
266910
  return (elm) => {
@@ -266756,7 +267014,7 @@ var cju8 = (circuitJsonInput, options = {}) => {
266756
267014
  });
266757
267015
  return su24;
266758
267016
  };
266759
- cju8.unparsed = cju8;
267017
+ cju9.unparsed = cju9;
266760
267018
  function createIdKey3(element) {
266761
267019
  const type = element.type;
266762
267020
  return `${type}:${element[`${type}_id`]}`;
@@ -275748,6 +276006,7 @@ registerCheckPinSpecification(program2);
275748
276006
  registerCheckPlacement(program2);
275749
276007
  registerCheckRoutingDifficulty(program2);
275750
276008
  registerCheckRouting(program2);
276009
+ registerCheckSchematicPlacement(program2);
275751
276010
  registerCheckTraceLength(program2);
275752
276011
  registerRegistry(program2);
275753
276012
  registerRegistryPackages(program2);
package/dist/lib/index.js CHANGED
@@ -65661,7 +65661,7 @@ var getNodeHandler = (winterSpec, { port, middleware = [] }) => {
65661
65661
  }));
65662
65662
  };
65663
65663
  // package.json
65664
- var version = "0.1.1288";
65664
+ var version = "0.1.1289";
65665
65665
  var package_default = {
65666
65666
  name: "@tscircuit/cli",
65667
65667
  version,
@@ -65675,6 +65675,7 @@ var package_default = {
65675
65675
  "@biomejs/biome": "^1.9.4",
65676
65676
  "@tscircuit/circuit-json-placement-analysis": "^0.0.6",
65677
65677
  "@tscircuit/circuit-json-routing-analysis": "^0.0.1",
65678
+ "@tscircuit/circuit-json-schematic-placement-analysis": "github:tscircuit/circuit-json-schematic-placement-analysis#d09c8d74f3085b29744bb0f1c9864c1154c69436",
65678
65679
  "@tscircuit/fake-snippets": "^0.0.182",
65679
65680
  "@tscircuit/file-server": "^0.0.32",
65680
65681
  "@tscircuit/image-utils": "^0.0.3",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/cli",
3
- "version": "0.1.1289",
3
+ "version": "0.1.1290",
4
4
  "main": "dist/cli/main.js",
5
5
  "exports": {
6
6
  ".": "./dist/cli/main.js",
@@ -11,6 +11,7 @@
11
11
  "@biomejs/biome": "^1.9.4",
12
12
  "@tscircuit/circuit-json-placement-analysis": "^0.0.6",
13
13
  "@tscircuit/circuit-json-routing-analysis": "^0.0.1",
14
+ "@tscircuit/circuit-json-schematic-placement-analysis": "github:tscircuit/circuit-json-schematic-placement-analysis#d09c8d74f3085b29744bb0f1c9864c1154c69436",
14
15
  "@tscircuit/fake-snippets": "^0.0.182",
15
16
  "@tscircuit/file-server": "^0.0.32",
16
17
  "@tscircuit/image-utils": "^0.0.3",