@kud/ink-ui 0.20.1 → 0.21.0

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 +23 -12
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -660,22 +660,26 @@ 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
+ };
666
667
  };
667
668
  var useSlide = (rules, active) => {
668
669
  const target = rules[active] ?? null;
669
670
  const [step, setStep] = useState(SLIDE_STEPS);
670
671
  const from = useRef(target);
671
672
  const last = useRef(active);
673
+ const litIndex = useRef(active);
672
674
  useEffect(() => {
673
675
  if (last.current === active) return;
674
- from.current = step >= SLIDE_STEPS ? rules[last.current] ?? target : between(
676
+ const settled = step >= SLIDE_STEPS;
677
+ from.current = settled ? rules[last.current] ?? target : between(
675
678
  from.current ?? target,
676
679
  rules[last.current] ?? target,
677
680
  step / SLIDE_STEPS
678
681
  );
682
+ if (settled) litIndex.current = last.current;
679
683
  last.current = active;
680
684
  setStep(0);
681
685
  }, [active]);
@@ -684,9 +688,14 @@ var useSlide = (rules, active) => {
684
688
  const id = setTimeout(() => setStep((s) => s + 1), SLIDE_MS);
685
689
  return () => clearTimeout(id);
686
690
  }, [step]);
687
- if (!target) return null;
688
- if (step >= SLIDE_STEPS || !from.current) return target;
689
- return between(from.current, target, step / SLIDE_STEPS);
691
+ const arrived = step >= SLIDE_STEPS;
692
+ if (arrived) litIndex.current = active;
693
+ if (!target) return { rule: null, lit: litIndex.current };
694
+ if (arrived || !from.current) return { rule: target, lit: active };
695
+ return {
696
+ rule: between(from.current, target, step / SLIDE_STEPS),
697
+ lit: litIndex.current
698
+ };
690
699
  };
691
700
  var Tabs = ({ active, items }) => {
692
701
  const cells = items.map((item) => ({
@@ -705,16 +714,18 @@ var Tabs = ({ active, items }) => {
705
714
  x += gutterOf(cell) + labelOf(cell) + GAP;
706
715
  }
707
716
  const activeIndex = cells.findIndex((c) => c.isActive);
708
- const rule = useSlide(rules, activeIndex) ?? { start: 0, width: 0 };
717
+ const slide = useSlide(rules, activeIndex);
718
+ const rule = slide.rule ?? { start: 0, width: 0 };
719
+ const litIndex = slide.lit;
709
720
  return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
710
- /* @__PURE__ */ jsx(Box, { gap: GAP, children: cells.map((cell) => /* @__PURE__ */ jsxs(Box, { children: [
721
+ /* @__PURE__ */ jsx(Box, { gap: GAP, children: cells.map((cell, i) => /* @__PURE__ */ jsxs(Box, { children: [
711
722
  cell.marker ? /* @__PURE__ */ jsx(Text, { color: cell.markerColor, children: cell.marker }) : null,
712
723
  /* @__PURE__ */ jsx(
713
724
  Text,
714
725
  {
715
- bold: cell.isActive,
716
- color: cell.isActive ? colors.accent : void 0,
717
- dimColor: !cell.isActive,
726
+ bold: i === litIndex,
727
+ color: i === litIndex ? colors.accent : void 0,
728
+ dimColor: i !== litIndex,
718
729
  children: cell.text
719
730
  }
720
731
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kud/ink-ui",
3
- "version": "0.20.1",
3
+ "version": "0.21.0",
4
4
  "description": "React component library for Ink CLIs",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",