c3d3ea7381250964ff8a120f98c56ff6.json 9.4 KB

1
  1. {"ast":null,"code":"import getRole from \"./getRole.mjs\";\n/**\n * Safe Element.localName for all supported environments\n * @param element\n */\n\nexport function getLocalName(element) {\n var _element$localName;\n\n return (// eslint-disable-next-line no-restricted-properties -- actual guard for environments without localName\n (_element$localName = element.localName) !== null && _element$localName !== void 0 ? _element$localName : // eslint-disable-next-line no-restricted-properties -- required for the fallback\n element.tagName.toLowerCase()\n );\n}\nexport function isElement(node) {\n return node !== null && node.nodeType === node.ELEMENT_NODE;\n}\nexport function isHTMLTableCaptionElement(node) {\n return isElement(node) && getLocalName(node) === \"caption\";\n}\nexport function isHTMLInputElement(node) {\n return isElement(node) && getLocalName(node) === \"input\";\n}\nexport function isHTMLOptGroupElement(node) {\n return isElement(node) && getLocalName(node) === \"optgroup\";\n}\nexport function isHTMLSelectElement(node) {\n return isElement(node) && getLocalName(node) === \"select\";\n}\nexport function isHTMLTableElement(node) {\n return isElement(node) && getLocalName(node) === \"table\";\n}\nexport function isHTMLTextAreaElement(node) {\n return isElement(node) && getLocalName(node) === \"textarea\";\n}\nexport function safeWindow(node) {\n var _ref = node.ownerDocument === null ? node : node.ownerDocument,\n defaultView = _ref.defaultView;\n\n if (defaultView === null) {\n throw new TypeError(\"no window available\");\n }\n\n return defaultView;\n}\nexport function isHTMLFieldSetElement(node) {\n return isElement(node) && getLocalName(node) === \"fieldset\";\n}\nexport function isHTMLLegendElement(node) {\n return isElement(node) && getLocalName(node) === \"legend\";\n}\nexport function isHTMLSlotElement(node) {\n return isElement(node) && getLocalName(node) === \"slot\";\n}\nexport function isSVGElement(node) {\n return isElement(node) && node.ownerSVGElement !== undefined;\n}\nexport function isSVGSVGElement(node) {\n return isElement(node) && getLocalName(node) === \"svg\";\n}\nexport function isSVGTitleElement(node) {\n return isSVGElement(node) && getLocalName(node) === \"title\";\n}\n/**\n *\n * @param {Node} node -\n * @param {string} attributeName -\n * @returns {Element[]} -\n */\n\nexport function queryIdRefs(node, attributeName) {\n if (isElement(node) && node.hasAttribute(attributeName)) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- safe due to hasAttribute check\n var ids = node.getAttribute(attributeName).split(\" \");\n return ids.map(function (id) {\n return node.ownerDocument.getElementById(id);\n }).filter(function (element) {\n return element !== null;\n } // TODO: why does this not narrow?\n );\n }\n\n return [];\n}\nexport function hasAnyConcreteRoles(node, roles) {\n if (isElement(node)) {\n return roles.indexOf(getRole(node)) !== -1;\n }\n\n return false;\n}","map":{"version":3,"sources":["../sources/util.ts"],"names":["element","node","isElement","getLocalName","defaultView","isSVGElement","ids","roles","getRole"],"mappings":"AAAA,OAAA,OAAA,MAAA,eAAA;AAEA;AACA;AACA;AACA;;AACA,OAAO,SAAA,YAAA,CAAA,OAAA,EAAgD;AAAA,MAAA,kBAAA;;AACtD,SACC;AADD,KAAA,kBAAA,GAECA,OAAO,CAFR,SAAA,MAAA,IAAA,IAAA,kBAAA,KAAA,KAAA,CAAA,GAAA,kBAAA,GAGC;AACAA,IAAAA,OAAO,CAAPA,OAAAA,CAAAA,WAAAA;AAJD;AAMA;AAED,OAAO,SAAA,SAAA,CAAA,IAAA,EAAuD;AAC7D,SAAOC,IAAI,KAAJA,IAAAA,IAAiBA,IAAI,CAAJA,QAAAA,KAAkBA,IAAI,CAA9C,YAAA;AACA;AAED,OAAO,SAAA,yBAAA,CAAA,IAAA,EAE4B;AAClC,SAAOC,SAAS,CAATA,IAAS,CAATA,IAAmBC,YAAY,CAAZA,IAAY,CAAZA,KAA1B,SAAA;AACA;AAED,OAAO,SAAA,kBAAA,CAAA,IAAA,EAEqB;AAC3B,SAAOD,SAAS,CAATA,IAAS,CAATA,IAAmBC,YAAY,CAAZA,IAAY,CAAZA,KAA1B,OAAA;AACA;AAED,OAAO,SAAA,qBAAA,CAAA,IAAA,EAEwB;AAC9B,SAAOD,SAAS,CAATA,IAAS,CAATA,IAAmBC,YAAY,CAAZA,IAAY,CAAZA,KAA1B,UAAA;AACA;AA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OAAO,SAAA,eAAA,CAAA,IAAA,EAAmE;AACzE,SAAOC,SAAS,CAATA,IAAS,CAATA,IAAmBC,YAAY,CAAZA,IAAY,CAAZA,KAA1B,KAAA;AACA;AAED,OAAO,SAAA,iBAAA,CAAA,IAAA,EAAuE;AAC7E,SAAOE,YAAY,CAAZA,IAAY,CAAZA,IAAsBF,YAAY,CAAZA,IAAY,CAAZA,KAA7B,OAAA;AACA;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAAA,WAAA,CAAA,IAAA,EAAA,aAAA,EAAmE;AACzE,MAAID,SAAS,CAATA,IAAS,CAATA,IAAmBD,IAAI,CAAJA,YAAAA,CAAvB,aAAuBA,CAAvB,EAAyD;AACxD;AACA,QAAMK,GAAG,GAAGL,IAAI,CAAJA,YAAAA,CAAAA,aAAAA,EAAAA,KAAAA,CAAZ,GAAYA,CAAZ;AAEA,WAAO,GAAG,CAAH,GAAA,CACD,UAAA,EAAA,EAAA;AAAA,aAAQA,IAAI,CAAJA,aAAAA,CAAAA,cAAAA,CAAR,EAAQA,CAAR;AADC,KAAA,EAAA,MAAA,CAGL,UAAA,OAAA,EAAA;AAAA,aAAiDD,OAAO,KAAxD,IAAA;AAHK,KAAA,CAIL;AAJK,KAAP;AAMA;;AAED,SAAA,EAAA;AACA;AAED,OAAO,SAAA,mBAAA,CAAA,IAAA,EAAA,KAAA,EAGY;AAClB,MAAIE,SAAS,CAAb,IAAa,CAAb,EAAqB;AACpB,WAAOK,KAAK,CAALA,OAAAA,CAAcC,OAAO,CAArBD,IAAqB,CAArBA,MAAiC,CAAxC,CAAA;AACA;;AACD,SAAA,KAAA;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 isHTMLOptGroupElement(\n\tnode: Node | null\n): node is HTMLOptGroupElement {\n\treturn isElement(node) && getLocalName(node) === \"optgroup\";\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"]},"metadata":{},"sourceType":"module"}