@tscircuit/core 0.0.998 → 0.0.1000

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
@@ -168,9 +168,9 @@ interface IRootCircuit {
168
168
  _hasIncompleteAsyncEffectsForPhase(phase: RenderPhase): boolean;
169
169
  }
170
170
 
171
- declare const orderedRenderPhases: readonly ["ReactSubtreesRender", "InflateSubcircuitCircuitJson", "SourceNameDuplicateComponentRemoval", "PcbFootprintStringRender", "InitializePortsFromChildren", "CreateNetsFromProps", "AssignFallbackProps", "CreateTracesFromProps", "CreateTracesFromNetLabels", "CreateTraceHintsFromProps", "SourceGroupRender", "AssignNameToUnnamedComponents", "SourceRender", "SourceParentAttachment", "PortMatching", "OptimizeSelectorCache", "SourceTraceRender", "SourceAddConnectivityMapKey", "SourceDesignRuleChecks", "SimulationRender", "SchematicComponentRender", "SchematicPortRender", "SchematicPrimitiveRender", "SchematicComponentSizeCalculation", "SchematicLayout", "SchematicTraceRender", "SchematicReplaceNetLabelsWithSymbols", "PanelBoardLayout", "PcbComponentRender", "PcbPrimitiveRender", "PcbFootprintLayout", "PcbPortRender", "PcbPortAttachment", "PcbComponentSizeCalculation", "PcbComponentAnchorAlignment", "PcbLayout", "PcbBoardAutoSize", "PanelLayout", "PcbTraceHintRender", "PcbManualTraceRender", "PcbTraceRender", "PcbRouteNetIslands", "PcbCopperPourRender", "PcbDesignRuleChecks", "SilkscreenOverlapAdjustment", "CadModelRender", "PartsEngineRender", "SimulationSpiceEngineRender"];
171
+ declare const orderedRenderPhases: readonly ["ReactSubtreesRender", "InflateSubcircuitCircuitJson", "SourceNameDuplicateComponentRemoval", "PcbFootprintStringRender", "InitializePortsFromChildren", "CreateNetsFromProps", "AssignFallbackProps", "CreateTracesFromProps", "CreateTracesFromNetLabels", "CreateTraceHintsFromProps", "SourceGroupRender", "AssignNameToUnnamedComponents", "SourceRender", "SourceParentAttachment", "PortMatching", "OptimizeSelectorCache", "SourceTraceRender", "SourceAddConnectivityMapKey", "SourceDesignRuleChecks", "SimulationRender", "SchematicComponentRender", "SchematicPortRender", "SchematicPrimitiveRender", "SchematicSymbolResize", "SchematicComponentSizeCalculation", "SchematicLayout", "SchematicTraceRender", "SchematicReplaceNetLabelsWithSymbols", "PanelBoardLayout", "PcbComponentRender", "PcbPrimitiveRender", "PcbFootprintLayout", "PcbPortRender", "PcbPortAttachment", "PcbComponentSizeCalculation", "PcbComponentAnchorAlignment", "PcbLayout", "PcbBoardAutoSize", "PanelLayout", "PcbTraceHintRender", "PcbManualTraceRender", "PcbTraceRender", "PcbRouteNetIslands", "PcbCopperPourRender", "PcbDesignRuleChecks", "SilkscreenOverlapAdjustment", "CadModelRender", "PartsEngineRender", "SimulationSpiceEngineRender"];
172
172
  type RenderPhase = (typeof orderedRenderPhases)[number];
173
- declare const renderPhaseIndexMap: Map<"ReactSubtreesRender" | "InflateSubcircuitCircuitJson" | "SourceNameDuplicateComponentRemoval" | "PcbFootprintStringRender" | "InitializePortsFromChildren" | "CreateNetsFromProps" | "AssignFallbackProps" | "CreateTracesFromProps" | "CreateTracesFromNetLabels" | "CreateTraceHintsFromProps" | "SourceGroupRender" | "AssignNameToUnnamedComponents" | "SourceRender" | "SourceParentAttachment" | "PortMatching" | "OptimizeSelectorCache" | "SourceTraceRender" | "SourceAddConnectivityMapKey" | "SourceDesignRuleChecks" | "SimulationRender" | "SchematicComponentRender" | "SchematicPortRender" | "SchematicPrimitiveRender" | "SchematicComponentSizeCalculation" | "SchematicLayout" | "SchematicTraceRender" | "SchematicReplaceNetLabelsWithSymbols" | "PanelBoardLayout" | "PcbComponentRender" | "PcbPrimitiveRender" | "PcbFootprintLayout" | "PcbPortRender" | "PcbPortAttachment" | "PcbComponentSizeCalculation" | "PcbComponentAnchorAlignment" | "PcbLayout" | "PcbBoardAutoSize" | "PanelLayout" | "PcbTraceHintRender" | "PcbManualTraceRender" | "PcbTraceRender" | "PcbRouteNetIslands" | "PcbCopperPourRender" | "PcbDesignRuleChecks" | "SilkscreenOverlapAdjustment" | "CadModelRender" | "PartsEngineRender" | "SimulationSpiceEngineRender", number>;
173
+ declare const renderPhaseIndexMap: Map<"ReactSubtreesRender" | "InflateSubcircuitCircuitJson" | "SourceNameDuplicateComponentRemoval" | "PcbFootprintStringRender" | "InitializePortsFromChildren" | "CreateNetsFromProps" | "AssignFallbackProps" | "CreateTracesFromProps" | "CreateTracesFromNetLabels" | "CreateTraceHintsFromProps" | "SourceGroupRender" | "AssignNameToUnnamedComponents" | "SourceRender" | "SourceParentAttachment" | "PortMatching" | "OptimizeSelectorCache" | "SourceTraceRender" | "SourceAddConnectivityMapKey" | "SourceDesignRuleChecks" | "SimulationRender" | "SchematicComponentRender" | "SchematicPortRender" | "SchematicPrimitiveRender" | "SchematicSymbolResize" | "SchematicComponentSizeCalculation" | "SchematicLayout" | "SchematicTraceRender" | "SchematicReplaceNetLabelsWithSymbols" | "PanelBoardLayout" | "PcbComponentRender" | "PcbPrimitiveRender" | "PcbFootprintLayout" | "PcbPortRender" | "PcbPortAttachment" | "PcbComponentSizeCalculation" | "PcbComponentAnchorAlignment" | "PcbLayout" | "PcbBoardAutoSize" | "PanelLayout" | "PcbTraceHintRender" | "PcbManualTraceRender" | "PcbTraceRender" | "PcbRouteNetIslands" | "PcbCopperPourRender" | "PcbDesignRuleChecks" | "SilkscreenOverlapAdjustment" | "CadModelRender" | "PartsEngineRender" | "SimulationSpiceEngineRender", number>;
174
174
  type RenderPhaseFn<K extends RenderPhase = RenderPhase> = `doInitial${K}` | `update${K}` | `remove${K}`;
175
175
  type RenderPhaseStates = Record<RenderPhase, {
176
176
  initialized: boolean;
@@ -373,6 +373,40 @@ interface ISubcircuit extends PrimitiveComponent {
373
373
  getNormalComponentNameMap?: () => Map<string, NormalComponent[]>;
374
374
  }
375
375
 
376
+ interface SchematicSymbolBounds {
377
+ minX: number;
378
+ maxX: number;
379
+ minY: number;
380
+ maxY: number;
381
+ }
382
+ interface ISymbol {
383
+ /**
384
+ * The transformation matrix to convert from user coordinates (as specified
385
+ * in the symbol's children) to the final resized symbol coordinates.
386
+ * This is computed lazily when first requested.
387
+ */
388
+ userCoordinateToResizedSymbolTransformMat?: Matrix;
389
+ /**
390
+ * The computed bounds of the symbol's schematic primitives before any
391
+ * resizing is applied.
392
+ */
393
+ schematicSymbolBoundsInUserCoordinates?: SchematicSymbolBounds;
394
+ /**
395
+ * Get the bounds of the symbol's schematic primitives.
396
+ * This triggers computation if not already done.
397
+ */
398
+ getSchematicSymbolBounds(): SchematicSymbolBounds | null;
399
+ /**
400
+ * Get the transformation matrix for resizing symbol contents.
401
+ * Returns null if no resizing is needed (no width/height specified).
402
+ */
403
+ getUserCoordinateToResizedSymbolTransform(): Matrix | null;
404
+ /**
405
+ * Check if this symbol has explicit width/height that requires resizing.
406
+ */
407
+ hasExplicitSize(): boolean;
408
+ }
409
+
376
410
  interface IGroup extends PrimitiveComponent {
377
411
  source_group_id: string | null;
378
412
  pcb_group_id: string | null;
@@ -471,6 +505,11 @@ declare abstract class PrimitiveComponent<ZodProps extends ZodType = any> extend
471
505
  */
472
506
  _computePcbGlobalTransformBeforeLayout(): Matrix;
473
507
  getPrimitiveContainer(): PrimitiveComponent | null;
508
+ /**
509
+ * Get the Symbol ancestor if this component is inside a Symbol primitive container.
510
+ * Used by schematic primitives to access the symbol's resize transform.
511
+ */
512
+ _getSymbolAncestor(): ISymbol | null;
474
513
  /**
475
514
  * Walk up the component hierarchy to find the nearest NormalComponent ancestor.
476
515
  * This is useful for primitive components that need access to component IDs
@@ -124604,6 +124643,7 @@ declare class TestPoint extends NormalComponent<typeof testpointProps> {
124604
124643
 
124605
124644
  declare class SchematicText extends PrimitiveComponent<typeof schematicTextProps> {
124606
124645
  isSchematicPrimitive: boolean;
124646
+ schematic_text_id?: string;
124607
124647
  get config(): {
124608
124648
  componentName: string;
124609
124649
  zodProps: zod.ZodObject<{
@@ -124633,6 +124673,7 @@ declare class SchematicText extends PrimitiveComponent<typeof schematicTextProps
124633
124673
  }>;
124634
124674
  };
124635
124675
  doInitialSchematicPrimitiveRender(): void;
124676
+ doInitialSchematicSymbolResize(): void;
124636
124677
  }
124637
124678
 
124638
124679
  declare class SchematicLine extends PrimitiveComponent<typeof schematicLineProps> {
@@ -124667,6 +124708,7 @@ declare class SchematicLine extends PrimitiveComponent<typeof schematicLineProps
124667
124708
  };
124668
124709
  schematic_line_id?: string;
124669
124710
  doInitialSchematicPrimitiveRender(): void;
124711
+ doInitialSchematicSymbolResize(): void;
124670
124712
  }
124671
124713
 
124672
124714
  declare class SchematicRect extends PrimitiveComponent<typeof schematicRectProps> {
@@ -124713,6 +124755,7 @@ declare class SchematicRect extends PrimitiveComponent<typeof schematicRectProps
124713
124755
  };
124714
124756
  schematic_rect_id?: string;
124715
124757
  doInitialSchematicPrimitiveRender(): void;
124758
+ doInitialSchematicSymbolResize(): void;
124716
124759
  }
124717
124760
 
124718
124761
  declare class SchematicArc extends PrimitiveComponent<typeof schematicArcProps> {
@@ -124765,6 +124808,7 @@ declare class SchematicArc extends PrimitiveComponent<typeof schematicArcProps>
124765
124808
  };
124766
124809
  schematic_arc_id?: string;
124767
124810
  doInitialSchematicPrimitiveRender(): void;
124811
+ doInitialSchematicSymbolResize(): void;
124768
124812
  }
124769
124813
 
124770
124814
  declare class SchematicCircle extends PrimitiveComponent<typeof schematicCircleProps> {
@@ -124814,10 +124858,12 @@ declare class SchematicCircle extends PrimitiveComponent<typeof schematicCircleP
124814
124858
  };
124815
124859
  schematic_circle_id?: string;
124816
124860
  doInitialSchematicPrimitiveRender(): void;
124861
+ doInitialSchematicSymbolResize(): void;
124817
124862
  }
124818
124863
 
124819
124864
  declare class SchematicPath extends PrimitiveComponent<typeof schematicPathProps> {
124820
124865
  isSchematicPrimitive: boolean;
124866
+ schematic_path_ids: string[];
124821
124867
  get config(): {
124822
124868
  componentName: string;
124823
124869
  zodProps: zod.ZodObject<{
@@ -124859,6 +124905,7 @@ declare class SchematicPath extends PrimitiveComponent<typeof schematicPathProps
124859
124905
  }>;
124860
124906
  };
124861
124907
  doInitialSchematicPrimitiveRender(): void;
124908
+ doInitialSchematicSymbolResize(): void;
124862
124909
  }
124863
124910
 
124864
124911
  declare class SchematicBox extends PrimitiveComponent<typeof schematicBoxProps> {
@@ -125077,18 +125124,34 @@ declare class SchematicCell extends PrimitiveComponent<typeof schematicCellProps
125077
125124
  };
125078
125125
  }
125079
125126
 
125080
- declare class SymbolComponent extends PrimitiveComponent<typeof symbolProps> {
125127
+ declare class SymbolComponent extends PrimitiveComponent<typeof symbolProps> implements ISymbol {
125081
125128
  isPrimitiveContainer: boolean;
125129
+ userCoordinateToResizedSymbolTransformMat?: Matrix;
125130
+ schematicSymbolBoundsInUserCoordinates?: SchematicSymbolBounds;
125082
125131
  get config(): {
125083
125132
  componentName: string;
125084
125133
  zodProps: zod.ZodObject<{
125085
125134
  originalFacingDirection: zod.ZodOptional<zod.ZodDefault<zod.ZodEnum<["up", "down", "left", "right"]>>>;
125135
+ width: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
125136
+ height: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
125137
+ name: zod.ZodOptional<zod.ZodString>;
125086
125138
  }, "strip", zod.ZodTypeAny, {
125139
+ name?: string | undefined;
125140
+ width?: number | undefined;
125141
+ height?: number | undefined;
125087
125142
  originalFacingDirection?: "up" | "down" | "left" | "right" | undefined;
125088
125143
  }, {
125144
+ name?: string | undefined;
125145
+ width?: string | number | undefined;
125146
+ height?: string | number | undefined;
125089
125147
  originalFacingDirection?: "up" | "down" | "left" | "right" | undefined;
125090
125148
  }>;
125091
125149
  };
125150
+ hasExplicitSize(): boolean;
125151
+ getSchematicSymbolBounds(): SchematicSymbolBounds | null;
125152
+ getUserCoordinateToResizedSymbolTransform(): Matrix | null;
125153
+ private _computeSchematicSymbolBounds;
125154
+ private _computeUserCoordinateToResizedSymbolTransform;
125092
125155
  }
125093
125156
 
125094
125157
  declare class AnalogSimulation extends PrimitiveComponent<typeof analogSimulationProps> {
package/dist/index.js CHANGED
@@ -136,6 +136,7 @@ var orderedRenderPhases = [
136
136
  "SchematicComponentRender",
137
137
  "SchematicPortRender",
138
138
  "SchematicPrimitiveRender",
139
+ "SchematicSymbolResize",
139
140
  "SchematicComponentSizeCalculation",
140
141
  "SchematicLayout",
141
142
  "SchematicTraceRender",
@@ -1060,6 +1061,17 @@ var PrimitiveComponent2 = class extends Renderable {
1060
1061
  if (this.isPrimitiveContainer) return this;
1061
1062
  return this.parent?.getPrimitiveContainer?.() ?? null;
1062
1063
  }
1064
+ /**
1065
+ * Get the Symbol ancestor if this component is inside a Symbol primitive container.
1066
+ * Used by schematic primitives to access the symbol's resize transform.
1067
+ */
1068
+ _getSymbolAncestor() {
1069
+ const container = this.getPrimitiveContainer();
1070
+ if (container?.componentName === "Symbol") {
1071
+ return container;
1072
+ }
1073
+ return null;
1074
+ }
1063
1075
  /**
1064
1076
  * Walk up the component hierarchy to find the nearest NormalComponent ancestor.
1065
1077
  * This is useful for primitive components that need access to component IDs
@@ -3918,9 +3930,15 @@ function getArcBounds(elm) {
3918
3930
  return { minX, maxX, minY, maxY };
3919
3931
  }
3920
3932
  function getBoundsForSchematic(db) {
3921
- let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
3933
+ let minX = Infinity;
3934
+ let minY = Infinity;
3935
+ let maxX = -Infinity;
3936
+ let maxY = -Infinity;
3922
3937
  for (const elm of db) {
3923
- let cx, cy, w, h;
3938
+ let cx;
3939
+ let cy;
3940
+ let w;
3941
+ let h;
3924
3942
  if (elm.type === "schematic_component") {
3925
3943
  cx = elm.center?.x;
3926
3944
  cy = elm.center?.y;
@@ -3972,6 +3990,19 @@ function getBoundsForSchematic(db) {
3972
3990
  maxY = Math.max(maxY, bounds.maxY);
3973
3991
  }
3974
3992
  continue;
3993
+ } else if (elm.type === "schematic_path") {
3994
+ const points = elm.points;
3995
+ if (Array.isArray(points)) {
3996
+ for (const point6 of points) {
3997
+ if (typeof point6.x === "number" && typeof point6.y === "number") {
3998
+ minX = Math.min(minX, point6.x);
3999
+ maxX = Math.max(maxX, point6.x);
4000
+ minY = Math.min(minY, point6.y);
4001
+ maxY = Math.max(maxY, point6.y);
4002
+ }
4003
+ }
4004
+ }
4005
+ continue;
3975
4006
  }
3976
4007
  if (typeof cx === "number" && typeof cy === "number" && typeof w === "number" && typeof h === "number") {
3977
4008
  minX = Math.min(minX, cx - w / 2);
@@ -9007,7 +9038,7 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
9007
9038
  font_size: 0.18
9008
9039
  });
9009
9040
  const component_name_text = db.schematic_text.insert({
9010
- text: props.name ?? "",
9041
+ text: props.displayName ?? props.name ?? "",
9011
9042
  schematic_component_id: schematic_component2.schematic_component_id,
9012
9043
  anchor: "left",
9013
9044
  rotation: 0,
@@ -20306,8 +20337,10 @@ var TestPoint = class extends NormalComponent3 {
20306
20337
 
20307
20338
  // lib/components/primitive-components/SchematicText.ts
20308
20339
  import { schematicTextProps } from "@tscircuit/props";
20340
+ import { applyToPoint as applyToPoint19 } from "transformation-matrix";
20309
20341
  var SchematicText = class extends PrimitiveComponent2 {
20310
20342
  isSchematicPrimitive = true;
20343
+ schematic_text_id;
20311
20344
  get config() {
20312
20345
  return {
20313
20346
  componentName: "SchematicText",
@@ -20319,7 +20352,7 @@ var SchematicText = class extends PrimitiveComponent2 {
20319
20352
  const { db } = this.root;
20320
20353
  const { _parsedProps: props } = this;
20321
20354
  const globalPos = this._getGlobalSchematicPositionBeforeLayout();
20322
- db.schematic_text.insert({
20355
+ const schematic_text = db.schematic_text.insert({
20323
20356
  anchor: props.anchor ?? "center",
20324
20357
  text: normalizeTextForCircuitJson(props.text),
20325
20358
  font_size: props.fontSize,
@@ -20330,11 +20363,27 @@ var SchematicText = class extends PrimitiveComponent2 {
20330
20363
  },
20331
20364
  rotation: props.schRotation ?? 0
20332
20365
  });
20366
+ this.schematic_text_id = schematic_text.schematic_text_id;
20367
+ }
20368
+ doInitialSchematicSymbolResize() {
20369
+ if (this.root?.schematicDisabled) return;
20370
+ if (!this.schematic_text_id) return;
20371
+ const symbol = this._getSymbolAncestor();
20372
+ const transform = symbol?.getUserCoordinateToResizedSymbolTransform();
20373
+ if (!transform) return;
20374
+ const { db } = this.root;
20375
+ const text = db.schematic_text.get(this.schematic_text_id);
20376
+ if (!text) return;
20377
+ const newPosition = applyToPoint19(transform, text.position);
20378
+ db.schematic_text.update(this.schematic_text_id, {
20379
+ position: { x: newPosition.x, y: newPosition.y }
20380
+ });
20333
20381
  }
20334
20382
  };
20335
20383
 
20336
20384
  // lib/components/primitive-components/SchematicLine.ts
20337
20385
  import { schematicLineProps } from "@tscircuit/props";
20386
+ import { applyToPoint as applyToPoint20 } from "transformation-matrix";
20338
20387
  var SchematicLine = class extends PrimitiveComponent2 {
20339
20388
  isSchematicPrimitive = true;
20340
20389
  get config() {
@@ -20363,10 +20412,29 @@ var SchematicLine = class extends PrimitiveComponent2 {
20363
20412
  });
20364
20413
  this.schematic_line_id = schematic_line.schematic_line_id;
20365
20414
  }
20415
+ doInitialSchematicSymbolResize() {
20416
+ if (this.root?.schematicDisabled) return;
20417
+ if (!this.schematic_line_id) return;
20418
+ const symbol = this._getSymbolAncestor();
20419
+ const transform = symbol?.getUserCoordinateToResizedSymbolTransform();
20420
+ if (!transform) return;
20421
+ const { db } = this.root;
20422
+ const line = db.schematic_line.get(this.schematic_line_id);
20423
+ if (!line) return;
20424
+ const p1 = applyToPoint20(transform, { x: line.x1, y: line.y1 });
20425
+ const p2 = applyToPoint20(transform, { x: line.x2, y: line.y2 });
20426
+ db.schematic_line.update(this.schematic_line_id, {
20427
+ x1: p1.x,
20428
+ y1: p1.y,
20429
+ x2: p2.x,
20430
+ y2: p2.y
20431
+ });
20432
+ }
20366
20433
  };
20367
20434
 
20368
20435
  // lib/components/primitive-components/SchematicRect.ts
20369
20436
  import { schematicRectProps } from "@tscircuit/props";
20437
+ import { applyToPoint as applyToPoint21 } from "transformation-matrix";
20370
20438
  var SchematicRect = class extends PrimitiveComponent2 {
20371
20439
  isSchematicPrimitive = true;
20372
20440
  get config() {
@@ -20399,10 +20467,40 @@ var SchematicRect = class extends PrimitiveComponent2 {
20399
20467
  });
20400
20468
  this.schematic_rect_id = schematic_rect.schematic_rect_id;
20401
20469
  }
20470
+ doInitialSchematicSymbolResize() {
20471
+ if (this.root?.schematicDisabled) return;
20472
+ if (!this.schematic_rect_id) return;
20473
+ const symbol = this._getSymbolAncestor();
20474
+ const transform = symbol?.getUserCoordinateToResizedSymbolTransform();
20475
+ if (!transform) return;
20476
+ const { db } = this.root;
20477
+ const rect = db.schematic_rect.get(this.schematic_rect_id);
20478
+ if (!rect) return;
20479
+ const topLeft = applyToPoint21(transform, {
20480
+ x: rect.center.x - rect.width / 2,
20481
+ y: rect.center.y + rect.height / 2
20482
+ });
20483
+ const bottomRight = applyToPoint21(transform, {
20484
+ x: rect.center.x + rect.width / 2,
20485
+ y: rect.center.y - rect.height / 2
20486
+ });
20487
+ const newWidth = Math.abs(bottomRight.x - topLeft.x);
20488
+ const newHeight = Math.abs(topLeft.y - bottomRight.y);
20489
+ const newCenter = {
20490
+ x: (topLeft.x + bottomRight.x) / 2,
20491
+ y: (topLeft.y + bottomRight.y) / 2
20492
+ };
20493
+ db.schematic_rect.update(this.schematic_rect_id, {
20494
+ center: newCenter,
20495
+ width: newWidth,
20496
+ height: newHeight
20497
+ });
20498
+ }
20402
20499
  };
20403
20500
 
20404
20501
  // lib/components/primitive-components/SchematicArc.ts
20405
20502
  import { schematicArcProps } from "@tscircuit/props";
20503
+ import { applyToPoint as applyToPoint22 } from "transformation-matrix";
20406
20504
  var SchematicArc = class extends PrimitiveComponent2 {
20407
20505
  isSchematicPrimitive = true;
20408
20506
  get config() {
@@ -20435,10 +20533,31 @@ var SchematicArc = class extends PrimitiveComponent2 {
20435
20533
  });
20436
20534
  this.schematic_arc_id = schematic_arc.schematic_arc_id;
20437
20535
  }
20536
+ doInitialSchematicSymbolResize() {
20537
+ if (this.root?.schematicDisabled) return;
20538
+ if (!this.schematic_arc_id) return;
20539
+ const symbol = this._getSymbolAncestor();
20540
+ const transform = symbol?.getUserCoordinateToResizedSymbolTransform();
20541
+ if (!transform) return;
20542
+ const { db } = this.root;
20543
+ const arc = db.schematic_arc.get(this.schematic_arc_id);
20544
+ if (!arc) return;
20545
+ const newCenter = applyToPoint22(transform, arc.center);
20546
+ const edgePoint = applyToPoint22(transform, {
20547
+ x: arc.center.x + arc.radius,
20548
+ y: arc.center.y
20549
+ });
20550
+ const newRadius = Math.abs(edgePoint.x - newCenter.x);
20551
+ db.schematic_arc.update(this.schematic_arc_id, {
20552
+ center: { x: newCenter.x, y: newCenter.y },
20553
+ radius: newRadius
20554
+ });
20555
+ }
20438
20556
  };
20439
20557
 
20440
20558
  // lib/components/primitive-components/SchematicCircle.ts
20441
20559
  import { schematicCircleProps } from "@tscircuit/props";
20560
+ import { applyToPoint as applyToPoint23 } from "transformation-matrix";
20442
20561
  var SchematicCircle = class extends PrimitiveComponent2 {
20443
20562
  isSchematicPrimitive = true;
20444
20563
  get config() {
@@ -20470,6 +20589,26 @@ var SchematicCircle = class extends PrimitiveComponent2 {
20470
20589
  });
20471
20590
  this.schematic_circle_id = schematic_circle.schematic_circle_id;
20472
20591
  }
20592
+ doInitialSchematicSymbolResize() {
20593
+ if (this.root?.schematicDisabled) return;
20594
+ if (!this.schematic_circle_id) return;
20595
+ const symbol = this._getSymbolAncestor();
20596
+ const transform = symbol?.getUserCoordinateToResizedSymbolTransform();
20597
+ if (!transform) return;
20598
+ const { db } = this.root;
20599
+ const circle = db.schematic_circle.get(this.schematic_circle_id);
20600
+ if (!circle) return;
20601
+ const newCenter = applyToPoint23(transform, circle.center);
20602
+ const edgePoint = applyToPoint23(transform, {
20603
+ x: circle.center.x + circle.radius,
20604
+ y: circle.center.y
20605
+ });
20606
+ const newRadius = Math.abs(edgePoint.x - newCenter.x);
20607
+ db.schematic_circle.update(this.schematic_circle_id, {
20608
+ center: { x: newCenter.x, y: newCenter.y },
20609
+ radius: newRadius
20610
+ });
20611
+ }
20473
20612
  };
20474
20613
 
20475
20614
  // lib/components/primitive-components/SchematicPath.ts
@@ -20604,8 +20743,10 @@ function svgPathToPoints(svgPath, samplesPerUnit = 10) {
20604
20743
  }
20605
20744
 
20606
20745
  // lib/components/primitive-components/SchematicPath.ts
20746
+ import { applyToPoint as applyToPoint24 } from "transformation-matrix";
20607
20747
  var SchematicPath = class extends PrimitiveComponent2 {
20608
20748
  isSchematicPrimitive = true;
20749
+ schematic_path_ids = [];
20609
20750
  get config() {
20610
20751
  return {
20611
20752
  componentName: "SchematicPath",
@@ -20619,10 +20760,11 @@ var SchematicPath = class extends PrimitiveComponent2 {
20619
20760
  const globalPos = this._getGlobalSchematicPositionBeforeLayout();
20620
20761
  const schematic_component_id = this.getPrimitiveContainer()?.parent?.schematic_component_id;
20621
20762
  const subcircuit_id = this.getSubcircuit().subcircuit_id ?? void 0;
20763
+ this.schematic_path_ids = [];
20622
20764
  if (props.svgPath) {
20623
20765
  const subpaths = svgPathToPoints(props.svgPath);
20624
20766
  for (const subpathPoints of subpaths) {
20625
- db.schematic_path.insert({
20767
+ const schematic_path = db.schematic_path.insert({
20626
20768
  schematic_component_id,
20627
20769
  points: subpathPoints.map((point6) => ({
20628
20770
  x: point6.x + globalPos.x,
@@ -20634,9 +20776,10 @@ var SchematicPath = class extends PrimitiveComponent2 {
20634
20776
  stroke_width: props.strokeWidth,
20635
20777
  subcircuit_id
20636
20778
  });
20779
+ this.schematic_path_ids.push(schematic_path.schematic_path_id);
20637
20780
  }
20638
20781
  } else if (props.points && props.points.length > 0) {
20639
- db.schematic_path.insert({
20782
+ const schematic_path = db.schematic_path.insert({
20640
20783
  schematic_component_id,
20641
20784
  points: props.points.map((point6) => ({
20642
20785
  x: point6.x + globalPos.x,
@@ -20648,6 +20791,26 @@ var SchematicPath = class extends PrimitiveComponent2 {
20648
20791
  stroke_width: props.strokeWidth,
20649
20792
  subcircuit_id
20650
20793
  });
20794
+ this.schematic_path_ids.push(schematic_path.schematic_path_id);
20795
+ }
20796
+ }
20797
+ doInitialSchematicSymbolResize() {
20798
+ if (this.root?.schematicDisabled) return;
20799
+ if (this.schematic_path_ids.length === 0) return;
20800
+ const symbol = this._getSymbolAncestor();
20801
+ const transform = symbol?.getUserCoordinateToResizedSymbolTransform();
20802
+ if (!transform) return;
20803
+ const { db } = this.root;
20804
+ for (const pathId of this.schematic_path_ids) {
20805
+ const path = db.schematic_path.get(pathId);
20806
+ if (!path) continue;
20807
+ const newPoints = path.points.map((point6) => {
20808
+ const transformed = applyToPoint24(transform, point6);
20809
+ return { x: transformed.x, y: transformed.y };
20810
+ });
20811
+ db.schematic_path.update(pathId, {
20812
+ points: newPoints
20813
+ });
20651
20814
  }
20652
20815
  }
20653
20816
  };
@@ -21002,16 +21165,98 @@ var SchematicCell = class extends PrimitiveComponent2 {
21002
21165
  }
21003
21166
  };
21004
21167
 
21005
- // lib/components/primitive-components/Symbol.ts
21168
+ // lib/components/primitive-components/Symbol/Symbol.ts
21006
21169
  import { symbolProps } from "@tscircuit/props";
21170
+ import { compose as compose7, translate as translate9, scale as scale2 } from "transformation-matrix";
21007
21171
  var SymbolComponent = class extends PrimitiveComponent2 {
21008
21172
  isPrimitiveContainer = true;
21173
+ userCoordinateToResizedSymbolTransformMat;
21174
+ schematicSymbolBoundsInUserCoordinates;
21009
21175
  get config() {
21010
21176
  return {
21011
21177
  componentName: "Symbol",
21012
21178
  zodProps: symbolProps
21013
21179
  };
21014
21180
  }
21181
+ hasExplicitSize() {
21182
+ const { _parsedProps: props } = this;
21183
+ return props.width !== void 0 || props.height !== void 0;
21184
+ }
21185
+ getSchematicSymbolBounds() {
21186
+ if (this.schematicSymbolBoundsInUserCoordinates) {
21187
+ return this.schematicSymbolBoundsInUserCoordinates;
21188
+ }
21189
+ this._computeSchematicSymbolBounds();
21190
+ return this.schematicSymbolBoundsInUserCoordinates ?? null;
21191
+ }
21192
+ getUserCoordinateToResizedSymbolTransform() {
21193
+ if (!this.hasExplicitSize()) {
21194
+ return null;
21195
+ }
21196
+ if (this.userCoordinateToResizedSymbolTransformMat) {
21197
+ return this.userCoordinateToResizedSymbolTransformMat;
21198
+ }
21199
+ this._computeUserCoordinateToResizedSymbolTransform();
21200
+ return this.userCoordinateToResizedSymbolTransformMat ?? null;
21201
+ }
21202
+ _computeSchematicSymbolBounds() {
21203
+ if (this.root?.schematicDisabled) return;
21204
+ const { db } = this.root;
21205
+ const schematicElements = [];
21206
+ for (const child of this.children) {
21207
+ if (!child.isSchematicPrimitive) continue;
21208
+ if (child.componentName === "SchematicLine") {
21209
+ const line = db.schematic_line.get(child.schematic_line_id);
21210
+ if (line) schematicElements.push(line);
21211
+ } else if (child.componentName === "SchematicRect") {
21212
+ const rect = db.schematic_rect.get(child.schematic_rect_id);
21213
+ if (rect) schematicElements.push(rect);
21214
+ } else if (child.componentName === "SchematicCircle") {
21215
+ const circle = db.schematic_circle.get(
21216
+ child.schematic_circle_id
21217
+ );
21218
+ if (circle) schematicElements.push(circle);
21219
+ } else if (child.componentName === "SchematicArc") {
21220
+ const arc = db.schematic_arc.get(child.schematic_arc_id);
21221
+ if (arc) schematicElements.push(arc);
21222
+ } else if (child.componentName === "SchematicText") {
21223
+ const text = db.schematic_text.get(child.schematic_text_id);
21224
+ if (text) schematicElements.push(text);
21225
+ } else if (child.componentName === "SchematicPath") {
21226
+ const pathIds = child.schematic_path_ids;
21227
+ if (pathIds) {
21228
+ for (const pathId of pathIds) {
21229
+ const path = db.schematic_path.get(pathId);
21230
+ if (path) schematicElements.push(path);
21231
+ }
21232
+ }
21233
+ }
21234
+ }
21235
+ if (schematicElements.length === 0) return;
21236
+ const bounds = getBoundsForSchematic(schematicElements);
21237
+ this.schematicSymbolBoundsInUserCoordinates = bounds;
21238
+ }
21239
+ _computeUserCoordinateToResizedSymbolTransform() {
21240
+ const bounds = this.getSchematicSymbolBounds();
21241
+ if (!bounds) return;
21242
+ const { _parsedProps: props } = this;
21243
+ const targetWidth = props.width;
21244
+ const targetHeight = props.height;
21245
+ if (targetWidth === void 0 && targetHeight === void 0) return;
21246
+ const currentWidth = bounds.maxX - bounds.minX;
21247
+ const currentHeight = bounds.maxY - bounds.minY;
21248
+ if (currentWidth === 0 && currentHeight === 0) return;
21249
+ const currentCenterX = (bounds.minX + bounds.maxX) / 2;
21250
+ const currentCenterY = (bounds.minY + bounds.maxY) / 2;
21251
+ const scaleX = targetWidth !== void 0 && currentWidth > 0 ? targetWidth / currentWidth : 1;
21252
+ const scaleY = targetHeight !== void 0 && currentHeight > 0 ? targetHeight / currentHeight : 1;
21253
+ const globalPos = this._getGlobalSchematicPositionBeforeLayout();
21254
+ this.userCoordinateToResizedSymbolTransformMat = compose7(
21255
+ translate9(globalPos.x, globalPos.y),
21256
+ scale2(scaleX, scaleY),
21257
+ translate9(-currentCenterX, -currentCenterY)
21258
+ );
21259
+ }
21015
21260
  };
21016
21261
 
21017
21262
  // lib/components/primitive-components/AnalogSimulation.ts
@@ -21318,7 +21563,7 @@ import { identity as identity5 } from "transformation-matrix";
21318
21563
  var package_default = {
21319
21564
  name: "@tscircuit/core",
21320
21565
  type: "module",
21321
- version: "0.0.997",
21566
+ version: "0.0.999",
21322
21567
  types: "dist/index.d.ts",
21323
21568
  main: "dist/index.js",
21324
21569
  module: "dist/index.js",
@@ -21361,7 +21606,7 @@ var package_default = {
21361
21606
  "@tscircuit/math-utils": "^0.0.29",
21362
21607
  "@tscircuit/miniflex": "^0.0.4",
21363
21608
  "@tscircuit/ngspice-spice-engine": "^0.0.8",
21364
- "@tscircuit/props": "^0.0.456",
21609
+ "@tscircuit/props": "^0.0.457",
21365
21610
  "@tscircuit/schematic-match-adapt": "^0.0.16",
21366
21611
  "@tscircuit/schematic-trace-solver": "^v0.0.45",
21367
21612
  "@tscircuit/solver-utils": "^0.0.3",
@@ -21374,7 +21619,7 @@ var package_default = {
21374
21619
  "bun-match-svg": "0.0.12",
21375
21620
  "calculate-elbow": "^0.0.12",
21376
21621
  "chokidar-cli": "^3.0.0",
21377
- "circuit-json": "^0.0.364",
21622
+ "circuit-json": "^0.0.370",
21378
21623
  "circuit-json-to-bpc": "^0.0.13",
21379
21624
  "circuit-json-to-connectivity-map": "^0.0.23",
21380
21625
  "circuit-json-to-gltf": "^0.0.62",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.998",
4
+ "version": "0.0.1000",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -44,7 +44,7 @@
44
44
  "@tscircuit/math-utils": "^0.0.29",
45
45
  "@tscircuit/miniflex": "^0.0.4",
46
46
  "@tscircuit/ngspice-spice-engine": "^0.0.8",
47
- "@tscircuit/props": "^0.0.456",
47
+ "@tscircuit/props": "^0.0.457",
48
48
  "@tscircuit/schematic-match-adapt": "^0.0.16",
49
49
  "@tscircuit/schematic-trace-solver": "^v0.0.45",
50
50
  "@tscircuit/solver-utils": "^0.0.3",
@@ -57,7 +57,7 @@
57
57
  "bun-match-svg": "0.0.12",
58
58
  "calculate-elbow": "^0.0.12",
59
59
  "chokidar-cli": "^3.0.0",
60
- "circuit-json": "^0.0.364",
60
+ "circuit-json": "^0.0.370",
61
61
  "circuit-json-to-bpc": "^0.0.13",
62
62
  "circuit-json-to-connectivity-map": "^0.0.23",
63
63
  "circuit-json-to-gltf": "^0.0.62",