@tscircuit/core 0.0.736 → 0.0.737

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.js CHANGED
@@ -48,6 +48,8 @@ __export(components_exports, {
48
48
  Resonator: () => Resonator,
49
49
  SchematicBox: () => SchematicBox,
50
50
  SchematicCell: () => SchematicCell,
51
+ SchematicLine: () => SchematicLine,
52
+ SchematicRect: () => SchematicRect,
51
53
  SchematicRow: () => SchematicRow,
52
54
  SchematicTable: () => SchematicTable,
53
55
  SchematicText: () => SchematicText,
@@ -60,6 +62,7 @@ __export(components_exports, {
60
62
  SolderJumper: () => SolderJumper,
61
63
  Subcircuit: () => Subcircuit,
62
64
  Switch: () => Switch,
65
+ Symbol: () => SymbolComponent,
63
66
  TestPoint: () => TestPoint,
64
67
  Trace: () => Trace3,
65
68
  TraceHint: () => TraceHint,
@@ -109,6 +112,7 @@ var orderedRenderPhases = [
109
112
  "SchematicComponentRender",
110
113
  "SchematicPortRender",
111
114
  "SchematicPrimitiveRender",
115
+ "SchematicComponentSizeCalculation",
112
116
  "SchematicLayout",
113
117
  "SchematicTraceRender",
114
118
  "SchematicReplaceNetLabelsWithSymbols",
@@ -3080,6 +3084,56 @@ function getBoundsOfPcbComponents(components) {
3080
3084
  };
3081
3085
  }
3082
3086
 
3087
+ // lib/utils/autorouting/getBoundsForSchematic.ts
3088
+ function getBoundsForSchematic(db) {
3089
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
3090
+ for (const elm of db) {
3091
+ let cx, cy, w, h;
3092
+ if (elm.type === "schematic_component") {
3093
+ cx = elm.center?.x;
3094
+ cy = elm.center?.y;
3095
+ w = elm.size?.width;
3096
+ h = elm.size?.height;
3097
+ } else if (elm.type === "schematic_box") {
3098
+ cx = elm.x;
3099
+ cy = elm.y;
3100
+ w = elm.width;
3101
+ h = elm.height;
3102
+ } else if (elm.type === "schematic_port") {
3103
+ cx = elm.center?.x;
3104
+ cy = elm.center?.y;
3105
+ w = 0.2;
3106
+ h = 0.2;
3107
+ } else if (elm.type === "schematic_text") {
3108
+ cx = elm.position?.x;
3109
+ cy = elm.position?.y;
3110
+ w = (elm.text?.length ?? 0) * 0.1;
3111
+ h = 0.2;
3112
+ } else if (elm.type === "schematic_line") {
3113
+ const x1 = elm.x1 ?? 0;
3114
+ const y1 = elm.y1 ?? 0;
3115
+ const x2 = elm.x2 ?? 0;
3116
+ const y2 = elm.y2 ?? 0;
3117
+ cx = (x1 + x2) / 2;
3118
+ cy = (y1 + y2) / 2;
3119
+ w = Math.abs(x2 - x1);
3120
+ h = Math.abs(y2 - y1);
3121
+ } else if (elm.type === "schematic_rect") {
3122
+ cx = elm.center?.x;
3123
+ cy = elm.center?.y;
3124
+ w = elm.width;
3125
+ h = elm.height;
3126
+ }
3127
+ if (typeof cx === "number" && typeof cy === "number" && typeof w === "number" && typeof h === "number") {
3128
+ minX = Math.min(minX, cx - w / 2);
3129
+ maxX = Math.max(maxX, cx + w / 2);
3130
+ minY = Math.min(minY, cy - h / 2);
3131
+ maxY = Math.max(maxY, cy + h / 2);
3132
+ }
3133
+ }
3134
+ return { minX, maxX, minY, maxY };
3135
+ }
3136
+
3083
3137
  // lib/utils/get-relative-direction.ts
3084
3138
  function getRelativeDirection(pointA, pointB) {
3085
3139
  const dx = pointB.x - pointA.x;
@@ -5181,42 +5235,6 @@ var createSchematicTraceJunctions = ({
5181
5235
  // lib/components/primitive-components/Trace/trace-utils/get-obstacles-for-trace.ts
5182
5236
  import { getUnitVectorFromDirection } from "@tscircuit/math-utils";
5183
5237
 
5184
- // lib/utils/autorouting/getBoundsForSchematic.ts
5185
- function getBoundsForSchematic(db) {
5186
- let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
5187
- for (const elm of db) {
5188
- let cx, cy, w, h;
5189
- if (elm.type === "schematic_component") {
5190
- cx = elm.center?.x;
5191
- cy = elm.center?.y;
5192
- w = elm.size?.width;
5193
- h = elm.size?.height;
5194
- } else if (elm.type === "schematic_box") {
5195
- cx = elm.x;
5196
- cy = elm.y;
5197
- w = elm.width;
5198
- h = elm.height;
5199
- } else if (elm.type === "schematic_port") {
5200
- cx = elm.center?.x;
5201
- cy = elm.center?.y;
5202
- w = 0.2;
5203
- h = 0.2;
5204
- } else if (elm.type === "schematic_text") {
5205
- cx = elm.position?.x;
5206
- cy = elm.position?.y;
5207
- w = (elm.text?.length ?? 0) * 0.1;
5208
- h = 0.2;
5209
- }
5210
- if (typeof cx === "number" && typeof cy === "number" && typeof w === "number" && typeof h === "number") {
5211
- minX = Math.min(minX, cx - w / 2);
5212
- maxX = Math.max(maxX, cx + w / 2);
5213
- minY = Math.min(minY, cy - h / 2);
5214
- maxY = Math.max(maxY, cy + h / 2);
5215
- }
5216
- }
5217
- return { minX, maxX, minY, maxY };
5218
- }
5219
-
5220
5238
  // lib/utils/autorouting/getObstaclesFromBounds.ts
5221
5239
  function getObstaclesFromBounds(bounds, opts = {}) {
5222
5240
  const { minX, maxX, minY, maxY } = bounds;
@@ -7404,7 +7422,10 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
7404
7422
  }
7405
7423
  }
7406
7424
  const { schematicSymbolName } = this.config;
7407
- if (schematicSymbolName) {
7425
+ const { _parsedProps: props } = this;
7426
+ if (props.symbol && isReactElement2(props.symbol)) {
7427
+ this._doInitialSchematicComponentRenderWithReactSymbol(props.symbol);
7428
+ } else if (schematicSymbolName) {
7408
7429
  this._doInitialSchematicComponentRenderWithSymbol();
7409
7430
  } else {
7410
7431
  const dimensions = this._getSchematicBoxDimensions();
@@ -7461,6 +7482,21 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
7461
7482
  this.schematic_component_id = schematic_component2.schematic_component_id;
7462
7483
  }
7463
7484
  }
7485
+ _doInitialSchematicComponentRenderWithReactSymbol(symbolElement) {
7486
+ if (this.root?.schematicDisabled) return;
7487
+ const { db } = this.root;
7488
+ const center = this._getGlobalSchematicPositionBeforeLayout();
7489
+ const schematic_component2 = db.schematic_component.insert({
7490
+ center,
7491
+ // width/height are computed in the SchematicComponentSizeCalculation phase
7492
+ size: { width: 0, height: 0 },
7493
+ source_component_id: this.source_component_id,
7494
+ symbol_name: "custom_symbol",
7495
+ symbol_display_value: this._getSchematicSymbolDisplayValue()
7496
+ });
7497
+ this.schematic_component_id = schematic_component2.schematic_component_id;
7498
+ this.add(symbolElement);
7499
+ }
7464
7500
  _doInitialSchematicComponentRenderWithSchematicBoxDimensions() {
7465
7501
  if (this.root?.schematicDisabled) return;
7466
7502
  const { db } = this.root;
@@ -7584,6 +7620,54 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
7584
7620
  updatePcbComponentSizeCalculation() {
7585
7621
  this.doInitialPcbComponentSizeCalculation();
7586
7622
  }
7623
+ /**
7624
+ * Calculate and update the size of a custom schematic symbol based on its children
7625
+ */
7626
+ doInitialSchematicComponentSizeCalculation() {
7627
+ if (this.root?.schematicDisabled) return;
7628
+ if (!this.schematic_component_id) return;
7629
+ const { db } = this.root;
7630
+ const schematic_component2 = db.schematic_component.get(
7631
+ this.schematic_component_id
7632
+ );
7633
+ if (!schematic_component2 || schematic_component2.symbol_name !== "custom_symbol")
7634
+ return;
7635
+ const schematicElements = [];
7636
+ const collectSchematicPrimitives = (children) => {
7637
+ for (const child of children) {
7638
+ if (child.isSchematicPrimitive && child.componentName === "SchematicLine") {
7639
+ const line = db.schematic_line.get(child.schematic_line_id);
7640
+ if (line) schematicElements.push(line);
7641
+ }
7642
+ if (child.isSchematicPrimitive && child.componentName === "SchematicRect") {
7643
+ const rect = db.schematic_rect.get(child.schematic_rect_id);
7644
+ if (rect) schematicElements.push(rect);
7645
+ }
7646
+ if (child.isSchematicPrimitive && child.componentName === "SchematicText") {
7647
+ const text = db.schematic_text.get(child.schematic_text_id);
7648
+ if (text) schematicElements.push(text);
7649
+ }
7650
+ if (child.children && child.children.length > 0) {
7651
+ collectSchematicPrimitives(child.children);
7652
+ }
7653
+ }
7654
+ };
7655
+ collectSchematicPrimitives(this.children);
7656
+ if (schematicElements.length === 0) return;
7657
+ const bounds = getBoundsForSchematic(schematicElements);
7658
+ const width = Math.abs(bounds.maxX - bounds.minX);
7659
+ const height = Math.abs(bounds.maxY - bounds.minY);
7660
+ if (width === 0 && height === 0) return;
7661
+ db.schematic_component.update(this.schematic_component_id, {
7662
+ size: {
7663
+ width,
7664
+ height
7665
+ }
7666
+ });
7667
+ }
7668
+ updateSchematicComponentSizeCalculation() {
7669
+ this.doInitialSchematicComponentSizeCalculation();
7670
+ }
7587
7671
  doInitialPcbComponentAnchorAlignment() {
7588
7672
  NormalComponent_doInitialPcbComponentAnchorAlignment(this);
7589
7673
  }
@@ -12637,6 +12721,8 @@ var stringProxy = new Proxy(
12637
12721
  }
12638
12722
  );
12639
12723
  var FTYPE = stringProxy;
12724
+ var SCHEMATIC_COMPONENT_OUTLINE_COLOR = "rgba(132, 0, 0)";
12725
+ var SCHEMATIC_COMPONENT_OUTLINE_STROKE_WIDTH = 0.12;
12640
12726
 
12641
12727
  // lib/components/normal-components/Capacitor.ts
12642
12728
  import { formatSiUnit } from "format-si-unit";
@@ -15014,6 +15100,74 @@ var SchematicText = class extends PrimitiveComponent2 {
15014
15100
  }
15015
15101
  };
15016
15102
 
15103
+ // lib/components/primitive-components/SchematicLine.ts
15104
+ import { schematicLineProps } from "@tscircuit/props";
15105
+ var SchematicLine = class extends PrimitiveComponent2 {
15106
+ isSchematicPrimitive = true;
15107
+ get config() {
15108
+ return {
15109
+ componentName: "SchematicLine",
15110
+ zodProps: schematicLineProps
15111
+ };
15112
+ }
15113
+ schematic_line_id;
15114
+ doInitialSchematicPrimitiveRender() {
15115
+ if (this.root?.schematicDisabled) return;
15116
+ const { db } = this.root;
15117
+ const { _parsedProps: props } = this;
15118
+ const globalPos = this._getGlobalSchematicPositionBeforeLayout();
15119
+ const schematic_component_id = this.getPrimitiveContainer()?.parent?.schematic_component_id;
15120
+ const schematic_line = db.schematic_line.insert({
15121
+ schematic_component_id,
15122
+ x1: props.x1 + globalPos.x,
15123
+ y1: props.y1 + globalPos.y,
15124
+ x2: props.x2 + globalPos.x,
15125
+ y2: props.y2 + globalPos.y,
15126
+ stroke_width: SCHEMATIC_COMPONENT_OUTLINE_STROKE_WIDTH,
15127
+ color: SCHEMATIC_COMPONENT_OUTLINE_COLOR,
15128
+ is_dashed: false,
15129
+ subcircuit_id: this.getSubcircuit().subcircuit_id ?? void 0
15130
+ });
15131
+ this.schematic_line_id = schematic_line.schematic_line_id;
15132
+ }
15133
+ };
15134
+
15135
+ // lib/components/primitive-components/SchematicRect.ts
15136
+ import { schematicRectProps } from "@tscircuit/props";
15137
+ var SchematicRect = class extends PrimitiveComponent2 {
15138
+ isSchematicPrimitive = true;
15139
+ get config() {
15140
+ return {
15141
+ componentName: "SchematicRect",
15142
+ zodProps: schematicRectProps
15143
+ };
15144
+ }
15145
+ schematic_rect_id;
15146
+ doInitialSchematicPrimitiveRender() {
15147
+ if (this.root?.schematicDisabled) return;
15148
+ const { db } = this.root;
15149
+ const { _parsedProps: props } = this;
15150
+ const globalPos = this._getGlobalSchematicPositionBeforeLayout();
15151
+ const schematic_component_id = this.getPrimitiveContainer()?.parent?.schematic_component_id;
15152
+ const schematic_rect = db.schematic_rect.insert({
15153
+ center: {
15154
+ x: props.center.x + globalPos.x,
15155
+ y: props.center.y + globalPos.y
15156
+ },
15157
+ width: props.width,
15158
+ height: props.height,
15159
+ stroke_width: SCHEMATIC_COMPONENT_OUTLINE_STROKE_WIDTH,
15160
+ color: SCHEMATIC_COMPONENT_OUTLINE_COLOR,
15161
+ is_filled: props.isFilled,
15162
+ schematic_component_id,
15163
+ is_dashed: props.isDashed,
15164
+ rotation: props.rotation ?? 0,
15165
+ subcircuit_id: this.getSubcircuit().subcircuit_id ?? void 0
15166
+ });
15167
+ this.schematic_rect_id = schematic_rect.schematic_rect_id;
15168
+ }
15169
+ };
15170
+
15017
15171
  // lib/components/primitive-components/SchematicBox.ts
15018
15172
  import { schematicBoxProps } from "@tscircuit/props";
15019
15173
 
@@ -15364,6 +15518,18 @@ var SchematicCell = class extends PrimitiveComponent2 {
15364
15518
  }
15365
15519
  };
15366
15520
 
15521
+ // lib/components/primitive-components/Symbol.ts
15522
+ import { symbolProps } from "@tscircuit/props";
15523
+ var SymbolComponent = class extends PrimitiveComponent2 {
15524
+ isPrimitiveContainer = true;
15525
+ get config() {
15526
+ return {
15527
+ componentName: "Symbol",
15528
+ zodProps: symbolProps
15529
+ };
15530
+ }
15531
+ };
15532
+
15367
15533
  // lib/RootCircuit.ts
15368
15534
  import { su as su5 } from "@tscircuit/circuit-json-util";
15369
15535
  import { isValidElement as isValidElement2 } from "react";
@@ -15373,7 +15539,7 @@ import { identity as identity6 } from "transformation-matrix";
15373
15539
  var package_default = {
15374
15540
  name: "@tscircuit/core",
15375
15541
  type: "module",
15376
- version: "0.0.735",
15542
+ version: "0.0.736",
15377
15543
  types: "dist/index.d.ts",
15378
15544
  main: "dist/index.js",
15379
15545
  module: "dist/index.js",
@@ -15412,7 +15578,7 @@ var package_default = {
15412
15578
  "@tscircuit/matchpack": "^0.0.16",
15413
15579
  "@tscircuit/math-utils": "^0.0.21",
15414
15580
  "@tscircuit/miniflex": "^0.0.4",
15415
- "@tscircuit/props": "0.0.334",
15581
+ "@tscircuit/props": "0.0.335",
15416
15582
  "@tscircuit/schematic-autolayout": "^0.0.6",
15417
15583
  "@tscircuit/schematic-match-adapt": "^0.0.16",
15418
15584
  "@tscircuit/schematic-trace-solver": "^0.0.37",
@@ -15430,7 +15596,7 @@ var package_default = {
15430
15596
  "circuit-json-to-bpc": "^0.0.13",
15431
15597
  "circuit-json-to-connectivity-map": "^0.0.22",
15432
15598
  "circuit-json-to-simple-3d": "^0.0.8",
15433
- "circuit-to-svg": "^0.0.194",
15599
+ "circuit-to-svg": "^0.0.196",
15434
15600
  concurrently: "^9.1.2",
15435
15601
  "connectivity-map": "^1.0.0",
15436
15602
  debug: "^4.3.6",
@@ -15920,6 +16086,8 @@ export {
15920
16086
  RootCircuit,
15921
16087
  SchematicBox,
15922
16088
  SchematicCell,
16089
+ SchematicLine,
16090
+ SchematicRect,
15923
16091
  SchematicRow,
15924
16092
  SchematicTable,
15925
16093
  SchematicText,
@@ -15932,6 +16100,7 @@ export {
15932
16100
  SolderJumper,
15933
16101
  Subcircuit,
15934
16102
  Switch,
16103
+ SymbolComponent as Symbol,
15935
16104
  TestPoint,
15936
16105
  Trace3 as Trace,
15937
16106
  TraceHint,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.736",
4
+ "version": "0.0.737",
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/matchpack": "^0.0.16",
41
41
  "@tscircuit/math-utils": "^0.0.21",
42
42
  "@tscircuit/miniflex": "^0.0.4",
43
- "@tscircuit/props": "0.0.334",
43
+ "@tscircuit/props": "0.0.335",
44
44
  "@tscircuit/schematic-autolayout": "^0.0.6",
45
45
  "@tscircuit/schematic-match-adapt": "^0.0.16",
46
46
  "@tscircuit/schematic-trace-solver": "^0.0.37",
@@ -58,7 +58,7 @@
58
58
  "circuit-json-to-bpc": "^0.0.13",
59
59
  "circuit-json-to-connectivity-map": "^0.0.22",
60
60
  "circuit-json-to-simple-3d": "^0.0.8",
61
- "circuit-to-svg": "^0.0.194",
61
+ "circuit-to-svg": "^0.0.196",
62
62
  "concurrently": "^9.1.2",
63
63
  "connectivity-map": "^1.0.0",
64
64
  "debug": "^4.3.6",