Source: selector/methods/DataAttrSelector.js

(function() {
    /** @augments Help4.selector.methods.BaseSelector */
    Help4.selector.methods.DataAttrSelector = class extends Help4.selector.methods.BaseSelector {
        /** @type {string[]} */
        static ATTRIBUTES = ['data-help-id', 'data-helpkey', 'data-tilecatalogid', 'data-ui5-stable'];
        /** @type {Object} */
        static BLOCK =  {'data-ui5-stable':  [/^ui5wc_/]};

        /**
         * @param {string} selector
         * @return {?HTMLElement}
         */
        static getElement(selector) {
            const {Utils} = Help4.selector.methods;

            if (selector.includes('data-help-id=')) {  // XRAY-5098
                const selector2 = selector.replace(/data-help-id=/, 'data-help-id2=');
                const element = Utils.getElement(selector2);
                if (element) return element;
            }

            return Utils.getElement(selector);
        }

        /**
         * @param {HTMLElement} element
         * @return {?Help4.selector.methods.Selector}
         */
        static getSelector(element) {
            const {methods, SELECTOR_QUALITY: {best: quality}} = Help4.selector;
            const {ATTRIBUTES, BLOCK} = this;

            for (const attName of ATTRIBUTES) {
                const isDataHelpId = attName === 'data-help-id';  // XRAY-5098
                const attValue = isDataHelpId
                    ? element.getAttribute('data-help-id2') || element.getAttribute(attName)  // XRAY-5098: prefer data-help-id2, if available
                    : element.getAttribute(attName);

                if (attValue) {
                    const block = BLOCK[attName];
                    if (block && block.some(rx => rx.test(attValue))) break;

                    const value = `*[${attName}='${methods.$E(attValue)}']`;

                    if (isDataHelpId) {
                        const value2 = value.replace(/data-help-id/, 'data-help-id2');
                        if (methods.$(value2).length === 1) return {value, quality};
                    }

                    if (methods.$(value).length === 1) return {value, quality};
                }
            }

            return null;
        }
    }
})();