util.mjs.map
6.52 KB
{"version":3,"sources":["../sources/util.ts"],"names":["getRole","getLocalName","element","localName","tagName","toLowerCase","isElement","node","nodeType","ELEMENT_NODE","isHTMLTableCaptionElement","isHTMLInputElement","isHTMLSelectElement","isHTMLTableElement","isHTMLTextAreaElement","safeWindow","ownerDocument","defaultView","TypeError","isHTMLFieldSetElement","isHTMLLegendElement","isHTMLSlotElement","isSVGElement","ownerSVGElement","undefined","isSVGSVGElement","isSVGTitleElement","queryIdRefs","attributeName","hasAttribute","ids","getAttribute","split","map","id","getElementById","filter","hasAnyConcreteRoles","roles","indexOf"],"mappings":"AAAA,OAAOA,OAAP,MAAoB,eAApB;AAEA;;;;;AAIA,OAAO,SAASC,YAAT,CAAsBC,OAAtB,EAAgD;AAAA;;AACtD,SACC;AADD,0BAECA,OAAO,CAACC,SAFT,mEAGC;AACAD,IAAAA,OAAO,CAACE,OAAR,CAAgBC,WAAhB;AAJD;AAMA;AAED,OAAO,SAASC,SAAT,CAAmBC,IAAnB,EAAuD;AAC7D,SAAOA,IAAI,KAAK,IAAT,IAAiBA,IAAI,CAACC,QAAL,KAAkBD,IAAI,CAACE,YAA/C;AACA;AAED,OAAO,SAASC,yBAAT,CACNH,IADM,EAE4B;AAClC,SAAOD,SAAS,CAACC,IAAD,CAAT,IAAmBN,YAAY,CAACM,IAAD,CAAZ,KAAuB,SAAjD;AACA;AAED,OAAO,SAASI,kBAAT,CACNJ,IADM,EAEqB;AAC3B,SAAOD,SAAS,CAACC,IAAD,CAAT,IAAmBN,YAAY,CAACM,IAAD,CAAZ,KAAuB,OAAjD;AACA;AAED,OAAO,SAASK,mBAAT,CACNL,IADM,EAEsB;AAC5B,SAAOD,SAAS,CAACC,IAAD,CAAT,IAAmBN,YAAY,CAACM,IAAD,CAAZ,KAAuB,QAAjD;AACA;AAED,OAAO,SAASM,kBAAT,CACNN,IADM,EAEqB;AAC3B,SAAOD,SAAS,CAACC,IAAD,CAAT,IAAmBN,YAAY,CAACM,IAAD,CAA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,CAAZ,KAAuB,OAApD;AACA;AAED;;;;;;;AAMA,OAAO,SAASoB,WAAT,CAAqBpB,IAArB,EAAiCqB,aAAjC,EAAmE;AACzE,MAAItB,SAAS,CAACC,IAAD,CAAT,IAAmBA,IAAI,CAACsB,YAAL,CAAkBD,aAAlB,CAAvB,EAAyD;AACxD;AACA,QAAME,GAAG,GAAGvB,IAAI,CAACwB,YAAL,CAAkBH,aAAlB,EAAkCI,KAAlC,CAAwC,GAAxC,CAAZ;AAEA,WAAOF,GAAG,CACRG,GADK,CACD,UAACC,EAAD;AAAA,aAAQ3B,IAAI,CAACS,aAAL,CAAmBmB,cAAnB,CAAkCD,EAAlC,CAAR;AAAA,KADC,EAELE,MAFK,CAGL,UAAClC,OAAD;AAAA,aAAiDA,OAAO,KAAK,IAA7D;AAAA,KAHK,CAIL;AAJK,KAAP;AAMA;;AAED,SAAO,EAAP;AACA;AAED,OAAO,SAASmC,mBAAT,CACN9B,IADM,EAEN+B,KAFM,EAGY;AAClB,MAAIhC,SAAS,CAACC,IAAD,CAAb,EAAqB;AACpB,WAAO+B,KAAK,CAACC,OAAN,CAAcvC,OAAO,CAACO,IAAD,CAArB,MAAiC,CAAC,CAAzC;AACA;;AACD,SAAO,KAAP;AACA","sourcesContent":["import getRole from \"./getRole\";\n\n/**\n * Safe Element.localName for all supported environments\n * @param element\n */\nexport function getLocalName(element: Element): string {\n\treturn (\n\t\t// eslint-disable-next-line no-restricted-properties -- actual guard for environments without localName\n\t\telement.localName ??\n\t\t// eslint-disable-next-line no-restricted-properties -- required for the fallback\n\t\telement.tagName.toLowerCase()\n\t);\n}\n\nexport function isElement(node: Node | null): node is Element {\n\treturn node !== null && node.nodeType === node.ELEMENT_NODE;\n}\n\nexport function isHTMLTableCaptionElement(\n\tnode: Node | null\n): node is HTMLTableCaptionElement {\n\treturn isElement(node) && getLocalName(node) === \"caption\";\n}\n\nexport function isHTMLInputElement(\n\tnode: Node | null\n): node is HTMLInputElement {\n\treturn isElement(node) && getLocalName(node) === \"input\";\n}\n\nexport function isHTMLSelectElement(\n\tnode: Node | null\n): node is HTMLSelectElement {\n\treturn isElement(node) && getLocalName(node) === \"select\";\n}\n\nexport function isHTMLTableElement(\n\tnode: Node | null\n): node is HTMLTableElement {\n\treturn isElement(node) && getLocalName(node) === \"table\";\n}\n\nexport function isHTMLTextAreaElement(\n\tnode: Node | null\n): node is HTMLTextAreaElement {\n\treturn isElement(node) && getLocalName(node) === \"textarea\";\n}\n\nexport function safeWindow(node: Node): Window {\n\tconst { defaultView } =\n\t\tnode.ownerDocument === null ? (node as Document) : node.ownerDocument;\n\n\tif (defaultView === null) {\n\t\tthrow new TypeError(\"no window available\");\n\t}\n\treturn defaultView;\n}\n\nexport function isHTMLFieldSetElement(\n\tnode: Node | null\n): node is HTMLFieldSetElement {\n\treturn isElement(node) && getLocalName(node) === \"fieldset\";\n}\n\nexport function isHTMLLegendElement(\n\tnode: Node | null\n): node is HTMLLegendElement {\n\treturn isElement(node) && getLocalName(node) === \"legend\";\n}\n\nexport function isHTMLSlotElement(node: Node | null): node is HTMLSlotElement {\n\treturn isElement(node) && getLocalName(node) === \"slot\";\n}\n\nexport function isSVGElement(node: Node | null): node is SVGElement {\n\treturn isElement(node) && (node as SVGElement).ownerSVGElement !== undefined;\n}\n\nexport function isSVGSVGElement(node: Node | null): node is SVGSVGElement {\n\treturn isElement(node) && getLocalName(node) === \"svg\";\n}\n\nexport function isSVGTitleElement(node: Node | null): node is SVGTitleElement {\n\treturn isSVGElement(node) && getLocalName(node) === \"title\";\n}\n\n/**\n *\n * @param {Node} node -\n * @param {string} attributeName -\n * @returns {Element[]} -\n */\nexport function queryIdRefs(node: Node, attributeName: string): Element[] {\n\tif (isElement(node) && node.hasAttribute(attributeName)) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- safe due to hasAttribute check\n\t\tconst ids = node.getAttribute(attributeName)!.split(\" \");\n\n\t\treturn ids\n\t\t\t.map((id) => node.ownerDocument.getElementById(id))\n\t\t\t.filter(\n\t\t\t\t(element: Element | null): element is Element => element !== null\n\t\t\t\t// TODO: why does this not narrow?\n\t\t\t) as Element[];\n\t}\n\n\treturn [];\n}\n\nexport function hasAnyConcreteRoles(\n\tnode: Node,\n\troles: Array<string | null>\n): node is Element {\n\tif (isElement(node)) {\n\t\treturn roles.indexOf(getRole(node)) !== -1;\n\t}\n\treturn false;\n}\n"],"file":"util.mjs"}