@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
package/src/_isType.ts DELETED
@@ -1,105 +0,0 @@
1
- /*
2
- * React Fabric
3
- * @version: 1.0.0
4
- *
5
- *
6
- * The MIT License (MIT)
7
- * Copyright (c) 2024 Adarsh Pastakia
8
- *
9
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
- * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
- * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
- * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
- * subject to the following conditions:
14
- *
15
- * The above copyright notice and this permission notice shall be included in all copies or substantial
16
- * portions of the Software.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
- * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- */
23
-
24
- export const isUndefined = (value: AnyObject): value is undefined => {
25
- return value === undefined;
26
- };
27
-
28
- export const isNull = (value: AnyObject): value is null => {
29
- return value === null;
30
- };
31
-
32
- export const isNil = (val: AnyObject): val is undefined => {
33
- return val === undefined || val === null;
34
- };
35
- export const isEmpty = (val: AnyObject): val is undefined => {
36
- if (val instanceof Date) return false;
37
- if (isNil(val) || val === "") {
38
- return true;
39
- }
40
- if (Array.isArray(val) && val.filter(Boolean).length === 0) {
41
- return true;
42
- }
43
- if (val instanceof Map || val instanceof Set) return val.size === 0;
44
- if (["boolean", "number", "bigint", "function"].includes(typeof val)) {
45
- return false;
46
- }
47
- return !!val && typeof val === "object" && Object.entries(val).length === 0;
48
- };
49
-
50
- export const isObject = (val: AnyObject): val is KeyValue => {
51
- return (
52
- !isNil(val) &&
53
- !(val instanceof Date) &&
54
- typeof val === "object" &&
55
- !Array.isArray(val)
56
- );
57
- };
58
- export const isArray = <T = AnyObject>(val: AnyObject): val is T[] => {
59
- return Array.isArray(val);
60
- };
61
-
62
- export const isString = (value: AnyObject): value is string => {
63
- return typeof value === "string";
64
- };
65
-
66
- export const isNumber = (value: AnyObject): value is number => {
67
- return typeof value === "number";
68
- };
69
-
70
- export const isBoolean = (value: AnyObject): value is boolean => {
71
- return typeof value === "boolean";
72
- };
73
- export const isTrue = (value: AnyObject = ""): value is true => {
74
- return (
75
- value === true ||
76
- value === 1 ||
77
- value?.toString().toLowerCase() === "yes" ||
78
- value?.toString().toLowerCase() === "true"
79
- );
80
- };
81
- export const isFalse = (value: AnyObject = ""): value is false => {
82
- return (
83
- value === false ||
84
- value === 0 ||
85
- value?.toString().toLowerCase() === "no" ||
86
- value?.toString().toLowerCase() === "false"
87
- );
88
- };
89
-
90
- export const isColor = (color: string) =>
91
- color.startsWith?.("#") ||
92
- color.startsWith?.("rgb") ||
93
- color.startsWith?.("hsl") ||
94
- color.startsWith?.("lab") ||
95
- color === "transparent";
96
-
97
- export const isSvgPath = (value: AnyObject): value is string => {
98
- return (
99
- typeof value === "string" && value.match(/^[Mm][\d.].*[\dzZ]$/) !== null
100
- );
101
- };
102
-
103
- export const isRtl = () => {
104
- return getComputedStyle(document.documentElement).direction === "rtl";
105
- };
package/src/_mergeRefs.ts DELETED
@@ -1,33 +0,0 @@
1
- /*
2
- * React Fabric
3
- * @version: 1.0.0
4
- *
5
- *
6
- * The MIT License (MIT)
7
- * Copyright (c) 2024 Adarsh Pastakia
8
- *
9
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
- * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
- * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
- * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
- * subject to the following conditions:
14
- *
15
- * The above copyright notice and this permission notice shall be included in all copies or substantial
16
- * portions of the Software.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
- * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- */
23
-
24
- /* istanbul ignore file */
25
-
26
- export const mergeRefs =
27
- (...refs: AnyObject[]) =>
28
- (el: AnyObject) => {
29
- refs.forEach((ref) => {
30
- if (typeof ref === "function") ref(el);
31
- if (ref && "current" in ref) ref.current = el;
32
- });
33
- };
package/src/_tokenize.ts DELETED
@@ -1,69 +0,0 @@
1
- /*
2
- * React Fabric
3
- * @version: 1.0.0
4
- *
5
- *
6
- * The MIT License (MIT)
7
- * Copyright (c) 2024 Adarsh Pastakia
8
- *
9
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
- * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
- * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
- * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
- * subject to the following conditions:
14
- *
15
- * The above copyright notice and this permission notice shall be included in all copies or substantial
16
- * portions of the Software.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
- * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- */
23
-
24
- import { isArray, isEmpty } from "./_isType";
25
-
26
- /**
27
- * split text into array of tokens by word boundaries
28
- * @param str
29
- * @param keywords
30
- * @internal
31
- */
32
- export const tokenize = (str: string, keywords?: string | string[]) => {
33
- if (isEmpty(keywords)) {
34
- return [[str, ""]];
35
- }
36
- const keys = isArray(keywords) ? keywords : [keywords];
37
- const keyMap = keys.map((key) => {
38
- // escape regex control characters
39
- let escapedKey = key.replace(/([+*.?^$()[\]\\!&|\-=])/gm, "\\$1");
40
- // place token within word boundaries if start/end with alpha-numeric
41
- if (key.match(/^[a-z0-9]/i) != null) escapedKey = `\\b${escapedKey}`;
42
- if (key.match(/[a-z0-9]$/i) != null) escapedKey = `${escapedKey}\\b`;
43
- return escapedKey;
44
- });
45
- const regx = new RegExp(`(${keyMap.join("|")})`, "img");
46
- let match;
47
- let lastIndex = 0;
48
- const tokens = [];
49
- while ((match = regx.exec(str)) !== null) {
50
- tokens.push([
51
- str.substring(lastIndex, match.index),
52
- str.substring(match.index, regx.lastIndex),
53
- ]);
54
- lastIndex = regx.lastIndex;
55
- }
56
- tokens.push([str.substring(lastIndex), ""]);
57
- return tokens;
58
- };
59
-
60
- export const iconToken = (str: string) => {
61
- const split = str.trim().split(" ");
62
- const first = split[0];
63
- const last = split.length > 1 && split.pop();
64
- return (
65
- first && last
66
- ? `${first.charAt(0)}${last.charAt(0)}`
67
- : `${first.substring(0, 2)}`
68
- ).toUpperCase();
69
- };
@@ -1,81 +0,0 @@
1
- /*
2
- * React Fabric
3
- * @version: 1.0.0
4
- *
5
- *
6
- * The MIT License (MIT)
7
- * Copyright (c) 2024 Adarsh Pastakia
8
- *
9
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
- * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
- * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
- * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
- * subject to the following conditions:
14
- *
15
- * The above copyright notice and this permission notice shall be included in all copies or substantial
16
- * portions of the Software.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
- * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- */
23
-
24
- /* istanbul ignore file */
25
-
26
- export const getImageColorset = (el: HTMLImageElement) => {
27
- // create canvas
28
- const canvas = document.createElement("canvas");
29
- canvas.width = Math.min(500, el.naturalWidth);
30
- canvas.height = Math.min(500, el.naturalHeight);
31
-
32
- const ctx = canvas.getContext("2d");
33
- if (ctx != null) {
34
- ctx.drawImage(
35
- el,
36
- 0,
37
- 0,
38
- el.naturalWidth,
39
- el.naturalHeight,
40
- 0,
41
- 0,
42
- canvas.width,
43
- canvas.height,
44
- );
45
-
46
- const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
47
- const data = imageData.data;
48
- let r, g, b;
49
- let dark = 0;
50
- let light = 0;
51
- let totalPixels = 0;
52
- let transparent = data?.[3] === 0;
53
-
54
- for (let x = 0, len = data.length; x < len; x += 4) {
55
- if (data[x + 3] === 0) {
56
- transparent = true;
57
- continue;
58
- }
59
- if (transparent && data[x - 1] === 1) {
60
- continue;
61
- }
62
- r = data[x];
63
- g = data[x + 1];
64
- b = data[x + 2];
65
- totalPixels++;
66
- 0.2126 * r + 0.7152 * g + 0.0722 * b < 128 ? dark++ : light++;
67
- }
68
-
69
- const diff = light / totalPixels - dark / totalPixels;
70
- let ret = diff > 0 ? "light" : "dark";
71
- if (transparent) {
72
- ret += "_transparent";
73
- }
74
- return ret;
75
- }
76
- return "light";
77
- };
78
-
79
- if (typeof window !== "undefined")
80
- // @ts-expect-error ignore
81
- window.getImageColorset = getImageColorset;
File without changes
File without changes
File without changes