@yamada-ui/utils 0.0.0-dev-20230606151107

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 (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +31 -0
  3. package/dist/array.d.ts +3 -0
  4. package/dist/array.js +30 -0
  5. package/dist/array.mjs +6 -0
  6. package/dist/assertion.d.ts +16 -0
  7. package/dist/assertion.js +63 -0
  8. package/dist/assertion.mjs +28 -0
  9. package/dist/calc.d.ts +17 -0
  10. package/dist/calc.js +55 -0
  11. package/dist/calc.mjs +6 -0
  12. package/dist/chunk-BZAW2D6U.mjs +6 -0
  13. package/dist/chunk-FW7XS4NH.mjs +120 -0
  14. package/dist/chunk-HUEOJZVC.mjs +403 -0
  15. package/dist/chunk-IVGIIDMV.mjs +28 -0
  16. package/dist/chunk-PF7LRFIA.mjs +51 -0
  17. package/dist/chunk-PURW64JE.mjs +6 -0
  18. package/dist/chunk-R5OUKGQ5.mjs +31 -0
  19. package/dist/chunk-SLJ4M7XC.mjs +0 -0
  20. package/dist/chunk-VYMGBE25.mjs +39 -0
  21. package/dist/color.d.ts +18 -0
  22. package/dist/color.js +183 -0
  23. package/dist/color.mjs +34 -0
  24. package/dist/dom.d.ts +33 -0
  25. package/dist/dom.js +168 -0
  26. package/dist/dom.mjs +54 -0
  27. package/dist/event.d.ts +30 -0
  28. package/dist/event.js +83 -0
  29. package/dist/event.mjs +22 -0
  30. package/dist/function.d.ts +6 -0
  31. package/dist/function.js +50 -0
  32. package/dist/function.mjs +20 -0
  33. package/dist/index.d.ts +13 -0
  34. package/dist/index.js +798 -0
  35. package/dist/index.mjs +221 -0
  36. package/dist/index.types.d.ts +14 -0
  37. package/dist/index.types.js +18 -0
  38. package/dist/index.types.mjs +1 -0
  39. package/dist/number.d.ts +8 -0
  40. package/dist/number.js +68 -0
  41. package/dist/number.mjs +16 -0
  42. package/dist/object.d.ts +18 -0
  43. package/dist/object.js +192 -0
  44. package/dist/object.mjs +40 -0
  45. package/dist/react.d.ts +44 -0
  46. package/dist/react.js +176 -0
  47. package/dist/react.mjs +46 -0
  48. package/dist/string.d.ts +3 -0
  49. package/dist/string.js +30 -0
  50. package/dist/string.mjs +6 -0
  51. package/package.json +66 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Hirotomo Yamada
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # @yamada-ui/utils
2
+
3
+ > This is an internal utility, not intended for public usage.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ $ pnpm add @yamada-ui/utils
9
+ ```
10
+
11
+ or
12
+
13
+ ```sh
14
+ $ yarn add @yamada-ui/utils
15
+ ```
16
+
17
+ or
18
+
19
+ ```sh
20
+ $ npm install @yamada-ui/utils
21
+ ```
22
+
23
+ ## Contribution
24
+
25
+ Wouldn't you like to contribute? That's amazing! We have prepared a [contribution guide](https://github.com/hirotomoyamada/yamada-ui/blob/main/CONTRIBUTING.md) to assist you.
26
+
27
+ ## Licence
28
+
29
+ This package is licensed under the terms of the
30
+
31
+ [MIT license](https://github.com/hirotomoyamada/yamada-ui/blob/main/LICENSE).
@@ -0,0 +1,3 @@
1
+ declare const filterEmpty: <T extends any[]>(array: T) => any[];
2
+
3
+ export { filterEmpty };
package/dist/array.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/array.ts
21
+ var array_exports = {};
22
+ __export(array_exports, {
23
+ filterEmpty: () => filterEmpty
24
+ });
25
+ module.exports = __toCommonJS(array_exports);
26
+ var filterEmpty = (array) => array.filter((value) => value != null);
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ filterEmpty
30
+ });
package/dist/array.mjs ADDED
@@ -0,0 +1,6 @@
1
+ import {
2
+ filterEmpty
3
+ } from "./chunk-PURW64JE.mjs";
4
+ export {
5
+ filterEmpty
6
+ };
@@ -0,0 +1,16 @@
1
+ import { Dict } from './index.types.js';
2
+
3
+ declare const isNumber: (value: any) => value is number;
4
+ declare const isNotNumber: (value: any) => boolean;
5
+ declare const isNumeric: (value: any) => boolean;
6
+ declare const isString: (value: any) => value is string;
7
+ declare const isUndefined: (value: any) => value is undefined;
8
+ declare const isNull: (value: any) => value is null;
9
+ declare const isObject: <T extends Dict<any>>(value: any) => value is T;
10
+ declare const isArray: <T extends any[]>(value: any) => value is T;
11
+ declare const isEmpty: (value: any) => boolean;
12
+ declare const isFunction: <T extends Function = Function>(value: any) => value is T;
13
+ declare const isUnit: (value: any) => boolean;
14
+ declare const cast: <T>(value: any) => T;
15
+
16
+ export { cast, isArray, isEmpty, isFunction, isNotNumber, isNull, isNumber, isNumeric, isObject, isString, isUndefined, isUnit };
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/assertion.ts
21
+ var assertion_exports = {};
22
+ __export(assertion_exports, {
23
+ cast: () => cast,
24
+ isArray: () => isArray,
25
+ isEmpty: () => isEmpty,
26
+ isFunction: () => isFunction,
27
+ isNotNumber: () => isNotNumber,
28
+ isNull: () => isNull,
29
+ isNumber: () => isNumber,
30
+ isNumeric: () => isNumeric,
31
+ isObject: () => isObject,
32
+ isString: () => isString,
33
+ isUndefined: () => isUndefined,
34
+ isUnit: () => isUnit
35
+ });
36
+ module.exports = __toCommonJS(assertion_exports);
37
+ var isNumber = (value) => typeof value === "number";
38
+ var isNotNumber = (value) => typeof value !== "number" || Number.isNaN(value) || !Number.isFinite(value);
39
+ var isNumeric = (value) => value != null && parseFloat(value.toString()) - parseFloat(value.toString()) + 1 >= 0;
40
+ var isString = (value) => Object.prototype.toString.call(value) === "[object String]";
41
+ var isUndefined = (value) => typeof value === "undefined" && value === void 0;
42
+ var isNull = (value) => value === null;
43
+ var isObject = (value) => value !== null && (typeof value === "object" || typeof value === "function") && !Array.isArray(value);
44
+ var isArray = (value) => Array.isArray(value);
45
+ var isEmpty = (value) => !Array.isArray(value) || !value.length || value.every((v) => v == null);
46
+ var isFunction = (value) => typeof value === "function";
47
+ var isUnit = (value) => /[0-9].*[px|rem|em|%|vw|vh]$/.test(value);
48
+ var cast = (value) => value;
49
+ // Annotate the CommonJS export names for ESM import in node:
50
+ 0 && (module.exports = {
51
+ cast,
52
+ isArray,
53
+ isEmpty,
54
+ isFunction,
55
+ isNotNumber,
56
+ isNull,
57
+ isNumber,
58
+ isNumeric,
59
+ isObject,
60
+ isString,
61
+ isUndefined,
62
+ isUnit
63
+ });
@@ -0,0 +1,28 @@
1
+ import {
2
+ cast,
3
+ isArray,
4
+ isEmpty,
5
+ isFunction,
6
+ isNotNumber,
7
+ isNull,
8
+ isNumber,
9
+ isNumeric,
10
+ isObject,
11
+ isString,
12
+ isUndefined,
13
+ isUnit
14
+ } from "./chunk-IVGIIDMV.mjs";
15
+ export {
16
+ cast,
17
+ isArray,
18
+ isEmpty,
19
+ isFunction,
20
+ isNotNumber,
21
+ isNull,
22
+ isNumber,
23
+ isNumeric,
24
+ isObject,
25
+ isString,
26
+ isUndefined,
27
+ isUnit
28
+ };
package/dist/calc.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ type Operand = string | number;
2
+ type Calc = {
3
+ add: (...args: Operand[]) => Calc;
4
+ subtract: (...args: Operand[]) => Calc;
5
+ multiply: (...args: Operand[]) => Calc;
6
+ divide: (...args: Operand[]) => Calc;
7
+ negate: () => Calc;
8
+ };
9
+ declare const calc: ((x: Operand) => Calc) & {
10
+ add: (...args: Operand[]) => string;
11
+ subtract: (...args: Operand[]) => string;
12
+ multiply: (...args: Operand[]) => string;
13
+ divide: (...args: Operand[]) => string;
14
+ negate: (value: Operand) => string;
15
+ };
16
+
17
+ export { Operand, calc };
package/dist/calc.js ADDED
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/calc.ts
21
+ var calc_exports = {};
22
+ __export(calc_exports, {
23
+ calc: () => calc
24
+ });
25
+ module.exports = __toCommonJS(calc_exports);
26
+ var toExpression = (operator, ...args) => args.join(` ${operator} `).replace(/calc/g, "");
27
+ var add = (...args) => `calc(${toExpression("+", ...args)})`;
28
+ var subtract = (...args) => `calc(${toExpression("-", ...args)})`;
29
+ var multiply = (...args) => `calc(${toExpression("*", ...args)})`;
30
+ var divide = (...args) => `calc(${toExpression("/", ...args)})`;
31
+ var negate = (value) => {
32
+ if (value != null && !isNaN(parseFloat(value.toString())))
33
+ return String(value).startsWith("-") ? String(value).slice(1) : `-${value}`;
34
+ return multiply(value, -1);
35
+ };
36
+ var calc = Object.assign(
37
+ (x) => ({
38
+ add: (...args) => calc(add(x, ...args)),
39
+ subtract: (...args) => calc(subtract(x, ...args)),
40
+ multiply: (...args) => calc(multiply(x, ...args)),
41
+ divide: (...args) => calc(divide(x, ...args)),
42
+ negate: () => calc(negate(x))
43
+ }),
44
+ {
45
+ add,
46
+ subtract,
47
+ multiply,
48
+ divide,
49
+ negate
50
+ }
51
+ );
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ calc
55
+ });
package/dist/calc.mjs ADDED
@@ -0,0 +1,6 @@
1
+ import {
2
+ calc
3
+ } from "./chunk-R5OUKGQ5.mjs";
4
+ export {
5
+ calc
6
+ };
@@ -0,0 +1,6 @@
1
+ // src/string.ts
2
+ var escape = (value, replaceValue = "") => value.replace(/\s+/g, replaceValue);
3
+
4
+ export {
5
+ escape
6
+ };
@@ -0,0 +1,120 @@
1
+ // src/dom.ts
2
+ var createdDom = () => !!(typeof window !== "undefined" && window.document && window.document.createElement);
3
+ var getPlatform = () => {
4
+ var _a, _b;
5
+ return (_b = (_a = navigator.userAgentData) == null ? void 0 : _a.platform) != null ? _b : navigator.platform;
6
+ };
7
+ var vendor = (v) => createdDom() && v.test(navigator.vendor);
8
+ var platform = (v) => createdDom() && v.test(getPlatform());
9
+ var isMac = () => platform(/^mac/);
10
+ var isApple = () => platform(/mac|iphone|ipad|ipod/i);
11
+ var isSafari = () => isApple() && vendor(/apple/i);
12
+ var isElement = (el) => el != null && typeof el == "object" && "nodeType" in el && el.nodeType === Node.ELEMENT_NODE;
13
+ var isHTMLElement = (el) => {
14
+ var _a;
15
+ if (!isElement(el))
16
+ return false;
17
+ const win = (_a = el.ownerDocument.defaultView) != null ? _a : window;
18
+ return el instanceof win.HTMLElement;
19
+ };
20
+ var isHidden = (el) => {
21
+ if (el.parentElement && isHidden(el.parentElement))
22
+ return true;
23
+ return el.hidden;
24
+ };
25
+ var isDisabled = (el) => Boolean(el.getAttribute("disabled")) === true || Boolean(el.getAttribute("aria-disabled")) === true;
26
+ var isVisible = (el) => el.offsetWidth > 0 && el.offsetHeight > 0;
27
+ var hasTabIndex = (el) => el.hasAttribute("tabindex");
28
+ var isContentEditable = (el) => {
29
+ const value = el.getAttribute("contenteditable");
30
+ return value !== "false" && value != null;
31
+ };
32
+ var isContains = (parent, child) => {
33
+ return parent === child || (parent == null ? void 0 : parent.contains(child));
34
+ };
35
+ var getEventRelatedTarget = (ev) => {
36
+ var _a;
37
+ return (_a = ev.relatedTarget) != null ? _a : ev.currentTarget.ownerDocument.activeElement;
38
+ };
39
+ var dataAttr = (condition) => condition ? "" : void 0;
40
+ var ariaAttr = (condition) => condition ? true : void 0;
41
+ var focusableElList = [
42
+ "input:not(:disabled):not([disabled])",
43
+ "select:not(:disabled):not([disabled])",
44
+ "textarea:not(:disabled):not([disabled])",
45
+ "embed",
46
+ "iframe",
47
+ "object",
48
+ "a[href]",
49
+ "area[href]",
50
+ "button:not(:disabled):not([disabled])",
51
+ "[tabindex]",
52
+ "audio[controls]",
53
+ "video[controls]",
54
+ "*[tabindex]:not([aria-disabled])",
55
+ "*[contenteditable]"
56
+ ];
57
+ var focusableElSelector = focusableElList.join();
58
+ var getAllFocusable = (container) => {
59
+ const focusableEls = Array.from(container.querySelectorAll(focusableElSelector));
60
+ focusableEls.unshift(container);
61
+ return focusableEls.filter((el) => isFocusable(el) && isVisible(el));
62
+ };
63
+ var isFocusable = (el) => {
64
+ if (!isHTMLElement(el) || isHidden(el) || isDisabled(el)) {
65
+ return false;
66
+ }
67
+ const { localName } = el;
68
+ const focusableTags = ["input", "select", "textarea", "button"];
69
+ if (focusableTags.indexOf(localName) >= 0)
70
+ return true;
71
+ const others = {
72
+ a: () => el.hasAttribute("href"),
73
+ audio: () => el.hasAttribute("controls"),
74
+ video: () => el.hasAttribute("controls")
75
+ };
76
+ if (localName in others)
77
+ return others[localName]();
78
+ if (isContentEditable(el))
79
+ return true;
80
+ return hasTabIndex(el);
81
+ };
82
+ var hasNegativeTabIndex = (el) => hasTabIndex(el) && el.tabIndex === -1;
83
+ var isTabbable = (el) => el ? isHTMLElement(el) && isFocusable(el) && !hasNegativeTabIndex(el) : false;
84
+ var getOwnerWindow = (node) => {
85
+ var _a, _b;
86
+ return (_b = (_a = getOwnerDocument(node)) == null ? void 0 : _a.defaultView) != null ? _b : window;
87
+ };
88
+ var getOwnerDocument = (el) => isElement(el) ? el.ownerDocument : document;
89
+ var getActiveElement = (el) => getOwnerDocument(el).activeElement;
90
+ var isActiveElement = (el) => {
91
+ return getActiveElement(el) === el;
92
+ };
93
+
94
+ export {
95
+ createdDom,
96
+ getPlatform,
97
+ vendor,
98
+ platform,
99
+ isMac,
100
+ isApple,
101
+ isSafari,
102
+ isElement,
103
+ isHTMLElement,
104
+ isHidden,
105
+ isDisabled,
106
+ hasTabIndex,
107
+ isContentEditable,
108
+ isContains,
109
+ getEventRelatedTarget,
110
+ dataAttr,
111
+ ariaAttr,
112
+ getAllFocusable,
113
+ isFocusable,
114
+ hasNegativeTabIndex,
115
+ isTabbable,
116
+ getOwnerWindow,
117
+ getOwnerDocument,
118
+ getActiveElement,
119
+ isActiveElement
120
+ };