{"version":3,"file":"getTextColorBasedOnBgColor-B3qlUF2t.cjs","names":[],"sources":["../src/Utils/getTextColorBasedOnBgColor.ts"],"sourcesContent":["function getRGB(rgbString: string) {\r\n  const regex = /^rgb\\((\\d{1,3}),\\s*(\\d{1,3}),\\s*(\\d{1,3})\\)$/;\r\n  const result = regex.exec(rgbString);\r\n  if (result) {\r\n    const r = parseInt(result[1], 10);\r\n    const g = parseInt(result[2], 10);\r\n    const b = parseInt(result[3], 10);\r\n    return { r, g, b };\r\n  }\r\n  throw new Error('Invalid RGB string format');\r\n}\r\n\r\nfunction getRGBFromHex(hexValue: string) {\r\n  const hex = hexValue.replace(/^#/, '');\r\n  const r = parseInt(hex.substring(0, 2), 16);\r\n  const g = parseInt(hex.substring(2, 4), 16);\r\n  const b = parseInt(hex.substring(4, 6), 16);\r\n  return { r, g, b };\r\n}\r\n\r\nfunction getLuminance(r: number, g: number, b: number) {\r\n  const normalizedR = r / 255;\r\n  const normalizedG = g / 255;\r\n  const normalizedB = b / 255;\r\n\r\n  const adjustedR =\r\n    normalizedR <= 0.03928 ? normalizedR / 12.92 : ((normalizedR + 0.055) / 1.055) ** 2.4;\r\n  const adjustedG =\r\n    normalizedG <= 0.03928 ? normalizedG / 12.92 : ((normalizedG + 0.055) / 1.055) ** 2.4;\r\n  const adjustedB =\r\n    normalizedB <= 0.03928 ? normalizedB / 12.92 : ((normalizedB + 0.055) / 1.055) ** 2.4;\r\n\r\n  return 0.2126 * adjustedR + 0.7152 * adjustedG + 0.0722 * adjustedB;\r\n}\r\n\r\n/**\r\n * Returns a contrasting text color (`#000` or `#fff`) based on the given background color.\r\n *\r\n * @param bgColor - A background color string in either hex (e.g., `#ffffff`) or RGB format (e.g., `rgb(255,255,255)`).\r\n * @returns `'#000'` for light backgrounds, `'#fff'` for dark backgrounds.\r\n *\r\n * @example\r\n * getTextColorBasedOnBgColor('#000000'); // \"#fff\"\r\n * getTextColorBasedOnBgColor('rgb(255,255,255)'); // \"#000\"\r\n */\r\n\r\nexport const getTextColorBasedOnBgColor = (bgColor: string) => {\r\n  try {\r\n    const rgb = bgColor[0] === 'r' ? getRGB(bgColor) : getRGBFromHex(bgColor);\r\n    const luminance = getLuminance(rgb.r, rgb.g, rgb.b);\r\n    return luminance > 0.4 ? '#000' : '#fff';\r\n  } catch {\r\n    return '#fff';\r\n  }\r\n};\r\n"],"mappings":"AAAA,SAAS,EAAO,EAAmB,CAEjC,IAAM,EAAS,+CAAM,KAAK,CAAS,EACnC,GAAI,EAIF,MAAO,CAAE,EAHC,SAAS,EAAO,GAAI,EAGrB,EAAG,EAFF,SAAS,EAAO,GAAI,EAElB,EAAG,EADL,SAAS,EAAO,GAAI,EACf,CAAE,EAEnB,MAAU,MAAM,2BAA2B,CAC7C,CAEA,SAAS,EAAc,EAAkB,CACvC,IAAM,EAAM,EAAS,QAAQ,KAAM,EAAE,EAIrC,MAAO,CAAE,EAHC,SAAS,EAAI,UAAU,EAAG,CAAC,EAAG,EAG/B,EAAG,EAFF,SAAS,EAAI,UAAU,EAAG,CAAC,EAAG,EAE5B,EAAG,EADL,SAAS,EAAI,UAAU,EAAG,CAAC,EAAG,EACzB,CAAE,CACnB,CAEA,SAAS,EAAa,EAAW,EAAW,EAAW,CACrD,IAAM,EAAc,EAAI,IAClB,EAAc,EAAI,IAClB,EAAc,EAAI,IAElB,EACJ,GAAe,OAAU,EAAc,QAAU,EAAc,MAAS,QAAU,IAC9E,EACJ,GAAe,OAAU,EAAc,QAAU,EAAc,MAAS,QAAU,IAC9E,EACJ,GAAe,OAAU,EAAc,QAAU,EAAc,MAAS,QAAU,IAEpF,MAAO,OAAS,EAAY,MAAS,EAAY,MAAS,CAC5D,CAaA,IAAa,EAA8B,GAAoB,CAC7D,GAAI,CACF,IAAM,EAAM,EAAQ,KAAO,IAAM,EAAO,CAAO,EAAI,EAAc,CAAO,EAExE,OADkB,EAAa,EAAI,EAAG,EAAI,EAAG,EAAI,CAC1C,EAAY,GAAM,OAAS,MACpC,MAAQ,CACN,MAAO,MACT,CACF"}