{"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 // {\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 {\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;\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();\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// {\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"}