@tscircuit/core 0.0.574 → 0.0.576

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 (2) hide show
  1. package/dist/index.js +194 -166
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2449,6 +2449,157 @@ var SilkscreenText = class extends PrimitiveComponent2 {
2449
2449
  }
2450
2450
  };
2451
2451
 
2452
+ // lib/components/primitive-components/Cutout.ts
2453
+ import { applyToPoint as applyToPoint4 } from "transformation-matrix";
2454
+ import { cutoutProps } from "@tscircuit/props";
2455
+ var Cutout = class extends PrimitiveComponent2 {
2456
+ pcb_cutout_id = null;
2457
+ isPcbPrimitive = true;
2458
+ get config() {
2459
+ return {
2460
+ componentName: "Cutout",
2461
+ zodProps: cutoutProps
2462
+ };
2463
+ }
2464
+ doInitialPcbPrimitiveRender() {
2465
+ if (this.root?.pcbDisabled) return;
2466
+ const { db } = this.root;
2467
+ const { _parsedProps: props } = this;
2468
+ const subcircuit = this.getSubcircuit();
2469
+ const pcb_group_id = this.getGroup()?.pcb_group_id ?? void 0;
2470
+ const globalPosition = this._getGlobalPcbPositionBeforeLayout();
2471
+ let inserted_pcb_cutout = void 0;
2472
+ if (props.shape === "rect") {
2473
+ const rectData = {
2474
+ shape: "rect",
2475
+ center: globalPosition,
2476
+ width: props.width,
2477
+ height: props.height,
2478
+ subcircuit_id: subcircuit?.subcircuit_id ?? void 0,
2479
+ pcb_group_id
2480
+ };
2481
+ inserted_pcb_cutout = db.pcb_cutout.insert(rectData);
2482
+ } else if (props.shape === "circle") {
2483
+ const circleData = {
2484
+ shape: "circle",
2485
+ center: globalPosition,
2486
+ radius: props.radius,
2487
+ subcircuit_id: subcircuit?.subcircuit_id ?? void 0,
2488
+ pcb_group_id
2489
+ };
2490
+ inserted_pcb_cutout = db.pcb_cutout.insert(circleData);
2491
+ } else if (props.shape === "polygon") {
2492
+ const transform = this._computePcbGlobalTransformBeforeLayout();
2493
+ const transformedPoints = props.points.map(
2494
+ (p) => applyToPoint4(transform, p)
2495
+ );
2496
+ const polygonData = {
2497
+ shape: "polygon",
2498
+ points: transformedPoints,
2499
+ subcircuit_id: subcircuit?.subcircuit_id ?? void 0,
2500
+ pcb_group_id
2501
+ };
2502
+ inserted_pcb_cutout = db.pcb_cutout.insert(polygonData);
2503
+ }
2504
+ if (inserted_pcb_cutout) {
2505
+ this.pcb_cutout_id = inserted_pcb_cutout.pcb_cutout_id;
2506
+ }
2507
+ }
2508
+ getPcbSize() {
2509
+ const { _parsedProps: props } = this;
2510
+ if (props.shape === "rect") {
2511
+ return { width: props.width, height: props.height };
2512
+ }
2513
+ if (props.shape === "circle") {
2514
+ return { width: props.radius * 2, height: props.radius * 2 };
2515
+ }
2516
+ if (props.shape === "polygon") {
2517
+ if (props.points.length === 0) return { width: 0, height: 0 };
2518
+ let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
2519
+ for (const point of props.points) {
2520
+ minX = Math.min(minX, point.x);
2521
+ maxX = Math.max(maxX, point.x);
2522
+ minY = Math.min(minY, point.y);
2523
+ maxY = Math.max(maxY, point.y);
2524
+ }
2525
+ return { width: maxX - minX, height: maxY - minY };
2526
+ }
2527
+ return { width: 0, height: 0 };
2528
+ }
2529
+ _getPcbCircuitJsonBounds() {
2530
+ if (!this.pcb_cutout_id) return super._getPcbCircuitJsonBounds();
2531
+ const { db } = this.root;
2532
+ const cutout = db.pcb_cutout.get(this.pcb_cutout_id);
2533
+ if (!cutout) return super._getPcbCircuitJsonBounds();
2534
+ if (cutout.shape === "rect") {
2535
+ return {
2536
+ center: cutout.center,
2537
+ bounds: {
2538
+ left: cutout.center.x - cutout.width / 2,
2539
+ top: cutout.center.y + cutout.height / 2,
2540
+ // Assuming Y is up
2541
+ right: cutout.center.x + cutout.width / 2,
2542
+ bottom: cutout.center.y - cutout.height / 2
2543
+ },
2544
+ width: cutout.width,
2545
+ height: cutout.height
2546
+ };
2547
+ } else if (cutout.shape === "circle") {
2548
+ return {
2549
+ center: cutout.center,
2550
+ bounds: {
2551
+ left: cutout.center.x - cutout.radius,
2552
+ top: cutout.center.y + cutout.radius,
2553
+ right: cutout.center.x + cutout.radius,
2554
+ bottom: cutout.center.y - cutout.radius
2555
+ },
2556
+ width: cutout.radius * 2,
2557
+ height: cutout.radius * 2
2558
+ };
2559
+ } else if (cutout.shape === "polygon") {
2560
+ if (cutout.points.length === 0) return super._getPcbCircuitJsonBounds();
2561
+ let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
2562
+ for (const point of cutout.points) {
2563
+ minX = Math.min(minX, point.x);
2564
+ maxX = Math.max(maxX, point.x);
2565
+ minY = Math.min(minY, point.y);
2566
+ maxY = Math.max(maxY, point.y);
2567
+ }
2568
+ return {
2569
+ center: { x: (minX + maxX) / 2, y: (minY + maxY) / 2 },
2570
+ bounds: { left: minX, top: maxY, right: maxX, bottom: minY },
2571
+ width: maxX - minX,
2572
+ height: maxY - minY
2573
+ };
2574
+ }
2575
+ return super._getPcbCircuitJsonBounds();
2576
+ }
2577
+ _setPositionFromLayout(newCenter) {
2578
+ if (!this.pcb_cutout_id) return;
2579
+ const { db } = this.root;
2580
+ const cutout = db.pcb_cutout.get(this.pcb_cutout_id);
2581
+ if (!cutout) return;
2582
+ if (cutout.shape === "rect" || cutout.shape === "circle") {
2583
+ db.pcb_cutout.update(this.pcb_cutout_id, {
2584
+ ...cutout,
2585
+ center: newCenter
2586
+ });
2587
+ } else if (cutout.shape === "polygon") {
2588
+ const oldCenter = this._getPcbCircuitJsonBounds().center;
2589
+ const dx = newCenter.x - oldCenter.x;
2590
+ const dy = newCenter.y - oldCenter.y;
2591
+ const newPoints = cutout.points.map((p) => ({
2592
+ x: p.x + dx,
2593
+ y: p.y + dy
2594
+ }));
2595
+ db.pcb_cutout.update(this.pcb_cutout_id, {
2596
+ ...cutout,
2597
+ points: newPoints
2598
+ });
2599
+ }
2600
+ }
2601
+ };
2602
+
2452
2603
  // lib/utils/createPinrowSilkscreenText.ts
2453
2604
  var createPinrowSilkscreenText = ({
2454
2605
  elm,
@@ -2576,6 +2727,34 @@ var createComponentsFromCircuitJson = ({
2576
2727
  diameter: elm.hole_diameter
2577
2728
  })
2578
2729
  );
2730
+ } else if (elm.type === "pcb_cutout") {
2731
+ if (elm.shape === "rect") {
2732
+ components.push(
2733
+ new Cutout({
2734
+ pcbX: elm.center.x,
2735
+ pcbY: elm.center.y,
2736
+ shape: "rect",
2737
+ width: elm.width,
2738
+ height: elm.height
2739
+ })
2740
+ );
2741
+ } else if (elm.shape === "circle") {
2742
+ components.push(
2743
+ new Cutout({
2744
+ pcbX: elm.center.x,
2745
+ pcbY: elm.center.y,
2746
+ shape: "circle",
2747
+ radius: elm.radius
2748
+ })
2749
+ );
2750
+ } else if (elm.shape === "polygon") {
2751
+ components.push(
2752
+ new Cutout({
2753
+ shape: "polygon",
2754
+ points: elm.points
2755
+ })
2756
+ );
2757
+ }
2579
2758
  } else if (elm.type === "pcb_silkscreen_text") {
2580
2759
  const ccwRotation = calculateCcwRotation(
2581
2760
  componentRotation,
@@ -2597,7 +2776,7 @@ var createComponentsFromCircuitJson = ({
2597
2776
  anchorAlignment: elm.anchor_alignment || "center",
2598
2777
  text: componentName,
2599
2778
  fontSize: elm.font_size + 0.2,
2600
- pcbX: isNaN(elm.anchor_position.x) ? 0 : elm.anchor_position.x,
2779
+ pcbX: Number.isNaN(elm.anchor_position.x) ? 0 : elm.anchor_position.x,
2601
2780
  pcbY: elm.anchor_position.y,
2602
2781
  pcbRotation: ccwRotation ?? 0
2603
2782
  })
@@ -2677,7 +2856,7 @@ function getRelativeDirection(pointA, pointB) {
2677
2856
 
2678
2857
  // lib/components/primitive-components/Port/Port.ts
2679
2858
  import "schematic-symbols";
2680
- import { applyToPoint as applyToPoint4, compose as compose3, translate as translate3 } from "transformation-matrix";
2859
+ import { applyToPoint as applyToPoint5, compose as compose3, translate as translate3 } from "transformation-matrix";
2681
2860
  import { z as z6 } from "zod";
2682
2861
 
2683
2862
  // lib/components/primitive-components/Port/areAllPcbPrimitivesOverlapping.ts
@@ -2850,7 +3029,7 @@ var Port = class extends PrimitiveComponent2 {
2850
3029
  this.parent.computeSchematicGlobalTransform(),
2851
3030
  translate3(-symbol.center.x, -symbol.center.y)
2852
3031
  );
2853
- return applyToPoint4(transform, schematicSymbolPortDef);
3032
+ return applyToPoint5(transform, schematicSymbolPortDef);
2854
3033
  }
2855
3034
  const parentBoxDim = this?.parent?._getSchematicBoxDimensions();
2856
3035
  if (parentBoxDim && this.props.pinNumber !== void 0) {
@@ -2862,7 +3041,7 @@ var Port = class extends PrimitiveComponent2 {
2862
3041
  `Couldn't find position for schematic_port for port ${this.getString()} inside of the schematic box`
2863
3042
  );
2864
3043
  }
2865
- return applyToPoint4(
3044
+ return applyToPoint5(
2866
3045
  this.parent.computeSchematicGlobalTransform(),
2867
3046
  localPortPosition
2868
3047
  );
@@ -6764,7 +6943,7 @@ import "zod";
6764
6943
 
6765
6944
  // lib/components/primitive-components/TraceHint.ts
6766
6945
  import { traceHintProps } from "@tscircuit/props";
6767
- import { applyToPoint as applyToPoint5 } from "transformation-matrix";
6946
+ import { applyToPoint as applyToPoint6 } from "transformation-matrix";
6768
6947
  var TraceHint = class extends PrimitiveComponent2 {
6769
6948
  matchedPort = null;
6770
6949
  get config() {
@@ -6804,7 +6983,7 @@ var TraceHint = class extends PrimitiveComponent2 {
6804
6983
  const globalTransform = this._computePcbGlobalTransformBeforeLayout();
6805
6984
  return offsets.map(
6806
6985
  (offset) => ({
6807
- ...applyToPoint5(globalTransform, offset),
6986
+ ...applyToPoint6(globalTransform, offset),
6808
6987
  via: offset.via,
6809
6988
  to_layer: offset.to_layer,
6810
6989
  trace_width: offset.trace_width
@@ -7807,8 +7986,8 @@ function Group_doInitialPcbLayoutGrid(group) {
7807
7986
  }
7808
7987
  if (group.pcb_group_id) {
7809
7988
  db.pcb_group.update(group.pcb_group_id, {
7810
- width: totalGridWidth,
7811
- height: totalGridHeight,
7989
+ width: props.width ?? totalGridWidth,
7990
+ height: props.height ?? totalGridHeight,
7812
7991
  center: groupCenter
7813
7992
  });
7814
7993
  }
@@ -7947,8 +8126,8 @@ var Group = class extends NormalComponent {
7947
8126
  centerY += (padTop - padBottom) / 2;
7948
8127
  }
7949
8128
  db.pcb_group.update(this.pcb_group_id, {
7950
- width,
7951
- height,
8129
+ width: Number(props.width ?? width),
8130
+ height: Number(props.height ?? height),
7952
8131
  center: {
7953
8132
  x: centerX,
7954
8133
  y: centerY
@@ -9402,7 +9581,7 @@ var Constraint2 = class extends PrimitiveComponent2 {
9402
9581
 
9403
9582
  // lib/components/primitive-components/FabricationNotePath.ts
9404
9583
  import { fabricationNotePathProps } from "@tscircuit/props";
9405
- import { applyToPoint as applyToPoint6 } from "transformation-matrix";
9584
+ import { applyToPoint as applyToPoint7 } from "transformation-matrix";
9406
9585
  var FabricationNotePath = class extends PrimitiveComponent2 {
9407
9586
  fabrication_note_path_id = null;
9408
9587
  get config() {
@@ -9428,7 +9607,7 @@ var FabricationNotePath = class extends PrimitiveComponent2 {
9428
9607
  layer,
9429
9608
  color: props.color,
9430
9609
  route: props.route.map((p) => {
9431
- const transformedPosition = applyToPoint6(transform, {
9610
+ const transformedPosition = applyToPoint7(transform, {
9432
9611
  x: p.x,
9433
9612
  y: p.y
9434
9613
  });
@@ -9602,7 +9781,7 @@ var BreakoutPoint = class extends PrimitiveComponent2 {
9602
9781
  // lib/components/primitive-components/NetLabel.ts
9603
9782
  import { netLabelProps } from "@tscircuit/props";
9604
9783
  import {
9605
- applyToPoint as applyToPoint7,
9784
+ applyToPoint as applyToPoint8,
9606
9785
  identity as identity4,
9607
9786
  translate as translate6
9608
9787
  } from "transformation-matrix";
@@ -9652,7 +9831,7 @@ var NetLabel = class extends PrimitiveComponent2 {
9652
9831
  const connectedPorts = this._getConnectedPorts();
9653
9832
  if (connectedPorts.length > 0) {
9654
9833
  const portPos = connectedPorts[0]._getGlobalSchematicPositionBeforeLayout();
9655
- const parentCenter = applyToPoint7(
9834
+ const parentCenter = applyToPoint8(
9656
9835
  this.parent?.computeSchematicGlobalTransform?.() ?? identity4(),
9657
9836
  { x: 0, y: 0 }
9658
9837
  );
@@ -9916,157 +10095,6 @@ var Via = class extends PrimitiveComponent2 {
9916
10095
  }
9917
10096
  };
9918
10097
 
9919
- // lib/components/primitive-components/Cutout.ts
9920
- import { applyToPoint as applyToPoint8 } from "transformation-matrix";
9921
- import { cutoutProps } from "@tscircuit/props";
9922
- var Cutout = class extends PrimitiveComponent2 {
9923
- pcb_cutout_id = null;
9924
- isPcbPrimitive = true;
9925
- get config() {
9926
- return {
9927
- componentName: "Cutout",
9928
- zodProps: cutoutProps
9929
- };
9930
- }
9931
- doInitialPcbPrimitiveRender() {
9932
- if (this.root?.pcbDisabled) return;
9933
- const { db } = this.root;
9934
- const { _parsedProps: props } = this;
9935
- const subcircuit = this.getSubcircuit();
9936
- const pcb_group_id = this.getGroup()?.pcb_group_id ?? void 0;
9937
- const globalPosition = this._getGlobalPcbPositionBeforeLayout();
9938
- let inserted_pcb_cutout = void 0;
9939
- if (props.shape === "rect") {
9940
- const rectData = {
9941
- shape: "rect",
9942
- center: globalPosition,
9943
- width: props.width,
9944
- height: props.height,
9945
- subcircuit_id: subcircuit?.subcircuit_id ?? void 0,
9946
- pcb_group_id
9947
- };
9948
- inserted_pcb_cutout = db.pcb_cutout.insert(rectData);
9949
- } else if (props.shape === "circle") {
9950
- const circleData = {
9951
- shape: "circle",
9952
- center: globalPosition,
9953
- radius: props.radius,
9954
- subcircuit_id: subcircuit?.subcircuit_id ?? void 0,
9955
- pcb_group_id
9956
- };
9957
- inserted_pcb_cutout = db.pcb_cutout.insert(circleData);
9958
- } else if (props.shape === "polygon") {
9959
- const transform = this._computePcbGlobalTransformBeforeLayout();
9960
- const transformedPoints = props.points.map(
9961
- (p) => applyToPoint8(transform, p)
9962
- );
9963
- const polygonData = {
9964
- shape: "polygon",
9965
- points: transformedPoints,
9966
- subcircuit_id: subcircuit?.subcircuit_id ?? void 0,
9967
- pcb_group_id
9968
- };
9969
- inserted_pcb_cutout = db.pcb_cutout.insert(polygonData);
9970
- }
9971
- if (inserted_pcb_cutout) {
9972
- this.pcb_cutout_id = inserted_pcb_cutout.pcb_cutout_id;
9973
- }
9974
- }
9975
- getPcbSize() {
9976
- const { _parsedProps: props } = this;
9977
- if (props.shape === "rect") {
9978
- return { width: props.width, height: props.height };
9979
- }
9980
- if (props.shape === "circle") {
9981
- return { width: props.radius * 2, height: props.radius * 2 };
9982
- }
9983
- if (props.shape === "polygon") {
9984
- if (props.points.length === 0) return { width: 0, height: 0 };
9985
- let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
9986
- for (const point of props.points) {
9987
- minX = Math.min(minX, point.x);
9988
- maxX = Math.max(maxX, point.x);
9989
- minY = Math.min(minY, point.y);
9990
- maxY = Math.max(maxY, point.y);
9991
- }
9992
- return { width: maxX - minX, height: maxY - minY };
9993
- }
9994
- return { width: 0, height: 0 };
9995
- }
9996
- _getPcbCircuitJsonBounds() {
9997
- if (!this.pcb_cutout_id) return super._getPcbCircuitJsonBounds();
9998
- const { db } = this.root;
9999
- const cutout = db.pcb_cutout.get(this.pcb_cutout_id);
10000
- if (!cutout) return super._getPcbCircuitJsonBounds();
10001
- if (cutout.shape === "rect") {
10002
- return {
10003
- center: cutout.center,
10004
- bounds: {
10005
- left: cutout.center.x - cutout.width / 2,
10006
- top: cutout.center.y + cutout.height / 2,
10007
- // Assuming Y is up
10008
- right: cutout.center.x + cutout.width / 2,
10009
- bottom: cutout.center.y - cutout.height / 2
10010
- },
10011
- width: cutout.width,
10012
- height: cutout.height
10013
- };
10014
- } else if (cutout.shape === "circle") {
10015
- return {
10016
- center: cutout.center,
10017
- bounds: {
10018
- left: cutout.center.x - cutout.radius,
10019
- top: cutout.center.y + cutout.radius,
10020
- right: cutout.center.x + cutout.radius,
10021
- bottom: cutout.center.y - cutout.radius
10022
- },
10023
- width: cutout.radius * 2,
10024
- height: cutout.radius * 2
10025
- };
10026
- } else if (cutout.shape === "polygon") {
10027
- if (cutout.points.length === 0) return super._getPcbCircuitJsonBounds();
10028
- let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
10029
- for (const point of cutout.points) {
10030
- minX = Math.min(minX, point.x);
10031
- maxX = Math.max(maxX, point.x);
10032
- minY = Math.min(minY, point.y);
10033
- maxY = Math.max(maxY, point.y);
10034
- }
10035
- return {
10036
- center: { x: (minX + maxX) / 2, y: (minY + maxY) / 2 },
10037
- bounds: { left: minX, top: maxY, right: maxX, bottom: minY },
10038
- width: maxX - minX,
10039
- height: maxY - minY
10040
- };
10041
- }
10042
- return super._getPcbCircuitJsonBounds();
10043
- }
10044
- _setPositionFromLayout(newCenter) {
10045
- if (!this.pcb_cutout_id) return;
10046
- const { db } = this.root;
10047
- const cutout = db.pcb_cutout.get(this.pcb_cutout_id);
10048
- if (!cutout) return;
10049
- if (cutout.shape === "rect" || cutout.shape === "circle") {
10050
- db.pcb_cutout.update(this.pcb_cutout_id, {
10051
- ...cutout,
10052
- center: newCenter
10053
- });
10054
- } else if (cutout.shape === "polygon") {
10055
- const oldCenter = this._getPcbCircuitJsonBounds().center;
10056
- const dx = newCenter.x - oldCenter.x;
10057
- const dy = newCenter.y - oldCenter.y;
10058
- const newPoints = cutout.points.map((p) => ({
10059
- x: p.x + dx,
10060
- y: p.y + dy
10061
- }));
10062
- db.pcb_cutout.update(this.pcb_cutout_id, {
10063
- ...cutout,
10064
- points: newPoints
10065
- });
10066
- }
10067
- }
10068
- };
10069
-
10070
10098
  // lib/components/normal-components/Battery.ts
10071
10099
  import { batteryProps } from "@tscircuit/props";
10072
10100
  var Battery = class extends NormalComponent {
@@ -10985,7 +11013,7 @@ import { identity as identity5 } from "transformation-matrix";
10985
11013
  var package_default = {
10986
11014
  name: "@tscircuit/core",
10987
11015
  type: "module",
10988
- version: "0.0.573",
11016
+ version: "0.0.575",
10989
11017
  types: "dist/index.d.ts",
10990
11018
  main: "dist/index.js",
10991
11019
  module: "dist/index.js",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.574",
4
+ "version": "0.0.576",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",