@react-fabric/utilities 1.0.0-beta.8 → 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,73 @@
1
+ 'use client';
2
+
3
+ import { isEmpty } from '../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(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
+ export { hash, shortHash, uuid };
@@ -0,0 +1,47 @@
1
+ 'use client';
2
+
3
+ import { getByPath } from '../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(model, b);
43
+ return typeof r === "string" || typeof r === "number" ? "".concat(r) : "";
44
+ });
45
+ }
46
+
47
+ export { interpolate };
@@ -0,0 +1,54 @@
1
+ 'use client';
2
+
3
+ import { ascii } from './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(base).toLowerCase();
50
+ var _match = ascii(match).toLowerCase();
51
+ return equality === true ? _base === _match : equality === "start" ? _base.startsWith(_match) : _base.includes(_match);
52
+ }
53
+
54
+ export { matchString };
@@ -0,0 +1,48 @@
1
+ 'use client';
2
+
3
+ import { getByPath } from '../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(model, b);
44
+ return typeof r === "string" || typeof r === "number" ? "".concat(r) : "";
45
+ });
46
+ }
47
+
48
+ export { renderTemplate };
@@ -0,0 +1,82 @@
1
+ 'use client';
2
+
3
+ import { isEmpty } from '../matchers/isEmpty.js';
4
+ import { isArray } from '../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(keywords)) {
44
+ return [[str, ""]];
45
+ }
46
+ var keys = 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
+ export { iconToken, tokenize };
@@ -0,0 +1,56 @@
1
+ 'use client';
2
+
3
+ import _typeof from '@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
+ export { mergeRefs };
@@ -0,0 +1,46 @@
1
+ /**
2
+ * React Fabric
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ /**
26
+ * Get box dimensions from a string or array.
27
+ * The box can be in the format "x,y,w,h" or [x,y,w,h].
28
+ * The box is adjusted to ensure that x and y are non-negative.
29
+ * The width and height are adjusted accordingly.
30
+ *
31
+ * @param box "x,y,w,h" | [x,y,w,h]
32
+ * @returns canvas box [x,y,w,h]
33
+ */
34
+ export declare function getBox(box?: string | [number, number, number, number]): [number, number, number, number];
35
+ /**
36
+ * Get bounding box dimensions from a string or array.
37
+ * The box can be in the format "x1,y1,x2,y2" or [x1,y1,x2,y2].
38
+ * The box is adjusted to ensure that x1 and y1 are non-negative.
39
+ * The width and height are calculated as x2 - x1 and y2 - y1 respectively.
40
+ * If x1 or y1 are negative, they are set to 0 and the width and height are adjusted accordingly.
41
+ * This is useful for ensuring that the bounding box is always within the canvas area.
42
+ *
43
+ * @param box "x1,y1,x2,y2" | [x1,y1,x2,y2]
44
+ * @returns canvas box [x,y,w,h]
45
+ */
46
+ export declare function getBoundingBox(box?: string | [number, number, number, number]): [number, number, number, number];
@@ -0,0 +1,26 @@
1
+ /**
2
+ * React Fabric
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ import { type ClassValue } from "clsx";
26
+ export declare const cn: (...classes: ClassValue[]) => string;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * React Fabric
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ /**
26
+ * Get the color set of an image element.
27
+ * This function analyzes the pixel data of an image to determine if it is predominantly light or dark.
28
+ * It returns "light", "dark", or "light_transparent"/"dark_transparent" based on the pixel analysis.
29
+ * It uses a canvas to draw the image and extract pixel data for analysis.
30
+ * * The function calculates the brightness of each pixel using the formula:
31
+ * brightness = 0.2126 * R + 0.7152 * G + 0.0722 * B
32
+ * * It counts the number of light and dark pixels, and determines the overall color set based on the ratio of light to dark pixels.
33
+ * * If the image has transparent pixels, it appends "_transparent" to the result.
34
+ * * This function is useful for determining the color scheme of an image, which can be helpful for UI design,
35
+ * theming, and accessibility considerations.
36
+ */
37
+ export declare function getImageColorset(el: HTMLImageElement, transparentOnly?: boolean): string;
@@ -0,0 +1,136 @@
1
+ /**
2
+ * React Fabric
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ import { type Country as _Ctry } from "world-countries";
26
+ export type Country = _Ctry & {
27
+ alpha: string;
28
+ phone: string;
29
+ iconCode: string;
30
+ currency: {
31
+ code: string;
32
+ name?: string;
33
+ symbol?: string;
34
+ };
35
+ };
36
+ /**
37
+ * Country list with helper functions
38
+ * This is a list of all countries with their details.
39
+ * It includes information such as continent, ISO codes, name, full name, capital, top-level domain (TLD), currency, phone code, and emoji.
40
+ * This list can be used to retrieve country information based on various codes or names.
41
+ * @type {Country[]}
42
+ */
43
+ declare const _default: {
44
+ /**
45
+ * Get ISO2 country code
46
+ *
47
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
48
+ * @return {string | undefined} - Returns the ISO2 country code if found, otherwise undefined.
49
+ */
50
+ toIso2(code: string): string | undefined;
51
+ /**
52
+ * Get ISO3 country code
53
+ *
54
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
55
+ * @return {string | undefined} - Returns the ISO3 country code if found, otherwise undefined.
56
+ */
57
+ toIso3(code: string): string | undefined;
58
+ /**
59
+ * Get country emoji
60
+ *
61
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
62
+ * @return {string} - Returns the emoji representation of the country if found, otherwise returns a default flag emoji.
63
+ */
64
+ emoji(code: string): string;
65
+ /**
66
+ * Get country name
67
+ *
68
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
69
+ * @return {string} - Returns the name of the country if found, otherwise returns the code itself.
70
+ */
71
+ name: (code: string) => string;
72
+ /**
73
+ * This function searches for a country in the list by its code.
74
+ * It supports various formats:
75
+ * - ISO2 code (e.g., "US")
76
+ * - ISO3 code (e.g., "USA")
77
+ * - Alternative code (e.g., "US", "USA", "United States")
78
+ * It returns the first matching country object or undefined if not found.
79
+ * This function is useful for retrieving country details based on different code formats.
80
+ *
81
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
82
+ * @return {Country | undefined} - Returns the country object if found, otherwise undefined.
83
+ */
84
+ find(code: string): Country | undefined;
85
+ /**
86
+ * Country list
87
+ * This is a list of all countries with their details.
88
+ * It includes information such as continent, ISO codes, name, full name, capital, top-level domain (TLD), currency, phone code, and emoji.
89
+ * This list can be used to retrieve country information based on various codes or names.
90
+ *
91
+ * @type {Country[]}
92
+ */
93
+ list: {
94
+ iconCode: string;
95
+ alpha: string;
96
+ phone: string;
97
+ region: string;
98
+ currency: {
99
+ code: string;
100
+ name?: string | undefined;
101
+ symbol?: string | undefined;
102
+ };
103
+ name: import("world-countries").CountryName;
104
+ tld: string[];
105
+ cca2: string;
106
+ ccn3: string;
107
+ cca3: string;
108
+ cioc: string;
109
+ independent: boolean;
110
+ status: string;
111
+ unMember: boolean;
112
+ unRegionalGroup: "African Group" | "Asia and the Pacific Group" | "Eastern European Group" | "Latin American and Caribbean Group" | "Western European and Others Group" | "";
113
+ currencies: {
114
+ [currencyCode: string]: import("world-countries").Currency;
115
+ };
116
+ idd: import("world-countries").IntlDirectDialingCode;
117
+ capital: string[];
118
+ altSpellings: string[];
119
+ subregion: string;
120
+ languages: {
121
+ [languageCode: string]: string;
122
+ };
123
+ translations: {
124
+ [languageCode: string]: import("world-countries").OfficialAndCommon;
125
+ };
126
+ latlng: [number, number];
127
+ demonyms: {
128
+ [languageCode: string]: import("world-countries").Demonyms;
129
+ };
130
+ landlocked: boolean;
131
+ borders: string[];
132
+ area: number;
133
+ flag: string;
134
+ }[];
135
+ };
136
+ export default _default;
@@ -1,5 +1,45 @@
1
+ /**
2
+ * React Fabric
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ /**
26
+ * File type utility to get the file type from a MIME type.
27
+ * This utility provides a mapping of common MIME types to their human-readable names.
28
+ * It can be used to display file types in a user-friendly manner.
29
+ */
1
30
  declare const _default: {
2
- mime(mime?: string): any;
31
+ /**
32
+ * Get the human-readable file type from a MIME type.
33
+ * This method looks up the MIME type in a predefined list
34
+ * and returns a user-friendly name.
35
+ *
36
+ * @param mime MIME type string, e.g. "application/pdf"
37
+ * @returns {string} - The human-readable file type.
38
+ */
39
+ mime(mime?: string): string;
40
+ /**
41
+ * List of common MIME types and their human-readable names.
42
+ */
3
43
  mimeList: {
4
44
  "application/x-tika-msoffice": string;
5
45
  "application/x-tika-ooxml": string;