UNPKG

@redocly/theme

Version:

Shared UI components lib

40 lines 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDisplayedHeadings = getDisplayedHeadings; exports.getDisplayedHeadingsIds = getDisplayedHeadingsIds; exports.getLeastDepth = getLeastDepth; function getDisplayedHeadings(headings, tocDepth) { if (!headings) { return []; } return headings.filter((heading, idx) => { if (!heading) { return false; } if (idx === 0 && heading.depth === 1) { return false; } return !(heading.depth && heading.depth > tocDepth); }); } function getDisplayedHeadingsIds(headings) { if (!headings) { return []; } return headings.map((header) => header === null || header === void 0 ? void 0 : header.id); } function getLeastDepth(headings) { if (!headings || headings.length === 0) { return 1; } let depth = null; for (const heading of headings) { if (!heading) continue; if (depth === null || depth > heading.depth) { depth = heading.depth; } } return depth !== null && depth !== void 0 ? depth : 1; } //# sourceMappingURL=toc.js.map