{"version":3,"names":["getRelativeElementIndex","parent","element","currentElement","parentElement","elementIndex","Array","prototype","indexOf","call","children","toString","padStart","hasContentBefore","precedingElement","previousSibling","nodeType","Node","ELEMENT_NODE","TEXT_NODE","textContent","trim","hasContentAfter","succeedingElement","nextSibling"],"sources":["../src/utils/dom.ts"],"sourcesContent":["/**\n * Returns the index of the given element compared to its parent\n * @param {Element} element element to get index for\n * @returns {number} index of the element compared to its parent\n */\nexport function getElementIndex(element: Element): number {\n\tconst parent = element.parentNode;\n\n\tif (parent) {\n\t\tconst children = Array.from(parent.children);\n\n\t\treturn children.indexOf(element);\n\t} else {\n\t\tthrow new Error('Element has no parent');\n\t}\n}\n\n/**\n * Returns the index of the given element compared to the given parent by recursively checking each and every\n * index from the element towards the parent. Each iteration retrieves the index for the 'current' level element,\n * normalizing the index by padding it with 0's, so it can be sorted properly.\n *\n * @param {Element} parent - element index should be relative to\n * @param {Element} element - element to get index for\n *\n * @returns {string} - element's index relative to parent\n */\nexport function getRelativeElementIndex(parent: Element, element: Element): string {\n\tlet currentElement: Element = element;\n\n\tlet parentElement: Element | null = currentElement.parentElement;\n\n\tlet elementIndex: string = '';\n\n\twhile (parentElement !== parent && parentElement !== null) {\n\t\t// Retrieve the index of the current element relative to its parent, convert it to string,\n\t\t// and pad the string with '0's until it has 3 digits\n\t\telementIndex = `${Array.prototype.indexOf\n\t\t\t.call(parentElement.children, currentElement)\n\t\t\t.toString()\n\t\t\t.padStart(3, '0')}${elementIndex}`;\n\n\t\tcurrentElement = parentElement;\n\n\t\tparentElement = parentElement.parentElement;\n\t}\n\n\treturn elementIndex;\n}\n\n/**\n * Returns whether the given element is preceded by text or element.\n *\n * This function checks whether the given element has a preceding element of nodeType Node.TEXT_NODE (3) that\n * does not only contain whitespace characters (spaces, tabs, newlines) or Node.ELEMENT_NODE (1). If such a preceding element\n * exists, the function returns true, otherwise it recursively checks the preceding sibling of the preceding element until\n * it finds a match or reaches the beginning of the tree.\n *\n * @param {Element} element - The element to check for preceding content.\n * @returns {boolean} - Whether the given element is preceded by text or element.\n */\nexport function hasContentBefore(element: Element): boolean {\n\t// Get the previous sibling of the given element\n\tconst precedingElement: Element | null = element.previousSibling as Element | null;\n\n\t// If there is no previous sibling, return false\n\tif (precedingElement === null) {\n\t\treturn false;\n\t}\n\n\t// If the previous sibling is an element node, return true\n\tif (precedingElement.nodeType === Node.ELEMENT_NODE) {\n\t\treturn true;\n\t}\n\n\t// If the previous sibling is a text node with non-whitespace content, return true\n\tif (precedingElement.nodeType === Node.TEXT_NODE && precedingElement.textContent.trim() !== '') {\n\t\treturn true;\n\t}\n\n\t// Recursively check the preceding sibling of the preceding element\n\treturn hasContentBefore(precedingElement);\n}\n\n/**\n * Returns whether the given element is succeeded by text or element.\n *\n * This function does a superficial check whether the given element has a succeeding element of nodeType\n * Node.TEXT_NODE (3) that does not only contain whitespace characters (spaces, tabs, newlines) or\n * Node.ELEMENT_NODE (1).\n *\n * @param {Element} element - the element to check for succeeding content\n * @returns {boolean} - whether the given element is succeeded by text or element\n */\nexport function hasContentAfter(element: Element): boolean {\n\t// Get the next sibling element of the given element\n\tconst succeedingElement: Element | null = element.nextSibling as Element | null;\n\n\t// If there is no next sibling element, then the given element does not have succeeding content\n\tif (succeedingElement === null) {\n\t\treturn false;\n\t}\n\n\t// If the next sibling element is an ELEMENT_NODE, then the given element is succeeded by an element\n\tif (succeedingElement.nodeType === Node.ELEMENT_NODE) {\n\t\treturn true;\n\t}\n\n\t// If the next sibling element is a TEXT_NODE that does not only contain whitespace characters,\n\t// then the given element is succeeded by text\n\tif (succeedingElement.nodeType === Node.TEXT_NODE && succeedingElement.textContent?.trim() !== '') {\n\t\treturn true;\n\t}\n\n\treturn hasContentAfter(succeedingElement);\n}\n"],"mappings":"SA2BgBA,EAAwBC,EAAiBC,GACxD,IAAIC,EAA0BD,EAE9B,IAAIE,EAAgCD,EAAeC,cAEnD,IAAIC,EAAuB,GAE3B,MAAOD,IAAkBH,GAAUG,IAAkB,KAAM,CAG1DC,EAAe,GAAGC,MAAMC,UAAUC,QAChCC,KAAKL,EAAcM,SAAUP,GAC7BQ,WACAC,SAAS,EAAG,OAAOP,IAErBF,EAAiBC,EAEjBA,EAAgBA,EAAcA,a,CAG/B,OAAOC,CACR,C,SAagBQ,EAAiBX,GAEhC,MAAMY,EAAmCZ,EAAQa,gBAGjD,GAAID,IAAqB,KAAM,CAC9B,OAAO,K,CAIR,GAAIA,EAAiBE,WAAaC,KAAKC,aAAc,CACpD,OAAO,I,CAIR,GAAIJ,EAAiBE,WAAaC,KAAKE,WAAaL,EAAiBM,YAAYC,SAAW,GAAI,CAC/F,OAAO,I,CAIR,OAAOR,EAAiBC,EACzB,C,SAYgBQ,EAAgBpB,GAE/B,MAAMqB,EAAoCrB,EAAQsB,YAGlD,GAAID,IAAsB,KAAM,CAC/B,OAAO,K,CAIR,GAAIA,EAAkBP,WAAaC,KAAKC,aAAc,CACrD,OAAO,I,CAKR,GAAIK,EAAkBP,WAAaC,KAAKE,WAAaI,EAAkBH,aAAaC,SAAW,GAAI,CAClG,OAAO,I,CAGR,OAAOC,EAAgBC,EACxB,Q","ignoreList":[]}