@kud/ink-ui 0.21.0 → 0.22.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 +6 -52
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -655,48 +655,6 @@ var ScrollView = ({
|
|
|
655
655
|
] });
|
|
656
656
|
};
|
|
657
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
|
-
return {
|
|
664
|
-
start: lerp(from.start, to.start),
|
|
665
|
-
width: Math.max(1, lerp(from.width, to.width))
|
|
666
|
-
};
|
|
667
|
-
};
|
|
668
|
-
var useSlide = (rules, active) => {
|
|
669
|
-
const target = rules[active] ?? null;
|
|
670
|
-
const [step, setStep] = useState(SLIDE_STEPS);
|
|
671
|
-
const from = useRef(target);
|
|
672
|
-
const last = useRef(active);
|
|
673
|
-
const litIndex = useRef(active);
|
|
674
|
-
useEffect(() => {
|
|
675
|
-
if (last.current === active) return;
|
|
676
|
-
const settled = step >= SLIDE_STEPS;
|
|
677
|
-
from.current = settled ? rules[last.current] ?? target : between(
|
|
678
|
-
from.current ?? target,
|
|
679
|
-
rules[last.current] ?? target,
|
|
680
|
-
step / SLIDE_STEPS
|
|
681
|
-
);
|
|
682
|
-
if (settled) litIndex.current = last.current;
|
|
683
|
-
last.current = active;
|
|
684
|
-
setStep(0);
|
|
685
|
-
}, [active]);
|
|
686
|
-
useEffect(() => {
|
|
687
|
-
if (step >= SLIDE_STEPS) return;
|
|
688
|
-
const id = setTimeout(() => setStep((s) => s + 1), SLIDE_MS);
|
|
689
|
-
return () => clearTimeout(id);
|
|
690
|
-
}, [step]);
|
|
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
|
-
};
|
|
699
|
-
};
|
|
700
658
|
var Tabs = ({ active, items }) => {
|
|
701
659
|
const cells = items.map((item) => ({
|
|
702
660
|
key: item.value,
|
|
@@ -707,25 +665,21 @@ var Tabs = ({ active, items }) => {
|
|
|
707
665
|
}));
|
|
708
666
|
const gutterOf = (cell) => [...cell.marker].length;
|
|
709
667
|
const labelOf = (cell) => [...cell.text].length;
|
|
710
|
-
const rules = [];
|
|
711
668
|
let x = 0;
|
|
669
|
+
let rule = { start: 0, width: 0 };
|
|
712
670
|
for (const cell of cells) {
|
|
713
|
-
|
|
671
|
+
if (cell.isActive) rule = { start: x + gutterOf(cell), width: labelOf(cell) };
|
|
714
672
|
x += gutterOf(cell) + labelOf(cell) + GAP;
|
|
715
673
|
}
|
|
716
|
-
const activeIndex = cells.findIndex((c) => c.isActive);
|
|
717
|
-
const slide = useSlide(rules, activeIndex);
|
|
718
|
-
const rule = slide.rule ?? { start: 0, width: 0 };
|
|
719
|
-
const litIndex = slide.lit;
|
|
720
674
|
return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
|
|
721
|
-
/* @__PURE__ */ jsx(Box, { gap: GAP, children: cells.map((cell
|
|
675
|
+
/* @__PURE__ */ jsx(Box, { gap: GAP, children: cells.map((cell) => /* @__PURE__ */ jsxs(Box, { children: [
|
|
722
676
|
cell.marker ? /* @__PURE__ */ jsx(Text, { color: cell.markerColor, children: cell.marker }) : null,
|
|
723
677
|
/* @__PURE__ */ jsx(
|
|
724
678
|
Text,
|
|
725
679
|
{
|
|
726
|
-
bold:
|
|
727
|
-
color:
|
|
728
|
-
dimColor:
|
|
680
|
+
bold: cell.isActive,
|
|
681
|
+
color: cell.isActive ? colors.accent : void 0,
|
|
682
|
+
dimColor: !cell.isActive,
|
|
729
683
|
children: cell.text
|
|
730
684
|
}
|
|
731
685
|
)
|