// packages/block-library/src/table-of-contents/utils.ts
function linearToNestedHeadingList(headingList) {
  const nestedHeadingList = [];
  headingList.forEach((heading, key) => {
    if (heading.content === "") {
      return;
    }
    if (heading.level === headingList[0].level) {
      if (headingList[key + 1]?.level > heading.level) {
        let endOfSlice = headingList.length;
        for (let i = key + 1; i < headingList.length; i++) {
          if (headingList[i].level === heading.level) {
            endOfSlice = i;
            break;
          }
        }
        nestedHeadingList.push({
          heading,
          children: linearToNestedHeadingList(
            headingList.slice(key + 1, endOfSlice)
          )
        });
      } else {
        nestedHeadingList.push({
          heading,
          children: null
        });
      }
    }
  });
  return nestedHeadingList;
}
export {
  linearToNestedHeadingList
};
//# sourceMappingURL=utils.js.map
