}}/** * Convert a hex color value to an RGB array * * @param {string} hex - The hex value of the color you want to convert. * @returns {Array<number>|null} The RGB values of the hex color **/function t_catalog_hexToRgb(hex) { // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF") var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; var expandedHex = hex.replace(shorthandRegex, function (m, r, g, b) { return r + r + g + g + b + b; }); var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(expandedHex); var colorModel = result ? { r: parseInt(result[1], 16), g: parseInt(result[2], 16), b: parseInt(result[3], 16), } : null; // TODO ST-2949_3: null / undefined (TS18047, TS18048, TS2531, TS2722, TS2454, TS2538) // @ts-expect-error ST-2949_3 return result ? [colorModel.r, colorModel.g, colorModel.b] : null;}/** * get first color from gradient and transform from RGBA to RGB * * @param {string} gradient - gradient * @returns {Array<*>} - color in RGB format */function t_catalog_getFirstColorFromGradient(gradient) { var rgbaRegExp = /rgba\(\d+,\d+,\d+,\d+\)/gi; var rgbComponentsRegExp = /(\d+),(\d+),(\d+)/i; var gradientColors = gradient.match(rgbaRegExp); var colorRgba = gradientColors ? gradientColors[0] : null; // TODO ST-2949_5: assignability, arguments, calls, return types (TS2345, TS2322, TS2554, TS2769, TS2740, TS2739, TS2353, TS2349, TS2355, TS2366, TS2774, TS18046) // @ts-expect-error ST-2949_5 var result = rgbComponentsRegExp.exec(colorRgba); var colorModel = result ? { r: result[1], g: result[2], b: result[3], } : null; // TODO ST-2949_3: null / undefined (TS18047, TS18048, TS2531, TS2722, TS2454, TS2538) // @ts-expect-error ST-2949_3 return result ? [colorModel.r, colorModel.g, colorModel.b] : null;}/** * Parse string color to rgb components * * @param {number[]|string} color - the color to parsed * @returns {number[]|null} - parsed color or `null` if parsing was not successful **/function t_catalog_parsecolor(color) { if (Array.isArray(color) && color.length === 3) return color; if (!color || typeof color !== 'string') return null; // Парсинг глобального стиля цвета const varRegexp = /^var\((--uc-color-color-[a-zA-Z0-9]+),\s*(.+)\)$/; const varMatch = varRegexp.exec(color); let colorString = color; if (varMatch && varMatch[1]) { const varName = varMatch[1]; const bodyStyle = window.getComputedStyle(document.body); colorString = bodyStyle.getPropertyValue(varName) || varMatch[2]; } const rgbMatch = /^rgba?\(([0-9]+),\s*([0-9]+),\s*([0-9]+)(?:,\s*[0-9.%]+)?\)$/i.exec(colorString); const hexMatch = /^#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})$/i.exec(colorString); if (rgbMatch) { const components = rgbMatch.splice(1).map(comp => parseInt(comp, 10)); return components; } if (hexMatch) { const components = hexMatch.splice(1).map(comp => parseInt(comp, 16));