@react-hive/honey-utils 3.24.0 → 3.25.0

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.
@@ -815,6 +815,79 @@ const timeout = async (promise, timeoutMs, errorMessage = 'Operation timed out')
815
815
  };
816
816
 
817
817
 
818
+ /***/ }),
819
+
820
+ /***/ "./src/color/hex-with-alpha.ts":
821
+ /*!*************************************!*\
822
+ !*** ./src/color/hex-with-alpha.ts ***!
823
+ \*************************************/
824
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
825
+
826
+ __webpack_require__.r(__webpack_exports__);
827
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
828
+ /* harmony export */ hexWithAlpha: () => (/* binding */ hexWithAlpha)
829
+ /* harmony export */ });
830
+ /* harmony import */ var _guards__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ~/guards */ "./src/guards.ts");
831
+
832
+ /**
833
+ * Adds an alpha channel to a 3- or 6-digit HEX color.
834
+ *
835
+ * Accepts `#RGB`, `#RRGGBB`, `RGB`, or `RRGGBB` formats
836
+ * and returns a normalized 8-digit HEX color in `#RRGGBBAA` format.
837
+ *
838
+ * The alpha value is converted to a two-digit hexadecimal
839
+ * representation using `Math.round(alpha * 255)`.
840
+ *
841
+ * @param input - Base HEX color (3 or 6 hex digits, with or without `#`).
842
+ * @param alpha - Opacity value between `0` (transparent) and `1` (opaque).
843
+ *
844
+ * @throws {Error}
845
+ * - If `alpha` is outside the `[0, 1]` range.
846
+ * - If `hex` is not a valid 3- or 6-digit hexadecimal color.
847
+ *
848
+ * @returns A normalized 8-digit HEX color in `#RRGGBBAA` format.
849
+ *
850
+ * @example
851
+ * ```ts
852
+ * hexWithAlpha('#ff0000', 0.5) // '#FF000080'
853
+ * hexWithAlpha('0f0', 1) // '#00FF00FF'
854
+ * ```
855
+ */
856
+ const hexWithAlpha = (input, alpha) => {
857
+ (0,_guards__WEBPACK_IMPORTED_MODULE_0__.assert)(alpha >= 0 && alpha <= 1, `[@react-hive/honey-utils]: Alpha "${alpha}" must be a number between 0 and 1.`);
858
+ const hexRegex = /^#?([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;
859
+ const match = input.match(hexRegex);
860
+ (0,_guards__WEBPACK_IMPORTED_MODULE_0__.assert)(match, `[@react-hive/honey-utils]: Invalid hex format: ${input}`);
861
+ const cleanHex = match[1];
862
+ // Expand 3-character hex to 6-character hex if necessary
863
+ const fullHex = cleanHex.length === 3
864
+ ? cleanHex[0] + cleanHex[0] + cleanHex[1] + cleanHex[1] + cleanHex[2] + cleanHex[2]
865
+ : cleanHex;
866
+ // Convert to 8-character hex with alpha
867
+ const alphaHex = Math.round(alpha * 255)
868
+ .toString(16)
869
+ .toUpperCase()
870
+ .padStart(2, '0');
871
+ return `#${fullHex + alphaHex}`;
872
+ };
873
+
874
+
875
+ /***/ }),
876
+
877
+ /***/ "./src/color/index.ts":
878
+ /*!****************************!*\
879
+ !*** ./src/color/index.ts ***!
880
+ \****************************/
881
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
882
+
883
+ __webpack_require__.r(__webpack_exports__);
884
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
885
+ /* harmony export */ hexWithAlpha: () => (/* reexport safe */ _hex_with_alpha__WEBPACK_IMPORTED_MODULE_0__.hexWithAlpha)
886
+ /* harmony export */ });
887
+ /* harmony import */ var _hex_with_alpha__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./hex-with-alpha */ "./src/color/hex-with-alpha.ts");
888
+
889
+
890
+
818
891
  /***/ }),
819
892
 
820
893
  /***/ "./src/dom/dom.ts":
@@ -3261,6 +3334,7 @@ __webpack_require__.r(__webpack_exports__);
3261
3334
  /* harmony export */ hasXOverflow: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_3__.hasXOverflow),
3262
3335
  /* harmony export */ hasYOverflow: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_3__.hasYOverflow),
3263
3336
  /* harmony export */ hashString: () => (/* reexport safe */ _math__WEBPACK_IMPORTED_MODULE_11__.hashString),
3337
+ /* harmony export */ hexWithAlpha: () => (/* reexport safe */ _color__WEBPACK_IMPORTED_MODULE_16__.hexWithAlpha),
3264
3338
  /* harmony export */ intersection: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.intersection),
3265
3339
  /* harmony export */ invokeIfFunction: () => (/* reexport safe */ _function__WEBPACK_IMPORTED_MODULE_6__.invokeIfFunction),
3266
3340
  /* harmony export */ isAnchorHtmlElement: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_3__.isAnchorHtmlElement),
@@ -3332,6 +3406,8 @@ __webpack_require__.r(__webpack_exports__);
3332
3406
  /* harmony import */ var _string__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./string */ "./src/string/index.ts");
3333
3407
  /* harmony import */ var _tree__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./tree */ "./src/tree/index.ts");
3334
3408
  /* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./types */ "./src/types.ts");
3409
+ /* harmony import */ var _color__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./color */ "./src/color/index.ts");
3410
+
3335
3411
 
3336
3412
 
3337
3413