ink-hud 0.1.0 → 0.1.1

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.cts CHANGED
@@ -1155,6 +1155,8 @@ interface GridItemProps {
1155
1155
  /** Overflow behavior */
1156
1156
  overflow?: 'visible' | 'hidden';
1157
1157
  children: React.ReactNode;
1158
+ /** Internal: index assigned by Grid parent */
1159
+ _gridIndex?: number;
1158
1160
  }
1159
1161
  /**
1160
1162
  * Grid Item
package/dist/index.d.ts CHANGED
@@ -1155,6 +1155,8 @@ interface GridItemProps {
1155
1155
  /** Overflow behavior */
1156
1156
  overflow?: 'visible' | 'hidden';
1157
1157
  children: React.ReactNode;
1158
+ /** Internal: index assigned by Grid parent */
1159
+ _gridIndex?: number;
1158
1160
  }
1159
1161
  /**
1160
1162
  * Grid Item
package/dist/index.js CHANGED
@@ -1363,6 +1363,43 @@ var GridContext = createContext({
1363
1363
  // Fallback
1364
1364
  });
1365
1365
  var GridItemContext = createContext(null);
1366
+ function calculateItemWidths(children, totalWidth, columns, gap) {
1367
+ const childArray = React6.Children.toArray(children);
1368
+ const itemWidths = [];
1369
+ const totalGapWidth = Math.max(0, (columns - 1) * gap);
1370
+ const availableWidth = Math.max(0, totalWidth - totalGapWidth);
1371
+ const baseColWidth = Math.floor(availableWidth / columns);
1372
+ const remainder = availableWidth % columns;
1373
+ let currentCol = 0;
1374
+ let remainingExtra = remainder;
1375
+ for (const child of childArray) {
1376
+ const span = React6.isValidElement(child) && typeof child.props.span === "number" ? Math.min(Math.max(1, child.props.span), columns) : 1;
1377
+ let itemExtra = 0;
1378
+ const startCol = currentCol;
1379
+ const endCol = Math.min(currentCol + span, columns);
1380
+ for (let col = startCol; col < endCol && remainingExtra > 0; col++) {
1381
+ if (col < remainder) {
1382
+ itemExtra++;
1383
+ remainingExtra--;
1384
+ }
1385
+ }
1386
+ itemExtra = 0;
1387
+ for (let col = currentCol; col < currentCol + span && col < columns; col++) {
1388
+ if (col < remainder) {
1389
+ itemExtra++;
1390
+ }
1391
+ }
1392
+ const itemGapWidth = Math.max(0, (span - 1) * gap);
1393
+ const itemWidth = baseColWidth * span + itemExtra + itemGapWidth;
1394
+ itemWidths.push(itemWidth);
1395
+ currentCol += span;
1396
+ if (currentCol >= columns) {
1397
+ currentCol = 0;
1398
+ remainingExtra = remainder;
1399
+ }
1400
+ }
1401
+ return itemWidths;
1402
+ }
1366
1403
  var Grid = ({
1367
1404
  columns = 12,
1368
1405
  gap = 0,
@@ -1381,9 +1418,19 @@ var Grid = ({
1381
1418
  stdout.off("resize", onResize);
1382
1419
  };
1383
1420
  }, [stdout]);
1384
- const defaultWidth = terminalWidth > 2 ? terminalWidth - 2 : terminalWidth;
1421
+ const safetyMargin = widthOffset > 0 ? 0 : 2;
1422
+ const defaultWidth = terminalWidth > safetyMargin ? terminalWidth - safetyMargin : terminalWidth;
1385
1423
  const totalWidth = propsWidth ?? Math.max(0, defaultWidth - widthOffset);
1386
- return /* @__PURE__ */ React6.createElement(GridContext.Provider, { value: { columns, gap, totalWidth, rowHeight } }, /* @__PURE__ */ React6.createElement(
1424
+ const itemWidths = calculateItemWidths(children, totalWidth, columns, gap);
1425
+ const childrenWithIndex = React6.Children.map(children, (child, index) => {
1426
+ if (React6.isValidElement(child)) {
1427
+ return React6.cloneElement(child, {
1428
+ _gridIndex: index
1429
+ });
1430
+ }
1431
+ return child;
1432
+ });
1433
+ return /* @__PURE__ */ React6.createElement(GridContext.Provider, { value: { columns, gap, totalWidth, rowHeight, itemWidths } }, /* @__PURE__ */ React6.createElement(
1387
1434
  Box,
1388
1435
  {
1389
1436
  flexDirection: "row",
@@ -1392,7 +1439,7 @@ var Grid = ({
1392
1439
  rowGap: gap,
1393
1440
  width: totalWidth
1394
1441
  },
1395
- children
1442
+ childrenWithIndex
1396
1443
  ));
1397
1444
  };
1398
1445
  var GridItem = ({
@@ -1400,20 +1447,32 @@ var GridItem = ({
1400
1447
  height,
1401
1448
  minHeight,
1402
1449
  overflow,
1403
- children
1450
+ children,
1451
+ _gridIndex
1404
1452
  }) => {
1405
- const { columns, gap, totalWidth, rowHeight: contextRowHeight } = useContext(GridContext);
1406
- const totalGapWidth = Math.max(0, (columns - 1) * gap);
1407
- const availableWidth = Math.max(0, totalWidth - totalGapWidth);
1408
- const colWidth = availableWidth / columns;
1409
- const itemGapWidth = Math.max(0, (span - 1) * gap);
1410
- const basisWidth = Math.floor(colWidth * span + itemGapWidth);
1453
+ const {
1454
+ columns,
1455
+ gap,
1456
+ totalWidth,
1457
+ rowHeight: contextRowHeight,
1458
+ itemWidths
1459
+ } = useContext(GridContext);
1460
+ let basisWidth;
1461
+ if (itemWidths !== void 0 && _gridIndex !== void 0 && _gridIndex < itemWidths.length) {
1462
+ basisWidth = itemWidths[_gridIndex] ?? 0;
1463
+ } else {
1464
+ const totalGapWidth = Math.max(0, (columns - 1) * gap);
1465
+ const availableWidth = Math.max(0, totalWidth - totalGapWidth);
1466
+ const colWidth = availableWidth / columns;
1467
+ const itemGapWidth = Math.max(0, (span - 1) * gap);
1468
+ basisWidth = Math.floor(colWidth * span + itemGapWidth);
1469
+ }
1411
1470
  const effectiveHeight = height ?? contextRowHeight;
1412
1471
  return /* @__PURE__ */ React6.createElement(GridItemContext.Provider, { value: { width: basisWidth, height: effectiveHeight } }, /* @__PURE__ */ React6.createElement(
1413
1472
  Box,
1414
1473
  {
1415
- flexGrow: 1,
1416
- flexShrink: 1,
1474
+ flexGrow: 0,
1475
+ flexShrink: 0,
1417
1476
  flexBasis: basisWidth,
1418
1477
  flexDirection: "column",
1419
1478
  ...effectiveHeight !== void 0 && { height: effectiveHeight },
@@ -1450,11 +1509,12 @@ function useChartLayout(props, config) {
1450
1509
  yTickCount = 5,
1451
1510
  yTickFormat,
1452
1511
  defaultWidth = 60,
1512
+ defaultHeight = 15,
1453
1513
  min,
1454
1514
  max
1455
1515
  } = config;
1456
1516
  const gridContext = useContext(GridItemContext);
1457
- const totalHeight = props.height ?? (typeof gridContext?.height === "number" ? gridContext.height : 15);
1517
+ const totalHeight = props.height ?? (typeof gridContext?.height === "number" ? gridContext.height : defaultHeight);
1458
1518
  let totalWidth = props.width;
1459
1519
  if (totalWidth === void 0) {
1460
1520
  if (gridContext?.width) {
@@ -1734,8 +1794,8 @@ var ChartContainer = ({
1734
1794
  legendItems = [],
1735
1795
  children
1736
1796
  }) => {
1737
- const { totalWidth, plotWidth, plotHeight, yAxisWidth } = layout;
1738
- return /* @__PURE__ */ React6.createElement(Box, { flexDirection: "column", width: totalWidth }, showLegend && legendPosition === "top" && /* @__PURE__ */ React6.createElement(Box, { marginBottom: 1, marginLeft: showYAxis ? yAxisWidth + 1 : 0 }, /* @__PURE__ */ React6.createElement(Legend, { items: legendItems, position: "horizontal" })), /* @__PURE__ */ React6.createElement(Box, { flexDirection: "row" }, showYAxis && yAxisConfig && /* @__PURE__ */ React6.createElement(Box, { marginRight: 1, width: yAxisWidth }, /* @__PURE__ */ React6.createElement(Axis, { type: "y", length: plotHeight, ...yAxisConfig })), /* @__PURE__ */ React6.createElement(Box, { flexDirection: "column" }, children), showLegend && legendPosition === "right" && /* @__PURE__ */ React6.createElement(Box, { marginLeft: 2 }, /* @__PURE__ */ React6.createElement(Legend, { items: legendItems, position: "vertical" }))), showXAxis && xAxisConfig && /* @__PURE__ */ React6.createElement(Box, { marginLeft: showYAxis ? yAxisWidth + 1 : 0 }, /* @__PURE__ */ React6.createElement(Axis, { type: "x", length: plotWidth, ...xAxisConfig })), showLegend && legendPosition === "bottom" && /* @__PURE__ */ React6.createElement(Box, { marginTop: 1, marginLeft: showYAxis ? yAxisWidth + 1 : 0 }, /* @__PURE__ */ React6.createElement(Legend, { items: legendItems, position: "horizontal" })));
1797
+ const { totalWidth, totalHeight, plotWidth, plotHeight, yAxisWidth } = layout;
1798
+ return /* @__PURE__ */ React6.createElement(Box, { flexDirection: "column", width: totalWidth, height: totalHeight }, showLegend && legendPosition === "top" && /* @__PURE__ */ React6.createElement(Box, { marginBottom: 1, marginLeft: showYAxis ? yAxisWidth + 1 : 0 }, /* @__PURE__ */ React6.createElement(Legend, { items: legendItems, position: "horizontal" })), /* @__PURE__ */ React6.createElement(Box, { flexDirection: "row" }, showYAxis && yAxisConfig && /* @__PURE__ */ React6.createElement(Box, { marginRight: 1, width: yAxisWidth }, /* @__PURE__ */ React6.createElement(Axis, { type: "y", length: plotHeight, ...yAxisConfig })), /* @__PURE__ */ React6.createElement(Box, { flexDirection: "column" }, children), showLegend && legendPosition === "right" && /* @__PURE__ */ React6.createElement(Box, { marginLeft: 2 }, /* @__PURE__ */ React6.createElement(Legend, { items: legendItems, position: "vertical" }))), showXAxis && xAxisConfig && /* @__PURE__ */ React6.createElement(Box, { marginLeft: showYAxis ? yAxisWidth + 1 : 0 }, /* @__PURE__ */ React6.createElement(Axis, { type: "x", length: plotWidth, ...xAxisConfig })), showLegend && legendPosition === "bottom" && /* @__PURE__ */ React6.createElement(Box, { marginTop: 1, marginLeft: showYAxis ? yAxisWidth + 1 : 0 }, /* @__PURE__ */ React6.createElement(Legend, { items: legendItems, position: "horizontal" })));
1739
1799
  };
1740
1800
  function useChartCore(props) {
1741
1801
  const { series: seriesProp, data, seriesName, colors: colorsProp, colorPalette } = props;
@@ -2433,7 +2493,7 @@ var PieChart = ({
2433
2493
  if (coloredLines.length === 0) {
2434
2494
  return null;
2435
2495
  }
2436
- return /* @__PURE__ */ React6.createElement(Box, { flexDirection: "column", width: totalWidth, alignItems: "center" }, /* @__PURE__ */ React6.createElement(Box, { flexDirection: "row" }, /* @__PURE__ */ React6.createElement(Box, { flexDirection: "column" }, coloredLines.map((segments, i) => /* @__PURE__ */ React6.createElement(Text, { key: `chart-line-${i}` }, segments.map((segment, j) => /* @__PURE__ */ React6.createElement(
2496
+ return /* @__PURE__ */ React6.createElement(Box, { flexDirection: "column", width: totalWidth, height: layout.totalHeight }, /* @__PURE__ */ React6.createElement(Box, { flexDirection: "row", justifyContent: "center" }, /* @__PURE__ */ React6.createElement(Box, { flexDirection: "column", width: canvasWidth }, coloredLines.map((segments, i) => /* @__PURE__ */ React6.createElement(Text, { key: `chart-line-${i}` }, segments.map((segment, j) => /* @__PURE__ */ React6.createElement(
2437
2497
  Text,
2438
2498
  {
2439
2499
  key: `seg-${i}-${j}`,
@@ -2505,9 +2565,11 @@ var Panel = ({
2505
2565
  const childContext = React6.useMemo(
2506
2566
  () => ({
2507
2567
  ...innerWidth !== void 0 ? { width: innerWidth } : {},
2508
- height: innerHeight
2568
+ // Pass innerHeight if calculated, or pass the raw effectiveHeight for reference
2569
+ // This allows children to know at least that a height constraint exists
2570
+ height: innerHeight ?? (typeof effectiveHeight === "string" ? effectiveHeight : void 0)
2509
2571
  }),
2510
- [innerWidth, innerHeight]
2572
+ [innerWidth, innerHeight, effectiveHeight]
2511
2573
  );
2512
2574
  return /* @__PURE__ */ React6.createElement(GridItemContext.Provider, { value: childContext }, /* @__PURE__ */ React6.createElement(Box, { ...boxProps }, title && /* @__PURE__ */ React6.createElement(
2513
2575
  Box,