Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
package.dist.util.AriaLabelHelper.js.map Maven / Gradle / Ivy
{"version":3,"file":"AriaLabelHelper.js","sourceRoot":"","sources":["../../src/util/AriaLabelHelper.ts"],"names":[],"mappings":"AAgBA,MAAM,kBAAkB,GAAG,IAAI,OAAO,EAAkC,CAAC;AACzE,MAAM,kBAAkB,GAAG,IAAI,OAAO,EAAiC,CAAC;AAOxE,MAAM,eAAe,GAAG;IACvB,UAAU,EAAE,IAAI;IAChB,SAAS,EAAE,IAAI;IACf,aAAa,EAAE,IAAI;IACnB,OAAO,EAAE,IAAI;CACb,CAAC;AAEF,MAAM,yBAAyB,GAAG,CAAC,EAAe,EAAE,EAAE;IACrD,MAAM,YAAY,GAAG,EAAuB,CAAC;IAE7C,IAAI,CAAC,YAAY,CAAC,iBAAiB,EAAE;QACpC,IAAI,YAAY,CAAC,cAAc,EAAE;YAChC,OAAO,YAAY,CAAC,cAAc,CAAC;SACnC;QAED,OAAO,SAAS,CAAC;KACjB;IAED,OAAO,4BAA4B,CAAC,EAAE,CAAC,CAAC;AACzC,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,4BAA4B,GAAG,CAAC,EAAe,EAAE,EAAE;IACxD,MAAM,GAAG,GAAI,EAAwB,CAAC,iBAAiB,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IAC1E,MAAM,KAAK,GAAG,EAAE,CAAC,WAAW,EAAiB,CAAC;IAC9C,IAAI,MAAM,GAAG,EAAE,CAAC;IAEhB,GAAG,CAAC,OAAO,CAAC,CAAC,SAAiB,EAAE,KAAa,EAAE,EAAE;QAChD,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAAC,QAAQ,SAAS,IAAI,CAAC,CAAC;QAC3D,MAAM,IAAI,GAAG,GAAG,OAAO,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,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G,iBAAiB,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAC5G,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,MAAM,EAAE;YACxC,iBAAiB,CAAC,QAAQ,EAAE,UAAU,EAAE,CAAC;YACzC,kBAAkB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;SACnC;KACD;IACD,iBAAiB,CAAC,gBAAgB,GAAG,iBAAiB,CAAC,gBAAgB,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,OAAO,CAAC,CAAC;AACxG,CAAC,CAAC;AAEF,MAAM,oBAAoB,GAAG,CAAC,EAAc,EAAE,EAAE;IAC/C,MAAM,iBAAiB,GAAG,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACrD,IAAI,CAAC,iBAAiB,EAAE;QACvB,OAAO;KACP;IACD,MAAM,mBAAmB,GAAG,CAAC,GAAG,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;IACpE,mBAAmB,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE;QAC7C,2CAA2C,CAAC,iBAAiB,EAAE,eAAe,CAAC,CAAC;IACjF,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,CAAC;IAC5D,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAC/B,CAAC,CAAC;AAEF,OAAO,EACN,yBAAyB,EACzB,0BAA0B,EAC1B,kBAAkB,EAClB,oBAAoB,EACpB,4BAA4B,GAC5B,CAAC","sourcesContent":["import type UI5Element from \"../UI5Element.js\";\nimport type { ChangeInfo } from \"../UI5Element.js\";\n\ntype InvalidateCallback = (changeInfo: ChangeInfo) => void;\ntype MutationCallback = () => void;\ntype AssociatedElement = {\n\tobserver: MutationObserver | null;\n\tcallbacks: Array;\n};\ntype RegisteredElement = {\n\thost: UI5Element;\n\tobservedElements: Array;\n\tcallback: MutationCallback;\n\tinvalidationCallback: InvalidateCallback;\n};\n\nconst associatedElements = new WeakMap();\nconst registeredElements = new WeakMap();\n\ntype AccessibleElement = HTMLElement & {\n\taccessibleNameRef?: string;\n\taccessibleName?: string;\n};\n\nconst observerOptions = {\n\tattributes: true,\n\tchildList: true,\n\tcharacterData: true,\n\tsubtree: true,\n};\n\nconst getEffectiveAriaLabelText = (el: HTMLElement) => {\n\tconst accessibleEl = el as AccessibleElement;\n\n\tif (!accessibleEl.accessibleNameRef) {\n\t\tif (accessibleEl.accessibleName) {\n\t\t\treturn accessibleEl.accessibleName;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\treturn getAllAccessibleNameRefTexts(el);\n};\n\n/**\n *\n * @param {HTMLElement} el Defines the HTMLElement, for which you need to get all related texts\n */\nconst getAllAccessibleNameRefTexts = (el: HTMLElement) => {\n\tconst ids = (el as AccessibleElement).accessibleNameRef?.split(\" \") ?? [];\n\tconst owner = el.getRootNode() as HTMLElement;\n\tlet result = \"\";\n\n\tids.forEach((elementId: string, index: number) => {\n\t\tconst element = owner.querySelector(`[id='${elementId}']`);\n\t\tconst text = `${element && element.textContent ? element.textContent : \"\"}`;\n\t\tif (text) {\n\t\t\tresult += text;\n\t\t\tif (index < ids.length - 1) {\n\t\t\t\tresult += \" \";\n\t\t\t}\n\t\t}\n\t});\n\n\treturn result;\n};\n\nconst _getAllAssociatedElementsFromDOM = (el: UI5Element): Array => {\n\tconst set = new Set();\n\t// adding labels with attribute for matching the el.id\n\tconst labelsForAssociated = _getAssociatedLabels(el);\n\tlabelsForAssociated.forEach(itm => {\n\t\tset.add(itm);\n\t});\n\t// adding other elements that id is the same as accessibleNameRef value\n\tconst value = el[\"accessibleNameRef\" as keyof typeof el] as string;\n\tconst ids = value?.split(\" \") ?? [];\n\tids.forEach(id => {\n\t\tconst refEl = _getReferencedElementById(el, id);\n\t\tif (refEl) {\n\t\t\tset.add(refEl);\n\t\t}\n\t});\n\treturn Array.from(set);\n};\n\nconst _getAssociatedLabels = (el: HTMLElement): Array => {\n\tconst labels = (el.getRootNode() as HTMLElement).querySelectorAll(`[for=\"${el.id}\"]`);\n\treturn Array.from(labels);\n};\n\nconst _getReferencedElementById = (el: HTMLElement, elementId: string): HTMLElement | null => {\n\treturn (el.getRootNode() as HTMLElement).querySelector(`[id='${elementId}']`);\n};\n\n/**\n * @param {HTMLElement} el Defines the HTMLElement, for which you need to get all related \"label for\" texts\n */\nconst getAssociatedLabelForTexts = (el: HTMLElement) => {\n\tconst results: Array = [];\n\tconst labels = _getAssociatedLabels(el);\n\n\tlabels.forEach((label: HTMLElement) => {\n\t\tconst labelText = label.textContent;\n\t\tlabelText && results.push(labelText);\n\t});\n\n\tif (results.length) {\n\t\treturn results.join(\" \");\n\t}\n\n\treturn undefined;\n};\n\nconst _createInvalidationCallback = (el: UI5Element) => {\n\tconst invalidationCallback = (changeInfo: ChangeInfo) => {\n\t\tif (!(changeInfo && changeInfo.type === \"property\" && changeInfo.name === \"accessibleNameRef\")) {\n\t\t\treturn;\n\t\t}\n\t\tconst registeredElement = registeredElements.get(el);\n\t\tif (!registeredElement) {\n\t\t\treturn;\n\t\t}\n\t\tconst oldAssociatedElements = registeredElement.observedElements;\n\t\tconst newAssociatedElements = _getAllAssociatedElementsFromDOM(el);\n\t\toldAssociatedElements.forEach(oldElement => {\n\t\t\tif (!newAssociatedElements.includes(oldElement)) {\n\t\t\t\t_removeObservedElementFromRegisteredElement(registeredElement, oldElement);\n\t\t\t}\n\t\t});\n\t\tnewAssociatedElements.forEach(newElement => {\n\t\t\tif (!oldAssociatedElements.includes(newElement)) {\n\t\t\t\t_addObservedElementToRegisteredElement(registeredElement, newElement);\n\t\t\t\tregisteredElement.observedElements.push(newElement);\n\t\t\t}\n\t\t});\n\t\tregisteredElement?.callback();\n\t};\n\treturn invalidationCallback;\n};\n\nconst registerUI5Element = (el: UI5Element, callback: MutationCallback) => {\n\tif (registeredElements.has(el)) {\n\t\treturn;\n\t}\n\tconst allAssociatedElements = _getAllAssociatedElementsFromDOM(el);\n\tconst invalidationCallback = _createInvalidationCallback(el);\n\tconst registeredElement = {\n\t\thost: el,\n\t\tobservedElements: allAssociatedElements,\n\t\tcallback,\n\t\tinvalidationCallback,\n\t};\n\tregisteredElements.set(el, registeredElement);\n\tel.attachInvalidate(invalidationCallback);\n\n\tallAssociatedElements.forEach((element: HTMLElement) => {\n\t\t_addObservedElementToRegisteredElement(registeredElement, element);\n\t});\n\tcallback();\n};\n\nconst _addObservedElementToRegisteredElement = (registeredElement: RegisteredElement, element: HTMLElement) => {\n\tlet associatedElement = associatedElements.get(element);\n\tif (!associatedElement) {\n\t\tassociatedElement = { observer: null, callbacks: [] };\n\t\tconst observer = new MutationObserver(() => {\n\t\t\tconst callbacks = (associatedElement as AssociatedElement).callbacks;\n\t\t\tcallbacks.forEach(callback => {\n\t\t\t\tcallback();\n\t\t\t});\n\t\t\tconst domEl = document.getElementById(element.id);\n\t\t\t// if no longer should be observed from this registeredElement, remove it\n\t\t\tif (!(registeredElement.host.id === element.getAttribute(\"for\") || domEl)) {\n\t\t\t\t_removeObservedElementFromRegisteredElement(registeredElement, element);\n\t\t\t}\n\t\t});\n\t\tassociatedElement.observer = observer;\n\t\tobserver.observe(element, observerOptions);\n\t\tassociatedElements.set(element, associatedElement);\n\t}\n\tif (!associatedElement.callbacks.includes(registeredElement.callback)) {\n\t\tassociatedElement.callbacks.push(registeredElement.callback);\n\t}\n};\n\nconst _removeObservedElementFromRegisteredElement = (registeredElement: RegisteredElement, element: HTMLElement) => {\n\tconst associatedElement = associatedElements.get(element);\n\tif (associatedElement) {\n\t\tassociatedElement.callbacks = associatedElement.callbacks.filter(itm => itm !== registeredElement.callback);\n\t\tif (!associatedElement.callbacks.length) {\n\t\t\tassociatedElement.observer?.disconnect();\n\t\t\tassociatedElements.delete(element);\n\t\t}\n\t}\n\tregisteredElement.observedElements = registeredElement.observedElements.filter(itm => itm !== element);\n};\n\nconst deregisterUI5Element = (el: UI5Element) => {\n\tconst registeredElement = registeredElements.get(el);\n\tif (!registeredElement) {\n\t\treturn;\n\t}\n\tconst oldObservedElements = [...registeredElement.observedElements];\n\toldObservedElements.forEach(observedElement => {\n\t\t_removeObservedElementFromRegisteredElement(registeredElement, observedElement);\n\t});\n\tel.detachInvalidate(registeredElement.invalidationCallback);\n\tregisteredElements.delete(el);\n};\n\nexport {\n\tgetEffectiveAriaLabelText,\n\tgetAssociatedLabelForTexts,\n\tregisterUI5Element,\n\tderegisterUI5Element,\n\tgetAllAccessibleNameRefTexts,\n};\n"]}