@thecb/components 11.2.2 → 11.2.3-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -6248,6 +6248,38 @@ var adjustHexColor = function adjustHexColor(hex, percent, action) {
6248
6248
  return "#".concat(((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1).padStart(6, "0"));
6249
6249
  };
6250
6250
 
6251
+ /**
6252
+ * Converts a hex color code to an RGBA color string with the specified alpha value.
6253
+ *
6254
+ * @param {string} hex - The hex color code (e.g., "#3498db" or "3498db").
6255
+ * @param {number} alpha - The alpha value (opacity) between 0 and 1.
6256
+ * @returns {string} - The RGBA color string (e.g., "rgba(52, 152, 219, 0.5)").
6257
+ * @throws {Error} - Throws an error if the hex code is not a valid 3 or 6-digit hex color.
6258
+ */
6259
+ var hexToRGBA = function hexToRGBA(hex, alpha) {
6260
+ // Remove hash at the start if present
6261
+ hex = hex.replace(/^\s*#/, "");
6262
+
6263
+ // If hex is 3 characters, convert it to 6 characters.
6264
+ if (hex.length === 3) {
6265
+ hex = hex.split("").map(function (_char) {
6266
+ return _char + _char;
6267
+ }).join("");
6268
+ }
6269
+
6270
+ // Validate hex length
6271
+ if (hex.length !== 6) {
6272
+ throw new Error("Invalid hex color provided. Expected a 3 or 6-digit hex color.");
6273
+ }
6274
+
6275
+ // Parse the hex color components
6276
+ var bigint = parseInt(hex, 16);
6277
+ var r = bigint >> 16 & 255;
6278
+ var g = bigint >> 8 & 255;
6279
+ var b = bigint & 255;
6280
+ return "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(alpha, ")");
6281
+ };
6282
+
6251
6283
  var general = /*#__PURE__*/Object.freeze({
6252
6284
  __proto__: null,
6253
6285
  noop: noop$1,
@@ -6269,7 +6301,8 @@ var general = /*#__PURE__*/Object.freeze({
6269
6301
  titleCaseString: titleCaseString,
6270
6302
  kebabCaseString: kebabCaseString,
6271
6303
  wrapIndex: wrapIndex,
6272
- adjustHexColor: adjustHexColor
6304
+ adjustHexColor: adjustHexColor,
6305
+ hexToRGBA: hexToRGBA
6273
6306
  });
6274
6307
 
6275
6308
  var _excluded$1 = ["themeValues", "weight", "color", "textWrap", "extraStyles", "hoverStyles", "onClick", "onKeyPress", "as", "dataQa", "children", "variant"];