@react-fabric/utilities 1.0.0-beta.9 → 1.0.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.
Files changed (168) hide show
  1. package/dist/cjs/css/boundingBox.js +72 -0
  2. package/dist/cjs/css/cn.js +39 -0
  3. package/dist/cjs/css/imageColorset.js +96 -0
  4. package/dist/cjs/data/countries.js +98 -0
  5. package/dist/cjs/{_fileType.js → data/fileType.js} +37 -19
  6. package/dist/cjs/data/format.js +136 -0
  7. package/dist/cjs/helpers/debounce.js +63 -0
  8. package/dist/cjs/{useLogger.js → helpers/getLogger.js} +96 -96
  9. package/dist/cjs/helpers/lonlat.js +99 -0
  10. package/dist/cjs/index.js +99 -76
  11. package/dist/cjs/lists/dedupe.js +54 -0
  12. package/dist/cjs/lists/flatten.js +66 -0
  13. package/dist/cjs/{_getByPath.js → lists/getByPath.js} +58 -37
  14. package/dist/cjs/lists/groupBy.js +49 -0
  15. package/dist/cjs/matchers/compare.js +70 -0
  16. package/dist/cjs/matchers/isEmpty.js +34 -0
  17. package/dist/cjs/matchers/isEqual.js +82 -0
  18. package/dist/cjs/matchers/nullChecks.js +61 -0
  19. package/dist/cjs/matchers/typeChecks.js +127 -0
  20. package/dist/cjs/strings/ascii.js +105 -0
  21. package/dist/cjs/strings/hash.js +75 -0
  22. package/dist/cjs/strings/interpolate.js +47 -0
  23. package/dist/cjs/strings/matchString.js +54 -0
  24. package/dist/cjs/strings/template.js +48 -0
  25. package/dist/cjs/strings/tokenize.js +83 -0
  26. package/dist/cjs/utils/mergeRefs.js +56 -0
  27. package/dist/esm/css/boundingBox.js +71 -0
  28. package/dist/esm/css/cn.js +39 -0
  29. package/dist/esm/css/imageColorset.js +96 -0
  30. package/dist/esm/data/countries.js +98 -0
  31. package/dist/esm/{_fileType.js → data/fileType.js} +37 -19
  32. package/dist/esm/data/format.js +138 -0
  33. package/dist/esm/helpers/debounce.js +63 -0
  34. package/dist/esm/{useLogger.js → helpers/getLogger.js} +96 -96
  35. package/dist/esm/helpers/lonlat.js +97 -0
  36. package/dist/esm/index.js +54 -36
  37. package/dist/esm/lists/dedupe.js +54 -0
  38. package/dist/esm/lists/flatten.js +65 -0
  39. package/dist/esm/{_getByPath.js → lists/getByPath.js} +50 -29
  40. package/dist/esm/lists/groupBy.js +49 -0
  41. package/dist/esm/matchers/compare.js +70 -0
  42. package/dist/esm/matchers/isEmpty.js +34 -0
  43. package/dist/esm/matchers/isEqual.js +82 -0
  44. package/dist/esm/matchers/nullChecks.js +58 -0
  45. package/dist/esm/matchers/typeChecks.js +119 -0
  46. package/dist/esm/strings/ascii.js +105 -0
  47. package/dist/esm/strings/hash.js +73 -0
  48. package/dist/esm/strings/interpolate.js +47 -0
  49. package/dist/esm/strings/matchString.js +54 -0
  50. package/dist/esm/strings/template.js +48 -0
  51. package/dist/esm/strings/tokenize.js +82 -0
  52. package/dist/esm/utils/mergeRefs.js +56 -0
  53. package/dist/types/css/boundingBox.d.ts +46 -0
  54. package/dist/types/css/cn.d.ts +26 -0
  55. package/dist/types/css/imageColorset.d.ts +37 -0
  56. package/dist/types/data/countries.d.ts +136 -0
  57. package/dist/types/{_fileType.d.ts → data/fileType.d.ts} +41 -1
  58. package/dist/types/data/format.d.ts +122 -0
  59. package/dist/types/helpers/debounce.d.ts +38 -0
  60. package/dist/types/helpers/getLogger.d.ts +49 -0
  61. package/dist/types/helpers/lonlat.d.ts +48 -0
  62. package/dist/types/index.d.ts +54 -20
  63. package/dist/types/lists/dedupe.d.ts +36 -0
  64. package/dist/types/lists/flatten.d.ts +47 -0
  65. package/dist/types/lists/getByPath.d.ts +45 -0
  66. package/dist/types/lists/groupBy.d.ts +36 -0
  67. package/dist/types/matchers/compare.d.ts +38 -0
  68. package/dist/types/matchers/isEmpty.d.ts +38 -0
  69. package/dist/types/matchers/isEqual.d.ts +39 -0
  70. package/dist/types/matchers/nullChecks.d.ts +43 -0
  71. package/dist/types/matchers/typeChecks.d.ts +107 -0
  72. package/dist/types/strings/ascii.d.ts +34 -0
  73. package/dist/types/strings/hash.d.ts +46 -0
  74. package/dist/types/strings/interpolate.d.ts +34 -0
  75. package/dist/types/strings/matchString.d.ts +41 -0
  76. package/dist/types/strings/template.d.ts +35 -0
  77. package/dist/types/strings/tokenize.d.ts +44 -0
  78. package/dist/types/utils/mergeRefs.d.ts +36 -0
  79. package/package.json +13 -11
  80. package/src/css/boundingBox.ts +80 -0
  81. package/src/css/cn.ts +32 -0
  82. package/src/css/imageColorset.ts +97 -0
  83. package/src/data/countries.ts +126 -0
  84. package/src/{_fileType.ts → data/fileType.ts} +72 -89
  85. package/src/data/format.ts +192 -0
  86. package/src/helpers/debounce.ts +49 -0
  87. package/src/{useLogger.ts → helpers/getLogger.ts} +52 -101
  88. package/src/helpers/lonlat.ts +124 -0
  89. package/src/index.ts +57 -37
  90. package/src/lists/dedupe.ts +46 -0
  91. package/src/lists/flatten.ts +56 -0
  92. package/src/lists/getByPath.ts +122 -0
  93. package/src/lists/groupBy.ts +47 -0
  94. package/src/matchers/compare.ts +64 -0
  95. package/src/matchers/isEmpty.ts +54 -0
  96. package/src/matchers/isEqual.ts +71 -0
  97. package/src/matchers/nullChecks.ts +55 -0
  98. package/src/matchers/typeChecks.ts +146 -0
  99. package/src/strings/ascii.ts +100 -0
  100. package/src/strings/hash.ts +68 -0
  101. package/src/strings/interpolate.ts +42 -0
  102. package/src/strings/matchString.ts +49 -0
  103. package/src/strings/template.ts +43 -0
  104. package/src/strings/tokenize.ts +77 -0
  105. package/src/utils/mergeRefs.ts +47 -0
  106. package/src/{yup.ts → utils/yup.ts} +3 -3
  107. package/dist/cjs/_ascii.js +0 -76
  108. package/dist/cjs/_boundingBox.js +0 -59
  109. package/dist/cjs/_countries.js +0 -2805
  110. package/dist/cjs/_debounce.js +0 -53
  111. package/dist/cjs/_dedupe.js +0 -63
  112. package/dist/cjs/_fetch.js +0 -128
  113. package/dist/cjs/_format.js +0 -118
  114. package/dist/cjs/_hash.js +0 -67
  115. package/dist/cjs/_interpolate.js +0 -47
  116. package/dist/cjs/_isEqual.js +0 -108
  117. package/dist/cjs/_isType.js +0 -98
  118. package/dist/cjs/_mergeRefs.js +0 -40
  119. package/dist/cjs/_tokenize.js +0 -67
  120. package/dist/cjs/getImageColorset.js +0 -70
  121. package/dist/esm/_ascii.js +0 -76
  122. package/dist/esm/_boundingBox.js +0 -58
  123. package/dist/esm/_countries.js +0 -2805
  124. package/dist/esm/_debounce.js +0 -53
  125. package/dist/esm/_dedupe.js +0 -60
  126. package/dist/esm/_fetch.js +0 -128
  127. package/dist/esm/_format.js +0 -120
  128. package/dist/esm/_hash.js +0 -65
  129. package/dist/esm/_interpolate.js +0 -46
  130. package/dist/esm/_isEqual.js +0 -106
  131. package/dist/esm/_isType.js +0 -85
  132. package/dist/esm/_mergeRefs.js +0 -40
  133. package/dist/esm/_tokenize.js +0 -66
  134. package/dist/esm/getImageColorset.js +0 -70
  135. package/dist/types/_ascii.d.ts +0 -5
  136. package/dist/types/_boundingBox.d.ts +0 -10
  137. package/dist/types/_countries.d.ts +0 -85
  138. package/dist/types/_debounce.d.ts +0 -8
  139. package/dist/types/_dedupe.d.ts +0 -4
  140. package/dist/types/_fetch.d.ts +0 -23
  141. package/dist/types/_format.d.ts +0 -27
  142. package/dist/types/_getByPath.d.ts +0 -10
  143. package/dist/types/_hash.d.ts +0 -16
  144. package/dist/types/_interpolate.d.ts +0 -6
  145. package/dist/types/_isEqual.d.ts +0 -15
  146. package/dist/types/_isType.d.ts +0 -14
  147. package/dist/types/_mergeRefs.d.ts +0 -1
  148. package/dist/types/_tokenize.d.ts +0 -8
  149. package/dist/types/getImageColorset.d.ts +0 -1
  150. package/dist/types/useLogger.d.ts +0 -25
  151. package/src/_ascii.ts +0 -93
  152. package/src/_boundingBox.ts +0 -72
  153. package/src/_countries.ts +0 -3046
  154. package/src/_debounce.ts +0 -42
  155. package/src/_dedupe.ts +0 -56
  156. package/src/_fetch.ts +0 -109
  157. package/src/_format.ts +0 -141
  158. package/src/_getByPath.ts +0 -108
  159. package/src/_hash.ts +0 -62
  160. package/src/_interpolate.ts +0 -42
  161. package/src/_isEqual.ts +0 -102
  162. package/src/_isType.ts +0 -105
  163. package/src/_mergeRefs.ts +0 -33
  164. package/src/_tokenize.ts +0 -69
  165. package/src/getImageColorset.ts +0 -81
  166. /package/dist/cjs/{yup.js → utils/yup.js} +0 -0
  167. /package/dist/esm/{yup.js → utils/yup.js} +0 -0
  168. /package/dist/types/{yup.d.ts → utils/yup.d.ts} +0 -0
@@ -0,0 +1,127 @@
1
+ 'use strict';
2
+
3
+ var _typeof = require('@babel/runtime/helpers/typeof');
4
+ var nullChecks = require('./nullChecks.js');
5
+
6
+ /**
7
+ * Check if a value is an object.
8
+ * An object is considered valid if it is:
9
+ * - not null or undefined
10
+ * - not a Date instance
11
+ * - of type 'object'
12
+ * - not an array
13
+ * @param val - The value to check.
14
+ * @returns true if the value is an object, false otherwise.
15
+ */
16
+ function isObject(val) {
17
+ return !nullChecks.isNil(val) && !(val instanceof Date) && _typeof(val) === "object" && !Array.isArray(val);
18
+ }
19
+
20
+ /**
21
+ * Check if a value is an array.
22
+ * An array is considered valid if it is:
23
+ * - not null or undefined
24
+ * - an instance of Array
25
+ * @param val - The value to check.
26
+ * @returns true if the value is an array, false otherwise.
27
+ */
28
+ function isArray(val) {
29
+ return Array.isArray(val);
30
+ }
31
+
32
+ /**
33
+ * Check if a value is a string.
34
+ * A string is considered valid if it is:
35
+ * - not null or undefined
36
+ * - of type 'string'
37
+ * @param value - The value to check.
38
+ * @returns true if the value is a string, false otherwise.
39
+ */
40
+ function isString(value) {
41
+ return typeof value === "string";
42
+ }
43
+
44
+ /**
45
+ * Check if a value is a number.
46
+ * A number is considered valid if it is:
47
+ * - not null or undefined
48
+ * - of type 'number'
49
+ * @param value - The value to check.
50
+ * @returns true if the value is a number, false otherwise.
51
+ */
52
+ function isNumber(value) {
53
+ return typeof value === "number";
54
+ }
55
+
56
+ /**
57
+ * Check if a value is a boolean.
58
+ * A boolean is considered valid if it is:
59
+ * - not null or undefined
60
+ * - of type 'boolean'
61
+ */
62
+ function isBoolean(value) {
63
+ return typeof value === "boolean";
64
+ }
65
+
66
+ /**
67
+ * Check if a value is a true.
68
+ * A value is considered true if it is:
69
+ * - strictly equal to true
70
+ * - equal to 1
71
+ * - a string that is "yes" or "true" (case insensitive)
72
+ */
73
+ function isTrue() {
74
+ var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
75
+ return value === true || value === 1 || (value === null || value === void 0 ? void 0 : value.toString().toLowerCase()) === "yes" || (value === null || value === void 0 ? void 0 : value.toString().toLowerCase()) === "true";
76
+ }
77
+
78
+ /**
79
+ * Check if a value is false.
80
+ * A value is considered false if it is:
81
+ * - strictly equal to false
82
+ * - equal to 0
83
+ * - a string that is "no" or "false" (case insensitive)
84
+ */
85
+ function isFalse() {
86
+ var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
87
+ return value === false || value === 0 || (value === null || value === void 0 ? void 0 : value.toString().toLowerCase()) === "no" || (value === null || value === void 0 ? void 0 : value.toString().toLowerCase()) === "false";
88
+ }
89
+
90
+ /**
91
+ * Check if a value is a valid color.
92
+ * A color is considered valid if it:
93
+ * - starts with a '#' (hex color)
94
+ * - starts with 'rgb' (RGB color)
95
+ * - starts with 'hsl' (HSL color)
96
+ * - starts with 'lab' (Lab color)
97
+ * - is equal to 'transparent'
98
+ * @param color - The value to check.
99
+ * @returns true if the value is a valid color, false otherwise.
100
+ */
101
+ function isColor(color) {
102
+ var _color$startsWith, _color$startsWith2, _color$startsWith3, _color$startsWith4;
103
+ return ((_color$startsWith = color.startsWith) === null || _color$startsWith === void 0 ? void 0 : _color$startsWith.call(color, "#")) || ((_color$startsWith2 = color.startsWith) === null || _color$startsWith2 === void 0 ? void 0 : _color$startsWith2.call(color, "rgb")) || ((_color$startsWith3 = color.startsWith) === null || _color$startsWith3 === void 0 ? void 0 : _color$startsWith3.call(color, "hsl")) || ((_color$startsWith4 = color.startsWith) === null || _color$startsWith4 === void 0 ? void 0 : _color$startsWith4.call(color, "lab")) || color === "transparent";
104
+ }
105
+
106
+ /**
107
+ * Check if a value is a valid SVG path.
108
+ * A valid SVG path is a string that:
109
+ * - starts with 'M' or 'm' (move to command)
110
+ * - contains at least one digit or decimal point
111
+ * - ends with 'Z' or 'z' (close path command)
112
+ * @param value - The value to check.
113
+ * @returns true if the value is a valid SVG path, false otherwise.
114
+ */
115
+ function isSvgPath(value) {
116
+ return typeof value === "string" && value.match(/^[Mm][\d.].*[\dzZ]$/) !== null;
117
+ }
118
+
119
+ exports.isArray = isArray;
120
+ exports.isBoolean = isBoolean;
121
+ exports.isColor = isColor;
122
+ exports.isFalse = isFalse;
123
+ exports.isNumber = isNumber;
124
+ exports.isObject = isObject;
125
+ exports.isString = isString;
126
+ exports.isSvgPath = isSvgPath;
127
+ exports.isTrue = isTrue;
@@ -0,0 +1,105 @@
1
+ 'use strict';
2
+
3
+ var isEmpty = require('../matchers/isEmpty.js');
4
+
5
+ /**
6
+ * React Fabric
7
+ * @version 1.0.0
8
+ * @license MIT
9
+ * @copyright 2024 Adarsh Pastakia
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights
14
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ * copies of the Software, and to permit persons to whom the Software is
16
+ * furnished to do so, subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice shall be included in all
19
+ * copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ * SOFTWARE.
28
+ */
29
+
30
+
31
+ /* istanbul ignore file */
32
+
33
+ /** ***************** latin-ascii conversions *******************/
34
+ var conversions = {
35
+ AE: "Æ|Ǽ",
36
+ Ae: "Ä",
37
+ ae: "ä|æ|ǽ",
38
+ OE: "Œ",
39
+ Oe: "Ö",
40
+ oe: "ö|œ",
41
+ Ue: "Ü",
42
+ ue: "ü",
43
+ IJ: "IJ",
44
+ ij: "ij",
45
+ ss: "ß",
46
+ A: "À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ",
47
+ a: "à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª",
48
+ C: "Ç|Ć|Ĉ|Ċ|Č",
49
+ c: "ç|ć|ĉ|ċ|č",
50
+ D: "Ð|Ď|Đ",
51
+ d: "ð|ď|đ",
52
+ E: "È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě",
53
+ e: "è|é|ê|ë|ē|ĕ|ė|ę|ě",
54
+ G: "Ĝ|Ğ|Ġ|Ģ",
55
+ g: "ĝ|ğ|ġ|ģ",
56
+ H: "Ĥ|Ħ",
57
+ h: "ĥ|ħ",
58
+ I: "Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ",
59
+ i: "ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı",
60
+ J: "Ĵ",
61
+ j: "ĵ",
62
+ K: "Ķ",
63
+ k: "ķ",
64
+ L: "Ĺ|Ļ|Ľ|Ŀ|Ł",
65
+ l: "ĺ|ļ|ľ|ŀ|ł",
66
+ N: "Ñ|Ń|Ņ|Ň",
67
+ n: "ñ|ń|ņ|ň|ʼn",
68
+ O: "Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ",
69
+ o: "ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º",
70
+ R: "Ŕ|Ŗ|Ř",
71
+ r: "ŕ|ŗ|ř",
72
+ S: "Ś|Ŝ|Ş|Š",
73
+ s: "ś|ŝ|ş|š|ſ",
74
+ T: "Ţ|Ť|Ŧ",
75
+ t: "ţ|ť|ŧ",
76
+ U: "Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ",
77
+ u: "ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ",
78
+ Y: "Ý|Ÿ|Ŷ",
79
+ y: "ý|ÿ|ŷ",
80
+ W: "Ŵ",
81
+ w: "ŵ",
82
+ Z: "Ź|Ż|Ž",
83
+ z: "ź|ż|ž",
84
+ f: "ƒ"
85
+ };
86
+
87
+ /**
88
+ * Converts a string to its ASCII representation by replacing
89
+ * special characters with their ASCII equivalents.
90
+ * This function is useful for normalizing strings for search or display purposes.
91
+ * It replaces characters like "Ä" with "Ae", "ß" with "ss", etc.
92
+ *
93
+ * @param {string} str - The input string to be converted.
94
+ * @returns {string} - The ASCII representation of the input string.
95
+ */
96
+ function ascii(str) {
97
+ if (isEmpty.isEmpty(str)) return "";
98
+ Object.entries(conversions).forEach(function (entry) {
99
+ var re = new RegExp(entry[1], "g");
100
+ str = "".concat(str).replace(re, entry[0]);
101
+ });
102
+ return str;
103
+ }
104
+
105
+ exports.ascii = ascii;
@@ -0,0 +1,75 @@
1
+ 'use strict';
2
+
3
+ var isEmpty = require('../matchers/isEmpty.js');
4
+
5
+ /**
6
+ * React Fabric
7
+ * @version 1.0.0
8
+ * @license MIT
9
+ * @copyright 2024 Adarsh Pastakia
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights
14
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ * copies of the Software, and to permit persons to whom the Software is
16
+ * furnished to do so, subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice shall be included in all
19
+ * copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ * SOFTWARE.
28
+ */
29
+
30
+
31
+ /**
32
+ * Generate a hash from a string.
33
+ * This function computes a simple hash by iterating over each character in the string,
34
+ * performing bitwise operations to produce a 32-bit integer hash.
35
+ * @param str
36
+ * @returns {number} A 32-bit integer hash of the input string.
37
+ */
38
+ function hash(str) {
39
+ var hash = 0;
40
+ var i;
41
+ var chr;
42
+ if (isEmpty.isEmpty(str)) return hash;
43
+ for (i = 0; i < str.length; i++) {
44
+ chr = str.charCodeAt(i);
45
+ hash = (hash << 5) - hash + chr;
46
+ hash |= 0; // Convert to 32bit integer
47
+ }
48
+ return hash;
49
+ }
50
+
51
+ /**
52
+ * Generate a short hash using the current timestamp and a random number.
53
+ * This function creates a unique identifier by combining the current time in milliseconds
54
+ * with a random number, and then converting it to a base-36 string.
55
+ * @returns {string} A short hash string.
56
+ */
57
+ function shortHash() {
58
+ return (new Date().getTime() * Math.random()).toString(36);
59
+ }
60
+
61
+ /**
62
+ * Generate a UUID (Universally Unique Identifier).
63
+ * This function creates a version 4 UUID by generating random numbers
64
+ * and formatting them according to the UUID standard.
65
+ * @returns {string} A UUID string in the format xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx.
66
+ */
67
+ function uuid() {
68
+ return [1e7, 1e3, 4e3, 8e3, 1e11].join("-").replace(/[018]/g, function (c) {
69
+ return (+c ^ Math.random() * 16 & 15 >> +c / 4).toString(16);
70
+ });
71
+ }
72
+
73
+ exports.hash = hash;
74
+ exports.shortHash = shortHash;
75
+ exports.uuid = uuid;
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ var getByPath = require('../lists/getByPath.js');
4
+
5
+ /**
6
+ * React Fabric
7
+ * @version 1.0.0
8
+ * @license MIT
9
+ * @copyright 2024 Adarsh Pastakia
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights
14
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ * copies of the Software, and to permit persons to whom the Software is
16
+ * furnished to do so, subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice shall be included in all
19
+ * copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ * SOFTWARE.
28
+ */
29
+
30
+
31
+ /**
32
+ * Interpolate a string with values from a model.
33
+ * This function replaces placeholders in the format ${key} with corresponding values from the model object.
34
+ * If the value is not a string or number, it returns an empty string.
35
+ *
36
+ * @param {string} str - The string to interpolate.
37
+ * @param {KeyValue} model - The model object containing key-value pairs for interpolation.
38
+ * @returns {string} The interpolated string with placeholders replaced by values from the model.
39
+ */
40
+ function interpolate(str, model) {
41
+ return str.replace(/\${([^{}]*)}/g, function (a, b) {
42
+ var r = getByPath.getByPath(model, b);
43
+ return typeof r === "string" || typeof r === "number" ? "".concat(r) : "";
44
+ });
45
+ }
46
+
47
+ exports.interpolate = interpolate;
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+
3
+ var ascii = require('./ascii.js');
4
+
5
+ /**
6
+ * React Fabric
7
+ * @version 1.0.0
8
+ * @license MIT
9
+ * @copyright 2024 Adarsh Pastakia
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights
14
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ * copies of the Software, and to permit persons to whom the Software is
16
+ * furnished to do so, subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice shall be included in all
19
+ * copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ * SOFTWARE.
28
+ */
29
+
30
+
31
+ /**
32
+ * Match a string against another string with options for equality.
33
+ * This function checks if the base string starts with, includes, or is equal to the match string,
34
+ * based on the specified equality condition.
35
+ * It normalizes both strings to lowercase and ASCII format before comparison.
36
+ * This is useful for case-insensitive and ASCII-only comparisons,
37
+ * such as when filtering or searching through text data.
38
+ *
39
+ * @param {string} base - The base string to match against.
40
+ * @param {string} match - The string to match with the base string.
41
+ * @param {("start" | boolean)} equality - The type of match to perform:
42
+ * - "start": checks if the base string starts with the match string.
43
+ * - true: checks for exact equality.
44
+ * - false (default): checks if the base string includes the match string.
45
+ * @returns {boolean} - Returns true if the base string matches the conditions specified by the match string and equality.
46
+ */
47
+ function matchString(base, match) {
48
+ var equality = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
49
+ var _base = ascii.ascii(base).toLowerCase();
50
+ var _match = ascii.ascii(match).toLowerCase();
51
+ return equality === true ? _base === _match : equality === "start" ? _base.startsWith(_match) : _base.includes(_match);
52
+ }
53
+
54
+ exports.matchString = matchString;
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ var getByPath = require('../lists/getByPath.js');
4
+
5
+ /**
6
+ * React Fabric
7
+ * @version 1.0.0
8
+ * @license MIT
9
+ * @copyright 2024 Adarsh Pastakia
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights
14
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ * copies of the Software, and to permit persons to whom the Software is
16
+ * furnished to do so, subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice shall be included in all
19
+ * copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ * SOFTWARE.
28
+ */
29
+
30
+
31
+ /**
32
+ * Render a template string with values from a model.
33
+ * This function replaces placeholders in the format {{key}} with corresponding values from the model object.
34
+ * If the value is not a string or number, it returns an empty string.
35
+ * This is similar to the interpolate function but for handlebar templates.
36
+ *
37
+ * @param {string} str - The template string to render.
38
+ * @param {KeyValue} model - The model object containing key-value pairs for rendering the template.
39
+ * @returns {string} The rendered template string with placeholders replaced by values from the model.
40
+ */
41
+ function renderTemplate(str, model) {
42
+ return str.replace(/{{([^{}]*)}}/g, function (a, b) {
43
+ var r = getByPath.getByPath(model, b);
44
+ return typeof r === "string" || typeof r === "number" ? "".concat(r) : "";
45
+ });
46
+ }
47
+
48
+ exports.renderTemplate = renderTemplate;
@@ -0,0 +1,83 @@
1
+ 'use strict';
2
+
3
+ var isEmpty = require('../matchers/isEmpty.js');
4
+ var typeChecks = require('../matchers/typeChecks.js');
5
+
6
+ /**
7
+ * React Fabric
8
+ * @version 1.0.0
9
+ * @license MIT
10
+ * @copyright 2024 Adarsh Pastakia
11
+ *
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ * of this software and associated documentation files (the "Software"), to deal
14
+ * in the Software without restriction, including without limitation the rights
15
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ * copies of the Software, and to permit persons to whom the Software is
17
+ * furnished to do so, subject to the following conditions:
18
+ *
19
+ * The above copyright notice and this permission notice shall be included in all
20
+ * copies or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ * SOFTWARE.
29
+ */
30
+
31
+
32
+ /**
33
+ * Tokenize a string based on provided keywords.
34
+ * This function splits the input string into tokens, where each token is an array containing
35
+ * the substring before the keyword and the keyword itself.
36
+ * If no keywords are provided, it returns the entire string as a single token.
37
+ *
38
+ * @param {string} str - The string to tokenize.
39
+ * @param {string | string[]} keywords - A string or an array of strings to use as keywords for tokenization.
40
+ * @returns {Array<[string, string]>} An array of tokens, where each token is an array of [substring, keyword].
41
+ */
42
+ function tokenize(str, keywords) {
43
+ if (isEmpty.isEmpty(keywords)) {
44
+ return [[str, ""]];
45
+ }
46
+ var keys = typeChecks.isArray(keywords) ? keywords : [keywords];
47
+ var keyMap = keys.map(function (key) {
48
+ // escape regex control characters
49
+ var escapedKey = key.replace(/([+*.?^$()[\]\\!&|\-=])/gm, "\\$1");
50
+ // place token within word boundaries if start/end with alpha-numeric
51
+ if (key.match(/^[a-z0-9]/i) != null) escapedKey = "\\b".concat(escapedKey);
52
+ if (key.match(/[a-z0-9]$/i) != null) escapedKey = "".concat(escapedKey, "\\b");
53
+ return escapedKey;
54
+ });
55
+ var regx = new RegExp("(".concat(keyMap.join("|"), ")"), "img");
56
+ var match;
57
+ var lastIndex = 0;
58
+ var tokens = [];
59
+ while ((match = regx.exec(str)) !== null) {
60
+ tokens.push([str.substring(lastIndex, match.index), str.substring(match.index, regx.lastIndex)]);
61
+ lastIndex = regx.lastIndex;
62
+ }
63
+ tokens.push([str.substring(lastIndex), ""]);
64
+ return tokens;
65
+ }
66
+
67
+ /**
68
+ * Generate a token from a string.
69
+ * This function creates a token by taking the first letter of the first word and the first letter of the last word,
70
+ * or the first two letters of the first word if there is no last word.
71
+ *
72
+ * @param {string} str - The string to tokenize.
73
+ * @returns {string} A string token consisting of the first letters of the first and last words, or the first two letters of the first word.
74
+ */
75
+ function iconToken(str) {
76
+ var split = str.trim().split(" ");
77
+ var first = split[0];
78
+ var last = split.length > 1 && split.pop();
79
+ return (first && last ? "".concat(first.charAt(0)).concat(last.charAt(0)) : "".concat(first.substring(0, 2))).toUpperCase();
80
+ }
81
+
82
+ exports.iconToken = iconToken;
83
+ exports.tokenize = tokenize;
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ var _typeof = require('@babel/runtime/helpers/typeof');
4
+
5
+ /**
6
+ * React Fabric
7
+ * @version 1.0.0
8
+ * @license MIT
9
+ * @copyright 2024 Adarsh Pastakia
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights
14
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ * copies of the Software, and to permit persons to whom the Software is
16
+ * furnished to do so, subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice shall be included in all
19
+ * copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ * SOFTWARE.
28
+ */
29
+
30
+ /* istanbul ignore file */
31
+
32
+ /**
33
+ * Merge multiple refs into a single ref callback.
34
+ * This function allows you to combine multiple refs (either callback refs or React refs)
35
+ * into a single ref callback that can be used in React components.
36
+ * This is particularly useful when you want to assign a single element to multiple refs,
37
+ * such as when using third-party libraries that require refs or when you want to share refs between components.
38
+ * The function iterates over the provided refs and assigns the element to each ref.
39
+ *
40
+ * @param {AnyObject[]} refs - An array of refs to merge.
41
+ * @returns {function} A function that takes an element and assigns it to all provided refs.
42
+ */
43
+ function mergeRefs() {
44
+ for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
45
+ refs[_key] = arguments[_key];
46
+ }
47
+ return function (el) {
48
+ refs.forEach(function (ref) {
49
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
50
+ if (typeof ref === "function") ref(el);
51
+ if (ref && _typeof(ref) === "object" && "current" in ref) ref.current = el;
52
+ });
53
+ };
54
+ }
55
+
56
+ exports.mergeRefs = mergeRefs;
@@ -0,0 +1,71 @@
1
+ 'use client';
2
+
3
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
+ import { isEmpty } from '../matchers/isEmpty.js';
5
+
6
+ function _getBox(box) {
7
+ var boundingBox;
8
+ if (isEmpty(box)) return [0, 0, 0, 0];
9
+ if (typeof box === "string") {
10
+ boundingBox = box.split(",").map(function (b) {
11
+ return parseInt(b, 10);
12
+ });
13
+ } else {
14
+ boundingBox = box;
15
+ }
16
+ return boundingBox;
17
+ }
18
+
19
+ /**
20
+ * Get box dimensions from a string or array.
21
+ * The box can be in the format "x,y,w,h" or [x,y,w,h].
22
+ * The box is adjusted to ensure that x and y are non-negative.
23
+ * The width and height are adjusted accordingly.
24
+ *
25
+ * @param box "x,y,w,h" | [x,y,w,h]
26
+ * @returns canvas box [x,y,w,h]
27
+ */
28
+ function getBox() {
29
+ var box = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "0,0,0,0";
30
+ var boundingBox = _getBox(box);
31
+ var _boundingBox = _slicedToArray(boundingBox, 4),
32
+ x = _boundingBox[0],
33
+ y = _boundingBox[1],
34
+ w = _boundingBox[2],
35
+ h = _boundingBox[3];
36
+ w = x < 0 ? w + x : w;
37
+ h = y < 0 ? h + y : h;
38
+ x = x > 0 ? x : 0;
39
+ y = y > 0 ? y : 0;
40
+ return [x, y, w, h];
41
+ }
42
+
43
+ /**
44
+ * Get bounding box dimensions from a string or array.
45
+ * The box can be in the format "x1,y1,x2,y2" or [x1,y1,x2,y2].
46
+ * The box is adjusted to ensure that x1 and y1 are non-negative.
47
+ * The width and height are calculated as x2 - x1 and y2 - y1 respectively.
48
+ * If x1 or y1 are negative, they are set to 0 and the width and height are adjusted accordingly.
49
+ * This is useful for ensuring that the bounding box is always within the canvas area.
50
+ *
51
+ * @param box "x1,y1,x2,y2" | [x1,y1,x2,y2]
52
+ * @returns canvas box [x,y,w,h]
53
+ */
54
+ function getBoundingBox() {
55
+ var box = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "0,0,0,0";
56
+ var boundingBox = _getBox(box);
57
+
58
+ // eslint-disable-next-line prefer-const
59
+ var _boundingBox2 = _slicedToArray(boundingBox, 4),
60
+ x1 = _boundingBox2[0],
61
+ y1 = _boundingBox2[1],
62
+ x2 = _boundingBox2[2],
63
+ y2 = _boundingBox2[3];
64
+ var w = x2 - x1;
65
+ var h = y2 - y1;
66
+ x1 = x1 > 0 ? x1 : 0;
67
+ y1 = y1 > 0 ? y1 : 0;
68
+ return [x1, y1, w, h];
69
+ }
70
+
71
+ export { getBoundingBox, getBox };