1 |
- {"ast":null,"code":"/**\n * implements https://w3c.github.io/accname/\n */\nimport ArrayFrom from \"./polyfills/array.from.mjs\";\nimport SetLike from \"./polyfills/SetLike.mjs\";\nimport { hasAnyConcreteRoles, isElement, isHTMLTableCaptionElement, isHTMLInputElement, isHTMLSelectElement, isHTMLTextAreaElement, safeWindow, isHTMLFieldSetElement, isHTMLLegendElement, isHTMLOptGroupElement, isHTMLTableElement, isHTMLSlotElement, isSVGSVGElement, isSVGTitleElement, queryIdRefs, getLocalName } from \"./util.mjs\";\n/**\n * A string of characters where all carriage returns, newlines, tabs, and form-feeds are replaced with a single space, and multiple spaces are reduced to a single space. The string contains only character data; it does not contain any markup.\n */\n\n/**\n *\n * @param {string} string -\n * @returns {FlatString} -\n */\n\nfunction asFlatString(s) {\n return s.trim().replace(/\\s\\s+/g, \" \");\n}\n/**\n *\n * @param node -\n * @param options - These are not optional to prevent accidentally calling it without options in `computeAccessibleName`\n * @returns {boolean} -\n */\n\n\nfunction isHidden(node, getComputedStyleImplementation) {\n if (!isElement(node)) {\n return false;\n }\n\n if (node.hasAttribute(\"hidden\") || node.getAttribute(\"aria-hidden\") === \"true\") {\n return true;\n }\n\n var style = getComputedStyleImplementation(node);\n return style.getPropertyValue(\"display\") === \"none\" || style.getPropertyValue(\"visibility\") === \"hidden\";\n}\n/**\n * @param {Node} node -\n * @returns {boolean} - As defined in step 2E of https://w3c.github.io/accname/#mapping_additional_nd_te\n */\n\n\nfunction isControl(node) {\n return hasAnyConcreteRoles(node, [\"button\", \"combobox\", \"listbox\", \"textbox\"]) || hasAbstractRole(node, \"range\");\n}\n\nfunction hasAbstractRole(node, role) {\n if (!isElement(node)) {\n return false;\n }\n\n switch (role) {\n case \"range\":\n return hasAnyConcreteRoles(node, [\"meter\", \"progressbar\", \"scrollbar\", \"slider\", \"spinbutton\"]);\n\n default:\n throw new TypeError(\"No knowledge about abstract role '\".concat(role, \"'. This is likely a bug :(\"));\n }\n}\n/**\n * element.querySelectorAll but also considers owned tree\n * @param element\n * @param selectors\n */\n\n\nfunction querySelectorAllSubtree(element, selectors) {\n var elements = ArrayFrom(element.querySelectorAll(selectors));\n queryIdRefs(element, \"aria-owns\").forEach(function (root) {\n // babel transpiles this assuming an iterator\n elements.push.apply(elements, ArrayFrom(root.querySelectorAll(selectors)));\n });\n return elements;\n}\n\nfunction querySelectedOptions(listbox) {\n if (isHTMLSelectElement(listbox)) {\n // IE11 polyfill\n return listbox.selectedOptions || querySelectorAllSubtree(listbox, \"[selected]\");\n }\n\n return querySelectorAllSubtree(listbox, '[aria-selected=\"true\"]');\n}\n\nfunction isMarkedPresentational(node) {\n return hasAnyConcreteRoles(node, [\"none\", \"presentation\"]);\n}\n/**\n * Elements specifically listed in html-aam\n *\n * We don't need this for `label` or `legend` elements.\n * Their implicit roles already allow \"naming from content\".\n *\n * sources:\n *\n * - https://w3c.github.io/html-aam/#table-element\n */\n\n\nfunction isNativeHostLanguageTextAlternativeElement(node) {\n return isHTMLTableCaptionElement(node);\n}\n/**\n * https://w3c.github.io/aria/#namefromcontent\n */\n\n\nfunction allowsNameFromContent(node) {\n return hasAnyConcreteRoles(node, [\"button\", \"cell\", \"checkbox\", \"columnheader\", \"gridcell\", \"heading\", \"label\", \"legend\", \"link\", \"menuitem\", \"menuitemcheckbox\", \"menuitemradio\", \"option\", \"radio\", \"row\", \"rowheader\", \"switch\", \"tab\", \"tooltip\", \"treeitem\"]);\n}\n/**\n * TODO https://github.com/eps1lon/dom-accessibility-api/issues/100\n */\n\n\nfunction isDescendantOfNativeHostLanguageTextAlternativeElement( // eslint-disable-next-line @typescript-eslint/no-unused-vars -- not implemented yet\nnode) {\n return false;\n}\n/**\n * TODO https://github.com/eps1lon/dom-accessibility-api/issues/101\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars -- not implemented yet\n\n\nfunction computeTooltipAttributeValue(node) {\n return null;\n}\n\nfunction getValueOfTextbox(element) {\n if (isHTMLInputElement(element) || isHTMLTextAreaElement(element)) {\n return element.value;\n } // https://github.com/eps1lon/dom-accessibility-api/issues/4\n\n\n return element.textContent || \"\";\n}\n\nfunction getTextualContent(declaration) {\n var content = declaration.getPropertyValue(\"content\");\n\n if (/^[\"'].*[\"']$/.test(content)) {\n return content.slice(1, -1);\n }\n\n return \"\";\n}\n/**\n * https://html.spec.whatwg.org/multipage/forms.html#category-label\n * TODO: form-associated custom elements\n * @param element\n */\n\n\nfunction isLabelableElement(element) {\n var localName = getLocalName(element);\n return localName === \"button\" || localName === \"input\" && element.getAttribute(\"type\") !== \"hidden\" || localName === \"meter\" || localName === \"output\" || localName === \"progress\" || localName === \"select\" || localName === \"textarea\";\n}\n/**\n * > [...], then the first such descendant in tree order is the label element's labeled control.\n * -- https://html.spec.whatwg.org/multipage/forms.html#labeled-control\n * @param element\n */\n\n\nfunction findLabelableElement(element) {\n if (isLabelableElement(element)) {\n return element;\n }\n\n var labelableElement = null;\n element.childNodes.forEach(function (childNode) {\n if (labelableElement === null && isElement(childNode)) {\n var descendantLabelableElement = findLabelableElement(childNode);\n\n if (descendantLabelableElement !== null) {\n labelableElement = descendantLabelableElement;\n }\n }\n });\n return labelableElement;\n}\n/**\n * Polyfill of HTMLLabelElement.control\n * https://html.spec.whatwg.org/multipage/forms.html#labeled-control\n * @param label\n */\n\n\nfunction getControlOfLabel(label) {\n if (label.control !== undefined) {\n return label.control;\n }\n\n var htmlFor = label.getAttribute(\"for\");\n\n if (htmlFor !== null) {\n return label.ownerDocument.getElementById(htmlFor);\n }\n\n return findLabelableElement(label);\n}\n/**\n * Polyfill of HTMLInputElement.labels\n * https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/labels\n * @param element\n */\n\n\nfunction getLabels(element) {\n var labelsProperty = element.labels;\n\n if (labelsProperty === null) {\n return labelsProperty;\n }\n\n if (labelsProperty !== undefined) {\n return ArrayFrom(labelsProperty);\n } // polyfill\n\n\n if (!isLabelableElement(element)) {\n return null;\n }\n\n var document = element.ownerDocument;\n return ArrayFrom(document.querySelectorAll(\"label\")).filter(function (label) {\n return getControlOfLabel(label) === element;\n });\n}\n/**\n * Gets the contents of a slot used for computing the accname\n * @param slot\n */\n\n\nfunction getSlotContents(slot) {\n // Computing the accessible name for elements containing slots is not\n // currently defined in the spec. This implementation reflects the\n // behavior of NVDA 2020.2/Firefox 81 and iOS VoiceOver/Safari 13.6.\n var assignedNodes = slot.assignedNodes();\n\n if (assignedNodes.length === 0) {\n // if no nodes are assigned to the slot, it displays the default content\n return ArrayFrom(slot.childNodes);\n }\n\n return assignedNodes;\n}\n/**\n * implements https://w3c.github.io/accname/#mapping_additional_nd_te\n * @param root\n * @param [options]\n * @param [options.getComputedStyle] - mock window.getComputedStyle. Needs `content`, `display` and `visibility`\n */\n\n\nexport function computeTextAlternative(root) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n var consultedNodes = new SetLike();\n var window = safeWindow(root);\n var _options$compute = options.compute,\n compute = _options$compute === void 0 ? \"name\" : _options$compute,\n _options$computedStyl = options.computedStyleSupportsPseudoElements,\n computedStyleSupportsPseudoElements = _options$computedStyl === void 0 ? options.getComputedStyle !== undefined : _options$computedStyl,\n _options$getComputedS = options.getComputedStyle,\n getComputedStyle = _options$getComputedS === void 0 ? window.getComputedStyle.bind(window) : _options$getComputedS; // 2F.i\n\n function computeMiscTextAlternative(node, context) {\n var accumulatedText = \"\";\n\n if (isElement(node) && computedStyleSupportsPseudoElements) {\n var pseudoBefore = getComputedStyle(node, \"::before\");\n var beforeContent = getTextualContent(pseudoBefore);\n accumulatedText = \"\".concat(beforeContent, \" \").concat(accumulatedText);\n } // FIXME: Including aria-owns is not defined in the spec\n // But it is required in the web-platform-test\n\n\n var childNodes = isHTMLSlotElement(node) ? getSlotContents(node) : ArrayFrom(node.childNodes).concat(queryIdRefs(node, \"aria-owns\"));\n childNodes.forEach(function (child) {\n var result = computeTextAlternative(child, {\n isEmbeddedInLabel: context.isEmbeddedInLabel,\n isReferenced: false,\n recursion: true\n }); // TODO: Unclear why display affects delimiter\n // see https://github.com/w3c/accname/issues/3\n\n var display = isElement(child) ? getComputedStyle(child).getPropertyValue(\"display\") : \"inline\";\n var separator = display !== \"inline\" ? \" \" : \"\"; // trailing separator for wpt tests\n\n accumulatedText += \"\".concat(separator).concat(result).concat(separator);\n });\n\n if (isElement(node) && computedStyleSupportsPseudoElements) {\n var pseudoAfter = getComputedStyle(node, \"::after\");\n var afterContent = getTextualContent(pseudoAfter);\n accumulatedText = \"\".concat(accumulatedText, \" \").concat(afterContent);\n }\n\n return accumulatedText;\n }\n\n function computeElementTextAlternative(node) {\n if (!isElement(node)) {\n return null;\n }\n /**\n *\n * @param element\n * @param attributeName\n * @returns A string non-empty string or `null`\n */\n\n\n function useAttribute(element, attributeName) {\n var attribute = element.getAttributeNode(attributeName);\n\n if (attribute !== null && !consultedNodes.has(attribute) && attribute.value.trim() !== \"\") {\n consultedNodes.add(attribute);\n return attribute.value;\n }\n\n return null;\n } // https://w3c.github.io/html-aam/#fieldset-and-legend-elements\n\n\n if (isHTMLFieldSetElement(node)) {\n consultedNodes.add(node);\n var children = ArrayFrom(node.childNodes);\n\n for (var i = 0; i < children.length; i += 1) {\n var child = children[i];\n\n if (isHTMLLegendElement(child)) {\n return computeTextAlternative(child, {\n isEmbeddedInLabel: false,\n isReferenced: false,\n recursion: false\n });\n }\n }\n } else if (isHTMLTableElement(node)) {\n // https://w3c.github.io/html-aam/#table-element\n consultedNodes.add(node);\n\n var _children = ArrayFrom(node.childNodes);\n\n for (var _i = 0; _i < _children.length; _i += 1) {\n var _child = _children[_i];\n\n if (isHTMLTableCaptionElement(_child)) {\n return computeTextAlternative(_child, {\n isEmbeddedInLabel: false,\n isReferenced: false,\n recursion: false\n });\n }\n }\n } else if (isSVGSVGElement(node)) {\n // https://www.w3.org/TR/svg-aam-1.0/\n consultedNodes.add(node);\n\n var _children2 = ArrayFrom(node.childNodes);\n\n for (var _i2 = 0; _i2 < _children2.length; _i2 += 1) {\n var _child2 = _children2[_i2];\n\n if (isSVGTitleElement(_child2)) {\n return _child2.textContent;\n }\n }\n\n return null;\n } else if (getLocalName(node) === \"img\" || getLocalName(node) === \"area\") {\n // https://w3c.github.io/html-aam/#area-element\n // https://w3c.github.io/html-aam/#img-element\n var nameFromAlt = useAttribute(node, \"alt\");\n\n if (nameFromAlt !== null) {\n return nameFromAlt;\n }\n } else if (isHTMLOptGroupElement(node)) {\n var nameFromLabel = useAttribute(node, \"label\");\n\n if (nameFromLabel !== null) {\n return nameFromLabel;\n }\n }\n\n if (isHTMLInputElement(node) && (node.type === \"button\" || node.type === \"submit\" || node.type === \"reset\")) {\n // https://w3c.github.io/html-aam/#input-type-text-input-type-password-input-type-search-input-type-tel-input-type-email-input-type-url-and-textarea-element-accessible-description-computation\n var nameFromValue = useAttribute(node, \"value\");\n\n if (nameFromValue !== null) {\n return nameFromValue;\n } // TODO: l10n\n\n\n if (node.type === \"submit\") {\n return \"Submit\";\n } // TODO: l10n\n\n\n if (node.type === \"reset\") {\n return \"Reset\";\n }\n }\n\n var labels = getLabels(node);\n\n if (labels !== null && labels.length !== 0) {\n consultedNodes.add(node);\n return ArrayFrom(labels).map(function (element) {\n return computeTextAlternative(element, {\n isEmbeddedInLabel: true,\n isReferenced: false,\n recursion: true\n });\n }).filter(function (label) {\n return label.length > 0;\n }).join(\" \");\n } // https://w3c.github.io/html-aam/#input-type-image-accessible-name-computation\n // TODO: wpt test consider label elements but html-aam does not mention them\n // We follow existing implementations over spec\n\n\n if (isHTMLInputElement(node) && node.type === \"image\") {\n var _nameFromAlt = useAttribute(node, \"alt\");\n\n if (_nameFromAlt !== null) {\n return _nameFromAlt;\n }\n\n var nameFromTitle = useAttribute(node, \"title\");\n\n if (nameFromTitle !== null) {\n return nameFromTitle;\n } // TODO: l10n\n\n\n return \"Submit Query\";\n }\n\n return useAttribute(node, \"title\");\n }\n\n function computeTextAlternative(current, context) {\n if (consultedNodes.has(current)) {\n return \"\";\n } // special casing, cheating to make tests pass\n // https://github.com/w3c/accname/issues/67\n\n\n if (hasAnyConcreteRoles(current, [\"menu\"])) {\n consultedNodes.add(current);\n return \"\";\n } // 2A\n\n\n if (isHidden(current, getComputedStyle) && !context.isReferenced) {\n consultedNodes.add(current);\n return \"\";\n } // 2B\n\n\n var labelElements = queryIdRefs(current, \"aria-labelledby\");\n\n if (compute === \"name\" && !context.isReferenced && labelElements.length > 0) {\n return labelElements.map(function (element) {\n return computeTextAlternative(element, {\n isEmbeddedInLabel: context.isEmbeddedInLabel,\n isReferenced: true,\n // thais isn't recursion as specified, otherwise we would skip\n // `aria-label` in\n // <input id=\"myself\" aria-label=\"foo\" aria-labelledby=\"myself\"\n recursion: false\n });\n }).join(\" \");\n } // 2C\n // Changed from the spec in anticipation of https://github.com/w3c/accname/issues/64\n // spec says we should only consider skipping if we have a non-empty label\n\n\n var skipToStep2E = context.recursion && isControl(current) && compute === \"name\";\n\n if (!skipToStep2E) {\n var ariaLabel = (isElement(current) && current.getAttribute(\"aria-label\") || \"\").trim();\n\n if (ariaLabel !== \"\" && compute === \"name\") {\n consultedNodes.add(current);\n return ariaLabel;\n } // 2D\n\n\n if (!isMarkedPresentational(current)) {\n var elementTextAlternative = computeElementTextAlternative(current);\n\n if (elementTextAlternative !== null) {\n consultedNodes.add(current);\n return elementTextAlternative;\n }\n }\n } // 2E\n\n\n if (skipToStep2E || context.isEmbeddedInLabel || context.isReferenced) {\n if (hasAnyConcreteRoles(current, [\"combobox\", \"listbox\"])) {\n consultedNodes.add(current);\n var selectedOptions = querySelectedOptions(current);\n\n if (selectedOptions.length === 0) {\n // defined per test `name_heading_combobox`\n return isHTMLInputElement(current) ? current.value : \"\";\n }\n\n return ArrayFrom(selectedOptions).map(function (selectedOption) {\n return computeTextAlternative(selectedOption, {\n isEmbeddedInLabel: context.isEmbeddedInLabel,\n isReferenced: false,\n recursion: true\n });\n }).join(\" \");\n }\n\n if (hasAbstractRole(current, \"range\")) {\n consultedNodes.add(current);\n\n if (current.hasAttribute(\"aria-valuetext\")) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- safe due to hasAttribute guard\n return current.getAttribute(\"aria-valuetext\");\n }\n\n if (current.hasAttribute(\"aria-valuenow\")) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- safe due to hasAttribute guard\n return current.getAttribute(\"aria-valuenow\");\n } // Otherwise, use the value as specified by a host language attribute.\n\n\n return current.getAttribute(\"value\") || \"\";\n }\n\n if (hasAnyConcreteRoles(current, [\"textbox\"])) {\n consultedNodes.add(current);\n return getValueOfTextbox(current);\n }\n } // 2F: https://w3c.github.io/accname/#step2F\n\n\n if (allowsNameFromContent(current) || isElement(current) && context.isReferenced || isNativeHostLanguageTextAlternativeElement(current) || isDescendantOfNativeHostLanguageTextAlternativeElement(current)) {\n consultedNodes.add(current);\n return computeMiscTextAlternative(current, {\n isEmbeddedInLabel: context.isEmbeddedInLabel,\n isReferenced: false\n });\n }\n\n if (current.nodeType === current.TEXT_NODE) {\n consultedNodes.add(current);\n return current.textContent || \"\";\n }\n\n if (context.recursion) {\n consultedNodes.add(current);\n return computeMiscTextAlternative(current, {\n isEmbeddedInLabel: context.isEmbeddedInLabel,\n isReferenced: false\n });\n }\n\n var tooltipAttributeValue = computeTooltipAttributeValue(current);\n\n if (tooltipAttributeValue !== null) {\n consultedNodes.add(current);\n return tooltipAttributeValue;\n } // TODO should this be reachable?\n\n\n consultedNodes.add(current);\n return \"\";\n }\n\n return asFlatString(computeTextAlternative(root, {\n isEmbeddedInLabel: false,\n // by spec computeAccessibleDescription starts with the referenced elements as roots\n isReferenced: compute === \"description\",\n recursion: false\n }));\n}","map":{"version":3,"sources":["../sources/accessible-name-and-description.ts"],"names":["s","isElement","node","style","getComputedStyleImplementation","hasAnyConcreteRoles","hasAbstractRole","elements","ArrayFrom","element","queryIdRefs","root","isHTMLSelectElement","listbox","querySelectorAllSubtree","isHTMLTableCaptionElement","isHTMLInputElement","isHTMLTextAreaElement","content","declaration","localName","getLocalName","isLabelableElement","labelableElement","descendantLabelableElement","findLabelableElement","label","htmlFor","labelsProperty","document","getControlOfLabel","assignedNodes","slot","options","consultedNodes","window","safeWindow","compute","computedStyleSupportsPseudoElements","getComputedStyle","accumulatedText","pseudoBefore","beforeContent","getTextualContent","childNodes","isHTMLSlotElement","getSlotContents","result","computeTextAlternative","isEmbeddedInLabel","context","isReferenced","recursion","display","separator","pseudoAfter","afterContent","attribute","isHTMLFieldSetElement","children","i","child","isHTMLLegendElement","isHTMLTableElement","isSVGSVGElement","isSVGTitleElement","nameFromAlt","useAttribute","isHTMLOptGroupElement","nameFromLabel","nameFromValue","labels","getLabels","nameFromTitle","isHidden","labelElements","skipToStep2E","isControl","ariaLabel","current","isMarkedPresentational","elementTextAlternative","computeElementTextAlternative","selectedOptions","querySelectedOptions","getValueOfTextbox","allowsNameFromContent","isNativeHostLanguageTextAlternativeElement","isDescendantOfNativeHostLanguageTextAlternativeElement","computeMiscTextAlternative","tooltipAttributeValue","computeTooltipAttributeValue","asFlatString"],"mappings":"AAAA;AACA;AACA;AACA,OAAA,SAAA,MAAA,4BAAA;AACA,OAAA,OAAA,MAAA,yBAAA;AACA,SAAA,mBAAA,EAAA,SAAA,EAAA,yBAAA,EAAA,kBAAA,EAAA,mBAAA,EAAA,qBAAA,EAAA,UAAA,EAAA,qBAAA,EAAA,mBAAA,EAAA,qBAAA,EAAA,kBAAA,EAAA,iBAAA,EAAA,eAAA,EAAA,iBAAA,EAAA,WAAA,EAAA,YAAA,QAAA,YAAA;AAmBA;AACA;AACA;;AAkBA;AACA;AACA;AACA;AACA;;AACA,SAAA,YAAA,CAAA,CAAA,EAA6C;AAC5C,SAAOA,CAAC,CAADA,IAAAA,GAAAA,OAAAA,CAAAA,QAAAA,EAAP,GAAOA,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACA,SAAA,QAAA,CAAA,IAAA,EAAA,8BAAA,EAGmB;AAClB,MAAI,CAACC,SAAS,CAAd,IAAc,CAAd,EAAsB;AACrB,WAAA,KAAA;AACA;;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A,iBAAiB,EAAEC,OAAO,CADgB,iBAAA;AAE1CC,QAAAA,YAAY,EAAE;AAF4B,OAAV,CAAjC;AAIA;;AAED,QAAI4B,OAAO,CAAPA,QAAAA,KAAqBA,OAAO,CAAhC,SAAA,EAA4C;AAC3C7C,MAAAA,cAAc,CAAdA,GAAAA,CAAAA,OAAAA;AACA,aAAO6C,OAAO,CAAPA,WAAAA,IAAP,EAAA;AACA;;AAED,QAAI7B,OAAO,CAAX,SAAA,EAAuB;AACtBhB,MAAAA,cAAc,CAAdA,GAAAA,CAAAA,OAAAA;AACA,aAAOuD,0BAA0B,CAAA,OAAA,EAAU;AAC1CxC,QAAAA,iBAAiB,EAAEC,OAAO,CADgB,iBAAA;AAE1CC,QAAAA,YAAY,EAAE;AAF4B,OAAV,CAAjC;AAIA;;AAED,QAAMuC,qBAAqB,GAAGC,4BAA4B,CAA1D,OAA0D,CAA1D;;AACA,QAAID,qBAAqB,KAAzB,IAAA,EAAoC;AACnCxD,MAAAA,cAAc,CAAdA,GAAAA,CAAAA,OAAAA;AACA,aAAA,qBAAA;AApIQ,KAAA,CAuIT;;;AACAA,IAAAA,cAAc,CAAdA,GAAAA,CAAAA,OAAAA;AACA,WAAA,EAAA;AACA;;AAED,SAAO0D,YAAY,CAClB5C,sBAAsB,CAAA,IAAA,EAAO;AAC5BC,IAAAA,iBAAiB,EADW,KAAA;AAE5B;AACAE,IAAAA,YAAY,EAAEd,OAAO,KAHO,aAAA;AAI5Be,IAAAA,SAAS,EAAE;AAJiB,GAAP,CADJ,CAAnB;AAQA","sourcesContent":["/**\n * implements https://w3c.github.io/accname/\n */\nimport ArrayFrom from \"./polyfills/array.from\";\nimport SetLike from \"./polyfills/SetLike\";\nimport {\n\thasAnyConcreteRoles,\n\tisElement,\n\tisHTMLTableCaptionElement,\n\tisHTMLInputElement,\n\tisHTMLSelectElement,\n\tisHTMLTextAreaElement,\n\tsafeWindow,\n\tisHTMLFieldSetElement,\n\tisHTMLLegendElement,\n\tisHTMLOptGroupElement,\n\tisHTMLTableElement,\n\tisHTMLSlotElement,\n\tisSVGSVGElement,\n\tisSVGTitleElement,\n\tqueryIdRefs,\n\tgetLocalName,\n} from \"./util\";\n\n/**\n * A string of characters where all carriage returns, newlines, tabs, and form-feeds are replaced with a single space, and multiple spaces are reduced to a single space. The string contains only character data; it does not contain any markup.\n */\ntype FlatString = string & {\n\t__flat: true;\n};\n\n/**\n * interface for an options-bag where `window.getComputedStyle` can be mocked\n */\nexport interface ComputeTextAlternativeOptions {\n\tcompute?: \"description\" | \"name\";\n\t/**\n\t * Set to true if window.computedStyle supports the second argument.\n\t * This should be false in JSDOM. Otherwise JSDOM will log console errors.\n\t */\n\tcomputedStyleSupportsPseudoElements?: boolean;\n\tgetComputedStyle?: typeof window.getComputedStyle;\n}\n\n/**\n *\n * @param {string} string -\n * @returns {FlatString} -\n */\nfunction asFlatString(s: string): FlatString {\n\treturn s.trim().replace(/\\s\\s+/g, \" \") as FlatString;\n}\n\n/**\n *\n * @param node -\n * @param options - These are not optional to prevent accidentally calling it without options in `computeAccessibleName`\n * @returns {boolean} -\n */\nfunction isHidden(\n\tnode: Node,\n\tgetComputedStyleImplementation: typeof window.getComputedStyle\n): node is Element {\n\tif (!isElement(node)) {\n\t\treturn false;\n\t}\n\n\tif (\n\t\tnode.hasAttribute(\"hidden\") ||\n\t\tnode.getAttribute(\"aria-hidden\") === \"true\"\n\t) {\n\t\treturn true;\n\t}\n\n\tconst style = getComputedStyleImplementation(node);\n\treturn (\n\t\tstyle.getPropertyValue(\"display\") === \"none\" ||\n\t\tstyle.getPropertyValue(\"visibility\") === \"hidden\"\n\t);\n}\n\n/**\n * @param {Node} node -\n * @returns {boolean} - As defined in step 2E of https://w3c.github.io/accname/#mapping_additional_nd_te\n */\nfunction isControl(node: Node): boolean {\n\treturn (\n\t\thasAnyConcreteRoles(node, [\"button\", \"combobox\", \"listbox\", \"textbox\"]) ||\n\t\thasAbstractRole(node, \"range\")\n\t);\n}\n\nfunction hasAbstractRole(node: Node, role: string): node is Element {\n\tif (!isElement(node)) {\n\t\treturn false;\n\t}\n\n\tswitch (role) {\n\t\tcase \"range\":\n\t\t\treturn hasAnyConcreteRoles(node, [\n\t\t\t\t\"meter\",\n\t\t\t\t\"progressbar\",\n\t\t\t\t\"scrollbar\",\n\t\t\t\t\"slider\",\n\t\t\t\t\"spinbutton\",\n\t\t\t]);\n\t\tdefault:\n\t\t\tthrow new TypeError(\n\t\t\t\t`No knowledge about abstract role '${role}'. This is likely a bug :(`\n\t\t\t);\n\t}\n}\n\n/**\n * element.querySelectorAll but also considers owned tree\n * @param element\n * @param selectors\n */\nfunction querySelectorAllSubtree(\n\telement: Element,\n\tselectors: string\n): Element[] {\n\tconst elements = ArrayFrom(element.querySelectorAll(selectors));\n\n\tqueryIdRefs(element, \"aria-owns\").forEach((root) => {\n\t\t// babel transpiles this assuming an iterator\n\t\telements.push.apply(elements, ArrayFrom(root.querySelectorAll(selectors)));\n\t});\n\n\treturn elements;\n}\n\nfunction querySelectedOptions(listbox: Element): ArrayLike<Element> {\n\tif (isHTMLSelectElement(listbox)) {\n\t\t// IE11 polyfill\n\t\treturn (\n\t\t\tlistbox.selectedOptions || querySelectorAllSubtree(listbox, \"[selected]\")\n\t\t);\n\t}\n\treturn querySelectorAllSubtree(listbox, '[aria-selected=\"true\"]');\n}\n\nfunction isMarkedPresentational(node: Node): node is Element {\n\treturn hasAnyConcreteRoles(node, [\"none\", \"presentation\"]);\n}\n\n/**\n * Elements specifically listed in html-aam\n *\n * We don't need this for `label` or `legend` elements.\n * Their implicit roles already allow \"naming from content\".\n *\n * sources:\n *\n * - https://w3c.github.io/html-aam/#table-element\n */\nfunction isNativeHostLanguageTextAlternativeElement(\n\tnode: Node\n): node is Element {\n\treturn isHTMLTableCaptionElement(node);\n}\n\n/**\n * https://w3c.github.io/aria/#namefromcontent\n */\nfunction allowsNameFromContent(node: Node): boolean {\n\treturn hasAnyConcreteRoles(node, [\n\t\t\"button\",\n\t\t\"cell\",\n\t\t\"checkbox\",\n\t\t\"columnheader\",\n\t\t\"gridcell\",\n\t\t\"heading\",\n\t\t\"label\",\n\t\t\"legend\",\n\t\t\"link\",\n\t\t\"menuitem\",\n\t\t\"menuitemcheckbox\",\n\t\t\"menuitemradio\",\n\t\t\"option\",\n\t\t\"radio\",\n\t\t\"row\",\n\t\t\"rowheader\",\n\t\t\"switch\",\n\t\t\"tab\",\n\t\t\"tooltip\",\n\t\t\"treeitem\",\n\t]);\n}\n\n/**\n * TODO https://github.com/eps1lon/dom-accessibility-api/issues/100\n */\nfunction isDescendantOfNativeHostLanguageTextAlternativeElement(\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars -- not implemented yet\n\tnode: Node\n): boolean {\n\treturn false;\n}\n\n/**\n * TODO https://github.com/eps1lon/dom-accessibility-api/issues/101\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars -- not implemented yet\nfunction computeTooltipAttributeValue(node: Node): string | null {\n\treturn null;\n}\n\nfunction getValueOfTextbox(element: Element): string {\n\tif (isHTMLInputElement(element) || isHTMLTextAreaElement(element)) {\n\t\treturn element.value;\n\t}\n\t// https://github.com/eps1lon/dom-accessibility-api/issues/4\n\treturn element.textContent || \"\";\n}\n\nfunction getTextualContent(declaration: CSSStyleDeclaration): string {\n\tconst content = declaration.getPropertyValue(\"content\");\n\tif (/^[\"'].*[\"']$/.test(content)) {\n\t\treturn content.slice(1, -1);\n\t}\n\treturn \"\";\n}\n\n/**\n * https://html.spec.whatwg.org/multipage/forms.html#category-label\n * TODO: form-associated custom elements\n * @param element\n */\nfunction isLabelableElement(element: Element): boolean {\n\tconst localName = getLocalName(element);\n\n\treturn (\n\t\tlocalName === \"button\" ||\n\t\t(localName === \"input\" && element.getAttribute(\"type\") !== \"hidden\") ||\n\t\tlocalName === \"meter\" ||\n\t\tlocalName === \"output\" ||\n\t\tlocalName === \"progress\" ||\n\t\tlocalName === \"select\" ||\n\t\tlocalName === \"textarea\"\n\t);\n}\n\n/**\n * > [...], then the first such descendant in tree order is the label element's labeled control.\n * -- https://html.spec.whatwg.org/multipage/forms.html#labeled-control\n * @param element\n */\nfunction findLabelableElement(element: Element): Element | null {\n\tif (isLabelableElement(element)) {\n\t\treturn element;\n\t}\n\tlet labelableElement: Element | null = null;\n\telement.childNodes.forEach((childNode) => {\n\t\tif (labelableElement === null && isElement(childNode)) {\n\t\t\tconst descendantLabelableElement = findLabelableElement(childNode);\n\t\t\tif (descendantLabelableElement !== null) {\n\t\t\t\tlabelableElement = descendantLabelableElement;\n\t\t\t}\n\t\t}\n\t});\n\n\treturn labelableElement;\n}\n\n/**\n * Polyfill of HTMLLabelElement.control\n * https://html.spec.whatwg.org/multipage/forms.html#labeled-control\n * @param label\n */\nfunction getControlOfLabel(label: HTMLLabelElement): Element | null {\n\tif (label.control !== undefined) {\n\t\treturn label.control;\n\t}\n\n\tconst htmlFor = label.getAttribute(\"for\");\n\tif (htmlFor !== null) {\n\t\treturn label.ownerDocument.getElementById(htmlFor);\n\t}\n\n\treturn findLabelableElement(label);\n}\n\n/**\n * Polyfill of HTMLInputElement.labels\n * https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/labels\n * @param element\n */\nfunction getLabels(element: Element): HTMLLabelElement[] | null {\n\tconst labelsProperty = (element as any).labels as\n\t\t| undefined\n\t\t| null\n\t\t| NodeListOf<HTMLLabelElement>;\n\tif (labelsProperty === null) {\n\t\treturn labelsProperty;\n\t}\n\tif (labelsProperty !== undefined) {\n\t\treturn ArrayFrom(labelsProperty);\n\t}\n\n\t// polyfill\n\tif (!isLabelableElement(element)) {\n\t\treturn null;\n\t}\n\tconst document = element.ownerDocument;\n\n\treturn ArrayFrom(document.querySelectorAll(\"label\")).filter((label) => {\n\t\treturn getControlOfLabel(label) === element;\n\t});\n}\n\n/**\n * Gets the contents of a slot used for computing the accname\n * @param slot\n */\nfunction getSlotContents(slot: HTMLSlotElement): Node[] {\n\t// Computing the accessible name for elements containing slots is not\n\t// currently defined in the spec. This implementation reflects the\n\t// behavior of NVDA 2020.2/Firefox 81 and iOS VoiceOver/Safari 13.6.\n\tconst assignedNodes = slot.assignedNodes();\n\tif (assignedNodes.length === 0) {\n\t\t// if no nodes are assigned to the slot, it displays the default content\n\t\treturn ArrayFrom(slot.childNodes);\n\t}\n\treturn assignedNodes;\n}\n\n/**\n * implements https://w3c.github.io/accname/#mapping_additional_nd_te\n * @param root\n * @param [options]\n * @param [options.getComputedStyle] - mock window.getComputedStyle. Needs `content`, `display` and `visibility`\n */\nexport function computeTextAlternative(\n\troot: Element,\n\toptions: ComputeTextAlternativeOptions = {}\n): string {\n\tconst consultedNodes = new SetLike<Node>();\n\n\tconst window = safeWindow(root);\n\tconst {\n\t\tcompute = \"name\",\n\t\tcomputedStyleSupportsPseudoElements = options.getComputedStyle !==\n\t\t\tundefined,\n\t\t// This might be overengineered. I don't know what happens if I call\n\t\t// window.getComputedStyle(elementFromAnotherWindow) or if I don't bind it\n\t\t// the type declarations don't require a `this`\n\t\t// eslint-disable-next-line no-restricted-properties\n\t\tgetComputedStyle = window.getComputedStyle.bind(window),\n\t} = options;\n\n\t// 2F.i\n\tfunction computeMiscTextAlternative(\n\t\tnode: Node,\n\t\tcontext: { isEmbeddedInLabel: boolean; isReferenced: boolean }\n\t): string {\n\t\tlet accumulatedText = \"\";\n\t\tif (isElement(node) && computedStyleSupportsPseudoElements) {\n\t\t\tconst pseudoBefore = getComputedStyle(node, \"::before\");\n\t\t\tconst beforeContent = getTextualContent(pseudoBefore);\n\t\t\taccumulatedText = `${beforeContent} ${accumulatedText}`;\n\t\t}\n\n\t\t// FIXME: Including aria-owns is not defined in the spec\n\t\t// But it is required in the web-platform-test\n\t\tconst childNodes = isHTMLSlotElement(node)\n\t\t\t? getSlotContents(node)\n\t\t\t: ArrayFrom(node.childNodes).concat(queryIdRefs(node, \"aria-owns\"));\n\t\tchildNodes.forEach((child) => {\n\t\t\tconst result = computeTextAlternative(child, {\n\t\t\t\tisEmbeddedInLabel: context.isEmbeddedInLabel,\n\t\t\t\tisReferenced: false,\n\t\t\t\trecursion: true,\n\t\t\t});\n\t\t\t// TODO: Unclear why display affects delimiter\n\t\t\t// see https://github.com/w3c/accname/issues/3\n\t\t\tconst display = isElement(child)\n\t\t\t\t? getComputedStyle(child).getPropertyValue(\"display\")\n\t\t\t\t: \"inline\";\n\t\t\tconst separator = display !== \"inline\" ? \" \" : \"\";\n\t\t\t// trailing separator for wpt tests\n\t\t\taccumulatedText += `${separator}${result}${separator}`;\n\t\t});\n\n\t\tif (isElement(node) && computedStyleSupportsPseudoElements) {\n\t\t\tconst pseudoAfter = getComputedStyle(node, \"::after\");\n\t\t\tconst afterContent = getTextualContent(pseudoAfter);\n\t\t\taccumulatedText = `${accumulatedText} ${afterContent}`;\n\t\t}\n\n\t\treturn accumulatedText;\n\t}\n\n\tfunction computeElementTextAlternative(node: Node): string | null {\n\t\tif (!isElement(node)) {\n\t\t\treturn null;\n\t\t}\n\n\t\t/**\n\t\t *\n\t\t * @param element\n\t\t * @param attributeName\n\t\t * @returns A string non-empty string or `null`\n\t\t */\n\t\tfunction useAttribute(\n\t\t\telement: Element,\n\t\t\tattributeName: string\n\t\t): string | null {\n\t\t\tconst attribute = element.getAttributeNode(attributeName);\n\t\t\tif (\n\t\t\t\tattribute !== null &&\n\t\t\t\t!consultedNodes.has(attribute) &&\n\t\t\t\tattribute.value.trim() !== \"\"\n\t\t\t) {\n\t\t\t\tconsultedNodes.add(attribute);\n\t\t\t\treturn attribute.value;\n\t\t\t}\n\t\t\treturn null;\n\t\t}\n\n\t\t// https://w3c.github.io/html-aam/#fieldset-and-legend-elements\n\t\tif (isHTMLFieldSetElement(node)) {\n\t\t\tconsultedNodes.add(node);\n\t\t\tconst children = ArrayFrom(node.childNodes);\n\t\t\tfor (let i = 0; i < children.length; i += 1) {\n\t\t\t\tconst child = children[i];\n\t\t\t\tif (isHTMLLegendElement(child)) {\n\t\t\t\t\treturn computeTextAlternative(child, {\n\t\t\t\t\t\tisEmbeddedInLabel: false,\n\t\t\t\t\t\tisReferenced: false,\n\t\t\t\t\t\trecursion: false,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (isHTMLTableElement(node)) {\n\t\t\t// https://w3c.github.io/html-aam/#table-element\n\t\t\tconsultedNodes.add(node);\n\t\t\tconst children = ArrayFrom(node.childNodes);\n\t\t\tfor (let i = 0; i < children.length; i += 1) {\n\t\t\t\tconst child = children[i];\n\t\t\t\tif (isHTMLTableCaptionElement(child)) {\n\t\t\t\t\treturn computeTextAlternative(child, {\n\t\t\t\t\t\tisEmbeddedInLabel: false,\n\t\t\t\t\t\tisReferenced: false,\n\t\t\t\t\t\trecursion: false,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (isSVGSVGElement(node)) {\n\t\t\t// https://www.w3.org/TR/svg-aam-1.0/\n\t\t\tconsultedNodes.add(node);\n\t\t\tconst children = ArrayFrom(node.childNodes);\n\t\t\tfor (let i = 0; i < children.length; i += 1) {\n\t\t\t\tconst child = children[i];\n\t\t\t\tif (isSVGTitleElement(child)) {\n\t\t\t\t\treturn child.textContent;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn null;\n\t\t} else if (getLocalName(node) === \"img\" || getLocalName(node) === \"area\") {\n\t\t\t// https://w3c.github.io/html-aam/#area-element\n\t\t\t// https://w3c.github.io/html-aam/#img-element\n\t\t\tconst nameFromAlt = useAttribute(node, \"alt\");\n\t\t\tif (nameFromAlt !== null) {\n\t\t\t\treturn nameFromAlt;\n\t\t\t}\n\t\t} else if (isHTMLOptGroupElement(node)) {\n\t\t\tconst nameFromLabel = useAttribute(node, \"label\");\n\t\t\tif (nameFromLabel !== null) {\n\t\t\t\treturn nameFromLabel;\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\tisHTMLInputElement(node) &&\n\t\t\t(node.type === \"button\" ||\n\t\t\t\tnode.type === \"submit\" ||\n\t\t\t\tnode.type === \"reset\")\n\t\t) {\n\t\t\t// https://w3c.github.io/html-aam/#input-type-text-input-type-password-input-type-search-input-type-tel-input-type-email-input-type-url-and-textarea-element-accessible-description-computation\n\t\t\tconst nameFromValue = useAttribute(node, \"value\");\n\t\t\tif (nameFromValue !== null) {\n\t\t\t\treturn nameFromValue;\n\t\t\t}\n\n\t\t\t// TODO: l10n\n\t\t\tif (node.type === \"submit\") {\n\t\t\t\treturn \"Submit\";\n\t\t\t}\n\t\t\t// TODO: l10n\n\t\t\tif (node.type === \"reset\") {\n\t\t\t\treturn \"Reset\";\n\t\t\t}\n\t\t}\n\n\t\tconst labels = getLabels(node);\n\t\tif (labels !== null && labels.length !== 0) {\n\t\t\tconsultedNodes.add(node);\n\t\t\treturn ArrayFrom(labels)\n\t\t\t\t.map((element) => {\n\t\t\t\t\treturn computeTextAlternative(element, {\n\t\t\t\t\t\tisEmbeddedInLabel: true,\n\t\t\t\t\t\tisReferenced: false,\n\t\t\t\t\t\trecursion: true,\n\t\t\t\t\t});\n\t\t\t\t})\n\t\t\t\t.filter((label) => {\n\t\t\t\t\treturn label.length > 0;\n\t\t\t\t})\n\t\t\t\t.join(\" \");\n\t\t}\n\n\t\t// https://w3c.github.io/html-aam/#input-type-image-accessible-name-computation\n\t\t// TODO: wpt test consider label elements but html-aam does not mention them\n\t\t// We follow existing implementations over spec\n\t\tif (isHTMLInputElement(node) && node.type === \"image\") {\n\t\t\tconst nameFromAlt = useAttribute(node, \"alt\");\n\t\t\tif (nameFromAlt !== null) {\n\t\t\t\treturn nameFromAlt;\n\t\t\t}\n\n\t\t\tconst nameFromTitle = useAttribute(node, \"title\");\n\t\t\tif (nameFromTitle !== null) {\n\t\t\t\treturn nameFromTitle;\n\t\t\t}\n\n\t\t\t// TODO: l10n\n\t\t\treturn \"Submit Query\";\n\t\t}\n\n\t\treturn useAttribute(node, \"title\");\n\t}\n\n\tfunction computeTextAlternative(\n\t\tcurrent: Node,\n\t\tcontext: {\n\t\t\tisEmbeddedInLabel: boolean;\n\t\t\tisReferenced: boolean;\n\t\t\trecursion: boolean;\n\t\t}\n\t): string {\n\t\tif (consultedNodes.has(current)) {\n\t\t\treturn \"\";\n\t\t}\n\n\t\t// special casing, cheating to make tests pass\n\t\t// https://github.com/w3c/accname/issues/67\n\t\tif (hasAnyConcreteRoles(current, [\"menu\"])) {\n\t\t\tconsultedNodes.add(current);\n\t\t\treturn \"\";\n\t\t}\n\n\t\t// 2A\n\t\tif (isHidden(current, getComputedStyle) && !context.isReferenced) {\n\t\t\tconsultedNodes.add(current);\n\t\t\treturn \"\" as FlatString;\n\t\t}\n\n\t\t// 2B\n\t\tconst labelElements = queryIdRefs(current, \"aria-labelledby\");\n\t\tif (\n\t\t\tcompute === \"name\" &&\n\t\t\t!context.isReferenced &&\n\t\t\tlabelElements.length > 0\n\t\t) {\n\t\t\treturn labelElements\n\t\t\t\t.map((element) =>\n\t\t\t\t\tcomputeTextAlternative(element, {\n\t\t\t\t\t\tisEmbeddedInLabel: context.isEmbeddedInLabel,\n\t\t\t\t\t\tisReferenced: true,\n\t\t\t\t\t\t// thais isn't recursion as specified, otherwise we would skip\n\t\t\t\t\t\t// `aria-label` in\n\t\t\t\t\t\t// <input id=\"myself\" aria-label=\"foo\" aria-labelledby=\"myself\"\n\t\t\t\t\t\trecursion: false,\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t\t.join(\" \");\n\t\t}\n\n\t\t// 2C\n\t\t// Changed from the spec in anticipation of https://github.com/w3c/accname/issues/64\n\t\t// spec says we should only consider skipping if we have a non-empty label\n\t\tconst skipToStep2E =\n\t\t\tcontext.recursion && isControl(current) && compute === \"name\";\n\t\tif (!skipToStep2E) {\n\t\t\tconst ariaLabel = (\n\t\t\t\t(isElement(current) && current.getAttribute(\"aria-label\")) ||\n\t\t\t\t\"\"\n\t\t\t).trim();\n\t\t\tif (ariaLabel !== \"\" && compute === \"name\") {\n\t\t\t\tconsultedNodes.add(current);\n\t\t\t\treturn ariaLabel;\n\t\t\t}\n\n\t\t\t// 2D\n\t\t\tif (!isMarkedPresentational(current)) {\n\t\t\t\tconst elementTextAlternative = computeElementTextAlternative(current);\n\t\t\t\tif (elementTextAlternative !== null) {\n\t\t\t\t\tconsultedNodes.add(current);\n\t\t\t\t\treturn elementTextAlternative;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// 2E\n\t\tif (skipToStep2E || context.isEmbeddedInLabel || context.isReferenced) {\n\t\t\tif (hasAnyConcreteRoles(current, [\"combobox\", \"listbox\"])) {\n\t\t\t\tconsultedNodes.add(current);\n\t\t\t\tconst selectedOptions = querySelectedOptions(current);\n\t\t\t\tif (selectedOptions.length === 0) {\n\t\t\t\t\t// defined per test `name_heading_combobox`\n\t\t\t\t\treturn isHTMLInputElement(current) ? current.value : \"\";\n\t\t\t\t}\n\t\t\t\treturn ArrayFrom(selectedOptions)\n\t\t\t\t\t.map((selectedOption) => {\n\t\t\t\t\t\treturn computeTextAlternative(selectedOption, {\n\t\t\t\t\t\t\tisEmbeddedInLabel: context.isEmbeddedInLabel,\n\t\t\t\t\t\t\tisReferenced: false,\n\t\t\t\t\t\t\trecursion: true,\n\t\t\t\t\t\t});\n\t\t\t\t\t})\n\t\t\t\t\t.join(\" \");\n\t\t\t}\n\t\t\tif (hasAbstractRole(current, \"range\")) {\n\t\t\t\tconsultedNodes.add(current);\n\t\t\t\tif (current.hasAttribute(\"aria-valuetext\")) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- safe due to hasAttribute guard\n\t\t\t\t\treturn current.getAttribute(\"aria-valuetext\")!;\n\t\t\t\t}\n\t\t\t\tif (current.hasAttribute(\"aria-valuenow\")) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- safe due to hasAttribute guard\n\t\t\t\t\treturn current.getAttribute(\"aria-valuenow\")!;\n\t\t\t\t}\n\t\t\t\t// Otherwise, use the value as specified by a host language attribute.\n\t\t\t\treturn current.getAttribute(\"value\") || \"\";\n\t\t\t}\n\t\t\tif (hasAnyConcreteRoles(current, [\"textbox\"])) {\n\t\t\t\tconsultedNodes.add(current);\n\t\t\t\treturn getValueOfTextbox(current);\n\t\t\t}\n\t\t}\n\n\t\t// 2F: https://w3c.github.io/accname/#step2F\n\t\tif (\n\t\t\tallowsNameFromContent(current) ||\n\t\t\t(isElement(current) && context.isReferenced) ||\n\t\t\tisNativeHostLanguageTextAlternativeElement(current) ||\n\t\t\tisDescendantOfNativeHostLanguageTextAlternativeElement(current)\n\t\t) {\n\t\t\tconsultedNodes.add(current);\n\t\t\treturn computeMiscTextAlternative(current, {\n\t\t\t\tisEmbeddedInLabel: context.isEmbeddedInLabel,\n\t\t\t\tisReferenced: false,\n\t\t\t});\n\t\t}\n\n\t\tif (current.nodeType === current.TEXT_NODE) {\n\t\t\tconsultedNodes.add(current);\n\t\t\treturn current.textContent || \"\";\n\t\t}\n\n\t\tif (context.recursion) {\n\t\t\tconsultedNodes.add(current);\n\t\t\treturn computeMiscTextAlternative(current, {\n\t\t\t\tisEmbeddedInLabel: context.isEmbeddedInLabel,\n\t\t\t\tisReferenced: false,\n\t\t\t});\n\t\t}\n\n\t\tconst tooltipAttributeValue = computeTooltipAttributeValue(current);\n\t\tif (tooltipAttributeValue !== null) {\n\t\t\tconsultedNodes.add(current);\n\t\t\treturn tooltipAttributeValue;\n\t\t}\n\n\t\t// TODO should this be reachable?\n\t\tconsultedNodes.add(current);\n\t\treturn \"\";\n\t}\n\n\treturn asFlatString(\n\t\tcomputeTextAlternative(root, {\n\t\t\tisEmbeddedInLabel: false,\n\t\t\t// by spec computeAccessibleDescription starts with the referenced elements as roots\n\t\t\tisReferenced: compute === \"description\",\n\t\t\trecursion: false,\n\t\t})\n\t);\n}\n"]},"metadata":{},"sourceType":"module"}
|