@tscircuit/core 0.0.735 → 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;
@@ -3176,6 +3230,17 @@ var Port = class extends PrimitiveComponent2 {
3176
3230
  }
3177
3231
  this.matchedComponents = [];
3178
3232
  }
3233
+ _isBoardPinoutFromAttributes() {
3234
+ const parent = this.parent;
3235
+ if (parent?._parsedProps?.pinAttributes) {
3236
+ const pinAttributes = parent._parsedProps.pinAttributes;
3237
+ for (const alias of this.getNameAndAliases()) {
3238
+ if (pinAttributes[alias]?.includeInBoardPinout) {
3239
+ return true;
3240
+ }
3241
+ }
3242
+ }
3243
+ }
3179
3244
  _getGlobalPcbPositionBeforeLayout() {
3180
3245
  const matchedPcbElm = this.matchedComponents.find((c) => c.isPcbPrimitive);
3181
3246
  const parentComponent = this.parent;
@@ -3421,7 +3486,8 @@ var Port = class extends PrimitiveComponent2 {
3421
3486
  pcb_group_id: this.getGroup()?.pcb_group_id ?? void 0,
3422
3487
  ...isBoardPinout ? { is_board_pinout: true } : {},
3423
3488
  ...matchCenter,
3424
- source_port_id: this.source_port_id
3489
+ source_port_id: this.source_port_id,
3490
+ is_board_pinout: this._isBoardPinoutFromAttributes()
3425
3491
  });
3426
3492
  this.pcb_port_id = pcb_port.pcb_port_id;
3427
3493
  } else {
@@ -3459,7 +3525,8 @@ var Port = class extends PrimitiveComponent2 {
3459
3525
  pcb_group_id: this.getGroup()?.pcb_group_id ?? void 0,
3460
3526
  ...isBoardPinout ? { is_board_pinout: true } : {},
3461
3527
  ...matchCenter,
3462
- source_port_id: this.source_port_id
3528
+ source_port_id: this.source_port_id,
3529
+ is_board_pinout: this._isBoardPinoutFromAttributes()
3463
3530
  });
3464
3531
  this.pcb_port_id = pcb_port.pcb_port_id;
3465
3532
  }
@@ -5168,42 +5235,6 @@ var createSchematicTraceJunctions = ({
5168
5235
  // lib/components/primitive-components/Trace/trace-utils/get-obstacles-for-trace.ts
5169
5236
  import { getUnitVectorFromDirection } from "@tscircuit/math-utils";
5170
5237
 
5171
- // lib/utils/autorouting/getBoundsForSchematic.ts
5172
- function getBoundsForSchematic(db) {
5173
- let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
5174
- for (const elm of db) {
5175
- let cx, cy, w, h;
5176
- if (elm.type === "schematic_component") {
5177
- cx = elm.center?.x;
5178
- cy = elm.center?.y;
5179
- w = elm.size?.width;
5180
- h = elm.size?.height;
5181
- } else if (elm.type === "schematic_box") {
5182
- cx = elm.x;
5183
- cy = elm.y;
5184
- w = elm.width;
5185
- h = elm.height;
5186
- } else if (elm.type === "schematic_port") {
5187
- cx = elm.center?.x;
5188
- cy = elm.center?.y;
5189
- w = 0.2;
5190
- h = 0.2;
5191
- } else if (elm.type === "schematic_text") {
5192
- cx = elm.position?.x;
5193
- cy = elm.position?.y;
5194
- w = (elm.text?.length ?? 0) * 0.1;
5195
- h = 0.2;
5196
- }
5197
- if (typeof cx === "number" && typeof cy === "number" && typeof w === "number" && typeof h === "number") {
5198
- minX = Math.min(minX, cx - w / 2);
5199
- maxX = Math.max(maxX, cx + w / 2);
5200
- minY = Math.min(minY, cy - h / 2);
5201
- maxY = Math.max(maxY, cy + h / 2);
5202
- }
5203
- }
5204
- return { minX, maxX, minY, maxY };
5205
- }
5206
-
5207
5238
  // lib/utils/autorouting/getObstaclesFromBounds.ts
5208
5239
  function getObstaclesFromBounds(bounds, opts = {}) {
5209
5240
  const { minX, maxX, minY, maxY } = bounds;
@@ -7391,7 +7422,10 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
7391
7422
  }
7392
7423
  }
7393
7424
  const { schematicSymbolName } = this.config;
7394
- if (schematicSymbolName) {
7425
+ const { _parsedProps: props } = this;
7426
+ if (props.symbol && isReactElement2(props.symbol)) {
7427
+ this._doInitialSchematicComponentRenderWithReactSymbol(props.symbol);
7428
+ } else if (schematicSymbolName) {
7395
7429
  this._doInitialSchematicComponentRenderWithSymbol();
7396
7430
  } else {
7397
7431
  const dimensions = this._getSchematicBoxDimensions();
@@ -7448,6 +7482,21 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
7448
7482
  this.schematic_component_id = schematic_component2.schematic_component_id;
7449
7483
  }
7450
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
+ }
7451
7500
  _doInitialSchematicComponentRenderWithSchematicBoxDimensions() {
7452
7501
  if (this.root?.schematicDisabled) return;
7453
7502
  const { db } = this.root;
@@ -7571,6 +7620,54 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
7571
7620
  updatePcbComponentSizeCalculation() {
7572
7621
  this.doInitialPcbComponentSizeCalculation();
7573
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
+ }
7574
7671
  doInitialPcbComponentAnchorAlignment() {
7575
7672
  NormalComponent_doInitialPcbComponentAnchorAlignment(this);
7576
7673
  }
@@ -12624,6 +12721,8 @@ var stringProxy = new Proxy(
12624
12721
  }
12625
12722
  );
12626
12723
  var FTYPE = stringProxy;
12724
+ var SCHEMATIC_COMPONENT_OUTLINE_COLOR = "rgba(132, 0, 0)";
12725
+ var SCHEMATIC_COMPONENT_OUTLINE_STROKE_WIDTH = 0.12;
12627
12726
 
12628
12727
  // lib/components/normal-components/Capacitor.ts
12629
12728
  import { formatSiUnit } from "format-si-unit";
@@ -15001,6 +15100,74 @@ var SchematicText = class extends PrimitiveComponent2 {
15001
15100
  }
15002
15101
  };
15003
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
+
15004
15171
  // lib/components/primitive-components/SchematicBox.ts
15005
15172
  import { schematicBoxProps } from "@tscircuit/props";
15006
15173
 
@@ -15351,6 +15518,18 @@ var SchematicCell = class extends PrimitiveComponent2 {
15351
15518
  }
15352
15519
  };
15353
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
+
15354
15533
  // lib/RootCircuit.ts
15355
15534
  import { su as su5 } from "@tscircuit/circuit-json-util";
15356
15535
  import { isValidElement as isValidElement2 } from "react";
@@ -15360,7 +15539,7 @@ import { identity as identity6 } from "transformation-matrix";
15360
15539
  var package_default = {
15361
15540
  name: "@tscircuit/core",
15362
15541
  type: "module",
15363
- version: "0.0.734",
15542
+ version: "0.0.736",
15364
15543
  types: "dist/index.d.ts",
15365
15544
  main: "dist/index.js",
15366
15545
  module: "dist/index.js",
@@ -15399,7 +15578,7 @@ var package_default = {
15399
15578
  "@tscircuit/matchpack": "^0.0.16",
15400
15579
  "@tscircuit/math-utils": "^0.0.21",
15401
15580
  "@tscircuit/miniflex": "^0.0.4",
15402
- "@tscircuit/props": "0.0.334",
15581
+ "@tscircuit/props": "0.0.335",
15403
15582
  "@tscircuit/schematic-autolayout": "^0.0.6",
15404
15583
  "@tscircuit/schematic-match-adapt": "^0.0.16",
15405
15584
  "@tscircuit/schematic-trace-solver": "^0.0.37",
@@ -15417,7 +15596,7 @@ var package_default = {
15417
15596
  "circuit-json-to-bpc": "^0.0.13",
15418
15597
  "circuit-json-to-connectivity-map": "^0.0.22",
15419
15598
  "circuit-json-to-simple-3d": "^0.0.8",
15420
- "circuit-to-svg": "^0.0.194",
15599
+ "circuit-to-svg": "^0.0.196",
15421
15600
  concurrently: "^9.1.2",
15422
15601
  "connectivity-map": "^1.0.0",
15423
15602
  debug: "^4.3.6",
@@ -15907,6 +16086,8 @@ export {
15907
16086
  RootCircuit,
15908
16087
  SchematicBox,
15909
16088
  SchematicCell,
16089
+ SchematicLine,
16090
+ SchematicRect,
15910
16091
  SchematicRow,
15911
16092
  SchematicTable,
15912
16093
  SchematicText,
@@ -15919,6 +16100,7 @@ export {
15919
16100
  SolderJumper,
15920
16101
  Subcircuit,
15921
16102
  Switch,
16103
+ SymbolComponent as Symbol,
15922
16104
  TestPoint,
15923
16105
  Trace3 as Trace,
15924
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.735",
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",