@react-hive/honey-utils 3.24.0 → 3.26.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,126 @@ 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
+
891
+ /***/ }),
892
+
893
+ /***/ "./src/dom/data-transfer.ts":
894
+ /*!**********************************!*\
895
+ !*** ./src/dom/data-transfer.ts ***!
896
+ \**********************************/
897
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
898
+
899
+ __webpack_require__.r(__webpack_exports__);
900
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
901
+ /* harmony export */ DATA_TRANSFER_JSON_MIME: () => (/* binding */ DATA_TRANSFER_JSON_MIME),
902
+ /* harmony export */ getDataTransferJson: () => (/* binding */ getDataTransferJson),
903
+ /* harmony export */ setDataTransferJson: () => (/* binding */ setDataTransferJson)
904
+ /* harmony export */ });
905
+ const DATA_TRANSFER_JSON_MIME = 'application/json';
906
+ /**
907
+ * Serializes and stores JSON data in a DataTransfer object.
908
+ *
909
+ * Useful for drag-and-drop communication between elements.
910
+ *
911
+ * @param dataTransfer DataTransfer instance from a drag event.
912
+ * @param data Data to serialize.
913
+ */
914
+ const setDataTransferJson = (dataTransfer, data) => {
915
+ dataTransfer.setData(DATA_TRANSFER_JSON_MIME, JSON.stringify(data));
916
+ };
917
+ /**
918
+ * Retrieves and parses JSON data from a DataTransfer object.
919
+ *
920
+ * @param dataTransfer DataTransfer instance from a drop event.
921
+ *
922
+ * @returns Parsed JSON value or undefined if not present or invalid.
923
+ */
924
+ const getDataTransferJson = (dataTransfer) => {
925
+ const rawData = dataTransfer.getData(DATA_TRANSFER_JSON_MIME);
926
+ if (!rawData) {
927
+ return undefined;
928
+ }
929
+ try {
930
+ return JSON.parse(rawData);
931
+ }
932
+ catch {
933
+ return undefined;
934
+ }
935
+ };
936
+
937
+
818
938
  /***/ }),
819
939
 
820
940
  /***/ "./src/dom/dom.ts":
@@ -968,22 +1088,27 @@ __webpack_require__.r(__webpack_exports__);
968
1088
 
969
1089
  __webpack_require__.r(__webpack_exports__);
970
1090
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
971
- /* harmony export */ centerElementInContainer: () => (/* reexport safe */ _layout__WEBPACK_IMPORTED_MODULE_2__.centerElementInContainer),
972
- /* harmony export */ cloneBlob: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_0__.cloneBlob),
973
- /* harmony export */ downloadFile: () => (/* reexport safe */ _file__WEBPACK_IMPORTED_MODULE_1__.downloadFile),
974
- /* harmony export */ getElementOffsetRect: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_0__.getElementOffsetRect),
975
- /* harmony export */ getXOverflowWidth: () => (/* reexport safe */ _layout__WEBPACK_IMPORTED_MODULE_2__.getXOverflowWidth),
976
- /* harmony export */ getYOverflowHeight: () => (/* reexport safe */ _layout__WEBPACK_IMPORTED_MODULE_2__.getYOverflowHeight),
977
- /* harmony export */ hasXOverflow: () => (/* reexport safe */ _layout__WEBPACK_IMPORTED_MODULE_2__.hasXOverflow),
978
- /* harmony export */ hasYOverflow: () => (/* reexport safe */ _layout__WEBPACK_IMPORTED_MODULE_2__.hasYOverflow),
979
- /* harmony export */ isAnchorHtmlElement: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_0__.isAnchorHtmlElement),
980
- /* harmony export */ isContentEditableHtmlElement: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_0__.isContentEditableHtmlElement),
981
- /* harmony export */ parse2DMatrix: () => (/* reexport safe */ _transform__WEBPACK_IMPORTED_MODULE_3__.parse2DMatrix)
1091
+ /* harmony export */ DATA_TRANSFER_JSON_MIME: () => (/* reexport safe */ _data_transfer__WEBPACK_IMPORTED_MODULE_0__.DATA_TRANSFER_JSON_MIME),
1092
+ /* harmony export */ centerElementInContainer: () => (/* reexport safe */ _layout__WEBPACK_IMPORTED_MODULE_3__.centerElementInContainer),
1093
+ /* harmony export */ cloneBlob: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_1__.cloneBlob),
1094
+ /* harmony export */ downloadFile: () => (/* reexport safe */ _file__WEBPACK_IMPORTED_MODULE_2__.downloadFile),
1095
+ /* harmony export */ getDataTransferJson: () => (/* reexport safe */ _data_transfer__WEBPACK_IMPORTED_MODULE_0__.getDataTransferJson),
1096
+ /* harmony export */ getElementOffsetRect: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_1__.getElementOffsetRect),
1097
+ /* harmony export */ getXOverflowWidth: () => (/* reexport safe */ _layout__WEBPACK_IMPORTED_MODULE_3__.getXOverflowWidth),
1098
+ /* harmony export */ getYOverflowHeight: () => (/* reexport safe */ _layout__WEBPACK_IMPORTED_MODULE_3__.getYOverflowHeight),
1099
+ /* harmony export */ hasXOverflow: () => (/* reexport safe */ _layout__WEBPACK_IMPORTED_MODULE_3__.hasXOverflow),
1100
+ /* harmony export */ hasYOverflow: () => (/* reexport safe */ _layout__WEBPACK_IMPORTED_MODULE_3__.hasYOverflow),
1101
+ /* harmony export */ isAnchorHtmlElement: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_1__.isAnchorHtmlElement),
1102
+ /* harmony export */ isContentEditableHtmlElement: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_1__.isContentEditableHtmlElement),
1103
+ /* harmony export */ parse2DMatrix: () => (/* reexport safe */ _transform__WEBPACK_IMPORTED_MODULE_4__.parse2DMatrix),
1104
+ /* harmony export */ setDataTransferJson: () => (/* reexport safe */ _data_transfer__WEBPACK_IMPORTED_MODULE_0__.setDataTransferJson)
982
1105
  /* harmony export */ });
983
- /* harmony import */ var _dom__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./dom */ "./src/dom/dom.ts");
984
- /* harmony import */ var _file__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./file */ "./src/dom/file/index.ts");
985
- /* harmony import */ var _layout__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./layout */ "./src/dom/layout/index.ts");
986
- /* harmony import */ var _transform__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./transform */ "./src/dom/transform/index.ts");
1106
+ /* harmony import */ var _data_transfer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./data-transfer */ "./src/dom/data-transfer.ts");
1107
+ /* harmony import */ var _dom__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./dom */ "./src/dom/dom.ts");
1108
+ /* harmony import */ var _file__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./file */ "./src/dom/file/index.ts");
1109
+ /* harmony import */ var _layout__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./layout */ "./src/dom/layout/index.ts");
1110
+ /* harmony import */ var _transform__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./transform */ "./src/dom/transform/index.ts");
1111
+
987
1112
 
988
1113
 
989
1114
 
@@ -3222,6 +3347,7 @@ var __webpack_exports__ = {};
3222
3347
  \**********************/
3223
3348
  __webpack_require__.r(__webpack_exports__);
3224
3349
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
3350
+ /* harmony export */ DATA_TRANSFER_JSON_MIME: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_3__.DATA_TRANSFER_JSON_MIME),
3225
3351
  /* harmony export */ FOCUSABLE_HTML_TAGS: () => (/* reexport safe */ _a11y__WEBPACK_IMPORTED_MODULE_0__.FOCUSABLE_HTML_TAGS),
3226
3352
  /* harmony export */ applyInertiaStep: () => (/* reexport safe */ _geometry__WEBPACK_IMPORTED_MODULE_7__.applyInertiaStep),
3227
3353
  /* harmony export */ assert: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_8__.assert),
@@ -3251,6 +3377,7 @@ __webpack_require__.r(__webpack_exports__);
3251
3377
  /* harmony export */ forEachChar: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_13__.forEachChar),
3252
3378
  /* harmony export */ generateEphemeralId: () => (/* reexport safe */ _id__WEBPACK_IMPORTED_MODULE_9__.generateEphemeralId),
3253
3379
  /* harmony export */ getDOMRectIntersectionRatio: () => (/* reexport safe */ _intersection__WEBPACK_IMPORTED_MODULE_10__.getDOMRectIntersectionRatio),
3380
+ /* harmony export */ getDataTransferJson: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_3__.getDataTransferJson),
3254
3381
  /* harmony export */ getElementOffsetRect: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_3__.getElementOffsetRect),
3255
3382
  /* harmony export */ getFocusableHtmlElements: () => (/* reexport safe */ _a11y__WEBPACK_IMPORTED_MODULE_0__.getFocusableHtmlElements),
3256
3383
  /* harmony export */ getLocalStorageCapabilities: () => (/* reexport safe */ _env__WEBPACK_IMPORTED_MODULE_4__.getLocalStorageCapabilities),
@@ -3261,6 +3388,7 @@ __webpack_require__.r(__webpack_exports__);
3261
3388
  /* harmony export */ hasXOverflow: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_3__.hasXOverflow),
3262
3389
  /* harmony export */ hasYOverflow: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_3__.hasYOverflow),
3263
3390
  /* harmony export */ hashString: () => (/* reexport safe */ _math__WEBPACK_IMPORTED_MODULE_11__.hashString),
3391
+ /* harmony export */ hexWithAlpha: () => (/* reexport safe */ _color__WEBPACK_IMPORTED_MODULE_16__.hexWithAlpha),
3264
3392
  /* harmony export */ intersection: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.intersection),
3265
3393
  /* harmony export */ invokeIfFunction: () => (/* reexport safe */ _function__WEBPACK_IMPORTED_MODULE_6__.invokeIfFunction),
3266
3394
  /* harmony export */ isAnchorHtmlElement: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_3__.isAnchorHtmlElement),
@@ -3308,6 +3436,7 @@ __webpack_require__.r(__webpack_exports__);
3308
3436
  /* harmony export */ runParallel: () => (/* reexport safe */ _async__WEBPACK_IMPORTED_MODULE_2__.runParallel),
3309
3437
  /* harmony export */ runSequential: () => (/* reexport safe */ _async__WEBPACK_IMPORTED_MODULE_2__.runSequential),
3310
3438
  /* harmony export */ searchTree: () => (/* reexport safe */ _tree__WEBPACK_IMPORTED_MODULE_14__.searchTree),
3439
+ /* harmony export */ setDataTransferJson: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_3__.setDataTransferJson),
3311
3440
  /* harmony export */ someAsync: () => (/* reexport safe */ _async__WEBPACK_IMPORTED_MODULE_2__.someAsync),
3312
3441
  /* harmony export */ splitMapJoin: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_13__.splitMapJoin),
3313
3442
  /* harmony export */ splitStringIntoWords: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_13__.splitStringIntoWords),
@@ -3332,6 +3461,8 @@ __webpack_require__.r(__webpack_exports__);
3332
3461
  /* harmony import */ var _string__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./string */ "./src/string/index.ts");
3333
3462
  /* harmony import */ var _tree__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./tree */ "./src/tree/index.ts");
3334
3463
  /* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./types */ "./src/types.ts");
3464
+ /* harmony import */ var _color__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./color */ "./src/color/index.ts");
3465
+
3335
3466
 
3336
3467
 
3337
3468