UNPKG

@zag-js/splitter

Version:

Core logic for the splitter widget implemented as a state machine

89 lines (87 loc) 2.73 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/utils/aria.ts var aria_exports = {}; __export(aria_exports, { calculateAriaValues: () => calculateAriaValues, getAriaValue: () => getAriaValue }); module.exports = __toCommonJS(aria_exports); var import_utils = require("@zag-js/utils"); function calculateAriaValues({ size, panels, pivotIndices }) { let currentMinSize = 0; let currentMaxSize = 100; let totalMinSize = 0; let totalMaxSize = 0; const firstIndex = pivotIndices[0]; (0, import_utils.ensure)(firstIndex, () => "No pivot index found"); panels.forEach((panel, index) => { const { maxSize = 100, minSize = 0 } = panel; if (index === firstIndex) { currentMinSize = minSize; currentMaxSize = maxSize; } else { totalMinSize += minSize; totalMaxSize += maxSize; } }); const valueMax = Math.min(currentMaxSize, 100 - totalMinSize); const valueMin = Math.max(currentMinSize, 100 - totalMaxSize); const valueNow = size[firstIndex]; return { valueMax, valueMin, valueNow }; } function getAriaValue(size, panels, handleId) { const [beforeId, afterId] = handleId.split(":"); const beforeIndex = panels.findIndex((panel) => panel.id === beforeId); const afterIndex = panels.findIndex((panel) => panel.id === afterId); if (beforeIndex === -1 || afterIndex === -1) { return { beforeId: beforeId || void 0, afterId: afterId || void 0, valueMax: void 0, valueMin: void 0, valueNow: void 0 }; } const { valueMax, valueMin, valueNow } = calculateAriaValues({ size, panels, pivotIndices: [beforeIndex, afterIndex] }); return { beforeId, afterId, valueMax: Math.round(valueMax), valueMin: Math.round(valueMin), valueNow: valueNow != null ? Math.round(valueNow) : void 0 }; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { calculateAriaValues, getAriaValue });