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ivr using Rollup v2.79.2 and Terser v5.39.0.\n * Original file: /npm/textsplitter@9.6.0/dist/textsplitter.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/* eslint-disable @typescript-eslint/restrict-template-expressions */\n/* eslint-disable @typescript-eslint/prefer-optional-chain */\n/* eslint-disable @typescript-eslint/strict-boolean-expressions */\n/* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\nconst resetContainer = (container: HTMLElement): (() => void) => {\n  const oldHTML = container.innerHTML\n\n  const reset = (): void => {\n    (container.innerHTML) = oldHTML\n  }\n\n  return reset\n}\n\nexport function splitLetters (container: HTMLElement, opentag: string, closingtag: string): { container: HTMLElement, destroy: () => any } {\n  const destroy = resetContainer(container)\n  const htmlMatches = container.innerHTML.match(/<[^>]+>/g) || []\n  const textParts = container.innerHTML.split(/<[^>]+>/g)\n\n  container.innerHTML = textParts.map((string, index) =>\n    string.replace(/(&[a-zA-Z]+;)|(\\S)/g, opentag + '$&' + closingtag) + (htmlMatches[index] || '')\n  ).join('')\n\n  return { container, destroy }\n}\n\nfunction splitWordsHelper (container: HTMLElement, opentag: string, closingtag: string): { container: HTMLElement, destroy: () => any } {\n  const destroy = resetContainer(container)\n  const html: string[] = [...container.innerHTML.match(/<[^>]+>/g) || '', '']\n\n  container.innerHTML = container.innerHTML.split(/<[^>]+>/g).map((string, index) => {\n    return string.replace(/((&[a-zA-Z]+;)|(\\w+|-)|(\\S))/g, opentag + '$1' + closingtag) + html[index]\n  }).join('')\n\n  return { container, destroy }\n}\n\nexport function splitWords (container: HTMLElement, opentag: string, closingtag: string): ({ container: HTMLElement, destroy: () => any }) {\n  const destroy = resetContainer(container)\n\n  splitWordsHelper(container, '<n>', '</n>')\n\n  const allElements = container.querySelectorAll('n')\n\n  allElements.forEach((node, index) => {\n    if (node.innerHTML.length === 1 && !node.innerHTML.match(/\\w+|[.,?/#!$%^&*;:{}=\\-_`~()]/g)) {\n      const firstWord = allElements[(index || 1) - 1]\n      const secondWord = allElements[index + 1] ?? allElements[index]\n      const { y: firstY } = firstWord.getBoundingClientRect()\n      const { y: secondY } = secondWord.getBoundingClientRect()\n\n      if (firstY === secondY) {\n        if (!node.innerHTML.match(/[^\\w\\u00AD]/g)) {\n          allElements[index].innerHTML = `${firstWord.innerHTML}${node.innerHTML}${secondWord.innerHTML}`\n          firstWord.remove()\n          secondWord.remove()\n        }\n      } else if (!node.innerHTML.match(/[^\\w\\u00AD]/g)) {\n        allElements[index].innerHTML = '-'\n      }\n    }\n  })\n\n  // console.log(container.innerHTML)\n\n  container.innerHTML = container.innerHTML.replace(/<n>/g, opentag).replace(/<\\/n>/g, closingtag)\n\n  return ({ container, destroy })\n}\n\nexport function splitLines (container: HTMLElement, opentag: string, closingtag: string): ({ container: HTMLElement, destroy: () => any }) {\n  const destroy = resetContainer(container)\n\n  splitWords(container, '<n>', '</n>')\n\n  let lastY = -9999\n\n  container.querySelectorAll('n').forEach((node) => {\n    const { y } = node.getBoundingClientRect()\n\n    if (y > lastY) {\n      lastY = y\n      node.outerHTML = `<line>${node.innerHTML}</line>`\n\n      return\n    }\n\n    node.outerHTML = `${node.innerHTML}`\n  })\n\n  let output = ''\n  let index = 0\n\n  // Array for storing opening tags for the next line\n  const nextLineOpeningTags: any = []\n  const nextLineClosingTags: any = [];\n\n  // Loop through each line\n  // Because it is possible that the FIRST line tag is not at the beginning of the string it might not get the correct opening tags\n  // To solve this issue remove the first line tag and add it at the beginning of the string\n  (`<line>${container.innerHTML.trim().replace('<line>', '')}`).split('<line>').forEach((str) => {\n    if (!str) return\n\n    // Remove closing tag from the end of the line\n    const string = str.replace('</line>', '')\n\n    // Get opening tags from the current line\n    // ALSO SKIP ALL BR TAGS\n    const openingtags: string[] = string.match(/<(?!\\/)(?!br)[^>]+>/g)! ?? []\n\n    // Get closing tags from the current line\n    const closingtags: string[] = string.match(/<\\/[^>]+>/g)! ?? []\n\n    // Get opening tags from the previous line if not exist return an empty array\n    const openingTagsLastLine = nextLineOpeningTags[index - 1] ?? []\n\n    // Get opening tags from the previous line if not exist return an empty array\n    const closingTagsLastLine = nextLineClosingTags[index - 1] ?? []\n\n    openingtags.push(...openingTagsLastLine)\n    closingtags.push(...closingTagsLastLine)\n\n    // Filter opening tags that are not closed\n    const filteredOpeningTagsEndOfLine = openingtags.slice().splice(0, openingtags.length - closingtags.length)\n    nextLineOpeningTags.push(filteredOpeningTagsEndOfLine)\n\n    const refactoredLine = `${opentag}${openingTagsLastLine.join('')}${string}${filteredOpeningTagsEndOfLine.slice().reverse().map(tag => tag.replace('<', '</')).join('')}${closingtag}`\n\n    output += refactoredLine\n    index += 1\n  })\n\n  container.innerHTML = output\n\n  return ({ container, destroy })\n}\n"]}