@kud/ink-ui 0.19.0 → 0.20.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.
- package/dist/index.js +46 -3
- 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 = 6;
|
|
659
|
+
var SLIDE_MS = 25;
|
|
660
|
+
var between = (from, to, t) => {
|
|
661
|
+
const ease = 1 - Math.pow(1 - t, 3);
|
|
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,
|
|
@@ -662,9 +696,18 @@ var Tabs = ({ active, items }) => {
|
|
|
662
696
|
text: item.count !== void 0 ? `${item.label} (${item.count})` : item.label,
|
|
663
697
|
isActive: item.value === active
|
|
664
698
|
}));
|
|
665
|
-
const
|
|
699
|
+
const gutterOf = (cell) => [...cell.marker].length;
|
|
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 };
|
|
666
709
|
return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
|
|
667
|
-
/* @__PURE__ */ jsx(Box, { gap:
|
|
710
|
+
/* @__PURE__ */ jsx(Box, { gap: GAP, children: cells.map((cell) => /* @__PURE__ */ jsxs(Box, { children: [
|
|
668
711
|
cell.marker ? /* @__PURE__ */ jsx(Text, { color: cell.markerColor, children: cell.marker }) : null,
|
|
669
712
|
/* @__PURE__ */ jsx(
|
|
670
713
|
Text,
|
|
@@ -676,7 +719,7 @@ var Tabs = ({ active, items }) => {
|
|
|
676
719
|
}
|
|
677
720
|
)
|
|
678
721
|
] }, cell.key)) }),
|
|
679
|
-
/* @__PURE__ */ jsx(Box, {
|
|
722
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, { color: colors.accent, children: " ".repeat(rule.start) + "\u2500".repeat(rule.width) }) })
|
|
680
723
|
] });
|
|
681
724
|
};
|
|
682
725
|
var useTabs = (items, { initial, isActive = true } = {}) => {
|