nodes, * and this function provides an array of the strings contains in an element. * * @param {object} element * A DOM element to be extracted. * @returns {Array} * All strings in an element. */ extractLabelStrings(element) { if (this._labelStrings.has(element)) { return this._labelStrings.get(element); } let strings = []; let _extractLabelStrings = el => { if (this.EXCLUDED_TAGS.includes(el.tagName)) { return; } if (el.nodeType == el.TEXT_NODE || !el.childNodes.length) { let trimmedText = el.textContent.trim(); if (trimmedText) { strings.push(trimmedText); } return; } for (let node of el.childNodes) { let nodeType = node.nodeType; if (nodeType != node.ELEMENT_NODE && nodeType != node.TEXT_NODE) { continue; } _extractLabelStrings(node); } }; _extractLabelStrings(element); this._labelStrings.set(element, strings); return strings; }, /** * From a starting label element, find a nearby input or select element * by traversing the nodes in document order, but don't search past another * related element or outside the form. */ findAdjacentControl(labelElement, potentialLabels) { // First, look for an form element after the label. let foundElementAfter = this.findNextFormControl( labelElement, false, potentialLabels ); // If the control has the same parent as the label, return it. if (foundElementAfter?.parentNode == labelElement.parentNode) { return foundElementAfter; } // Otherwise, look for a form control with the same parent backwards // in the document. let foundElementBefore = this.findNextFormControl( labelElement, true, potentialLabels ); if (foundElementBefore?.parentNode == labelElement.parentNode) { return foundElementBefore; } // If there is no form control with the same parent forward or backward, // return the form control nearest forward, if any, even though it doesn't // have the same parent. return foundElementAfter; }, /** * Find the next form control in the document tree after a starting label that * could correspond to the label. If the form control is in potentialLabels, then * it has already been possibly matched to another label so should be ignored. * * @param {HTMLLabelElement} element * starting