You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
4.0 KiB
1 line
4.0 KiB
2 years ago
|
{"version":3,"sources":["../sources/is-inaccessible.ts"],"names":["isInaccessible","element","options","getComputedStyle","ownerDocument","defaultView","isSubtreeInaccessible","isSubtreeInaccessibleImpl","TypeError","visibility","currentElement","parentElement","hidden","getAttribute","display"],"mappings":";;;;;;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,cAAT,CACNC,OADM,EAGI;AAAA;;AAAA,MADVC,OACU,uEADuB,EACvB;AACV,8BAGIA,OAHJ,CACCC,gBADD;AAAA,MACCA,gBADD,+DACoBF,OAAO,CAACG,aAAR,CAAsBC,WAD1C,0DACoB,sBAAmCF,gBADvD;AAAA,8BAGID,OAHJ,CAECI,qBAFD;AAAA,MAEwBC,yBAFxB,sCAEoDD,qBAFpD;;AAIA,MAAI,OAAOH,gBAAP,KAA4B,UAAhC,EAA4C;AAC3C,UAAM,IAAIK,SAAJ,CACL,mEADK,CAAN;AAGA,GATS,CAUV;;;AACA,MAAIL,gBAAgB,CAACF,OAAD,CAAhB,CAA0BQ,UAA1B,KAAyC,QAA7C,EAAuD;AACtD,WAAO,IAAP;AACA;;AAED,MAAIC,cAA8B,GAAGT,OAArC;;AACA,SAAOS,cAAP,EAAuB;AACtB,QAAIH,yBAAyB,CAACG,cAAD,EAAiB;AAAEP,MAAAA,gBAAgB,EAAhBA;AAAF,KAAjB,CAA7B,EAAqE;AACpE,aAAO,IAAP;AACA;;AAEDO,IAAAA,cAAc,GAAGA,cAAc,CAACC,aAAhC;AACA;;AAED,SAAO,KAAP;AACA;;AAMD;AACA;AACA;AACA;AACA;AACA;AACO,SAASL,qBAAT,CACNL,OADM,EAGI;AAAA;;AAAA,MADVC,OACU,uEAD8B,EAC9B;AACV,+BAEIA,OAFJ,CACCC,gBADD;AAAA,MACCA,gBADD,iEACoBF,OAAO,CAACG,aAAR,CAAsBC,WAD1C,2DACoB,uBAAmCF,gBADvD;;AAGA,MAAI,OAAOA,gBAAP,KAA4B,UAAhC,EAA4C;AAC3C,UAAM,IAAIK,SAAJ,CACL,mEADK,CAAN;AAGA;;AAED,MAAKP,OAAD,CAAyBW,MAAzB,KAAoC,IAAxC,EAA8C;AAC7C,WAAO,IAAP;AACA;;AAED,MAAIX,OAAO,CAACY,YAAR,CAAqB,aAArB,MAAwC,MAA5C,EAAoD;AACnD,WAAO,IAAP;AACA;;AAED,MAAIV,gBAAgB,CAACF,OAAD,CAAhB,CAA0Ba,OAA1B,KAAsC,MAA1C,EAAkD;AACjD,WAAO,IAAP;AACA;;AAED,SAAO,KAAP;AACA","sourcesContent":["export interface IsInaccessibleOptions {\n\tgetComputedStyle?: typeof window.getComputedStyle;\n\t/**\n\t * Can be used to return cached results from previous isSubtreeInaccessible calls.\n\t */\n\tisSubtreeInaccessible?: (element: Element) => boolean;\n}\n\n/**\n * Partial implementation https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion\n * which should only be used for elements with a non-presentational role i.e.\n * `role=\"none\"` and `role=\"presentation\"` will not be excluded.\n *\n * Implements aria-hidden semantics (i.e. parent overrides child)\n * Ignores \"Child Presentational: True\" characteristics\n *\n * @param element\n * @param options\n * @returns {boolean} true if excluded, otherwise false\n */\nexport function isInaccessible(\n\telement: Element,\n\toptions: IsInaccessibleOptions = {}\n): boolean {\n\tconst {\n\t\tgetComputedStyle = element.ownerDocument.defaultView?.getComputedStyle,\n\t\tisSubtreeInaccessible: isSubtreeInaccessibleImpl = isSubtreeInaccessible,\n\t} = options;\n\tif (typeof getComputedStyle !== \"function\") {\n\t\tthrow new TypeError(\n\t\t\t\"Owner document of the element needs to have an associated window.\"\n\t\t);\n\t}\n\t// since visibility is inherited we can exit early\n\tif (getComputedStyle(element).visibility === \"hidden\") {\n\t\treturn true;\n\t}\n\n\tlet currentElement: Element | null = element;\n\twhile (currentElement) {\n\t\tif (isSubtreeInaccessibleImpl(currentElement, { getComputedStyle })) {\n\t\t\treturn true;\n\t\t}\n\n\t\tcurrentElement = currentElement.parentElement;\n\t}\n\n\treturn false;\n}\n\nexport interface IsSubtreeInaccessibleOptions {\n\tgetComputedStyle?: typeof window.getComputedStyle;\n}\n\n/**\n *\n * @param element\n * @param options\n * @returns {boolean} - `true` if every child of the element is inaccessible\n */\nexport function isSubtreeInaccessible(\n\telement: Element,\n\toptions: IsSubtreeInaccessibleOptions = {}\n): boolean {\n\tconst {\n\t\tgetComputedStyle = element.ownerDocument.defaultView?.getComputedStyle,\n\t} = options;\n\tif (typeof getComputedStyle !== \"function\") {\n\t\tthrow new TypeError(\n\t\t\t\"Owner document of the element needs to have an associated window.\"\n\t\t);\n\t}\n\n\tif ((element as HTMLElement).hidden === true) {\n\t\treturn true;\n\t}\n\n\tif (element.getAttribute(\"aria-hidden\") === \"true\") {\n\t\treturn true;\n\t}\n\n\tif (getComputedStyle(element).display === \"none\") {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n"],"file":"is-inaccessible.js
|