@tscircuit/core 0.0.942 → 0.0.944

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +1643 -459
  2. package/dist/index.js +243 -19
  3. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ __export(components_exports, {
20
20
  CopperPour: () => CopperPour,
21
21
  CopperText: () => CopperText,
22
22
  Crystal: () => Crystal,
23
+ CurrentSource: () => CurrentSource,
23
24
  Cutout: () => Cutout,
24
25
  Diode: () => Diode,
25
26
  FabricationNoteDimension: () => FabricationNoteDimension,
@@ -2562,7 +2563,10 @@ var SilkscreenPath = class extends PrimitiveComponent2 {
2562
2563
  route: newRoute
2563
2564
  });
2564
2565
  }
2565
- _repositionOnPcb({ deltaX, deltaY }) {
2566
+ _moveCircuitJsonElements({
2567
+ deltaX,
2568
+ deltaY
2569
+ }) {
2566
2570
  if (this.root?.pcbDisabled) return;
2567
2571
  const { db } = this.root;
2568
2572
  if (!this.pcb_silkscreen_path_id) return;
@@ -3223,7 +3227,10 @@ var SilkscreenText = class extends PrimitiveComponent2 {
3223
3227
  const textHeight = fontSize;
3224
3228
  return { width: textWidth * fontSize, height: textHeight * fontSize };
3225
3229
  }
3226
- _repositionOnPcb({ deltaX, deltaY }) {
3230
+ _moveCircuitJsonElements({
3231
+ deltaX,
3232
+ deltaY
3233
+ }) {
3227
3234
  if (this.root?.pcbDisabled) return;
3228
3235
  const { db } = this.root;
3229
3236
  for (const id of this.pcb_silkscreen_text_ids) {
@@ -16004,8 +16011,8 @@ var Board = class extends Group6 {
16004
16011
  y: childOldCenter.y + deltaY
16005
16012
  });
16006
16013
  }
16007
- } else if (child.isPcbPrimitive && "_repositionOnPcb" in child && typeof child._repositionOnPcb === "function") {
16008
- child._repositionOnPcb({ deltaX, deltaY });
16014
+ } else if (child.isPcbPrimitive && "_moveCircuitJsonElements" in child && typeof child._moveCircuitJsonElements === "function") {
16015
+ child._moveCircuitJsonElements({ deltaX, deltaY });
16009
16016
  }
16010
16017
  }
16011
16018
  if (this.pcb_board_id) {
@@ -17029,6 +17036,104 @@ var VoltageSource = class extends NormalComponent3 {
17029
17036
  terminal2 = this.portMap.terminal2;
17030
17037
  };
17031
17038
 
17039
+ // lib/components/normal-components/CurrentSource.ts
17040
+ import { currentSourceProps } from "@tscircuit/props";
17041
+ import { formatSiUnit as formatSiUnit6 } from "format-si-unit";
17042
+ var CurrentSource = class extends NormalComponent3 {
17043
+ get config() {
17044
+ const symbolName = "current_source";
17045
+ return {
17046
+ componentName: "CurrentSource",
17047
+ schematicSymbolName: symbolName,
17048
+ zodProps: currentSourceProps,
17049
+ sourceFtype: "simple_current_source"
17050
+ };
17051
+ }
17052
+ runRenderPhaseForChildren(phase) {
17053
+ if (phase.startsWith("Pcb")) {
17054
+ return;
17055
+ }
17056
+ for (const child of this.children) {
17057
+ child.runRenderPhaseForChildren(phase);
17058
+ child.runRenderPhase(phase);
17059
+ }
17060
+ }
17061
+ doInitialPcbComponentRender() {
17062
+ }
17063
+ initPorts() {
17064
+ super.initPorts({
17065
+ additionalAliases: {
17066
+ pin1: ["pos"],
17067
+ pin2: ["neg"]
17068
+ }
17069
+ });
17070
+ }
17071
+ _getSchematicSymbolDisplayValue() {
17072
+ const { current, frequency: frequency2, peakToPeakCurrent } = this._parsedProps;
17073
+ const parts = [];
17074
+ if (current !== void 0) {
17075
+ parts.push(`${formatSiUnit6(current)}A`);
17076
+ }
17077
+ if (peakToPeakCurrent !== void 0) {
17078
+ parts.push(`${formatSiUnit6(peakToPeakCurrent)}A p-p`);
17079
+ }
17080
+ if (frequency2 !== void 0) {
17081
+ parts.push(`${formatSiUnit6(frequency2)}Hz`);
17082
+ }
17083
+ return parts.length > 0 ? parts.join(" ") : void 0;
17084
+ }
17085
+ doInitialSourceRender() {
17086
+ const { db } = this.root;
17087
+ const { _parsedProps: props } = this;
17088
+ const source_component = db.source_component.insert({
17089
+ ftype: "simple_current_source",
17090
+ name: this.name,
17091
+ current: props.current,
17092
+ frequency: props.frequency,
17093
+ peak_to_peak_current: props.peakToPeakCurrent,
17094
+ wave_shape: props.waveShape,
17095
+ phase: props.phase,
17096
+ duty_cycle: props.dutyCycle,
17097
+ supplier_part_numbers: props.supplierPartNumbers,
17098
+ are_pins_interchangeable: true
17099
+ });
17100
+ this.source_component_id = source_component.source_component_id;
17101
+ }
17102
+ doInitialSimulationRender() {
17103
+ const { db } = this.root;
17104
+ const { _parsedProps: props } = this;
17105
+ const isAc = props.frequency !== void 0 || props.peakToPeakCurrent !== void 0 || props.waveShape !== void 0;
17106
+ const posPort = this.portMap.pos;
17107
+ const negPort = this.portMap.neg;
17108
+ if (isAc) {
17109
+ db.simulation_current_source.insert({
17110
+ type: "simulation_current_source",
17111
+ is_dc_source: false,
17112
+ terminal1_source_port_id: posPort.source_port_id,
17113
+ terminal2_source_port_id: negPort.source_port_id,
17114
+ current: props.current,
17115
+ // DC offset
17116
+ frequency: props.frequency,
17117
+ peak_to_peak_current: props.peakToPeakCurrent,
17118
+ wave_shape: props.waveShape,
17119
+ phase: props.phase,
17120
+ duty_cycle: props.dutyCycle
17121
+ });
17122
+ } else {
17123
+ if (props.current === void 0) return;
17124
+ db.simulation_current_source.insert({
17125
+ type: "simulation_current_source",
17126
+ is_dc_source: true,
17127
+ positive_source_port_id: posPort.source_port_id,
17128
+ negative_source_port_id: negPort.source_port_id,
17129
+ current: props.current
17130
+ });
17131
+ }
17132
+ }
17133
+ pos = this.portMap.pos;
17134
+ neg = this.portMap.neg;
17135
+ };
17136
+
17032
17137
  // lib/components/primitive-components/Constraint.ts
17033
17138
  import { constraintProps } from "@tscircuit/props";
17034
17139
  import "zod";
@@ -17097,6 +17202,7 @@ import { fabricationNoteRectProps } from "@tscircuit/props";
17097
17202
  import "transformation-matrix";
17098
17203
  var FabricationNoteRect = class extends PrimitiveComponent2 {
17099
17204
  fabrication_note_rect_id = null;
17205
+ isPcbPrimitive = true;
17100
17206
  get config() {
17101
17207
  return {
17102
17208
  componentName: "FabricationNoteRect",
@@ -17142,6 +17248,23 @@ var FabricationNoteRect = class extends PrimitiveComponent2 {
17142
17248
  const { _parsedProps: props } = this;
17143
17249
  return { width: props.width, height: props.height };
17144
17250
  }
17251
+ _moveCircuitJsonElements({
17252
+ deltaX,
17253
+ deltaY
17254
+ }) {
17255
+ if (this.root?.pcbDisabled) return;
17256
+ const { db } = this.root;
17257
+ if (!this.fabrication_note_rect_id) return;
17258
+ const rect = db.pcb_fabrication_note_rect.get(this.fabrication_note_rect_id);
17259
+ if (rect) {
17260
+ db.pcb_fabrication_note_rect.update(this.fabrication_note_rect_id, {
17261
+ center: {
17262
+ x: rect.center.x + deltaX,
17263
+ y: rect.center.y + deltaY
17264
+ }
17265
+ });
17266
+ }
17267
+ }
17145
17268
  };
17146
17269
 
17147
17270
  // lib/components/primitive-components/FabricationNotePath.ts
@@ -17149,6 +17272,7 @@ import { fabricationNotePathProps } from "@tscircuit/props";
17149
17272
  import { applyToPoint as applyToPoint10 } from "transformation-matrix";
17150
17273
  var FabricationNotePath = class extends PrimitiveComponent2 {
17151
17274
  fabrication_note_path_id = null;
17275
+ isPcbPrimitive = true;
17152
17276
  get config() {
17153
17277
  return {
17154
17278
  componentName: "FabricationNotePath",
@@ -17188,11 +17312,46 @@ var FabricationNotePath = class extends PrimitiveComponent2 {
17188
17312
  });
17189
17313
  this.fabrication_note_path_id = fabrication_note_path.pcb_fabrication_note_path_id;
17190
17314
  }
17315
+ getPcbSize() {
17316
+ const { _parsedProps: props } = this;
17317
+ if (props.route.length === 0) return { width: 0, height: 0 };
17318
+ const xs = props.route.map(
17319
+ (point2) => typeof point2.x === "string" ? parseFloat(point2.x) : point2.x
17320
+ );
17321
+ const ys = props.route.map(
17322
+ (point2) => typeof point2.y === "string" ? parseFloat(point2.y) : point2.y
17323
+ );
17324
+ const minX = Math.min(...xs);
17325
+ const maxX = Math.max(...xs);
17326
+ const minY = Math.min(...ys);
17327
+ const maxY = Math.max(...ys);
17328
+ return { width: maxX - minX, height: maxY - minY };
17329
+ }
17330
+ _moveCircuitJsonElements({
17331
+ deltaX,
17332
+ deltaY
17333
+ }) {
17334
+ if (this.root?.pcbDisabled) return;
17335
+ const { db } = this.root;
17336
+ if (!this.fabrication_note_path_id) return;
17337
+ const path = db.pcb_fabrication_note_path.get(this.fabrication_note_path_id);
17338
+ if (path) {
17339
+ db.pcb_fabrication_note_path.update(this.fabrication_note_path_id, {
17340
+ route: path.route.map((p) => ({
17341
+ ...p,
17342
+ x: p.x + deltaX,
17343
+ y: p.y + deltaY
17344
+ }))
17345
+ });
17346
+ }
17347
+ }
17191
17348
  };
17192
17349
 
17193
17350
  // lib/components/primitive-components/FabricationNoteText.ts
17194
17351
  import { fabricationNoteTextProps } from "@tscircuit/props";
17195
17352
  var FabricationNoteText = class extends PrimitiveComponent2 {
17353
+ pcb_fabrication_note_text_id = null;
17354
+ isPcbPrimitive = true;
17196
17355
  get config() {
17197
17356
  return {
17198
17357
  componentName: "FabricationNoteText",
@@ -17206,7 +17365,7 @@ var FabricationNoteText = class extends PrimitiveComponent2 {
17206
17365
  const { pcbX, pcbY } = this.getResolvedPcbPositionProp();
17207
17366
  const container = this.getPrimitiveContainer();
17208
17367
  const subcircuit = this.getSubcircuit();
17209
- db.pcb_fabrication_note_text.insert({
17368
+ const pcb_fabrication_note_text = db.pcb_fabrication_note_text.insert({
17210
17369
  anchor_alignment: props.anchorAlignment,
17211
17370
  anchor_position: {
17212
17371
  x: pcbX,
@@ -17221,6 +17380,35 @@ var FabricationNoteText = class extends PrimitiveComponent2 {
17221
17380
  subcircuit_id: subcircuit?.subcircuit_id ?? void 0,
17222
17381
  pcb_group_id: this.getGroup()?.pcb_group_id ?? void 0
17223
17382
  });
17383
+ this.pcb_fabrication_note_text_id = pcb_fabrication_note_text.pcb_fabrication_note_text_id;
17384
+ }
17385
+ getPcbSize() {
17386
+ const { _parsedProps: props } = this;
17387
+ const fontSize = typeof props.fontSize === "string" ? parseFloat(props.fontSize) : props.fontSize ?? 1;
17388
+ const charWidth = fontSize * 0.6;
17389
+ const width = (props.text ?? "").length * charWidth;
17390
+ const height = fontSize;
17391
+ return { width, height };
17392
+ }
17393
+ _moveCircuitJsonElements({
17394
+ deltaX,
17395
+ deltaY
17396
+ }) {
17397
+ if (this.root?.pcbDisabled) return;
17398
+ const { db } = this.root;
17399
+ if (this.pcb_fabrication_note_text_id) {
17400
+ const text = db.pcb_fabrication_note_text.get(
17401
+ this.pcb_fabrication_note_text_id
17402
+ );
17403
+ if (text) {
17404
+ db.pcb_fabrication_note_text.update(this.pcb_fabrication_note_text_id, {
17405
+ anchor_position: {
17406
+ x: text.anchor_position.x + deltaX,
17407
+ y: text.anchor_position.y + deltaY
17408
+ }
17409
+ });
17410
+ }
17411
+ }
17224
17412
  }
17225
17413
  };
17226
17414
 
@@ -17289,6 +17477,32 @@ var FabricationNoteDimension = class extends PrimitiveComponent2 {
17289
17477
  );
17290
17478
  this.fabrication_note_dimension_id = fabrication_note_dimension.pcb_fabrication_note_dimension_id;
17291
17479
  }
17480
+ _moveCircuitJsonElements({
17481
+ deltaX,
17482
+ deltaY
17483
+ }) {
17484
+ if (this.root?.pcbDisabled) return;
17485
+ const { db } = this.root;
17486
+ if (!this.fabrication_note_dimension_id) return;
17487
+ const dimension = db.pcb_fabrication_note_dimension.get(
17488
+ this.fabrication_note_dimension_id
17489
+ );
17490
+ if (dimension) {
17491
+ db.pcb_fabrication_note_dimension.update(
17492
+ this.fabrication_note_dimension_id,
17493
+ {
17494
+ from: {
17495
+ x: dimension.from.x + deltaX,
17496
+ y: dimension.from.y + deltaY
17497
+ },
17498
+ to: {
17499
+ x: dimension.to.x + deltaX,
17500
+ y: dimension.to.y + deltaY
17501
+ }
17502
+ }
17503
+ );
17504
+ }
17505
+ }
17292
17506
  getPcbSize() {
17293
17507
  const transform = this._computePcbGlobalTransformBeforeLayout();
17294
17508
  const from = this._resolvePoint(this._parsedProps.from, transform);
@@ -17970,7 +18184,10 @@ var SilkscreenCircle = class extends PrimitiveComponent2 {
17970
18184
  const diameter = props.radius * 2;
17971
18185
  return { width: diameter, height: diameter };
17972
18186
  }
17973
- _repositionOnPcb({ deltaX, deltaY }) {
18187
+ _moveCircuitJsonElements({
18188
+ deltaX,
18189
+ deltaY
18190
+ }) {
17974
18191
  if (this.root?.pcbDisabled) return;
17975
18192
  const { db } = this.root;
17976
18193
  if (!this.pcb_silkscreen_circle_id) return;
@@ -18032,7 +18249,10 @@ var SilkscreenRect = class extends PrimitiveComponent2 {
18032
18249
  const { _parsedProps: props } = this;
18033
18250
  return { width: props.width, height: props.height };
18034
18251
  }
18035
- _repositionOnPcb({ deltaX, deltaY }) {
18252
+ _moveCircuitJsonElements({
18253
+ deltaX,
18254
+ deltaY
18255
+ }) {
18036
18256
  if (this.root?.pcbDisabled) return;
18037
18257
  const { db } = this.root;
18038
18258
  if (!this.pcb_silkscreen_rect_id) return;
@@ -18091,7 +18311,10 @@ var SilkscreenLine = class extends PrimitiveComponent2 {
18091
18311
  const height = Math.abs(props.y2 - props.y1);
18092
18312
  return { width, height };
18093
18313
  }
18094
- _repositionOnPcb({ deltaX, deltaY }) {
18314
+ _moveCircuitJsonElements({
18315
+ deltaX,
18316
+ deltaY
18317
+ }) {
18095
18318
  if (this.root?.pcbDisabled) return;
18096
18319
  const { db } = this.root;
18097
18320
  if (!this.pcb_silkscreen_line_id) return;
@@ -18548,7 +18771,7 @@ var PinHeader = class extends NormalComponent3 {
18548
18771
 
18549
18772
  // lib/components/normal-components/Resonator.ts
18550
18773
  import { resonatorProps } from "@tscircuit/props";
18551
- import { formatSiUnit as formatSiUnit6 } from "format-si-unit";
18774
+ import { formatSiUnit as formatSiUnit7 } from "format-si-unit";
18552
18775
  function getResonatorSymbolName(variant) {
18553
18776
  switch (variant) {
18554
18777
  case "two_ground_pins":
@@ -18586,9 +18809,9 @@ var Resonator = class extends NormalComponent3 {
18586
18809
  this.source_component_id = source_component.source_component_id;
18587
18810
  }
18588
18811
  _getSchematicSymbolDisplayValue() {
18589
- const freqDisplay = `${formatSiUnit6(this._parsedProps.frequency)}Hz`;
18812
+ const freqDisplay = `${formatSiUnit7(this._parsedProps.frequency)}Hz`;
18590
18813
  if (this._parsedProps.loadCapacitance) {
18591
- return `${freqDisplay} / ${formatSiUnit6(this._parsedProps.loadCapacitance)}F`;
18814
+ return `${freqDisplay} / ${formatSiUnit7(this._parsedProps.loadCapacitance)}F`;
18592
18815
  }
18593
18816
  return freqDisplay;
18594
18817
  }
@@ -18596,7 +18819,7 @@ var Resonator = class extends NormalComponent3 {
18596
18819
 
18597
18820
  // lib/components/normal-components/Potentiometer.ts
18598
18821
  import { potentiometerProps } from "@tscircuit/props";
18599
- import { formatSiUnit as formatSiUnit7 } from "format-si-unit";
18822
+ import { formatSiUnit as formatSiUnit8 } from "format-si-unit";
18600
18823
  function getPotentiometerSymbolName(variant) {
18601
18824
  switch (variant) {
18602
18825
  case "three_pin":
@@ -18617,7 +18840,7 @@ var Potentiometer = class extends NormalComponent3 {
18617
18840
  };
18618
18841
  }
18619
18842
  _getSchematicSymbolDisplayValue() {
18620
- return `${formatSiUnit7(this._parsedProps.maxResistance)}\u03A9`;
18843
+ return `${formatSiUnit8(this._parsedProps.maxResistance)}\u03A9`;
18621
18844
  }
18622
18845
  doInitialSourceRender() {
18623
18846
  const { db } = this.root;
@@ -18701,7 +18924,7 @@ var PushButton = class extends NormalComponent3 {
18701
18924
 
18702
18925
  // lib/components/normal-components/Crystal.ts
18703
18926
  import { crystalProps } from "@tscircuit/props";
18704
- import { formatSiUnit as formatSiUnit8 } from "format-si-unit";
18927
+ import { formatSiUnit as formatSiUnit9 } from "format-si-unit";
18705
18928
  var Crystal = class extends NormalComponent3 {
18706
18929
  // @ts-ignore
18707
18930
  get config() {
@@ -18728,9 +18951,9 @@ var Crystal = class extends NormalComponent3 {
18728
18951
  });
18729
18952
  }
18730
18953
  _getSchematicSymbolDisplayValue() {
18731
- const freqDisplay = `${formatSiUnit8(this._parsedProps.frequency)}Hz`;
18954
+ const freqDisplay = `${formatSiUnit9(this._parsedProps.frequency)}Hz`;
18732
18955
  if (this._parsedProps.loadCapacitance) {
18733
- return `${freqDisplay} / ${formatSiUnit8(
18956
+ return `${freqDisplay} / ${formatSiUnit9(
18734
18957
  this._parsedProps.loadCapacitance
18735
18958
  )}F`;
18736
18959
  }
@@ -19785,7 +20008,7 @@ import { identity as identity5 } from "transformation-matrix";
19785
20008
  var package_default = {
19786
20009
  name: "@tscircuit/core",
19787
20010
  type: "module",
19788
- version: "0.0.941",
20011
+ version: "0.0.943",
19789
20012
  types: "dist/index.d.ts",
19790
20013
  main: "dist/index.js",
19791
20014
  module: "dist/index.js",
@@ -19828,7 +20051,7 @@ var package_default = {
19828
20051
  "@tscircuit/math-utils": "^0.0.29",
19829
20052
  "@tscircuit/miniflex": "^0.0.4",
19830
20053
  "@tscircuit/ngspice-spice-engine": "^0.0.8",
19831
- "@tscircuit/props": "^0.0.435",
20054
+ "@tscircuit/props": "^0.0.438",
19832
20055
  "@tscircuit/schematic-match-adapt": "^0.0.16",
19833
20056
  "@tscircuit/schematic-trace-solver": "^v0.0.45",
19834
20057
  "@tscircuit/solver-utils": "^0.0.3",
@@ -19862,7 +20085,7 @@ var package_default = {
19862
20085
  poppygl: "^0.0.16",
19863
20086
  react: "^19.1.0",
19864
20087
  "react-dom": "^19.1.0",
19865
- "schematic-symbols": "^0.0.202",
20088
+ "schematic-symbols": "^0.0.203",
19866
20089
  spicey: "^0.0.14",
19867
20090
  "ts-expect": "^1.3.0",
19868
20091
  tsup: "^8.2.4",
@@ -20336,6 +20559,7 @@ export {
20336
20559
  CopperPour,
20337
20560
  CopperText,
20338
20561
  Crystal,
20562
+ CurrentSource,
20339
20563
  Cutout,
20340
20564
  Diode,
20341
20565
  FabricationNoteDimension,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.942",
4
+ "version": "0.0.944",
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.435",
47
+ "@tscircuit/props": "^0.0.438",
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",
@@ -78,7 +78,7 @@
78
78
  "poppygl": "^0.0.16",
79
79
  "react": "^19.1.0",
80
80
  "react-dom": "^19.1.0",
81
- "schematic-symbols": "^0.0.202",
81
+ "schematic-symbols": "^0.0.203",
82
82
  "spicey": "^0.0.14",
83
83
  "ts-expect": "^1.3.0",
84
84
  "tsup": "^8.2.4",