@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.cjs.js CHANGED
@@ -6256,6 +6256,38 @@ var adjustHexColor = function adjustHexColor(hex, percent, action) {
6256
6256
  return "#".concat(((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1).padStart(6, "0"));
6257
6257
  };
6258
6258
 
6259
+ /**
6260
+ * Converts a hex color code to an RGBA color string with the specified alpha value.
6261
+ *
6262
+ * @param {string} hex - The hex color code (e.g., "#3498db" or "3498db").
6263
+ * @param {number} alpha - The alpha value (opacity) between 0 and 1.
6264
+ * @returns {string} - The RGBA color string (e.g., "rgba(52, 152, 219, 0.5)").
6265
+ * @throws {Error} - Throws an error if the hex code is not a valid 3 or 6-digit hex color.
6266
+ */
6267
+ var hexToRGBA = function hexToRGBA(hex, alpha) {
6268
+ // Remove hash at the start if present
6269
+ hex = hex.replace(/^\s*#/, "");
6270
+
6271
+ // If hex is 3 characters, convert it to 6 characters.
6272
+ if (hex.length === 3) {
6273
+ hex = hex.split("").map(function (_char) {
6274
+ return _char + _char;
6275
+ }).join("");
6276
+ }
6277
+
6278
+ // Validate hex length
6279
+ if (hex.length !== 6) {
6280
+ throw new Error("Invalid hex color provided. Expected a 3 or 6-digit hex color.");
6281
+ }
6282
+
6283
+ // Parse the hex color components
6284
+ var bigint = parseInt(hex, 16);
6285
+ var r = bigint >> 16 & 255;
6286
+ var g = bigint >> 8 & 255;
6287
+ var b = bigint & 255;
6288
+ return "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(alpha, ")");
6289
+ };
6290
+
6259
6291
  var general = /*#__PURE__*/Object.freeze({
6260
6292
  __proto__: null,
6261
6293
  noop: noop$1,
@@ -6277,7 +6309,8 @@ var general = /*#__PURE__*/Object.freeze({
6277
6309
  titleCaseString: titleCaseString,
6278
6310
  kebabCaseString: kebabCaseString,
6279
6311
  wrapIndex: wrapIndex,
6280
- adjustHexColor: adjustHexColor
6312
+ adjustHexColor: adjustHexColor,
6313
+ hexToRGBA: hexToRGBA
6281
6314
  });
6282
6315
 
6283
6316
  var _excluded$1 = ["themeValues", "weight", "color", "textWrap", "extraStyles", "hoverStyles", "onClick", "onKeyPress", "as", "dataQa", "children", "variant"];