mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 09:25:15 +00:00
1 line
11 KiB
Plaintext
1 line
11 KiB
Plaintext
{"version":3,"sources":["../sources/getRole.ts"],"names":["getLocalName","localNameToRoleMappings","article","aside","button","datalist","dd","details","dialog","dt","fieldset","figure","form","footer","h1","h2","h3","h4","h5","h6","header","hr","html","legend","li","math","main","menu","nav","ol","optgroup","option","output","progress","section","summary","table","tbody","textarea","tfoot","td","th","thead","tr","ul","prohibitedAttributes","caption","Set","code","deletion","emphasis","generic","insertion","paragraph","presentation","strong","subscript","superscript","hasGlobalAriaAttributes","element","role","some","attributeName","hasAttribute","has","ignorePresentationalRole","implicitRole","getRole","explicitRole","getExplicitRole","getImplicitRole","mappedByTag","undefined","getAttribute","type","size","trim","split","length"],"mappings":"AAAA;AAEA,SAASA,YAAT,QAA6B,YAA7B;AAEA,IAAMC,uBAA2D,GAAG;AACnEC,EAAAA,OAAO,EAAE,SAD0D;AAEnEC,EAAAA,KAAK,EAAE,eAF4D;AAGnEC,EAAAA,MAAM,EAAE,QAH2D;AAInEC,EAAAA,QAAQ,EAAE,SAJyD;AAKnEC,EAAAA,EAAE,EAAE,YAL+D;AAMnEC,EAAAA,OAAO,EAAE,OAN0D;AAOnEC,EAAAA,MAAM,EAAE,QAP2D;AAQnEC,EAAAA,EAAE,EAAE,MAR+D;AASnEC,EAAAA,QAAQ,EAAE,OATyD;AAUnEC,EAAAA,MAAM,EAAE,QAV2D;AAWnE;AACAC,EAAAA,IAAI,EAAE,MAZ6D;AAanEC,EAAAA,MAAM,EAAE,aAb2D;AAcnEC,EAAAA,EAAE,EAAE,SAd+D;AAenEC,EAAAA,EAAE,EAAE,SAf+D;AAgBnEC,EAAAA,EAAE,EAAE,SAhB+D;AAiBnEC,EAAAA,EAAE,EAAE,SAjB+D;AAkBnEC,EAAAA,EAAE,EAAE,SAlB+D;AAmBnEC,EAAAA,EAAE,EAAE,SAnB+D;AAoBnEC,EAAAA,MAAM,EAAE,QAp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;AACA,eAAK,OAAL;AACC,mBAAOA,IAAP;;AACD,eAAK,OAAL;AACC,mBAAO,QAAP;;AACD,eAAK,OAAL;AACA,eAAK,KAAL;AACA,eAAK,MAAL;AACA,eAAK,KAAL;AACC,gBAAIf,OAAO,CAACI,YAAR,CAAqB,MAArB,CAAJ,EAAkC;AACjC,qBAAO,UAAP;AACA;;AACD,mBAAO,SAAP;;AAED,eAAK,QAAL;AACC,gBAAIJ,OAAO,CAACI,YAAR,CAAqB,MAArB,CAAJ,EAAkC;AACjC,qBAAO,UAAP;AACA;;AACD,mBAAO,WAAP;;AACD;AACC,mBAAO,IAAP;AA1BF;AA4BA;;AACD,SAAK,QAAL;AACC,UACCJ,OAAO,CAACI,YAAR,CAAqB,UAArB,KACCJ,OAAD,CAA+BgB,IAA/B,GAAsC,CAFvC,EAGE;AACD,eAAO,SAAP;AACA;;AACD,aAAO,UAAP;AAtDF;;AAwDA,SAAO,IAAP;AACA;;AAED,SAASN,eAAT,CAAyBV,OAAzB,EAA0D;AACzD,MAAMC,IAAI,GAAGD,OAAO,CAACc,YAAR,CAAqB,MAArB,CAAb;;AACA,MAAIb,IAAI,KAAK,IAAb,EAAmB;AAClB,QAAMQ,YAAY,GAAGR,IAAI,CAACgB,IAAL,GAAYC,KAAZ,CAAkB,GAAlB,EAAuB,CAAvB,CAArB,CADkB,CAElB;AACA;;AACA,QAAIT,YAAY,CAACU,MAAb,GAAsB,CAA1B,EAA6B;AAC5B,aAAOV,YAAP;AACA;AACD;;AAED,SAAO,IAAP;AACA","sourcesContent":["// https://w3c.github.io/html-aria/#document-conformance-requirements-for-use-of-aria-attributes-in-html\n\nimport { getLocalName } from \"./util\";\n\nconst localNameToRoleMappings: Record<string, string | undefined> = {\n\tarticle: \"article\",\n\taside: \"complementary\",\n\tbutton: \"button\",\n\tdatalist: \"listbox\",\n\tdd: \"definition\",\n\tdetails: \"group\",\n\tdialog: \"dialog\",\n\tdt: \"term\",\n\tfieldset: \"group\",\n\tfigure: \"figure\",\n\t// WARNING: Only with an accessible name\n\tform: \"form\",\n\tfooter: \"contentinfo\",\n\th1: \"heading\",\n\th2: \"heading\",\n\th3: \"heading\",\n\th4: \"heading\",\n\th5: \"heading\",\n\th6: \"heading\",\n\theader: \"banner\",\n\thr: \"separator\",\n\thtml: \"document\",\n\tlegend: \"legend\",\n\tli: \"listitem\",\n\tmath: \"math\",\n\tmain: \"main\",\n\tmenu: \"list\",\n\tnav: \"navigation\",\n\tol: \"list\",\n\toptgroup: \"group\",\n\t// WARNING: Only in certain context\n\toption: \"option\",\n\toutput: \"status\",\n\tprogress: \"progressbar\",\n\t// WARNING: Only with an accessible name\n\tsection: \"region\",\n\tsummary: \"button\",\n\ttable: \"table\",\n\ttbody: \"rowgroup\",\n\ttextarea: \"textbox\",\n\ttfoot: \"rowgroup\",\n\t// WARNING: Only in certain context\n\ttd: \"cell\",\n\tth: \"columnheader\",\n\tthead: \"rowgroup\",\n\ttr: \"row\",\n\tul: \"list\",\n};\n\nconst prohibitedAttributes: Record<string, Set<string>> = {\n\tcaption: new Set([\"aria-label\", \"aria-labelledby\"]),\n\tcode: new Set([\"aria-label\", \"aria-labelledby\"]),\n\tdeletion: new Set([\"aria-label\", \"aria-labelledby\"]),\n\temphasis: new Set([\"aria-label\", \"aria-labelledby\"]),\n\tgeneric: new Set([\"aria-label\", \"aria-labelledby\", \"aria-roledescription\"]),\n\tinsertion: new Set([\"aria-label\", \"aria-labelledby\"]),\n\tparagraph: new Set([\"aria-label\", \"aria-labelledby\"]),\n\tpresentation: new Set([\"aria-label\", \"aria-labelledby\"]),\n\tstrong: new Set([\"aria-label\", \"aria-labelledby\"]),\n\tsubscript: new Set([\"aria-label\", \"aria-labelledby\"]),\n\tsuperscript: new Set([\"aria-label\", \"aria-labelledby\"]),\n};\n\n/**\n *\n * @param element\n * @param role The role used for this element. This is specified to control whether you want to use the implicit or explicit role.\n */\nfunction hasGlobalAriaAttributes(element: Element, role: string): boolean {\n\t// https://rawgit.com/w3c/aria/stable/#global_states\n\t// commented attributes are deprecated\n\treturn [\n\t\t\"aria-atomic\",\n\t\t\"aria-busy\",\n\t\t\"aria-controls\",\n\t\t\"aria-current\",\n\t\t\"aria-describedby\",\n\t\t\"aria-details\",\n\t\t// \"disabled\",\n\t\t\"aria-dropeffect\",\n\t\t// \"errormessage\",\n\t\t\"aria-flowto\",\n\t\t\"aria-grabbed\",\n\t\t// \"haspopup\",\n\t\t\"aria-hidden\",\n\t\t// \"invalid\",\n\t\t\"aria-keyshortcuts\",\n\t\t\"aria-label\",\n\t\t\"aria-labelledby\",\n\t\t\"aria-live\",\n\t\t\"aria-owns\",\n\t\t\"aria-relevant\",\n\t\t\"aria-roledescription\",\n\t].some((attributeName) => {\n\t\treturn (\n\t\t\telement.hasAttribute(attributeName) &&\n\t\t\t!prohibitedAttributes[role]?.has(attributeName)\n\t\t);\n\t});\n}\n\nfunction ignorePresentationalRole(\n\telement: Element,\n\timplicitRole: string\n): boolean {\n\t// https://rawgit.com/w3c/aria/stable/#conflict_resolution_presentation_none\n\treturn hasGlobalAriaAttributes(element, implicitRole);\n}\n\nexport default function getRole(element: Element): string | null {\n\tconst explicitRole = getExplicitRole(element);\n\tif (explicitRole === null || explicitRole === \"presentation\") {\n\t\tconst implicitRole = getImplicitRole(element);\n\t\tif (\n\t\t\texplicitRole !== \"presentation\" ||\n\t\t\tignorePresentationalRole(element, implicitRole || \"\")\n\t\t) {\n\t\t\treturn implicitRole;\n\t\t}\n\t}\n\n\treturn explicitRole;\n}\n\nfunction getImplicitRole(element: Element): string | null {\n\tconst mappedByTag = localNameToRoleMappings[getLocalName(element)];\n\tif (mappedByTag !== undefined) {\n\t\treturn mappedByTag;\n\t}\n\n\tswitch (getLocalName(element)) {\n\t\tcase \"a\":\n\t\tcase \"area\":\n\t\tcase \"link\":\n\t\t\tif (element.hasAttribute(\"href\")) {\n\t\t\t\treturn \"link\";\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"img\":\n\t\t\tif (\n\t\t\t\telement.getAttribute(\"alt\") === \"\" &&\n\t\t\t\t!ignorePresentationalRole(element, \"img\")\n\t\t\t) {\n\t\t\t\treturn \"presentation\";\n\t\t\t}\n\t\t\treturn \"img\";\n\t\tcase \"input\": {\n\t\t\tconst { type } = element as HTMLInputElement;\n\t\t\tswitch (type) {\n\t\t\t\tcase \"button\":\n\t\t\t\tcase \"image\":\n\t\t\t\tcase \"reset\":\n\t\t\t\tcase \"submit\":\n\t\t\t\t\treturn \"button\";\n\t\t\t\tcase \"checkbox\":\n\t\t\t\tcase \"radio\":\n\t\t\t\t\treturn type;\n\t\t\t\tcase \"range\":\n\t\t\t\t\treturn \"slider\";\n\t\t\t\tcase \"email\":\n\t\t\t\tcase \"tel\":\n\t\t\t\tcase \"text\":\n\t\t\t\tcase \"url\":\n\t\t\t\t\tif (element.hasAttribute(\"list\")) {\n\t\t\t\t\t\treturn \"combobox\";\n\t\t\t\t\t}\n\t\t\t\t\treturn \"textbox\";\n\n\t\t\t\tcase \"search\":\n\t\t\t\t\tif (element.hasAttribute(\"list\")) {\n\t\t\t\t\t\treturn \"combobox\";\n\t\t\t\t\t}\n\t\t\t\t\treturn \"searchbox\";\n\t\t\t\tdefault:\n\t\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\tcase \"select\":\n\t\t\tif (\n\t\t\t\telement.hasAttribute(\"multiple\") ||\n\t\t\t\t(element as HTMLSelectElement).size > 1\n\t\t\t) {\n\t\t\t\treturn \"listbox\";\n\t\t\t}\n\t\t\treturn \"combobox\";\n\t}\n\treturn null;\n}\n\nfunction getExplicitRole(element: Element): string | null {\n\tconst role = element.getAttribute(\"role\");\n\tif (role !== null) {\n\t\tconst explicitRole = role.trim().split(\" \")[0];\n\t\t// String.prototype.split(sep, limit) will always return an array with at least one member\n\t\t// as long as limit is either undefined or > 0\n\t\tif (explicitRole.length > 0) {\n\t\t\treturn explicitRole;\n\t\t}\n\t}\n\n\treturn null;\n}\n"],"file":"getRole.mjs"} |