@kud/ink-ui 0.20.1 → 0.20.2

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 +17 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -660,9 +660,18 @@ var SLIDE_MS = 28;
660
660
  var between = (from, to, t) => {
661
661
  const ease = t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
662
662
  const lerp = (a, b) => Math.round(a + (b - a) * ease);
663
- const left = lerp(from.start, to.start);
664
- const right = lerp(from.start + from.width, to.start + to.width);
665
- return { start: left, width: Math.max(1, right - left) };
663
+ return {
664
+ start: lerp(from.start, to.start),
665
+ width: Math.max(1, lerp(from.width, to.width))
666
+ };
667
+ };
668
+ var nearestTo = (rules, rule, fallback) => {
669
+ const centre = (r) => r.start + r.width / 2;
670
+ if (rules.length === 0) return fallback;
671
+ return rules.reduce(
672
+ (best, r, i) => Math.abs(centre(r) - centre(rule)) < Math.abs(centre(rules[best]) - centre(rule)) ? i : best,
673
+ Math.min(fallback, rules.length - 1)
674
+ );
666
675
  };
667
676
  var useSlide = (rules, active) => {
668
677
  const target = rules[active] ?? null;
@@ -706,15 +715,16 @@ var Tabs = ({ active, items }) => {
706
715
  }
707
716
  const activeIndex = cells.findIndex((c) => c.isActive);
708
717
  const rule = useSlide(rules, activeIndex) ?? { start: 0, width: 0 };
718
+ const litIndex = nearestTo(rules, rule, Math.max(0, activeIndex));
709
719
  return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
710
- /* @__PURE__ */ jsx(Box, { gap: GAP, children: cells.map((cell) => /* @__PURE__ */ jsxs(Box, { children: [
720
+ /* @__PURE__ */ jsx(Box, { gap: GAP, children: cells.map((cell, i) => /* @__PURE__ */ jsxs(Box, { children: [
711
721
  cell.marker ? /* @__PURE__ */ jsx(Text, { color: cell.markerColor, children: cell.marker }) : null,
712
722
  /* @__PURE__ */ jsx(
713
723
  Text,
714
724
  {
715
- bold: cell.isActive,
716
- color: cell.isActive ? colors.accent : void 0,
717
- dimColor: !cell.isActive,
725
+ bold: i === litIndex,
726
+ color: i === litIndex ? colors.accent : void 0,
727
+ dimColor: i !== litIndex,
718
728
  children: cell.text
719
729
  }
720
730
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kud/ink-ui",
3
- "version": "0.20.1",
3
+ "version": "0.20.2",
4
4
  "description": "React component library for Ink CLIs",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",