@tscircuit/core 0.0.999 → 0.0.1001

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", "SymbolContainerRender", "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" | "SymbolContainerRender" | "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,45 @@ 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 circuit-json schematic_symbol_id for this symbol.
385
+ * Created during SchematicPrimitiveRender phase.
386
+ */
387
+ schematic_symbol_id?: string;
388
+ /**
389
+ * The transformation matrix to convert from user coordinates (as specified
390
+ * in the symbol's children) to the final resized symbol coordinates.
391
+ * This is computed lazily when first requested.
392
+ */
393
+ userCoordinateToResizedSymbolTransformMat?: Matrix;
394
+ /**
395
+ * The computed bounds of the symbol's schematic primitives before any
396
+ * resizing is applied.
397
+ */
398
+ schematicSymbolBoundsInUserCoordinates?: SchematicSymbolBounds;
399
+ /**
400
+ * Get the bounds of the symbol's schematic primitives.
401
+ * This triggers computation if not already done.
402
+ */
403
+ getSchematicSymbolBounds(): SchematicSymbolBounds | null;
404
+ /**
405
+ * Get the transformation matrix for resizing symbol contents.
406
+ * Returns null if no resizing is needed (no width/height specified).
407
+ */
408
+ getUserCoordinateToResizedSymbolTransform(): Matrix | null;
409
+ /**
410
+ * Check if this symbol has explicit width/height that requires resizing.
411
+ */
412
+ hasExplicitSize(): boolean;
413
+ }
414
+
376
415
  interface IGroup extends PrimitiveComponent {
377
416
  source_group_id: string | null;
378
417
  pcb_group_id: string | null;
@@ -471,6 +510,11 @@ declare abstract class PrimitiveComponent<ZodProps extends ZodType = any> extend
471
510
  */
472
511
  _computePcbGlobalTransformBeforeLayout(): Matrix;
473
512
  getPrimitiveContainer(): PrimitiveComponent | null;
513
+ /**
514
+ * Get the Symbol ancestor if this component is inside a Symbol primitive container.
515
+ * Used by schematic primitives to access the symbol's resize transform.
516
+ */
517
+ _getSymbolAncestor(): ISymbol | null;
474
518
  /**
475
519
  * Walk up the component hierarchy to find the nearest NormalComponent ancestor.
476
520
  * This is useful for primitive components that need access to component IDs
@@ -124604,6 +124648,7 @@ declare class TestPoint extends NormalComponent<typeof testpointProps> {
124604
124648
 
124605
124649
  declare class SchematicText extends PrimitiveComponent<typeof schematicTextProps> {
124606
124650
  isSchematicPrimitive: boolean;
124651
+ schematic_text_id?: string;
124607
124652
  get config(): {
124608
124653
  componentName: string;
124609
124654
  zodProps: zod.ZodObject<{
@@ -124633,6 +124678,7 @@ declare class SchematicText extends PrimitiveComponent<typeof schematicTextProps
124633
124678
  }>;
124634
124679
  };
124635
124680
  doInitialSchematicPrimitiveRender(): void;
124681
+ doInitialSchematicSymbolResize(): void;
124636
124682
  }
124637
124683
 
124638
124684
  declare class SchematicLine extends PrimitiveComponent<typeof schematicLineProps> {
@@ -124667,6 +124713,7 @@ declare class SchematicLine extends PrimitiveComponent<typeof schematicLineProps
124667
124713
  };
124668
124714
  schematic_line_id?: string;
124669
124715
  doInitialSchematicPrimitiveRender(): void;
124716
+ doInitialSchematicSymbolResize(): void;
124670
124717
  }
124671
124718
 
124672
124719
  declare class SchematicRect extends PrimitiveComponent<typeof schematicRectProps> {
@@ -124713,6 +124760,7 @@ declare class SchematicRect extends PrimitiveComponent<typeof schematicRectProps
124713
124760
  };
124714
124761
  schematic_rect_id?: string;
124715
124762
  doInitialSchematicPrimitiveRender(): void;
124763
+ doInitialSchematicSymbolResize(): void;
124716
124764
  }
124717
124765
 
124718
124766
  declare class SchematicArc extends PrimitiveComponent<typeof schematicArcProps> {
@@ -124765,6 +124813,7 @@ declare class SchematicArc extends PrimitiveComponent<typeof schematicArcProps>
124765
124813
  };
124766
124814
  schematic_arc_id?: string;
124767
124815
  doInitialSchematicPrimitiveRender(): void;
124816
+ doInitialSchematicSymbolResize(): void;
124768
124817
  }
124769
124818
 
124770
124819
  declare class SchematicCircle extends PrimitiveComponent<typeof schematicCircleProps> {
@@ -124814,10 +124863,12 @@ declare class SchematicCircle extends PrimitiveComponent<typeof schematicCircleP
124814
124863
  };
124815
124864
  schematic_circle_id?: string;
124816
124865
  doInitialSchematicPrimitiveRender(): void;
124866
+ doInitialSchematicSymbolResize(): void;
124817
124867
  }
124818
124868
 
124819
124869
  declare class SchematicPath extends PrimitiveComponent<typeof schematicPathProps> {
124820
124870
  isSchematicPrimitive: boolean;
124871
+ schematic_path_ids: string[];
124821
124872
  get config(): {
124822
124873
  componentName: string;
124823
124874
  zodProps: zod.ZodObject<{
@@ -124859,6 +124910,7 @@ declare class SchematicPath extends PrimitiveComponent<typeof schematicPathProps
124859
124910
  }>;
124860
124911
  };
124861
124912
  doInitialSchematicPrimitiveRender(): void;
124913
+ doInitialSchematicSymbolResize(): void;
124862
124914
  }
124863
124915
 
124864
124916
  declare class SchematicBox extends PrimitiveComponent<typeof schematicBoxProps> {
@@ -125077,18 +125129,41 @@ declare class SchematicCell extends PrimitiveComponent<typeof schematicCellProps
125077
125129
  };
125078
125130
  }
125079
125131
 
125080
- declare class SymbolComponent extends PrimitiveComponent<typeof symbolProps> {
125132
+ declare class SymbolComponent extends PrimitiveComponent<typeof symbolProps> implements ISymbol {
125081
125133
  isPrimitiveContainer: boolean;
125134
+ schematic_symbol_id?: string;
125135
+ userCoordinateToResizedSymbolTransformMat?: Matrix;
125136
+ schematicSymbolBoundsInUserCoordinates?: SchematicSymbolBounds;
125082
125137
  get config(): {
125083
125138
  componentName: string;
125084
125139
  zodProps: zod.ZodObject<{
125085
125140
  originalFacingDirection: zod.ZodOptional<zod.ZodDefault<zod.ZodEnum<["up", "down", "left", "right"]>>>;
125141
+ width: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
125142
+ height: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
125143
+ name: zod.ZodOptional<zod.ZodString>;
125086
125144
  }, "strip", zod.ZodTypeAny, {
125145
+ name?: string | undefined;
125146
+ width?: number | undefined;
125147
+ height?: number | undefined;
125087
125148
  originalFacingDirection?: "up" | "down" | "left" | "right" | undefined;
125088
125149
  }, {
125150
+ name?: string | undefined;
125151
+ width?: string | number | undefined;
125152
+ height?: string | number | undefined;
125089
125153
  originalFacingDirection?: "up" | "down" | "left" | "right" | undefined;
125090
125154
  }>;
125091
125155
  };
125156
+ hasExplicitSize(): boolean;
125157
+ /**
125158
+ * Create the schematic_symbol element in SymbolContainerRender phase.
125159
+ * This runs before SchematicPrimitiveRender, ensuring children can
125160
+ * reference the schematic_symbol_id when they render.
125161
+ */
125162
+ doInitialSymbolContainerRender(): void;
125163
+ getSchematicSymbolBounds(): SchematicSymbolBounds | null;
125164
+ getUserCoordinateToResizedSymbolTransform(): Matrix | null;
125165
+ private _computeSchematicSymbolBounds;
125166
+ private _computeUserCoordinateToResizedSymbolTransform;
125092
125167
  }
125093
125168
 
125094
125169
  declare class AnalogSimulation extends PrimitiveComponent<typeof analogSimulationProps> {
package/dist/index.js CHANGED
@@ -135,7 +135,9 @@ var orderedRenderPhases = [
135
135
  "SimulationRender",
136
136
  "SchematicComponentRender",
137
137
  "SchematicPortRender",
138
+ "SymbolContainerRender",
138
139
  "SchematicPrimitiveRender",
140
+ "SchematicSymbolResize",
139
141
  "SchematicComponentSizeCalculation",
140
142
  "SchematicLayout",
141
143
  "SchematicTraceRender",
@@ -1060,6 +1062,17 @@ var PrimitiveComponent2 = class extends Renderable {
1060
1062
  if (this.isPrimitiveContainer) return this;
1061
1063
  return this.parent?.getPrimitiveContainer?.() ?? null;
1062
1064
  }
1065
+ /**
1066
+ * Get the Symbol ancestor if this component is inside a Symbol primitive container.
1067
+ * Used by schematic primitives to access the symbol's resize transform.
1068
+ */
1069
+ _getSymbolAncestor() {
1070
+ const container = this.getPrimitiveContainer();
1071
+ if (container?.componentName === "Symbol") {
1072
+ return container;
1073
+ }
1074
+ return null;
1075
+ }
1063
1076
  /**
1064
1077
  * Walk up the component hierarchy to find the nearest NormalComponent ancestor.
1065
1078
  * This is useful for primitive components that need access to component IDs
@@ -3918,9 +3931,15 @@ function getArcBounds(elm) {
3918
3931
  return { minX, maxX, minY, maxY };
3919
3932
  }
3920
3933
  function getBoundsForSchematic(db) {
3921
- let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
3934
+ let minX = Infinity;
3935
+ let minY = Infinity;
3936
+ let maxX = -Infinity;
3937
+ let maxY = -Infinity;
3922
3938
  for (const elm of db) {
3923
- let cx, cy, w, h;
3939
+ let cx;
3940
+ let cy;
3941
+ let w;
3942
+ let h;
3924
3943
  if (elm.type === "schematic_component") {
3925
3944
  cx = elm.center?.x;
3926
3945
  cy = elm.center?.y;
@@ -3972,6 +3991,19 @@ function getBoundsForSchematic(db) {
3972
3991
  maxY = Math.max(maxY, bounds.maxY);
3973
3992
  }
3974
3993
  continue;
3994
+ } else if (elm.type === "schematic_path") {
3995
+ const points = elm.points;
3996
+ if (Array.isArray(points)) {
3997
+ for (const point6 of points) {
3998
+ if (typeof point6.x === "number" && typeof point6.y === "number") {
3999
+ minX = Math.min(minX, point6.x);
4000
+ maxX = Math.max(maxX, point6.x);
4001
+ minY = Math.min(minY, point6.y);
4002
+ maxY = Math.max(maxY, point6.y);
4003
+ }
4004
+ }
4005
+ }
4006
+ continue;
3975
4007
  }
3976
4008
  if (typeof cx === "number" && typeof cy === "number" && typeof w === "number" && typeof h === "number") {
3977
4009
  minX = Math.min(minX, cx - w / 2);
@@ -20306,8 +20338,10 @@ var TestPoint = class extends NormalComponent3 {
20306
20338
 
20307
20339
  // lib/components/primitive-components/SchematicText.ts
20308
20340
  import { schematicTextProps } from "@tscircuit/props";
20341
+ import { applyToPoint as applyToPoint19 } from "transformation-matrix";
20309
20342
  var SchematicText = class extends PrimitiveComponent2 {
20310
20343
  isSchematicPrimitive = true;
20344
+ schematic_text_id;
20311
20345
  get config() {
20312
20346
  return {
20313
20347
  componentName: "SchematicText",
@@ -20319,7 +20353,9 @@ var SchematicText = class extends PrimitiveComponent2 {
20319
20353
  const { db } = this.root;
20320
20354
  const { _parsedProps: props } = this;
20321
20355
  const globalPos = this._getGlobalSchematicPositionBeforeLayout();
20322
- db.schematic_text.insert({
20356
+ const schematic_symbol_id = this._getSymbolAncestor()?.schematic_symbol_id;
20357
+ const schematic_text = db.schematic_text.insert({
20358
+ schematic_symbol_id,
20323
20359
  anchor: props.anchor ?? "center",
20324
20360
  text: normalizeTextForCircuitJson(props.text),
20325
20361
  font_size: props.fontSize,
@@ -20330,11 +20366,27 @@ var SchematicText = class extends PrimitiveComponent2 {
20330
20366
  },
20331
20367
  rotation: props.schRotation ?? 0
20332
20368
  });
20369
+ this.schematic_text_id = schematic_text.schematic_text_id;
20370
+ }
20371
+ doInitialSchematicSymbolResize() {
20372
+ if (this.root?.schematicDisabled) return;
20373
+ if (!this.schematic_text_id) return;
20374
+ const symbol = this._getSymbolAncestor();
20375
+ const transform = symbol?.getUserCoordinateToResizedSymbolTransform();
20376
+ if (!transform) return;
20377
+ const { db } = this.root;
20378
+ const text = db.schematic_text.get(this.schematic_text_id);
20379
+ if (!text) return;
20380
+ const newPosition = applyToPoint19(transform, text.position);
20381
+ db.schematic_text.update(this.schematic_text_id, {
20382
+ position: { x: newPosition.x, y: newPosition.y }
20383
+ });
20333
20384
  }
20334
20385
  };
20335
20386
 
20336
20387
  // lib/components/primitive-components/SchematicLine.ts
20337
20388
  import { schematicLineProps } from "@tscircuit/props";
20389
+ import { applyToPoint as applyToPoint20 } from "transformation-matrix";
20338
20390
  var SchematicLine = class extends PrimitiveComponent2 {
20339
20391
  isSchematicPrimitive = true;
20340
20392
  get config() {
@@ -20350,8 +20402,10 @@ var SchematicLine = class extends PrimitiveComponent2 {
20350
20402
  const { _parsedProps: props } = this;
20351
20403
  const globalPos = this._getGlobalSchematicPositionBeforeLayout();
20352
20404
  const schematic_component_id = this.getPrimitiveContainer()?.parent?.schematic_component_id;
20405
+ const schematic_symbol_id = this._getSymbolAncestor()?.schematic_symbol_id;
20353
20406
  const schematic_line = db.schematic_line.insert({
20354
20407
  schematic_component_id,
20408
+ schematic_symbol_id,
20355
20409
  x1: props.x1 + globalPos.x,
20356
20410
  y1: props.y1 + globalPos.y,
20357
20411
  x2: props.x2 + globalPos.x,
@@ -20363,10 +20417,29 @@ var SchematicLine = class extends PrimitiveComponent2 {
20363
20417
  });
20364
20418
  this.schematic_line_id = schematic_line.schematic_line_id;
20365
20419
  }
20420
+ doInitialSchematicSymbolResize() {
20421
+ if (this.root?.schematicDisabled) return;
20422
+ if (!this.schematic_line_id) return;
20423
+ const symbol = this._getSymbolAncestor();
20424
+ const transform = symbol?.getUserCoordinateToResizedSymbolTransform();
20425
+ if (!transform) return;
20426
+ const { db } = this.root;
20427
+ const line = db.schematic_line.get(this.schematic_line_id);
20428
+ if (!line) return;
20429
+ const p1 = applyToPoint20(transform, { x: line.x1, y: line.y1 });
20430
+ const p2 = applyToPoint20(transform, { x: line.x2, y: line.y2 });
20431
+ db.schematic_line.update(this.schematic_line_id, {
20432
+ x1: p1.x,
20433
+ y1: p1.y,
20434
+ x2: p2.x,
20435
+ y2: p2.y
20436
+ });
20437
+ }
20366
20438
  };
20367
20439
 
20368
20440
  // lib/components/primitive-components/SchematicRect.ts
20369
20441
  import { schematicRectProps } from "@tscircuit/props";
20442
+ import { applyToPoint as applyToPoint21 } from "transformation-matrix";
20370
20443
  var SchematicRect = class extends PrimitiveComponent2 {
20371
20444
  isSchematicPrimitive = true;
20372
20445
  get config() {
@@ -20382,7 +20455,9 @@ var SchematicRect = class extends PrimitiveComponent2 {
20382
20455
  const { _parsedProps: props } = this;
20383
20456
  const globalPos = this._getGlobalSchematicPositionBeforeLayout();
20384
20457
  const schematic_component_id = this.getPrimitiveContainer()?.parent?.schematic_component_id;
20458
+ const schematic_symbol_id = this._getSymbolAncestor()?.schematic_symbol_id;
20385
20459
  const schematic_rect = db.schematic_rect.insert({
20460
+ schematic_symbol_id,
20386
20461
  center: {
20387
20462
  x: globalPos.x,
20388
20463
  y: globalPos.y
@@ -20399,10 +20474,40 @@ var SchematicRect = class extends PrimitiveComponent2 {
20399
20474
  });
20400
20475
  this.schematic_rect_id = schematic_rect.schematic_rect_id;
20401
20476
  }
20477
+ doInitialSchematicSymbolResize() {
20478
+ if (this.root?.schematicDisabled) return;
20479
+ if (!this.schematic_rect_id) return;
20480
+ const symbol = this._getSymbolAncestor();
20481
+ const transform = symbol?.getUserCoordinateToResizedSymbolTransform();
20482
+ if (!transform) return;
20483
+ const { db } = this.root;
20484
+ const rect = db.schematic_rect.get(this.schematic_rect_id);
20485
+ if (!rect) return;
20486
+ const topLeft = applyToPoint21(transform, {
20487
+ x: rect.center.x - rect.width / 2,
20488
+ y: rect.center.y + rect.height / 2
20489
+ });
20490
+ const bottomRight = applyToPoint21(transform, {
20491
+ x: rect.center.x + rect.width / 2,
20492
+ y: rect.center.y - rect.height / 2
20493
+ });
20494
+ const newWidth = Math.abs(bottomRight.x - topLeft.x);
20495
+ const newHeight = Math.abs(topLeft.y - bottomRight.y);
20496
+ const newCenter = {
20497
+ x: (topLeft.x + bottomRight.x) / 2,
20498
+ y: (topLeft.y + bottomRight.y) / 2
20499
+ };
20500
+ db.schematic_rect.update(this.schematic_rect_id, {
20501
+ center: newCenter,
20502
+ width: newWidth,
20503
+ height: newHeight
20504
+ });
20505
+ }
20402
20506
  };
20403
20507
 
20404
20508
  // lib/components/primitive-components/SchematicArc.ts
20405
20509
  import { schematicArcProps } from "@tscircuit/props";
20510
+ import { applyToPoint as applyToPoint22 } from "transformation-matrix";
20406
20511
  var SchematicArc = class extends PrimitiveComponent2 {
20407
20512
  isSchematicPrimitive = true;
20408
20513
  get config() {
@@ -20418,8 +20523,10 @@ var SchematicArc = class extends PrimitiveComponent2 {
20418
20523
  const { _parsedProps: props } = this;
20419
20524
  const globalPos = this._getGlobalSchematicPositionBeforeLayout();
20420
20525
  const schematic_component_id = this.getPrimitiveContainer()?.parent?.schematic_component_id;
20526
+ const schematic_symbol_id = this._getSymbolAncestor()?.schematic_symbol_id;
20421
20527
  const schematic_arc = db.schematic_arc.insert({
20422
20528
  schematic_component_id,
20529
+ schematic_symbol_id,
20423
20530
  center: {
20424
20531
  x: props.center.x + globalPos.x,
20425
20532
  y: props.center.y + globalPos.y
@@ -20435,10 +20542,31 @@ var SchematicArc = class extends PrimitiveComponent2 {
20435
20542
  });
20436
20543
  this.schematic_arc_id = schematic_arc.schematic_arc_id;
20437
20544
  }
20545
+ doInitialSchematicSymbolResize() {
20546
+ if (this.root?.schematicDisabled) return;
20547
+ if (!this.schematic_arc_id) return;
20548
+ const symbol = this._getSymbolAncestor();
20549
+ const transform = symbol?.getUserCoordinateToResizedSymbolTransform();
20550
+ if (!transform) return;
20551
+ const { db } = this.root;
20552
+ const arc = db.schematic_arc.get(this.schematic_arc_id);
20553
+ if (!arc) return;
20554
+ const newCenter = applyToPoint22(transform, arc.center);
20555
+ const edgePoint = applyToPoint22(transform, {
20556
+ x: arc.center.x + arc.radius,
20557
+ y: arc.center.y
20558
+ });
20559
+ const newRadius = Math.abs(edgePoint.x - newCenter.x);
20560
+ db.schematic_arc.update(this.schematic_arc_id, {
20561
+ center: { x: newCenter.x, y: newCenter.y },
20562
+ radius: newRadius
20563
+ });
20564
+ }
20438
20565
  };
20439
20566
 
20440
20567
  // lib/components/primitive-components/SchematicCircle.ts
20441
20568
  import { schematicCircleProps } from "@tscircuit/props";
20569
+ import { applyToPoint as applyToPoint23 } from "transformation-matrix";
20442
20570
  var SchematicCircle = class extends PrimitiveComponent2 {
20443
20571
  isSchematicPrimitive = true;
20444
20572
  get config() {
@@ -20454,8 +20582,10 @@ var SchematicCircle = class extends PrimitiveComponent2 {
20454
20582
  const { _parsedProps: props } = this;
20455
20583
  const globalPos = this._getGlobalSchematicPositionBeforeLayout();
20456
20584
  const schematic_component_id = this.getPrimitiveContainer()?.parent?.schematic_component_id;
20585
+ const schematic_symbol_id = this._getSymbolAncestor()?.schematic_symbol_id;
20457
20586
  const schematic_circle = db.schematic_circle.insert({
20458
20587
  schematic_component_id,
20588
+ schematic_symbol_id,
20459
20589
  center: {
20460
20590
  x: props.center.x + globalPos.x,
20461
20591
  y: props.center.y + globalPos.y
@@ -20470,6 +20600,26 @@ var SchematicCircle = class extends PrimitiveComponent2 {
20470
20600
  });
20471
20601
  this.schematic_circle_id = schematic_circle.schematic_circle_id;
20472
20602
  }
20603
+ doInitialSchematicSymbolResize() {
20604
+ if (this.root?.schematicDisabled) return;
20605
+ if (!this.schematic_circle_id) return;
20606
+ const symbol = this._getSymbolAncestor();
20607
+ const transform = symbol?.getUserCoordinateToResizedSymbolTransform();
20608
+ if (!transform) return;
20609
+ const { db } = this.root;
20610
+ const circle = db.schematic_circle.get(this.schematic_circle_id);
20611
+ if (!circle) return;
20612
+ const newCenter = applyToPoint23(transform, circle.center);
20613
+ const edgePoint = applyToPoint23(transform, {
20614
+ x: circle.center.x + circle.radius,
20615
+ y: circle.center.y
20616
+ });
20617
+ const newRadius = Math.abs(edgePoint.x - newCenter.x);
20618
+ db.schematic_circle.update(this.schematic_circle_id, {
20619
+ center: { x: newCenter.x, y: newCenter.y },
20620
+ radius: newRadius
20621
+ });
20622
+ }
20473
20623
  };
20474
20624
 
20475
20625
  // lib/components/primitive-components/SchematicPath.ts
@@ -20604,8 +20754,10 @@ function svgPathToPoints(svgPath, samplesPerUnit = 10) {
20604
20754
  }
20605
20755
 
20606
20756
  // lib/components/primitive-components/SchematicPath.ts
20757
+ import { applyToPoint as applyToPoint24 } from "transformation-matrix";
20607
20758
  var SchematicPath = class extends PrimitiveComponent2 {
20608
20759
  isSchematicPrimitive = true;
20760
+ schematic_path_ids = [];
20609
20761
  get config() {
20610
20762
  return {
20611
20763
  componentName: "SchematicPath",
@@ -20618,12 +20770,15 @@ var SchematicPath = class extends PrimitiveComponent2 {
20618
20770
  const { _parsedProps: props } = this;
20619
20771
  const globalPos = this._getGlobalSchematicPositionBeforeLayout();
20620
20772
  const schematic_component_id = this.getPrimitiveContainer()?.parent?.schematic_component_id;
20773
+ const schematic_symbol_id = this._getSymbolAncestor()?.schematic_symbol_id;
20621
20774
  const subcircuit_id = this.getSubcircuit().subcircuit_id ?? void 0;
20775
+ this.schematic_path_ids = [];
20622
20776
  if (props.svgPath) {
20623
20777
  const subpaths = svgPathToPoints(props.svgPath);
20624
20778
  for (const subpathPoints of subpaths) {
20625
- db.schematic_path.insert({
20779
+ const schematic_path = db.schematic_path.insert({
20626
20780
  schematic_component_id,
20781
+ schematic_symbol_id,
20627
20782
  points: subpathPoints.map((point6) => ({
20628
20783
  x: point6.x + globalPos.x,
20629
20784
  y: point6.y + globalPos.y
@@ -20634,10 +20789,12 @@ var SchematicPath = class extends PrimitiveComponent2 {
20634
20789
  stroke_width: props.strokeWidth,
20635
20790
  subcircuit_id
20636
20791
  });
20792
+ this.schematic_path_ids.push(schematic_path.schematic_path_id);
20637
20793
  }
20638
20794
  } else if (props.points && props.points.length > 0) {
20639
- db.schematic_path.insert({
20795
+ const schematic_path = db.schematic_path.insert({
20640
20796
  schematic_component_id,
20797
+ schematic_symbol_id,
20641
20798
  points: props.points.map((point6) => ({
20642
20799
  x: point6.x + globalPos.x,
20643
20800
  y: point6.y + globalPos.y
@@ -20648,6 +20805,26 @@ var SchematicPath = class extends PrimitiveComponent2 {
20648
20805
  stroke_width: props.strokeWidth,
20649
20806
  subcircuit_id
20650
20807
  });
20808
+ this.schematic_path_ids.push(schematic_path.schematic_path_id);
20809
+ }
20810
+ }
20811
+ doInitialSchematicSymbolResize() {
20812
+ if (this.root?.schematicDisabled) return;
20813
+ if (this.schematic_path_ids.length === 0) return;
20814
+ const symbol = this._getSymbolAncestor();
20815
+ const transform = symbol?.getUserCoordinateToResizedSymbolTransform();
20816
+ if (!transform) return;
20817
+ const { db } = this.root;
20818
+ for (const pathId of this.schematic_path_ids) {
20819
+ const path = db.schematic_path.get(pathId);
20820
+ if (!path) continue;
20821
+ const newPoints = path.points.map((point6) => {
20822
+ const transformed = applyToPoint24(transform, point6);
20823
+ return { x: transformed.x, y: transformed.y };
20824
+ });
20825
+ db.schematic_path.update(pathId, {
20826
+ points: newPoints
20827
+ });
20651
20828
  }
20652
20829
  }
20653
20830
  };
@@ -21002,16 +21179,113 @@ var SchematicCell = class extends PrimitiveComponent2 {
21002
21179
  }
21003
21180
  };
21004
21181
 
21005
- // lib/components/primitive-components/Symbol.ts
21182
+ // lib/components/primitive-components/Symbol/Symbol.ts
21006
21183
  import { symbolProps } from "@tscircuit/props";
21184
+ import { compose as compose7, translate as translate9, scale as scale2 } from "transformation-matrix";
21007
21185
  var SymbolComponent = class extends PrimitiveComponent2 {
21008
21186
  isPrimitiveContainer = true;
21187
+ schematic_symbol_id;
21188
+ userCoordinateToResizedSymbolTransformMat;
21189
+ schematicSymbolBoundsInUserCoordinates;
21009
21190
  get config() {
21010
21191
  return {
21011
21192
  componentName: "Symbol",
21012
21193
  zodProps: symbolProps
21013
21194
  };
21014
21195
  }
21196
+ hasExplicitSize() {
21197
+ const { _parsedProps: props } = this;
21198
+ return props.width !== void 0 || props.height !== void 0;
21199
+ }
21200
+ /**
21201
+ * Create the schematic_symbol element in SymbolContainerRender phase.
21202
+ * This runs before SchematicPrimitiveRender, ensuring children can
21203
+ * reference the schematic_symbol_id when they render.
21204
+ */
21205
+ doInitialSymbolContainerRender() {
21206
+ if (this.root?.schematicDisabled) return;
21207
+ const { db } = this.root;
21208
+ const { _parsedProps: props } = this;
21209
+ const schematic_symbol = db.schematic_symbol.insert({
21210
+ name: props.name
21211
+ });
21212
+ this.schematic_symbol_id = schematic_symbol.schematic_symbol_id;
21213
+ }
21214
+ getSchematicSymbolBounds() {
21215
+ if (this.schematicSymbolBoundsInUserCoordinates) {
21216
+ return this.schematicSymbolBoundsInUserCoordinates;
21217
+ }
21218
+ this._computeSchematicSymbolBounds();
21219
+ return this.schematicSymbolBoundsInUserCoordinates ?? null;
21220
+ }
21221
+ getUserCoordinateToResizedSymbolTransform() {
21222
+ if (!this.hasExplicitSize()) {
21223
+ return null;
21224
+ }
21225
+ if (this.userCoordinateToResizedSymbolTransformMat) {
21226
+ return this.userCoordinateToResizedSymbolTransformMat;
21227
+ }
21228
+ this._computeUserCoordinateToResizedSymbolTransform();
21229
+ return this.userCoordinateToResizedSymbolTransformMat ?? null;
21230
+ }
21231
+ _computeSchematicSymbolBounds() {
21232
+ if (this.root?.schematicDisabled) return;
21233
+ const { db } = this.root;
21234
+ const schematicElements = [];
21235
+ for (const child of this.children) {
21236
+ if (!child.isSchematicPrimitive) continue;
21237
+ if (child.componentName === "SchematicLine") {
21238
+ const line = db.schematic_line.get(child.schematic_line_id);
21239
+ if (line) schematicElements.push(line);
21240
+ } else if (child.componentName === "SchematicRect") {
21241
+ const rect = db.schematic_rect.get(child.schematic_rect_id);
21242
+ if (rect) schematicElements.push(rect);
21243
+ } else if (child.componentName === "SchematicCircle") {
21244
+ const circle = db.schematic_circle.get(
21245
+ child.schematic_circle_id
21246
+ );
21247
+ if (circle) schematicElements.push(circle);
21248
+ } else if (child.componentName === "SchematicArc") {
21249
+ const arc = db.schematic_arc.get(child.schematic_arc_id);
21250
+ if (arc) schematicElements.push(arc);
21251
+ } else if (child.componentName === "SchematicText") {
21252
+ const text = db.schematic_text.get(child.schematic_text_id);
21253
+ if (text) schematicElements.push(text);
21254
+ } else if (child.componentName === "SchematicPath") {
21255
+ const pathIds = child.schematic_path_ids;
21256
+ if (pathIds) {
21257
+ for (const pathId of pathIds) {
21258
+ const path = db.schematic_path.get(pathId);
21259
+ if (path) schematicElements.push(path);
21260
+ }
21261
+ }
21262
+ }
21263
+ }
21264
+ if (schematicElements.length === 0) return;
21265
+ const bounds = getBoundsForSchematic(schematicElements);
21266
+ this.schematicSymbolBoundsInUserCoordinates = bounds;
21267
+ }
21268
+ _computeUserCoordinateToResizedSymbolTransform() {
21269
+ const bounds = this.getSchematicSymbolBounds();
21270
+ if (!bounds) return;
21271
+ const { _parsedProps: props } = this;
21272
+ const targetWidth = props.width;
21273
+ const targetHeight = props.height;
21274
+ if (targetWidth === void 0 && targetHeight === void 0) return;
21275
+ const currentWidth = bounds.maxX - bounds.minX;
21276
+ const currentHeight = bounds.maxY - bounds.minY;
21277
+ if (currentWidth === 0 && currentHeight === 0) return;
21278
+ const currentCenterX = (bounds.minX + bounds.maxX) / 2;
21279
+ const currentCenterY = (bounds.minY + bounds.maxY) / 2;
21280
+ const scaleX = targetWidth !== void 0 && currentWidth > 0 ? targetWidth / currentWidth : 1;
21281
+ const scaleY = targetHeight !== void 0 && currentHeight > 0 ? targetHeight / currentHeight : 1;
21282
+ const globalPos = this._getGlobalSchematicPositionBeforeLayout();
21283
+ this.userCoordinateToResizedSymbolTransformMat = compose7(
21284
+ translate9(globalPos.x, globalPos.y),
21285
+ scale2(scaleX, scaleY),
21286
+ translate9(-currentCenterX, -currentCenterY)
21287
+ );
21288
+ }
21015
21289
  };
21016
21290
 
21017
21291
  // lib/components/primitive-components/AnalogSimulation.ts
@@ -21318,7 +21592,7 @@ import { identity as identity5 } from "transformation-matrix";
21318
21592
  var package_default = {
21319
21593
  name: "@tscircuit/core",
21320
21594
  type: "module",
21321
- version: "0.0.998",
21595
+ version: "0.0.1000",
21322
21596
  types: "dist/index.d.ts",
21323
21597
  main: "dist/index.js",
21324
21598
  module: "dist/index.js",
@@ -21361,7 +21635,7 @@ var package_default = {
21361
21635
  "@tscircuit/math-utils": "^0.0.29",
21362
21636
  "@tscircuit/miniflex": "^0.0.4",
21363
21637
  "@tscircuit/ngspice-spice-engine": "^0.0.8",
21364
- "@tscircuit/props": "^0.0.456",
21638
+ "@tscircuit/props": "^0.0.457",
21365
21639
  "@tscircuit/schematic-match-adapt": "^0.0.16",
21366
21640
  "@tscircuit/schematic-trace-solver": "^v0.0.45",
21367
21641
  "@tscircuit/solver-utils": "^0.0.3",
@@ -21374,7 +21648,7 @@ var package_default = {
21374
21648
  "bun-match-svg": "0.0.12",
21375
21649
  "calculate-elbow": "^0.0.12",
21376
21650
  "chokidar-cli": "^3.0.0",
21377
- "circuit-json": "^0.0.364",
21651
+ "circuit-json": "^0.0.371",
21378
21652
  "circuit-json-to-bpc": "^0.0.13",
21379
21653
  "circuit-json-to-connectivity-map": "^0.0.23",
21380
21654
  "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.999",
4
+ "version": "0.0.1001",
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.371",
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",