@tscircuit/core 0.0.142 → 0.0.144

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
@@ -3,10 +3,11 @@ import * as zod from 'zod';
3
3
  import { ZodType, z } from 'zod';
4
4
  import { SchSymbol, BaseSymbolName } from 'schematic-symbols';
5
5
  import { PcbTraceError, PcbPlacementError, LayerRef, AnyCircuitElement, AnySourceComponent, RouteHintPoint } from 'circuit-json';
6
- import { SoupUtilObjects } from '@tscircuit/soup-util';
7
6
  import { Matrix } from 'transformation-matrix';
7
+ import { SoupUtilObjects } from '@tscircuit/soup-util';
8
8
  import * as _tscircuit_props from '@tscircuit/props';
9
9
  import { traceProps, groupProps, boardProps, capacitorProps, chipProps, diodeProps, jumperProps, ledProps, powerSourceProps, resistorProps, constraintProps, fabricationNotePathProps, fabricationNoteTextProps, footprintProps, holeProps, pcbKeepoutProps, netAliasProps, platedHoleProps, silkscreenCircleProps, silkscreenPathProps, silkscreenRectProps, silkscreenTextProps, smtPadProps, traceHintProps, viaProps, batteryProps, inductorProps, CapacitorProps, ChipProps, ResistorProps } from '@tscircuit/props';
10
+ import * as _tscircuit_layout from '@tscircuit/layout';
10
11
 
11
12
  declare const orderedRenderPhases: readonly ["ReactSubtreesRender", "InitializePortsFromChildren", "CreateNetsFromProps", "CreateTracesFromProps", "CreateTraceHintsFromProps", "SourceRender", "SourceParentAttachment", "PortDiscovery", "PortMatching", "SourceTraceRender", "SchematicComponentRender", "SchematicPortRender", "SchematicLayout", "SchematicTraceRender", "PcbComponentRender", "PcbPrimitiveRender", "PcbFootprintLayout", "PcbPortRender", "PcbPortAttachment", "PcbLayout", "PcbTraceRender", "PcbTraceHintRender", "PcbRouteNetIslands", "PcbComponentSizeCalculation", "CadModelRender"];
12
13
  type RenderPhase = (typeof orderedRenderPhases)[number];
@@ -833,7 +834,8 @@ declare class Board extends Group<typeof boardProps> {
833
834
  }>, "many">>;
834
835
  pcbX: z.ZodDefault<z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, number, string | number>>>;
835
836
  pcbY: z.ZodDefault<z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, number, string | number>>>;
836
- layout: z.ZodOptional<z.ZodAny>;
837
+ layout: z.ZodOptional<z.ZodType<_tscircuit_layout.LayoutBuilder, z.ZodTypeDef, _tscircuit_layout.LayoutBuilder>>;
838
+ manualEdits: z.ZodOptional<z.ZodType<_tscircuit_layout.ManualEditFile, z.ZodTypeDef, _tscircuit_layout.ManualEditFile>>;
837
839
  routingDisabled: z.ZodOptional<z.ZodBoolean>;
838
840
  children: z.ZodAny;
839
841
  defaultTraceWidth: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, number, string | number>>;
@@ -844,28 +846,30 @@ declare class Board extends Group<typeof boardProps> {
844
846
  children?: any;
845
847
  width?: number | undefined;
846
848
  height?: number | undefined;
847
- layout?: any;
848
- routingDisabled?: boolean | undefined;
849
- defaultTraceWidth?: number | undefined;
850
- schAutoLayoutEnabled?: boolean | undefined;
851
849
  outline?: {
852
850
  x: number;
853
851
  y: number;
854
852
  }[] | undefined;
853
+ layout?: _tscircuit_layout.LayoutBuilder | undefined;
854
+ manualEdits?: _tscircuit_layout.ManualEditFile | undefined;
855
+ routingDisabled?: boolean | undefined;
856
+ defaultTraceWidth?: number | undefined;
857
+ schAutoLayoutEnabled?: boolean | undefined;
855
858
  }, {
856
859
  pcbX?: string | number | undefined;
857
860
  pcbY?: string | number | undefined;
858
861
  children?: any;
859
862
  width?: string | number | undefined;
860
863
  height?: string | number | undefined;
861
- layout?: any;
862
- routingDisabled?: boolean | undefined;
863
- defaultTraceWidth?: string | number | undefined;
864
- schAutoLayoutEnabled?: boolean | undefined;
865
864
  outline?: {
866
865
  x: string | number;
867
866
  y: string | number;
868
867
  }[] | undefined;
868
+ layout?: _tscircuit_layout.LayoutBuilder | undefined;
869
+ manualEdits?: _tscircuit_layout.ManualEditFile | undefined;
870
+ routingDisabled?: boolean | undefined;
871
+ defaultTraceWidth?: string | number | undefined;
872
+ schAutoLayoutEnabled?: boolean | undefined;
869
873
  }>;
870
874
  };
871
875
  get boardThickness(): number;
package/dist/index.js CHANGED
@@ -354,18 +354,32 @@ var createInstanceFromReactElement = (reactElm) => {
354
354
  return rootContainer.children[0];
355
355
  };
356
356
 
357
- // lib/components/base-components/PrimitiveComponent.ts
358
- import { z } from "zod";
359
- import { symbols } from "schematic-symbols";
360
- import "react";
361
- import {
362
- applyToPoint,
363
- compose,
364
- flipY,
365
- identity as identity2,
366
- rotate,
367
- translate
368
- } from "transformation-matrix";
357
+ // lib/errors/InvalidProps.ts
358
+ var InvalidProps = class extends Error {
359
+ constructor(componentName, originalProps, formattedError) {
360
+ let message;
361
+ const propsWithError = Object.keys(formattedError).filter(
362
+ (k) => k !== "_errors"
363
+ );
364
+ const propMessage = propsWithError.map((k) => {
365
+ if (formattedError[k]._errors[0]) {
366
+ return `${k} (${formattedError[k]._errors[0]})`;
367
+ }
368
+ return `${k} (${JSON.stringify(formattedError[k])})`;
369
+ }).join(", ");
370
+ if ("name" in originalProps) {
371
+ message = `Invalid props for ${componentName} "${originalProps.name}": ${propMessage}`;
372
+ } else if ("footprint" in originalProps && typeof originalProps.footprint === "string") {
373
+ message = `Invalid props for ${componentName} (unnamed ${originalProps.footprint} component): ${propMessage}`;
374
+ } else {
375
+ message = `Invalid props for ${componentName} (unnamed): ${propMessage}`;
376
+ }
377
+ super(message);
378
+ this.componentName = componentName;
379
+ this.originalProps = originalProps;
380
+ this.formattedError = formattedError;
381
+ }
382
+ };
369
383
 
370
384
  // lib/utils/selector-matching/is-matching-selector.ts
371
385
  function isMatchingSelector(component, selector) {
@@ -396,34 +410,17 @@ function isMatchingSelector(component, selector) {
396
410
  });
397
411
  }
398
412
 
399
- // lib/errors/InvalidProps.ts
400
- var InvalidProps = class extends Error {
401
- constructor(componentName, originalProps, formattedError) {
402
- let message;
403
- const propsWithError = Object.keys(formattedError).filter(
404
- (k) => k !== "_errors"
405
- );
406
- const propMessage = propsWithError.map((k) => {
407
- if (formattedError[k]._errors[0]) {
408
- return `${k} (${formattedError[k]._errors[0]})`;
409
- }
410
- return `${k} (${JSON.stringify(formattedError[k])})`;
411
- }).join(", ");
412
- if ("name" in originalProps) {
413
- message = `Invalid props for ${componentName} "${originalProps.name}": ${propMessage}`;
414
- } else if ("footprint" in originalProps && typeof originalProps.footprint === "string") {
415
- message = `Invalid props for ${componentName} (unnamed ${originalProps.footprint} component): ${propMessage}`;
416
- } else {
417
- message = `Invalid props for ${componentName} (unnamed): ${propMessage}`;
418
- }
419
- super(message);
420
- this.componentName = componentName;
421
- this.originalProps = originalProps;
422
- this.formattedError = formattedError;
423
- }
424
- };
425
-
426
413
  // lib/components/base-components/PrimitiveComponent.ts
414
+ import { symbols } from "schematic-symbols";
415
+ import {
416
+ applyToPoint,
417
+ compose,
418
+ flipY,
419
+ identity as identity2,
420
+ rotate,
421
+ translate
422
+ } from "transformation-matrix";
423
+ import { z } from "zod";
427
424
  var PrimitiveComponent = class extends Renderable {
428
425
  parent = null;
429
426
  children;
@@ -630,16 +627,17 @@ var PrimitiveComponent = class extends Renderable {
630
627
  _getManualPlacementForComponent(component) {
631
628
  if (!this.isSubcircuit) return null;
632
629
  const layout = this.props.layout;
633
- if (!layout) return null;
634
- const placementConfig = layout.manual_pcb_placement_config;
635
- if (!placementConfig) return null;
636
- for (const position of placementConfig.positions) {
637
- if (isMatchingSelector(component, position.selector)) {
630
+ const manualEdits = this.props.manualEdits;
631
+ if (!layout && !manualEdits) return null;
632
+ const placementConfigPositions = layout?.manual_pcb_placement_config?.positions || manualEdits?.pcb_placements;
633
+ if (!placementConfigPositions) return null;
634
+ for (const position of placementConfigPositions) {
635
+ if (layout && isMatchingSelector(component, position.selector) || component.props.name === position.selector) {
638
636
  const center = applyToPoint(
639
637
  this._computePcbGlobalTransformBeforeLayout(),
640
638
  position.center
641
639
  );
642
- return center;
640
+ return Array.isArray(center) ? { x: center[0], y: center[1] } : center;
643
641
  }
644
642
  }
645
643
  return null;
@@ -1802,7 +1800,7 @@ function getPortFromHints(hints) {
1802
1800
 
1803
1801
  // lib/components/base-components/NormalComponent.ts
1804
1802
  import {
1805
- isValidElement as isReactElement2,
1803
+ isValidElement as isReactElement,
1806
1804
  isValidElement
1807
1805
  } from "react";
1808
1806
  import { symbols as symbols2 } from "schematic-symbols";
@@ -2244,7 +2242,13 @@ var NormalComponent = class extends PrimitiveComponent {
2244
2242
  const { db } = this.root;
2245
2243
  const { _parsedProps: props } = this;
2246
2244
  const bounds = getBoundsOfPcbComponents(this.children);
2245
+ if (bounds.width === 0 || bounds.height === 0) return;
2246
+ const center = {
2247
+ x: (bounds.minX + bounds.maxX) / 2,
2248
+ y: (bounds.minY + bounds.maxY) / 2
2249
+ };
2247
2250
  db.pcb_component.update(this.pcb_component_id, {
2251
+ center,
2248
2252
  width: bounds.width,
2249
2253
  height: bounds.height
2250
2254
  });
@@ -2259,7 +2263,7 @@ var NormalComponent = class extends PrimitiveComponent {
2259
2263
  this.initPorts();
2260
2264
  }
2261
2265
  doInitialReactSubtreesRender() {
2262
- if (isReactElement2(this.props.footprint)) {
2266
+ if (isReactElement(this.props.footprint)) {
2263
2267
  if (this.reactSubtrees.some((rs) => rs.element === this.props.footprint))
2264
2268
  return;
2265
2269
  const subtree = this._renderReactSubtree(this.props.footprint);
@@ -2279,7 +2283,7 @@ var NormalComponent = class extends PrimitiveComponent {
2279
2283
  }
2280
2284
  add(componentOrElm) {
2281
2285
  let component;
2282
- if (isReactElement2(componentOrElm)) {
2286
+ if (isReactElement(componentOrElm)) {
2283
2287
  const subtree = this._renderReactSubtree(componentOrElm);
2284
2288
  this.reactSubtrees.push(subtree);
2285
2289
  component = subtree.component;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.142",
4
+ "version": "0.0.144",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -40,7 +40,7 @@
40
40
  "@tscircuit/footprinter": "^0.0.77",
41
41
  "@tscircuit/infgrid-ijump-astar": "^0.0.24",
42
42
  "@tscircuit/math-utils": "^0.0.4",
43
- "@tscircuit/props": "^0.0.77",
43
+ "@tscircuit/props": "^0.0.78",
44
44
  "@tscircuit/schematic-autolayout": "^0.0.5",
45
45
  "@tscircuit/soup-util": "^0.0.33",
46
46
  "circuit-json": "^0.0.91",