@zag-js/splitter
Version:
Core logic for the splitter widget implemented as a state machine
29 lines (27 loc) • 818 B
JavaScript
import "../chunk-QZ7TP4HQ.mjs";
// src/utils/resize-panel.ts
import { ensure } from "@zag-js/utils";
import { fuzzyCompareNumbers, PRECISION } from "./fuzzy.mjs";
function resizePanel({ panels, index, size }) {
const panel = panels[index];
ensure(panel, () => `Panel data not found for index ${index}`);
let { collapsedSize = 0, collapsible, maxSize = 100, minSize = 0 } = panel;
if (fuzzyCompareNumbers(size, minSize) < 0) {
if (collapsible) {
const halfwayPoint = (collapsedSize + minSize) / 2;
if (fuzzyCompareNumbers(size, halfwayPoint) < 0) {
size = collapsedSize;
} else {
size = minSize;
}
} else {
size = minSize;
}
}
size = Math.min(maxSize, size);
size = parseFloat(size.toFixed(PRECISION));
return size;
}
export {
resizePanel
};