@kud/ink-ui 0.19.1 → 0.20.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.
Files changed (2) hide show
  1. package/dist/index.js +44 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -654,6 +654,40 @@ var ScrollView = ({
654
654
  showIndicator && hasMore && /* @__PURE__ */ jsx(Text, { dimColor: true, children: ` ${clamped + 1}\u2013${clamped + visible.length} / ${lines.length}` + (atEnd ? " (end)" : " \u2193 j/space") })
655
655
  ] });
656
656
  };
657
+ var GAP = 2;
658
+ var SLIDE_STEPS = 12;
659
+ var SLIDE_MS = 28;
660
+ var between = (from, to, t) => {
661
+ const ease = t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
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) };
666
+ };
667
+ var useSlide = (rules, active) => {
668
+ const target = rules[active] ?? null;
669
+ const [step, setStep] = useState(SLIDE_STEPS);
670
+ const from = useRef(target);
671
+ const last = useRef(active);
672
+ useEffect(() => {
673
+ if (last.current === active) return;
674
+ from.current = step >= SLIDE_STEPS ? rules[last.current] ?? target : between(
675
+ from.current ?? target,
676
+ rules[last.current] ?? target,
677
+ step / SLIDE_STEPS
678
+ );
679
+ last.current = active;
680
+ setStep(0);
681
+ }, [active]);
682
+ useEffect(() => {
683
+ if (step >= SLIDE_STEPS) return;
684
+ const id = setTimeout(() => setStep((s) => s + 1), SLIDE_MS);
685
+ return () => clearTimeout(id);
686
+ }, [step]);
687
+ if (!target) return null;
688
+ if (step >= SLIDE_STEPS || !from.current) return target;
689
+ return between(from.current, target, step / SLIDE_STEPS);
690
+ };
657
691
  var Tabs = ({ active, items }) => {
658
692
  const cells = items.map((item) => ({
659
693
  key: item.value,
@@ -664,8 +698,16 @@ var Tabs = ({ active, items }) => {
664
698
  }));
665
699
  const gutterOf = (cell) => [...cell.marker].length;
666
700
  const labelOf = (cell) => [...cell.text].length;
701
+ const rules = [];
702
+ let x = 0;
703
+ for (const cell of cells) {
704
+ rules.push({ start: x + gutterOf(cell), width: labelOf(cell) });
705
+ x += gutterOf(cell) + labelOf(cell) + GAP;
706
+ }
707
+ const activeIndex = cells.findIndex((c) => c.isActive);
708
+ const rule = useSlide(rules, activeIndex) ?? { start: 0, width: 0 };
667
709
  return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
668
- /* @__PURE__ */ jsx(Box, { gap: 2, children: cells.map((cell) => /* @__PURE__ */ jsxs(Box, { children: [
710
+ /* @__PURE__ */ jsx(Box, { gap: GAP, children: cells.map((cell) => /* @__PURE__ */ jsxs(Box, { children: [
669
711
  cell.marker ? /* @__PURE__ */ jsx(Text, { color: cell.markerColor, children: cell.marker }) : null,
670
712
  /* @__PURE__ */ jsx(
671
713
  Text,
@@ -677,7 +719,7 @@ var Tabs = ({ active, items }) => {
677
719
  }
678
720
  )
679
721
  ] }, cell.key)) }),
680
- /* @__PURE__ */ jsx(Box, { gap: 2, children: cells.map((cell) => /* @__PURE__ */ jsx(Text, { color: colors.accent, children: " ".repeat(gutterOf(cell)) + (cell.isActive ? "\u2500" : " ").repeat(labelOf(cell)) }, cell.key)) })
722
+ /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, { color: colors.accent, children: " ".repeat(rule.start) + "\u2500".repeat(rule.width) }) })
681
723
  ] });
682
724
  };
683
725
  var useTabs = (items, { initial, isActive = true } = {}) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kud/ink-ui",
3
- "version": "0.19.1",
3
+ "version": "0.20.1",
4
4
  "description": "React component library for Ink CLIs",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",