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.cjs +80 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +80 -18
- package/dist/index.js.map +1 -1
- package/package.json +84 -87
package/dist/index.cjs
CHANGED
|
@@ -1371,6 +1371,43 @@ var GridContext = React6.createContext({
|
|
|
1371
1371
|
// Fallback
|
|
1372
1372
|
});
|
|
1373
1373
|
var GridItemContext = React6.createContext(null);
|
|
1374
|
+
function calculateItemWidths(children, totalWidth, columns, gap) {
|
|
1375
|
+
const childArray = React6__default.default.Children.toArray(children);
|
|
1376
|
+
const itemWidths = [];
|
|
1377
|
+
const totalGapWidth = Math.max(0, (columns - 1) * gap);
|
|
1378
|
+
const availableWidth = Math.max(0, totalWidth - totalGapWidth);
|
|
1379
|
+
const baseColWidth = Math.floor(availableWidth / columns);
|
|
1380
|
+
const remainder = availableWidth % columns;
|
|
1381
|
+
let currentCol = 0;
|
|
1382
|
+
let remainingExtra = remainder;
|
|
1383
|
+
for (const child of childArray) {
|
|
1384
|
+
const span = React6__default.default.isValidElement(child) && typeof child.props.span === "number" ? Math.min(Math.max(1, child.props.span), columns) : 1;
|
|
1385
|
+
let itemExtra = 0;
|
|
1386
|
+
const startCol = currentCol;
|
|
1387
|
+
const endCol = Math.min(currentCol + span, columns);
|
|
1388
|
+
for (let col = startCol; col < endCol && remainingExtra > 0; col++) {
|
|
1389
|
+
if (col < remainder) {
|
|
1390
|
+
itemExtra++;
|
|
1391
|
+
remainingExtra--;
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
itemExtra = 0;
|
|
1395
|
+
for (let col = currentCol; col < currentCol + span && col < columns; col++) {
|
|
1396
|
+
if (col < remainder) {
|
|
1397
|
+
itemExtra++;
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
const itemGapWidth = Math.max(0, (span - 1) * gap);
|
|
1401
|
+
const itemWidth = baseColWidth * span + itemExtra + itemGapWidth;
|
|
1402
|
+
itemWidths.push(itemWidth);
|
|
1403
|
+
currentCol += span;
|
|
1404
|
+
if (currentCol >= columns) {
|
|
1405
|
+
currentCol = 0;
|
|
1406
|
+
remainingExtra = remainder;
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
return itemWidths;
|
|
1410
|
+
}
|
|
1374
1411
|
var Grid = ({
|
|
1375
1412
|
columns = 12,
|
|
1376
1413
|
gap = 0,
|
|
@@ -1389,9 +1426,19 @@ var Grid = ({
|
|
|
1389
1426
|
stdout.off("resize", onResize);
|
|
1390
1427
|
};
|
|
1391
1428
|
}, [stdout]);
|
|
1392
|
-
const
|
|
1429
|
+
const safetyMargin = widthOffset > 0 ? 0 : 2;
|
|
1430
|
+
const defaultWidth = terminalWidth > safetyMargin ? terminalWidth - safetyMargin : terminalWidth;
|
|
1393
1431
|
const totalWidth = propsWidth ?? Math.max(0, defaultWidth - widthOffset);
|
|
1394
|
-
|
|
1432
|
+
const itemWidths = calculateItemWidths(children, totalWidth, columns, gap);
|
|
1433
|
+
const childrenWithIndex = React6__default.default.Children.map(children, (child, index) => {
|
|
1434
|
+
if (React6__default.default.isValidElement(child)) {
|
|
1435
|
+
return React6__default.default.cloneElement(child, {
|
|
1436
|
+
_gridIndex: index
|
|
1437
|
+
});
|
|
1438
|
+
}
|
|
1439
|
+
return child;
|
|
1440
|
+
});
|
|
1441
|
+
return /* @__PURE__ */ React6__default.default.createElement(GridContext.Provider, { value: { columns, gap, totalWidth, rowHeight, itemWidths } }, /* @__PURE__ */ React6__default.default.createElement(
|
|
1395
1442
|
ink.Box,
|
|
1396
1443
|
{
|
|
1397
1444
|
flexDirection: "row",
|
|
@@ -1400,7 +1447,7 @@ var Grid = ({
|
|
|
1400
1447
|
rowGap: gap,
|
|
1401
1448
|
width: totalWidth
|
|
1402
1449
|
},
|
|
1403
|
-
|
|
1450
|
+
childrenWithIndex
|
|
1404
1451
|
));
|
|
1405
1452
|
};
|
|
1406
1453
|
var GridItem = ({
|
|
@@ -1408,20 +1455,32 @@ var GridItem = ({
|
|
|
1408
1455
|
height,
|
|
1409
1456
|
minHeight,
|
|
1410
1457
|
overflow,
|
|
1411
|
-
children
|
|
1458
|
+
children,
|
|
1459
|
+
_gridIndex
|
|
1412
1460
|
}) => {
|
|
1413
|
-
const {
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1461
|
+
const {
|
|
1462
|
+
columns,
|
|
1463
|
+
gap,
|
|
1464
|
+
totalWidth,
|
|
1465
|
+
rowHeight: contextRowHeight,
|
|
1466
|
+
itemWidths
|
|
1467
|
+
} = React6.useContext(GridContext);
|
|
1468
|
+
let basisWidth;
|
|
1469
|
+
if (itemWidths !== void 0 && _gridIndex !== void 0 && _gridIndex < itemWidths.length) {
|
|
1470
|
+
basisWidth = itemWidths[_gridIndex] ?? 0;
|
|
1471
|
+
} else {
|
|
1472
|
+
const totalGapWidth = Math.max(0, (columns - 1) * gap);
|
|
1473
|
+
const availableWidth = Math.max(0, totalWidth - totalGapWidth);
|
|
1474
|
+
const colWidth = availableWidth / columns;
|
|
1475
|
+
const itemGapWidth = Math.max(0, (span - 1) * gap);
|
|
1476
|
+
basisWidth = Math.floor(colWidth * span + itemGapWidth);
|
|
1477
|
+
}
|
|
1419
1478
|
const effectiveHeight = height ?? contextRowHeight;
|
|
1420
1479
|
return /* @__PURE__ */ React6__default.default.createElement(GridItemContext.Provider, { value: { width: basisWidth, height: effectiveHeight } }, /* @__PURE__ */ React6__default.default.createElement(
|
|
1421
1480
|
ink.Box,
|
|
1422
1481
|
{
|
|
1423
|
-
flexGrow:
|
|
1424
|
-
flexShrink:
|
|
1482
|
+
flexGrow: 0,
|
|
1483
|
+
flexShrink: 0,
|
|
1425
1484
|
flexBasis: basisWidth,
|
|
1426
1485
|
flexDirection: "column",
|
|
1427
1486
|
...effectiveHeight !== void 0 && { height: effectiveHeight },
|
|
@@ -1458,11 +1517,12 @@ function useChartLayout(props, config) {
|
|
|
1458
1517
|
yTickCount = 5,
|
|
1459
1518
|
yTickFormat,
|
|
1460
1519
|
defaultWidth = 60,
|
|
1520
|
+
defaultHeight = 15,
|
|
1461
1521
|
min,
|
|
1462
1522
|
max
|
|
1463
1523
|
} = config;
|
|
1464
1524
|
const gridContext = React6.useContext(GridItemContext);
|
|
1465
|
-
const totalHeight = props.height ?? (typeof gridContext?.height === "number" ? gridContext.height :
|
|
1525
|
+
const totalHeight = props.height ?? (typeof gridContext?.height === "number" ? gridContext.height : defaultHeight);
|
|
1466
1526
|
let totalWidth = props.width;
|
|
1467
1527
|
if (totalWidth === void 0) {
|
|
1468
1528
|
if (gridContext?.width) {
|
|
@@ -1742,8 +1802,8 @@ var ChartContainer = ({
|
|
|
1742
1802
|
legendItems = [],
|
|
1743
1803
|
children
|
|
1744
1804
|
}) => {
|
|
1745
|
-
const { totalWidth, plotWidth, plotHeight, yAxisWidth } = layout;
|
|
1746
|
-
return /* @__PURE__ */ React6__default.default.createElement(ink.Box, { flexDirection: "column", width: totalWidth }, showLegend && legendPosition === "top" && /* @__PURE__ */ React6__default.default.createElement(ink.Box, { marginBottom: 1, marginLeft: showYAxis ? yAxisWidth + 1 : 0 }, /* @__PURE__ */ React6__default.default.createElement(Legend, { items: legendItems, position: "horizontal" })), /* @__PURE__ */ React6__default.default.createElement(ink.Box, { flexDirection: "row" }, showYAxis && yAxisConfig && /* @__PURE__ */ React6__default.default.createElement(ink.Box, { marginRight: 1, width: yAxisWidth }, /* @__PURE__ */ React6__default.default.createElement(Axis, { type: "y", length: plotHeight, ...yAxisConfig })), /* @__PURE__ */ React6__default.default.createElement(ink.Box, { flexDirection: "column" }, children), showLegend && legendPosition === "right" && /* @__PURE__ */ React6__default.default.createElement(ink.Box, { marginLeft: 2 }, /* @__PURE__ */ React6__default.default.createElement(Legend, { items: legendItems, position: "vertical" }))), showXAxis && xAxisConfig && /* @__PURE__ */ React6__default.default.createElement(ink.Box, { marginLeft: showYAxis ? yAxisWidth + 1 : 0 }, /* @__PURE__ */ React6__default.default.createElement(Axis, { type: "x", length: plotWidth, ...xAxisConfig })), showLegend && legendPosition === "bottom" && /* @__PURE__ */ React6__default.default.createElement(ink.Box, { marginTop: 1, marginLeft: showYAxis ? yAxisWidth + 1 : 0 }, /* @__PURE__ */ React6__default.default.createElement(Legend, { items: legendItems, position: "horizontal" })));
|
|
1805
|
+
const { totalWidth, totalHeight, plotWidth, plotHeight, yAxisWidth } = layout;
|
|
1806
|
+
return /* @__PURE__ */ React6__default.default.createElement(ink.Box, { flexDirection: "column", width: totalWidth, height: totalHeight }, showLegend && legendPosition === "top" && /* @__PURE__ */ React6__default.default.createElement(ink.Box, { marginBottom: 1, marginLeft: showYAxis ? yAxisWidth + 1 : 0 }, /* @__PURE__ */ React6__default.default.createElement(Legend, { items: legendItems, position: "horizontal" })), /* @__PURE__ */ React6__default.default.createElement(ink.Box, { flexDirection: "row" }, showYAxis && yAxisConfig && /* @__PURE__ */ React6__default.default.createElement(ink.Box, { marginRight: 1, width: yAxisWidth }, /* @__PURE__ */ React6__default.default.createElement(Axis, { type: "y", length: plotHeight, ...yAxisConfig })), /* @__PURE__ */ React6__default.default.createElement(ink.Box, { flexDirection: "column" }, children), showLegend && legendPosition === "right" && /* @__PURE__ */ React6__default.default.createElement(ink.Box, { marginLeft: 2 }, /* @__PURE__ */ React6__default.default.createElement(Legend, { items: legendItems, position: "vertical" }))), showXAxis && xAxisConfig && /* @__PURE__ */ React6__default.default.createElement(ink.Box, { marginLeft: showYAxis ? yAxisWidth + 1 : 0 }, /* @__PURE__ */ React6__default.default.createElement(Axis, { type: "x", length: plotWidth, ...xAxisConfig })), showLegend && legendPosition === "bottom" && /* @__PURE__ */ React6__default.default.createElement(ink.Box, { marginTop: 1, marginLeft: showYAxis ? yAxisWidth + 1 : 0 }, /* @__PURE__ */ React6__default.default.createElement(Legend, { items: legendItems, position: "horizontal" })));
|
|
1747
1807
|
};
|
|
1748
1808
|
function useChartCore(props) {
|
|
1749
1809
|
const { series: seriesProp, data, seriesName, colors: colorsProp, colorPalette } = props;
|
|
@@ -2441,7 +2501,7 @@ var PieChart = ({
|
|
|
2441
2501
|
if (coloredLines.length === 0) {
|
|
2442
2502
|
return null;
|
|
2443
2503
|
}
|
|
2444
|
-
return /* @__PURE__ */ React6__default.default.createElement(ink.Box, { flexDirection: "column", width: totalWidth,
|
|
2504
|
+
return /* @__PURE__ */ React6__default.default.createElement(ink.Box, { flexDirection: "column", width: totalWidth, height: layout.totalHeight }, /* @__PURE__ */ React6__default.default.createElement(ink.Box, { flexDirection: "row", justifyContent: "center" }, /* @__PURE__ */ React6__default.default.createElement(ink.Box, { flexDirection: "column", width: canvasWidth }, coloredLines.map((segments, i) => /* @__PURE__ */ React6__default.default.createElement(ink.Text, { key: `chart-line-${i}` }, segments.map((segment, j) => /* @__PURE__ */ React6__default.default.createElement(
|
|
2445
2505
|
ink.Text,
|
|
2446
2506
|
{
|
|
2447
2507
|
key: `seg-${i}-${j}`,
|
|
@@ -2513,9 +2573,11 @@ var Panel = ({
|
|
|
2513
2573
|
const childContext = React6__default.default.useMemo(
|
|
2514
2574
|
() => ({
|
|
2515
2575
|
...innerWidth !== void 0 ? { width: innerWidth } : {},
|
|
2516
|
-
|
|
2576
|
+
// Pass innerHeight if calculated, or pass the raw effectiveHeight for reference
|
|
2577
|
+
// This allows children to know at least that a height constraint exists
|
|
2578
|
+
height: innerHeight ?? (typeof effectiveHeight === "string" ? effectiveHeight : void 0)
|
|
2517
2579
|
}),
|
|
2518
|
-
[innerWidth, innerHeight]
|
|
2580
|
+
[innerWidth, innerHeight, effectiveHeight]
|
|
2519
2581
|
);
|
|
2520
2582
|
return /* @__PURE__ */ React6__default.default.createElement(GridItemContext.Provider, { value: childContext }, /* @__PURE__ */ React6__default.default.createElement(ink.Box, { ...boxProps }, title && /* @__PURE__ */ React6__default.default.createElement(
|
|
2521
2583
|
ink.Box,
|