@tscircuit/core 0.0.869 → 0.0.871

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
@@ -2720,6 +2720,7 @@ declare class Board extends Group<typeof boardProps> {
2720
2720
 
2721
2721
  declare class Panel extends Group<typeof panelProps> {
2722
2722
  pcb_panel_id: string | null;
2723
+ _tabsAndMouseBitesGenerated: boolean;
2723
2724
  get config(): {
2724
2725
  componentName: string;
2725
2726
  zodProps: zod.ZodObject<Omit<{
@@ -3734,6 +3735,7 @@ declare class Panel extends Group<typeof panelProps> {
3734
3735
  get isGroup(): boolean;
3735
3736
  get isSubcircuit(): boolean;
3736
3737
  add(component: PrimitiveComponent): void;
3738
+ doInitialPcbComponentAnchorAlignment(): void;
3737
3739
  runRenderCycle(): void;
3738
3740
  doInitialPcbComponentRender(): void;
3739
3741
  updatePcbComponentRender(): void;
package/dist/index.js CHANGED
@@ -14298,8 +14298,243 @@ var Board = class extends Group6 {
14298
14298
  // lib/components/normal-components/Panel.ts
14299
14299
  import { panelProps } from "@tscircuit/props";
14300
14300
  import { distance as distance7 } from "circuit-json";
14301
+
14302
+ // lib/utils/panels/generate-panel-tabs-and-mouse-bites.ts
14303
+ var TAB_CONFIG = {
14304
+ TAB_WIDTH: 4,
14305
+ TAB_DEPTH: 0.5,
14306
+ TAB_TO_SPACE_RATIO: 5,
14307
+ MOUSE_BITE_DIAMETER: 0.2,
14308
+ MOUSE_BITE_SPACING: 0.1,
14309
+ MOUSE_BITES_PER_GAP: 5
14310
+ };
14311
+ function rectanglesOverlap(rect1, rect2) {
14312
+ const r1Left = rect1.center.x - rect1.width / 2;
14313
+ const r1Right = rect1.center.x + rect1.width / 2;
14314
+ const r1Bottom = rect1.center.y - rect1.height / 2;
14315
+ const r1Top = rect1.center.y + rect1.height / 2;
14316
+ const r2Left = rect2.center.x - rect2.width / 2;
14317
+ const r2Right = rect2.center.x + rect2.width / 2;
14318
+ const r2Bottom = rect2.center.y - rect2.height / 2;
14319
+ const r2Top = rect2.center.y + rect2.height / 2;
14320
+ return !(r1Right <= r2Left || r1Left >= r2Right || r1Top <= r2Bottom || r1Bottom >= r2Top);
14321
+ }
14322
+ function pointOverlapsRectangle(point, radius, rect) {
14323
+ const rectLeft = rect.center.x - rect.width / 2;
14324
+ const rectRight = rect.center.x + rect.width / 2;
14325
+ const rectBottom = rect.center.y - rect.height / 2;
14326
+ const rectTop = rect.center.y + rect.height / 2;
14327
+ const closestX = Math.max(rectLeft, Math.min(point.x, rectRight));
14328
+ const closestY = Math.max(rectBottom, Math.min(point.y, rectTop));
14329
+ const distanceX = point.x - closestX;
14330
+ const distanceY = point.y - closestY;
14331
+ return distanceX * distanceX + distanceY * distanceY <= radius * radius;
14332
+ }
14333
+ function generateTabsForEdge(board, edge, existingTabs, otherBoards) {
14334
+ const tabs = [];
14335
+ if (!board.width || !board.height) return tabs;
14336
+ const boardLeft = board.center.x - board.width / 2;
14337
+ const boardRight = board.center.x + board.width / 2;
14338
+ const boardBottom = board.center.y - board.height / 2;
14339
+ const boardTop = board.center.y + board.height / 2;
14340
+ let edgeLength;
14341
+ let isHorizontal;
14342
+ let edgeCenter;
14343
+ if (edge === "top" || edge === "bottom") {
14344
+ edgeLength = board.width;
14345
+ isHorizontal = true;
14346
+ edgeCenter = edge === "top" ? boardTop : boardBottom;
14347
+ } else {
14348
+ edgeLength = board.height;
14349
+ isHorizontal = false;
14350
+ edgeCenter = edge === "right" ? boardRight : boardLeft;
14351
+ }
14352
+ const totalTabWidth = TAB_CONFIG.TAB_WIDTH;
14353
+ const minSpacingForMouseBites = TAB_CONFIG.MOUSE_BITES_PER_GAP * TAB_CONFIG.MOUSE_BITE_DIAMETER + (TAB_CONFIG.MOUSE_BITES_PER_GAP - 1) * TAB_CONFIG.MOUSE_BITE_SPACING;
14354
+ const fixedSpacing = minSpacingForMouseBites * 1.1;
14355
+ let numTabs = Math.floor(
14356
+ (edgeLength - fixedSpacing) / (totalTabWidth + fixedSpacing)
14357
+ );
14358
+ if (numTabs < 1 && edgeLength >= totalTabWidth) {
14359
+ numTabs = 1;
14360
+ }
14361
+ if (numTabs === 0) return tabs;
14362
+ const actualSpacing = fixedSpacing;
14363
+ const boardStart = -edgeLength / 2;
14364
+ const boardEnd = edgeLength / 2;
14365
+ for (let i = 0; i < numTabs; i++) {
14366
+ const offsetAlongEdge = boardStart + actualSpacing + i * (totalTabWidth + actualSpacing) + totalTabWidth / 2;
14367
+ const isFirstTab = i === 0;
14368
+ const isLastTab = i === numTabs - 1;
14369
+ const isCornerTab = isFirstTab || isLastTab;
14370
+ let axisStart = offsetAlongEdge - totalTabWidth / 2;
14371
+ let axisEnd = offsetAlongEdge + totalTabWidth / 2;
14372
+ if (isCornerTab) {
14373
+ if (isFirstTab) axisStart = boardStart;
14374
+ if (isLastTab) axisEnd = boardEnd;
14375
+ }
14376
+ axisStart = Math.max(axisStart, boardStart);
14377
+ axisEnd = Math.min(axisEnd, boardEnd);
14378
+ if (isCornerTab) {
14379
+ if (isFirstTab) axisStart -= TAB_CONFIG.TAB_DEPTH;
14380
+ if (isLastTab) axisEnd += TAB_CONFIG.TAB_DEPTH;
14381
+ }
14382
+ if (axisEnd <= axisStart) continue;
14383
+ const axisCenterOffset = (axisStart + axisEnd) / 2;
14384
+ const axisLength = axisEnd - axisStart;
14385
+ const crossAxisOffset = edge === "top" || edge === "right" ? TAB_CONFIG.TAB_DEPTH / 2 : -TAB_CONFIG.TAB_DEPTH / 2;
14386
+ const tabCenter = isHorizontal ? {
14387
+ x: board.center.x + axisCenterOffset,
14388
+ y: edgeCenter + crossAxisOffset
14389
+ } : {
14390
+ x: edgeCenter + crossAxisOffset,
14391
+ y: board.center.y + axisCenterOffset
14392
+ };
14393
+ const tabWidth = isHorizontal ? axisLength : TAB_CONFIG.TAB_DEPTH;
14394
+ const tabHeight = isHorizontal ? TAB_CONFIG.TAB_DEPTH : axisLength;
14395
+ const newTab = {
14396
+ center: tabCenter,
14397
+ width: tabWidth,
14398
+ height: tabHeight,
14399
+ boardId: `${board.center.x}_${board.center.y}`
14400
+ };
14401
+ let overlapsBoard = false;
14402
+ for (const otherBoard of otherBoards) {
14403
+ if (!otherBoard.width || !otherBoard.height) continue;
14404
+ const boardRect = {
14405
+ center: otherBoard.center,
14406
+ width: otherBoard.width,
14407
+ height: otherBoard.height
14408
+ };
14409
+ if (rectanglesOverlap(newTab, boardRect)) {
14410
+ overlapsBoard = true;
14411
+ break;
14412
+ }
14413
+ }
14414
+ if (overlapsBoard && !isCornerTab) continue;
14415
+ tabs.push(newTab);
14416
+ }
14417
+ return tabs;
14418
+ }
14419
+ function generateMouseBitesForEdge(board, edge, edgeTabs, allTabs, allBoards, existingMouseBites) {
14420
+ const mouseBites = [];
14421
+ if (edgeTabs.length === 0) return mouseBites;
14422
+ if (!board.width || !board.height) return mouseBites;
14423
+ const boardLeft = board.center.x - board.width / 2;
14424
+ const boardRight = board.center.x + board.width / 2;
14425
+ const boardBottom = board.center.y - board.height / 2;
14426
+ const boardTop = board.center.y + board.height / 2;
14427
+ const isHorizontal = edge === "top" || edge === "bottom";
14428
+ let mouseBitePosition;
14429
+ const radius = TAB_CONFIG.MOUSE_BITE_DIAMETER / 2;
14430
+ if (edge === "top") {
14431
+ mouseBitePosition = boardTop;
14432
+ } else if (edge === "bottom") {
14433
+ mouseBitePosition = boardBottom;
14434
+ } else if (edge === "right") {
14435
+ mouseBitePosition = boardRight;
14436
+ } else {
14437
+ mouseBitePosition = boardLeft;
14438
+ }
14439
+ const sortedTabs = [...edgeTabs].sort((a, b) => {
14440
+ if (isHorizontal) {
14441
+ return a.center.x - b.center.x;
14442
+ } else {
14443
+ return a.center.y - b.center.y;
14444
+ }
14445
+ });
14446
+ for (let i = 0; i < sortedTabs.length - 1; i++) {
14447
+ const tab1 = sortedTabs[i];
14448
+ const tab2 = sortedTabs[i + 1];
14449
+ let gapStart;
14450
+ let gapEnd;
14451
+ if (isHorizontal) {
14452
+ gapStart = tab1.center.x + tab1.width / 2;
14453
+ gapEnd = tab2.center.x - tab2.width / 2;
14454
+ } else {
14455
+ gapStart = tab1.center.y + tab1.height / 2;
14456
+ gapEnd = tab2.center.y - tab2.height / 2;
14457
+ }
14458
+ const gapLength = gapEnd - gapStart;
14459
+ const totalMouseBiteWidth = TAB_CONFIG.MOUSE_BITES_PER_GAP * TAB_CONFIG.MOUSE_BITE_DIAMETER;
14460
+ const totalSpacing = (TAB_CONFIG.MOUSE_BITES_PER_GAP - 1) * TAB_CONFIG.MOUSE_BITE_SPACING;
14461
+ if (gapLength < totalMouseBiteWidth + totalSpacing) continue;
14462
+ const gapCenter = (gapStart + gapEnd) / 2;
14463
+ for (let j = 0; j < TAB_CONFIG.MOUSE_BITES_PER_GAP; j++) {
14464
+ const posOffset = (j - (TAB_CONFIG.MOUSE_BITES_PER_GAP - 1) / 2) * (TAB_CONFIG.MOUSE_BITE_DIAMETER + TAB_CONFIG.MOUSE_BITE_SPACING);
14465
+ const newMouseBite = isHorizontal ? { x: gapCenter + posOffset, y: mouseBitePosition } : { x: mouseBitePosition, y: gapCenter + posOffset };
14466
+ const radius2 = TAB_CONFIG.MOUSE_BITE_DIAMETER / 2;
14467
+ let overlapsBoard = false;
14468
+ for (const otherBoard of allBoards) {
14469
+ if (!otherBoard.width || !otherBoard.height) continue;
14470
+ const boardRect = {
14471
+ center: otherBoard.center,
14472
+ width: otherBoard.width,
14473
+ height: otherBoard.height
14474
+ };
14475
+ if (pointOverlapsRectangle(newMouseBite, radius2, boardRect)) {
14476
+ overlapsBoard = true;
14477
+ break;
14478
+ }
14479
+ }
14480
+ if (overlapsBoard) continue;
14481
+ mouseBites.push(newMouseBite);
14482
+ }
14483
+ }
14484
+ return mouseBites;
14485
+ }
14486
+ function generatePanelTabsAndMouseBites(boards) {
14487
+ const allTabCutouts = [];
14488
+ const allMouseBites = [];
14489
+ for (let boardIndex = 0; boardIndex < boards.length; boardIndex++) {
14490
+ const board = boards[boardIndex];
14491
+ const otherBoards = boards.filter((_, i) => i !== boardIndex);
14492
+ for (const edge of ["top", "bottom", "left", "right"]) {
14493
+ const edgeTabs = generateTabsForEdge(
14494
+ board,
14495
+ edge,
14496
+ allTabCutouts,
14497
+ otherBoards
14498
+ );
14499
+ allTabCutouts.push(...edgeTabs);
14500
+ const edgeMouseBites = generateMouseBitesForEdge(
14501
+ board,
14502
+ edge,
14503
+ edgeTabs,
14504
+ allTabCutouts,
14505
+ otherBoards,
14506
+ allMouseBites
14507
+ );
14508
+ allMouseBites.push(...edgeMouseBites);
14509
+ }
14510
+ }
14511
+ const tabCutouts = allTabCutouts.map((tab, index) => ({
14512
+ type: "pcb_cutout",
14513
+ pcb_cutout_id: `panel_tab_${index}`,
14514
+ shape: "rect",
14515
+ center: tab.center,
14516
+ width: tab.width,
14517
+ height: tab.height,
14518
+ corner_radius: 0.25
14519
+ }));
14520
+ const mouseBiteHoles = allMouseBites.map((bite, index) => ({
14521
+ type: "pcb_hole",
14522
+ pcb_hole_id: `panel_mouse_bite_${index}`,
14523
+ hole_shape: "circle",
14524
+ hole_diameter: TAB_CONFIG.MOUSE_BITE_DIAMETER,
14525
+ x: bite.x,
14526
+ y: bite.y
14527
+ }));
14528
+ return {
14529
+ tabCutouts,
14530
+ mouseBiteHoles
14531
+ };
14532
+ }
14533
+
14534
+ // lib/components/normal-components/Panel.ts
14301
14535
  var Panel = class extends Group6 {
14302
14536
  pcb_panel_id = null;
14537
+ _tabsAndMouseBitesGenerated = false;
14303
14538
  get config() {
14304
14539
  return {
14305
14540
  componentName: "Panel",
@@ -14318,6 +14553,99 @@ var Panel = class extends Group6 {
14318
14553
  }
14319
14554
  super.add(component);
14320
14555
  }
14556
+ doInitialPcbComponentAnchorAlignment() {
14557
+ if (this.root?.pcbDisabled) return;
14558
+ super.doInitialPcbComponentAnchorAlignment();
14559
+ const { db } = this.root;
14560
+ const childBoardInstances = this.children.filter(
14561
+ (c) => c instanceof Board
14562
+ );
14563
+ const hasAnyPositionedBoards = childBoardInstances.some(
14564
+ (b) => b.props.pcbX !== void 0 || b.props.pcbY !== void 0
14565
+ );
14566
+ const unpositionedBoards = childBoardInstances.filter(
14567
+ (b) => b.props.pcbX === void 0 && b.props.pcbY === void 0
14568
+ );
14569
+ if (unpositionedBoards.length > 0 && !hasAnyPositionedBoards) {
14570
+ const gridCols = Math.ceil(Math.sqrt(unpositionedBoards.length));
14571
+ const gridRows = Math.ceil(unpositionedBoards.length / gridCols);
14572
+ const colWidths = Array(gridCols).fill(0);
14573
+ const rowHeights = Array(gridRows).fill(0);
14574
+ unpositionedBoards.forEach((board, i) => {
14575
+ const col = i % gridCols;
14576
+ const row = Math.floor(i / gridCols);
14577
+ const pcbBoard = db.pcb_board.get(board.pcb_board_id);
14578
+ if (!pcbBoard || pcbBoard.width === void 0 || pcbBoard.height === void 0)
14579
+ return;
14580
+ colWidths[col] = Math.max(colWidths[col], pcbBoard.width);
14581
+ rowHeights[row] = Math.max(rowHeights[row], pcbBoard.height);
14582
+ });
14583
+ const totalGridWidth = colWidths.reduce((a, b) => a + b, 0) + (gridCols > 1 ? (gridCols - 1) * TAB_CONFIG.TAB_DEPTH : 0);
14584
+ const totalGridHeight = rowHeights.reduce((a, b) => a + b, 0) + (gridRows > 1 ? (gridRows - 1) * TAB_CONFIG.TAB_DEPTH : 0);
14585
+ const startX = -totalGridWidth / 2;
14586
+ const startY = -totalGridHeight / 2;
14587
+ const rowYOffsets = [startY];
14588
+ for (let i = 0; i < gridRows - 1; i++) {
14589
+ rowYOffsets.push(rowYOffsets[i] + rowHeights[i] + TAB_CONFIG.TAB_DEPTH);
14590
+ }
14591
+ const colXOffsets = [startX];
14592
+ for (let i = 0; i < gridCols - 1; i++) {
14593
+ colXOffsets.push(colXOffsets[i] + colWidths[i] + TAB_CONFIG.TAB_DEPTH);
14594
+ }
14595
+ unpositionedBoards.forEach((board, i) => {
14596
+ const col = i % gridCols;
14597
+ const row = Math.floor(i / gridCols);
14598
+ const pcbBoard = db.pcb_board.get(board.pcb_board_id);
14599
+ if (!pcbBoard || !pcbBoard.width || !pcbBoard.height) return;
14600
+ const xPos = colXOffsets[col] + colWidths[col] / 2;
14601
+ const yPos = rowYOffsets[row] + rowHeights[row] / 2;
14602
+ db.pcb_board.update(board.pcb_board_id, {
14603
+ center: { x: xPos, y: yPos }
14604
+ });
14605
+ });
14606
+ const allBoardPcbIds = childBoardInstances.map((b) => b.pcb_board_id).filter((id) => !!id);
14607
+ const allBoardsInPanel = db.pcb_board.list().filter((b) => allBoardPcbIds.includes(b.pcb_board_id));
14608
+ let minX = Infinity;
14609
+ let minY = Infinity;
14610
+ let maxX = -Infinity;
14611
+ let maxY = -Infinity;
14612
+ for (const board of allBoardsInPanel) {
14613
+ if (board.width === void 0 || board.height === void 0 || !isFinite(board.width) || !isFinite(board.height))
14614
+ continue;
14615
+ const left = board.center.x - board.width / 2;
14616
+ const right = board.center.x + board.width / 2;
14617
+ const bottom = board.center.y - board.height / 2;
14618
+ const top = board.center.y + board.height / 2;
14619
+ minX = Math.min(minX, left);
14620
+ maxX = Math.max(maxX, right);
14621
+ minY = Math.min(minY, bottom);
14622
+ maxY = Math.max(maxY, top);
14623
+ }
14624
+ if (isFinite(minX)) {
14625
+ const boundsWidth = maxX - minX;
14626
+ const boundsHeight = maxY - minY;
14627
+ const margin = TAB_CONFIG.TAB_DEPTH * 3;
14628
+ const newPanelWidth = boundsWidth + 2 * margin;
14629
+ const newPanelHeight = boundsHeight + 2 * margin;
14630
+ db.pcb_panel.update(this.pcb_panel_id, {
14631
+ width: newPanelWidth,
14632
+ height: newPanelHeight
14633
+ });
14634
+ }
14635
+ }
14636
+ if (this._tabsAndMouseBitesGenerated) return;
14637
+ const childBoardIds = childBoardInstances.map((c) => c.pcb_board_id).filter((id) => !!id);
14638
+ const boardsInPanel = db.pcb_board.list().filter((b) => childBoardIds.includes(b.pcb_board_id));
14639
+ if (boardsInPanel.length === 0) return;
14640
+ const { tabCutouts, mouseBiteHoles } = generatePanelTabsAndMouseBites(boardsInPanel);
14641
+ for (const tabCutout of tabCutouts) {
14642
+ db.pcb_cutout.insert(tabCutout);
14643
+ }
14644
+ for (const mouseBiteHole of mouseBiteHoles) {
14645
+ db.pcb_hole.insert(mouseBiteHole);
14646
+ }
14647
+ this._tabsAndMouseBitesGenerated = true;
14648
+ }
14321
14649
  runRenderCycle() {
14322
14650
  if (!this.children.some((child) => child.componentName === "Board")) {
14323
14651
  throw new Error("<panel> must contain at least one <board>");
@@ -18132,7 +18460,7 @@ import { identity as identity6 } from "transformation-matrix";
18132
18460
  var package_default = {
18133
18461
  name: "@tscircuit/core",
18134
18462
  type: "module",
18135
- version: "0.0.868",
18463
+ version: "0.0.870",
18136
18464
  types: "dist/index.d.ts",
18137
18465
  main: "dist/index.js",
18138
18466
  module: "dist/index.js",
@@ -18190,13 +18518,13 @@ var package_default = {
18190
18518
  "bun-match-svg": "0.0.12",
18191
18519
  "calculate-elbow": "^0.0.12",
18192
18520
  "chokidar-cli": "^3.0.0",
18193
- "circuit-json": "^0.0.316",
18521
+ "circuit-json": "^0.0.317",
18194
18522
  "circuit-json-to-bpc": "^0.0.13",
18195
18523
  "circuit-json-to-connectivity-map": "^0.0.22",
18196
18524
  "circuit-json-to-gltf": "^0.0.31",
18197
18525
  "circuit-json-to-simple-3d": "^0.0.9",
18198
18526
  "circuit-json-to-spice": "^0.0.24",
18199
- "circuit-to-svg": "^0.0.271",
18527
+ "circuit-to-svg": "^0.0.274",
18200
18528
  concurrently: "^9.1.2",
18201
18529
  "connectivity-map": "^1.0.0",
18202
18530
  debug: "^4.3.6",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.869",
4
+ "version": "0.0.871",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -59,13 +59,13 @@
59
59
  "bun-match-svg": "0.0.12",
60
60
  "calculate-elbow": "^0.0.12",
61
61
  "chokidar-cli": "^3.0.0",
62
- "circuit-json": "^0.0.316",
62
+ "circuit-json": "^0.0.317",
63
63
  "circuit-json-to-bpc": "^0.0.13",
64
64
  "circuit-json-to-connectivity-map": "^0.0.22",
65
65
  "circuit-json-to-gltf": "^0.0.31",
66
66
  "circuit-json-to-simple-3d": "^0.0.9",
67
67
  "circuit-json-to-spice": "^0.0.24",
68
- "circuit-to-svg": "^0.0.271",
68
+ "circuit-to-svg": "^0.0.274",
69
69
  "concurrently": "^9.1.2",
70
70
  "connectivity-map": "^1.0.0",
71
71
  "debug": "^4.3.6",