@yamada-ui/utils 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +31 -0
- package/dist/array.d.ts +3 -0
- package/dist/array.js +30 -0
- package/dist/array.mjs +6 -0
- package/dist/assertion.d.ts +16 -0
- package/dist/assertion.js +63 -0
- package/dist/assertion.mjs +28 -0
- package/dist/calc.d.ts +17 -0
- package/dist/calc.js +55 -0
- package/dist/calc.mjs +6 -0
- package/dist/chunk-A6J4FUU7.mjs +401 -0
- package/dist/chunk-BZAW2D6U.mjs +6 -0
- package/dist/chunk-FW7XS4NH.mjs +120 -0
- package/dist/chunk-IVGIIDMV.mjs +28 -0
- package/dist/chunk-PF7LRFIA.mjs +51 -0
- package/dist/chunk-PURW64JE.mjs +6 -0
- package/dist/chunk-R5OUKGQ5.mjs +31 -0
- package/dist/chunk-SLJ4M7XC.mjs +0 -0
- package/dist/chunk-VYMGBE25.mjs +39 -0
- package/dist/color.d.ts +19 -0
- package/dist/color.js +181 -0
- package/dist/color.mjs +34 -0
- package/dist/dom.d.ts +33 -0
- package/dist/dom.js +168 -0
- package/dist/dom.mjs +54 -0
- package/dist/event.d.ts +30 -0
- package/dist/event.js +83 -0
- package/dist/event.mjs +22 -0
- package/dist/function.d.ts +6 -0
- package/dist/function.js +50 -0
- package/dist/function.mjs +20 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +796 -0
- package/dist/index.mjs +221 -0
- package/dist/index.types.d.ts +14 -0
- package/dist/index.types.js +18 -0
- package/dist/index.types.mjs +1 -0
- package/dist/number.d.ts +8 -0
- package/dist/number.js +68 -0
- package/dist/number.mjs +16 -0
- package/dist/object.d.ts +18 -0
- package/dist/object.js +192 -0
- package/dist/object.mjs +40 -0
- package/dist/react.d.ts +44 -0
- package/dist/react.js +176 -0
- package/dist/react.mjs +46 -0
- package/dist/string.d.ts +3 -0
- package/dist/string.js +30 -0
- package/dist/string.mjs +6 -0
- 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).
|
package/dist/array.d.ts
ADDED
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,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,401 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isArray,
|
|
3
|
+
isFunction,
|
|
4
|
+
isNumber,
|
|
5
|
+
isObject,
|
|
6
|
+
isString
|
|
7
|
+
} from "./chunk-IVGIIDMV.mjs";
|
|
8
|
+
|
|
9
|
+
// src/function.ts
|
|
10
|
+
var noop = () => {
|
|
11
|
+
};
|
|
12
|
+
var runIfFunc = (valOrFunc, ...args) => isFunction(valOrFunc) ? valOrFunc(...args) : valOrFunc;
|
|
13
|
+
var handlerAll = (...funcs) => (event) => {
|
|
14
|
+
funcs.some((func) => {
|
|
15
|
+
func == null ? void 0 : func(event);
|
|
16
|
+
return event == null ? void 0 : event.defaultPrevented;
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
var funcAll = (...funcs) => (arg) => funcs.forEach((func) => func == null ? void 0 : func(arg));
|
|
20
|
+
|
|
21
|
+
// src/react.tsx
|
|
22
|
+
import * as React from "react";
|
|
23
|
+
var createContext2 = ({
|
|
24
|
+
strict = true,
|
|
25
|
+
errorMessage = "useContext: `context` is undefined. Seems you forgot to wrap component within the Provider",
|
|
26
|
+
name
|
|
27
|
+
} = {}) => {
|
|
28
|
+
const Context = React.createContext(void 0);
|
|
29
|
+
Context.displayName = name;
|
|
30
|
+
const useContext2 = () => {
|
|
31
|
+
var _a;
|
|
32
|
+
const context = React.useContext(Context);
|
|
33
|
+
if (!context && strict) {
|
|
34
|
+
const error = new Error(errorMessage);
|
|
35
|
+
error.name = "ContextError";
|
|
36
|
+
(_a = Error.captureStackTrace) == null ? void 0 : _a.call(Error, error, useContext2);
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
return context;
|
|
40
|
+
};
|
|
41
|
+
return [Context.Provider, useContext2, Context];
|
|
42
|
+
};
|
|
43
|
+
var useSafeLayoutEffect = Boolean(globalThis == null ? void 0 : globalThis.document) ? React.useLayoutEffect : React.useEffect;
|
|
44
|
+
var useUnmountEffect = (callback) => (
|
|
45
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
46
|
+
React.useEffect(() => () => callback(), [])
|
|
47
|
+
);
|
|
48
|
+
var useIsMounted = () => {
|
|
49
|
+
const isMounted = React.useRef(false);
|
|
50
|
+
useSafeLayoutEffect(() => {
|
|
51
|
+
isMounted.current = true;
|
|
52
|
+
return () => {
|
|
53
|
+
isMounted.current = false;
|
|
54
|
+
};
|
|
55
|
+
}, []);
|
|
56
|
+
return isMounted;
|
|
57
|
+
};
|
|
58
|
+
var getValidChildren = (children) => React.Children.toArray(children).filter(
|
|
59
|
+
(child) => React.isValidElement(child)
|
|
60
|
+
);
|
|
61
|
+
var isValidElement2 = (child) => React.isValidElement(child) || isString(child) || isNumber(child);
|
|
62
|
+
var findChildren = (children, ...types) => children.find((child) => types.some((type) => child.type === type)) ? children.sort(
|
|
63
|
+
(a, b) => types.some((type) => a.type === type) ? -1 : types.some((type) => b.type === type) ? 1 : 0
|
|
64
|
+
) : [void 0, ...children];
|
|
65
|
+
var includesChildren = (children, ...types) => children.some((child) => {
|
|
66
|
+
if (types.some((type) => child.type === type))
|
|
67
|
+
return true;
|
|
68
|
+
const children2 = getValidChildren(child.props.children);
|
|
69
|
+
return children2.length ? includesChildren(children2, ...types) : false;
|
|
70
|
+
});
|
|
71
|
+
var omitChildren = (children, ...types) => children.filter((child) => types.every((type) => child.type !== type));
|
|
72
|
+
var pickChildren = (children, ...types) => children.filter((child) => types.every((type) => child.type === type));
|
|
73
|
+
var cx = (...classNames) => classNames.filter(Boolean).join(" ");
|
|
74
|
+
var isRefObject = (val) => "current" in val;
|
|
75
|
+
var assignRef = (ref, value) => {
|
|
76
|
+
if (ref == null)
|
|
77
|
+
return;
|
|
78
|
+
if (typeof ref === "function") {
|
|
79
|
+
ref(value);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
ref.current = value;
|
|
84
|
+
} catch (error) {
|
|
85
|
+
throw new Error(`Cannot assign value '${value}' to ref '${ref}'`);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
var mergeRefs = (...refs) => (node) => {
|
|
89
|
+
refs.forEach((ref) => {
|
|
90
|
+
assignRef(ref, node);
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
var useMergeRefs = (...refs) => React.useMemo(() => mergeRefs(...refs), [refs]);
|
|
94
|
+
var useCallbackRef = (callback, deps = []) => {
|
|
95
|
+
const callbackRef = React.useRef(callback);
|
|
96
|
+
React.useEffect(() => {
|
|
97
|
+
callbackRef.current = callback;
|
|
98
|
+
});
|
|
99
|
+
return React.useCallback((...args) => {
|
|
100
|
+
var _a;
|
|
101
|
+
return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
|
|
102
|
+
}, deps);
|
|
103
|
+
};
|
|
104
|
+
var useUpdateEffect = (callback, deps) => {
|
|
105
|
+
const renderCycleRef = React.useRef(false);
|
|
106
|
+
const effectCycleRef = React.useRef(false);
|
|
107
|
+
React.useEffect(() => {
|
|
108
|
+
const mounted = renderCycleRef.current;
|
|
109
|
+
const run = mounted && effectCycleRef.current;
|
|
110
|
+
if (run)
|
|
111
|
+
return callback();
|
|
112
|
+
effectCycleRef.current = true;
|
|
113
|
+
}, deps);
|
|
114
|
+
React.useEffect(() => {
|
|
115
|
+
renderCycleRef.current = true;
|
|
116
|
+
return () => {
|
|
117
|
+
renderCycleRef.current = false;
|
|
118
|
+
};
|
|
119
|
+
}, []);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// src/color.ts
|
|
123
|
+
import { TinyColor } from "@ctrl/tinycolor";
|
|
124
|
+
var getColor = (color, fallback) => (theme, colorMode) => {
|
|
125
|
+
const hex = getMemoizedObject(
|
|
126
|
+
theme,
|
|
127
|
+
`colors.${color}`,
|
|
128
|
+
color
|
|
129
|
+
);
|
|
130
|
+
if (isArray(hex)) {
|
|
131
|
+
const [lightHex, darkHex] = hex;
|
|
132
|
+
const { isValid, originalInput } = new TinyColor(colorMode !== "dark" ? lightHex : darkHex);
|
|
133
|
+
return isValid ? originalInput : fallback;
|
|
134
|
+
} else {
|
|
135
|
+
const { isValid, originalInput } = new TinyColor(hex);
|
|
136
|
+
return isValid ? originalInput : fallback;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
var lightenColor = (color, amount) => (theme, colorMode) => {
|
|
140
|
+
const raw = getColor(color)(theme, colorMode);
|
|
141
|
+
return new TinyColor(raw).lighten(amount).toRgbString();
|
|
142
|
+
};
|
|
143
|
+
var darkenColor = (color, amount) => (theme, colorMode) => {
|
|
144
|
+
const raw = getColor(color)(theme, colorMode);
|
|
145
|
+
return new TinyColor(raw).darken(amount).toRgbString();
|
|
146
|
+
};
|
|
147
|
+
var brightenColor = (color, amount) => (theme, colorMode) => {
|
|
148
|
+
const raw = getColor(color)(theme, colorMode);
|
|
149
|
+
return new TinyColor(raw).brighten(amount).toRgbString();
|
|
150
|
+
};
|
|
151
|
+
var tintColor = (color, amount) => (theme, colorMode) => {
|
|
152
|
+
const raw = getColor(color)(theme, colorMode);
|
|
153
|
+
return new TinyColor(raw).tint(amount).toRgbString();
|
|
154
|
+
};
|
|
155
|
+
var shadeColor = (color, amount) => (theme, colorMode) => {
|
|
156
|
+
const raw = getColor(color)(theme, colorMode);
|
|
157
|
+
return new TinyColor(raw).shade(amount).toRgbString();
|
|
158
|
+
};
|
|
159
|
+
var transparentizeColor = (color, alpha) => (theme, colorMode) => {
|
|
160
|
+
const raw = getColor(color)(theme, colorMode);
|
|
161
|
+
return new TinyColor(raw).setAlpha(alpha).toRgbString();
|
|
162
|
+
};
|
|
163
|
+
var toneColor = (color, l) => (theme, colorMode) => {
|
|
164
|
+
const raw = getColor(color)(theme, colorMode);
|
|
165
|
+
if (l < 0 || 900 < l)
|
|
166
|
+
return color;
|
|
167
|
+
let n = (l - 500) / 10;
|
|
168
|
+
const isLighten = n <= 0;
|
|
169
|
+
if (isLighten)
|
|
170
|
+
n *= -1;
|
|
171
|
+
if (n !== 0)
|
|
172
|
+
n = n - 5 * (isLighten ? 1 : -1);
|
|
173
|
+
return new TinyColor(raw)[isLighten ? "lighten" : "shade"](n).toString();
|
|
174
|
+
};
|
|
175
|
+
var randomColor = ({ string, colors } = {}) => {
|
|
176
|
+
const fallback = randomHex();
|
|
177
|
+
if (string && colors)
|
|
178
|
+
return randomColorFromList(string, colors);
|
|
179
|
+
if (string && !colors)
|
|
180
|
+
return randomColorFromString(string);
|
|
181
|
+
if (colors && !string)
|
|
182
|
+
return randomFromList(colors);
|
|
183
|
+
return fallback;
|
|
184
|
+
};
|
|
185
|
+
var randomHex = () => `#${Math.floor(Math.random() * 16777215).toString(16).padEnd(6, "0")}`;
|
|
186
|
+
var randomColorFromString = (str) => {
|
|
187
|
+
let hash = 0;
|
|
188
|
+
if (str.length === 0)
|
|
189
|
+
return hash.toString();
|
|
190
|
+
for (let i = 0; i < str.length; i += 1) {
|
|
191
|
+
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
192
|
+
hash = hash & hash;
|
|
193
|
+
}
|
|
194
|
+
let color = "#";
|
|
195
|
+
for (let j = 0; j < 3; j += 1) {
|
|
196
|
+
const value = hash >> j * 8 & 255;
|
|
197
|
+
color += `00${value.toString(16)}`.substr(-2);
|
|
198
|
+
}
|
|
199
|
+
return color;
|
|
200
|
+
};
|
|
201
|
+
var randomColorFromList = (str, list) => {
|
|
202
|
+
let index = 0;
|
|
203
|
+
if (str.length === 0)
|
|
204
|
+
return list[0];
|
|
205
|
+
for (let i = 0; i < str.length; i += 1) {
|
|
206
|
+
index = str.charCodeAt(i) + ((index << 5) - index);
|
|
207
|
+
index = index & index;
|
|
208
|
+
}
|
|
209
|
+
index = (index % list.length + list.length) % list.length;
|
|
210
|
+
return list[index];
|
|
211
|
+
};
|
|
212
|
+
var randomFromList = (list) => list[Math.floor(Math.random() * list.length)];
|
|
213
|
+
var isLight = (color) => (theme, colorMode) => {
|
|
214
|
+
const raw = getColor(color)(theme, colorMode);
|
|
215
|
+
return new TinyColor(raw).isLight();
|
|
216
|
+
};
|
|
217
|
+
var isDark = (color) => (theme, colorMode) => {
|
|
218
|
+
const raw = getColor(color)(theme, colorMode);
|
|
219
|
+
return new TinyColor(raw).isDark();
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// src/object.ts
|
|
223
|
+
var omitObject = (obj, keys) => {
|
|
224
|
+
const result = {};
|
|
225
|
+
Object.keys(obj).forEach((key) => {
|
|
226
|
+
if (keys.includes(key))
|
|
227
|
+
return;
|
|
228
|
+
result[key] = obj[key];
|
|
229
|
+
});
|
|
230
|
+
return result;
|
|
231
|
+
};
|
|
232
|
+
var pickObject = (obj, keys) => {
|
|
233
|
+
const result = {};
|
|
234
|
+
keys.forEach((key) => {
|
|
235
|
+
if (key in obj)
|
|
236
|
+
result[key] = obj[key];
|
|
237
|
+
});
|
|
238
|
+
return result;
|
|
239
|
+
};
|
|
240
|
+
var splitObject = (obj, keys) => {
|
|
241
|
+
const picked = {};
|
|
242
|
+
const omitted = {};
|
|
243
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
244
|
+
if (keys.includes(key)) {
|
|
245
|
+
picked[key] = value;
|
|
246
|
+
} else {
|
|
247
|
+
omitted[key] = value;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return [picked, omitted];
|
|
251
|
+
};
|
|
252
|
+
var filterObject = (obj, func) => {
|
|
253
|
+
const result = {};
|
|
254
|
+
Object.entries(obj).forEach(([key, value]) => {
|
|
255
|
+
const shouldPass = func(key, value, obj);
|
|
256
|
+
if (shouldPass)
|
|
257
|
+
result[key] = value;
|
|
258
|
+
});
|
|
259
|
+
return result;
|
|
260
|
+
};
|
|
261
|
+
var filterUndefined = (obj) => filterObject(obj, (_, val) => val !== null && val !== void 0);
|
|
262
|
+
var merge = (target, source, overrideArray = false) => {
|
|
263
|
+
let result = Object.assign({}, target);
|
|
264
|
+
if (isObject(target) && isObject(source)) {
|
|
265
|
+
for (const [sourceKey, sourceValue] of Object.entries(source)) {
|
|
266
|
+
const targetValue = target[sourceKey];
|
|
267
|
+
if (overrideArray && Array.isArray(sourceValue) && Array.isArray(targetValue)) {
|
|
268
|
+
result[sourceKey] = targetValue.concat(...sourceValue);
|
|
269
|
+
} else if (!isFunction(sourceValue) && isObject(sourceValue) && target.hasOwnProperty(sourceKey)) {
|
|
270
|
+
result[sourceKey] = merge(targetValue, sourceValue, overrideArray);
|
|
271
|
+
} else {
|
|
272
|
+
Object.assign(result, { [sourceKey]: sourceValue });
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return result;
|
|
277
|
+
};
|
|
278
|
+
var flattenObject = (obj, maxDepth = Infinity) => {
|
|
279
|
+
if (!isObject(obj) && !isArray(obj) || !maxDepth)
|
|
280
|
+
return obj;
|
|
281
|
+
return Object.entries(obj).reduce((result, [key, value]) => {
|
|
282
|
+
if (isObject(value)) {
|
|
283
|
+
Object.entries(flattenObject(value, maxDepth - 1)).forEach(([childKey, childValue]) => {
|
|
284
|
+
result[`${key}.${childKey}`] = childValue;
|
|
285
|
+
});
|
|
286
|
+
} else {
|
|
287
|
+
result[key] = value;
|
|
288
|
+
}
|
|
289
|
+
return result;
|
|
290
|
+
}, {});
|
|
291
|
+
};
|
|
292
|
+
var objectFromEntries = (entries) => entries.reduce((result, [key, value]) => {
|
|
293
|
+
result[key] = value;
|
|
294
|
+
return result;
|
|
295
|
+
}, {});
|
|
296
|
+
var keysFormObject = (obj) => Object.keys(obj);
|
|
297
|
+
var replaceObject = (objOrArray, callBack) => {
|
|
298
|
+
if (isArray(objOrArray)) {
|
|
299
|
+
return objOrArray.map(callBack);
|
|
300
|
+
} else if (isObject(objOrArray)) {
|
|
301
|
+
return Object.entries(objOrArray).reduce((obj, [key, value]) => {
|
|
302
|
+
obj[key] = callBack(value);
|
|
303
|
+
return obj;
|
|
304
|
+
}, {});
|
|
305
|
+
} else {
|
|
306
|
+
return callBack(objOrArray);
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
var getObject = (obj, path, fallback, i) => {
|
|
310
|
+
const k = typeof path === "string" ? path.split(".") : [path];
|
|
311
|
+
for (i = 0; i < k.length; i += 1) {
|
|
312
|
+
if (!obj)
|
|
313
|
+
break;
|
|
314
|
+
obj = obj[k[i]];
|
|
315
|
+
}
|
|
316
|
+
return obj === void 0 ? fallback : obj;
|
|
317
|
+
};
|
|
318
|
+
var memoizeObject = (func) => {
|
|
319
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
320
|
+
const memoizedFunc = (obj, path, fallback, i) => {
|
|
321
|
+
if (typeof obj === "undefined") {
|
|
322
|
+
return func(obj, path, fallback);
|
|
323
|
+
}
|
|
324
|
+
if (!cache.has(obj))
|
|
325
|
+
cache.set(obj, /* @__PURE__ */ new Map());
|
|
326
|
+
const map = cache.get(obj);
|
|
327
|
+
if (map.has(path))
|
|
328
|
+
return map.get(path);
|
|
329
|
+
const value = func(obj, path, fallback, i);
|
|
330
|
+
map.set(path, value);
|
|
331
|
+
return value;
|
|
332
|
+
};
|
|
333
|
+
return memoizedFunc;
|
|
334
|
+
};
|
|
335
|
+
var getMemoizedObject = memoizeObject(getObject);
|
|
336
|
+
var assignAfter = (target, ...sources) => {
|
|
337
|
+
if (target == null)
|
|
338
|
+
throw new TypeError("Cannot convert undefined or null to object");
|
|
339
|
+
const result = { ...target };
|
|
340
|
+
for (const nextSource of sources) {
|
|
341
|
+
if (nextSource == null)
|
|
342
|
+
continue;
|
|
343
|
+
for (const nextKey in nextSource) {
|
|
344
|
+
if (!Object.prototype.hasOwnProperty.call(nextSource, nextKey))
|
|
345
|
+
continue;
|
|
346
|
+
if (nextKey in result)
|
|
347
|
+
delete result[nextKey];
|
|
348
|
+
result[nextKey] = nextSource[nextKey];
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return result;
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
export {
|
|
355
|
+
omitObject,
|
|
356
|
+
pickObject,
|
|
357
|
+
splitObject,
|
|
358
|
+
filterObject,
|
|
359
|
+
filterUndefined,
|
|
360
|
+
merge,
|
|
361
|
+
flattenObject,
|
|
362
|
+
objectFromEntries,
|
|
363
|
+
keysFormObject,
|
|
364
|
+
replaceObject,
|
|
365
|
+
getObject,
|
|
366
|
+
memoizeObject,
|
|
367
|
+
getMemoizedObject,
|
|
368
|
+
assignAfter,
|
|
369
|
+
noop,
|
|
370
|
+
runIfFunc,
|
|
371
|
+
handlerAll,
|
|
372
|
+
funcAll,
|
|
373
|
+
createContext2 as createContext,
|
|
374
|
+
useSafeLayoutEffect,
|
|
375
|
+
useUnmountEffect,
|
|
376
|
+
useIsMounted,
|
|
377
|
+
getValidChildren,
|
|
378
|
+
isValidElement2 as isValidElement,
|
|
379
|
+
findChildren,
|
|
380
|
+
includesChildren,
|
|
381
|
+
omitChildren,
|
|
382
|
+
pickChildren,
|
|
383
|
+
cx,
|
|
384
|
+
isRefObject,
|
|
385
|
+
assignRef,
|
|
386
|
+
mergeRefs,
|
|
387
|
+
useMergeRefs,
|
|
388
|
+
useCallbackRef,
|
|
389
|
+
useUpdateEffect,
|
|
390
|
+
getColor,
|
|
391
|
+
lightenColor,
|
|
392
|
+
darkenColor,
|
|
393
|
+
brightenColor,
|
|
394
|
+
tintColor,
|
|
395
|
+
shadeColor,
|
|
396
|
+
transparentizeColor,
|
|
397
|
+
toneColor,
|
|
398
|
+
randomColor,
|
|
399
|
+
isLight,
|
|
400
|
+
isDark
|
|
401
|
+
};
|