@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/dist/react.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/react.tsx
|
|
31
|
+
var react_exports = {};
|
|
32
|
+
__export(react_exports, {
|
|
33
|
+
assignRef: () => assignRef,
|
|
34
|
+
createContext: () => createContext2,
|
|
35
|
+
cx: () => cx,
|
|
36
|
+
findChildren: () => findChildren,
|
|
37
|
+
getValidChildren: () => getValidChildren,
|
|
38
|
+
includesChildren: () => includesChildren,
|
|
39
|
+
isRefObject: () => isRefObject,
|
|
40
|
+
isValidElement: () => isValidElement2,
|
|
41
|
+
mergeRefs: () => mergeRefs,
|
|
42
|
+
omitChildren: () => omitChildren,
|
|
43
|
+
pickChildren: () => pickChildren,
|
|
44
|
+
useCallbackRef: () => useCallbackRef,
|
|
45
|
+
useIsMounted: () => useIsMounted,
|
|
46
|
+
useMergeRefs: () => useMergeRefs,
|
|
47
|
+
useSafeLayoutEffect: () => useSafeLayoutEffect,
|
|
48
|
+
useUnmountEffect: () => useUnmountEffect,
|
|
49
|
+
useUpdateEffect: () => useUpdateEffect
|
|
50
|
+
});
|
|
51
|
+
module.exports = __toCommonJS(react_exports);
|
|
52
|
+
var React = __toESM(require("react"));
|
|
53
|
+
|
|
54
|
+
// src/assertion.ts
|
|
55
|
+
var isNumber = (value) => typeof value === "number";
|
|
56
|
+
var isString = (value) => Object.prototype.toString.call(value) === "[object String]";
|
|
57
|
+
|
|
58
|
+
// src/react.tsx
|
|
59
|
+
var createContext2 = ({
|
|
60
|
+
strict = true,
|
|
61
|
+
errorMessage = "useContext: `context` is undefined. Seems you forgot to wrap component within the Provider",
|
|
62
|
+
name
|
|
63
|
+
} = {}) => {
|
|
64
|
+
const Context = React.createContext(void 0);
|
|
65
|
+
Context.displayName = name;
|
|
66
|
+
const useContext2 = () => {
|
|
67
|
+
var _a;
|
|
68
|
+
const context = React.useContext(Context);
|
|
69
|
+
if (!context && strict) {
|
|
70
|
+
const error = new Error(errorMessage);
|
|
71
|
+
error.name = "ContextError";
|
|
72
|
+
(_a = Error.captureStackTrace) == null ? void 0 : _a.call(Error, error, useContext2);
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
return context;
|
|
76
|
+
};
|
|
77
|
+
return [Context.Provider, useContext2, Context];
|
|
78
|
+
};
|
|
79
|
+
var useSafeLayoutEffect = Boolean(globalThis == null ? void 0 : globalThis.document) ? React.useLayoutEffect : React.useEffect;
|
|
80
|
+
var useUnmountEffect = (callback) => (
|
|
81
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
82
|
+
React.useEffect(() => () => callback(), [])
|
|
83
|
+
);
|
|
84
|
+
var useIsMounted = () => {
|
|
85
|
+
const isMounted = React.useRef(false);
|
|
86
|
+
useSafeLayoutEffect(() => {
|
|
87
|
+
isMounted.current = true;
|
|
88
|
+
return () => {
|
|
89
|
+
isMounted.current = false;
|
|
90
|
+
};
|
|
91
|
+
}, []);
|
|
92
|
+
return isMounted;
|
|
93
|
+
};
|
|
94
|
+
var getValidChildren = (children) => React.Children.toArray(children).filter(
|
|
95
|
+
(child) => React.isValidElement(child)
|
|
96
|
+
);
|
|
97
|
+
var isValidElement2 = (child) => React.isValidElement(child) || isString(child) || isNumber(child);
|
|
98
|
+
var findChildren = (children, ...types) => children.find((child) => types.some((type) => child.type === type)) ? children.sort(
|
|
99
|
+
(a, b) => types.some((type) => a.type === type) ? -1 : types.some((type) => b.type === type) ? 1 : 0
|
|
100
|
+
) : [void 0, ...children];
|
|
101
|
+
var includesChildren = (children, ...types) => children.some((child) => {
|
|
102
|
+
if (types.some((type) => child.type === type))
|
|
103
|
+
return true;
|
|
104
|
+
const children2 = getValidChildren(child.props.children);
|
|
105
|
+
return children2.length ? includesChildren(children2, ...types) : false;
|
|
106
|
+
});
|
|
107
|
+
var omitChildren = (children, ...types) => children.filter((child) => types.every((type) => child.type !== type));
|
|
108
|
+
var pickChildren = (children, ...types) => children.filter((child) => types.every((type) => child.type === type));
|
|
109
|
+
var cx = (...classNames) => classNames.filter(Boolean).join(" ");
|
|
110
|
+
var isRefObject = (val) => "current" in val;
|
|
111
|
+
var assignRef = (ref, value) => {
|
|
112
|
+
if (ref == null)
|
|
113
|
+
return;
|
|
114
|
+
if (typeof ref === "function") {
|
|
115
|
+
ref(value);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
ref.current = value;
|
|
120
|
+
} catch (error) {
|
|
121
|
+
throw new Error(`Cannot assign value '${value}' to ref '${ref}'`);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
var mergeRefs = (...refs) => (node) => {
|
|
125
|
+
refs.forEach((ref) => {
|
|
126
|
+
assignRef(ref, node);
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
var useMergeRefs = (...refs) => React.useMemo(() => mergeRefs(...refs), [refs]);
|
|
130
|
+
var useCallbackRef = (callback, deps = []) => {
|
|
131
|
+
const callbackRef = React.useRef(callback);
|
|
132
|
+
React.useEffect(() => {
|
|
133
|
+
callbackRef.current = callback;
|
|
134
|
+
});
|
|
135
|
+
return React.useCallback((...args) => {
|
|
136
|
+
var _a;
|
|
137
|
+
return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
|
|
138
|
+
}, deps);
|
|
139
|
+
};
|
|
140
|
+
var useUpdateEffect = (callback, deps) => {
|
|
141
|
+
const renderCycleRef = React.useRef(false);
|
|
142
|
+
const effectCycleRef = React.useRef(false);
|
|
143
|
+
React.useEffect(() => {
|
|
144
|
+
const mounted = renderCycleRef.current;
|
|
145
|
+
const run = mounted && effectCycleRef.current;
|
|
146
|
+
if (run)
|
|
147
|
+
return callback();
|
|
148
|
+
effectCycleRef.current = true;
|
|
149
|
+
}, deps);
|
|
150
|
+
React.useEffect(() => {
|
|
151
|
+
renderCycleRef.current = true;
|
|
152
|
+
return () => {
|
|
153
|
+
renderCycleRef.current = false;
|
|
154
|
+
};
|
|
155
|
+
}, []);
|
|
156
|
+
};
|
|
157
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
158
|
+
0 && (module.exports = {
|
|
159
|
+
assignRef,
|
|
160
|
+
createContext,
|
|
161
|
+
cx,
|
|
162
|
+
findChildren,
|
|
163
|
+
getValidChildren,
|
|
164
|
+
includesChildren,
|
|
165
|
+
isRefObject,
|
|
166
|
+
isValidElement,
|
|
167
|
+
mergeRefs,
|
|
168
|
+
omitChildren,
|
|
169
|
+
pickChildren,
|
|
170
|
+
useCallbackRef,
|
|
171
|
+
useIsMounted,
|
|
172
|
+
useMergeRefs,
|
|
173
|
+
useSafeLayoutEffect,
|
|
174
|
+
useUnmountEffect,
|
|
175
|
+
useUpdateEffect
|
|
176
|
+
});
|
package/dist/react.mjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assignRef,
|
|
3
|
+
createContext,
|
|
4
|
+
cx,
|
|
5
|
+
findChildren,
|
|
6
|
+
getValidChildren,
|
|
7
|
+
includesChildren,
|
|
8
|
+
isRefObject,
|
|
9
|
+
isValidElement,
|
|
10
|
+
mergeRefs,
|
|
11
|
+
omitChildren,
|
|
12
|
+
pickChildren,
|
|
13
|
+
useCallbackRef,
|
|
14
|
+
useIsMounted,
|
|
15
|
+
useMergeRefs,
|
|
16
|
+
useSafeLayoutEffect,
|
|
17
|
+
useUnmountEffect,
|
|
18
|
+
useUpdateEffect
|
|
19
|
+
} from "./chunk-A6J4FUU7.mjs";
|
|
20
|
+
import "./chunk-SLJ4M7XC.mjs";
|
|
21
|
+
import "./chunk-VYMGBE25.mjs";
|
|
22
|
+
import "./chunk-BZAW2D6U.mjs";
|
|
23
|
+
import "./chunk-PURW64JE.mjs";
|
|
24
|
+
import "./chunk-IVGIIDMV.mjs";
|
|
25
|
+
import "./chunk-R5OUKGQ5.mjs";
|
|
26
|
+
import "./chunk-FW7XS4NH.mjs";
|
|
27
|
+
import "./chunk-PF7LRFIA.mjs";
|
|
28
|
+
export {
|
|
29
|
+
assignRef,
|
|
30
|
+
createContext,
|
|
31
|
+
cx,
|
|
32
|
+
findChildren,
|
|
33
|
+
getValidChildren,
|
|
34
|
+
includesChildren,
|
|
35
|
+
isRefObject,
|
|
36
|
+
isValidElement,
|
|
37
|
+
mergeRefs,
|
|
38
|
+
omitChildren,
|
|
39
|
+
pickChildren,
|
|
40
|
+
useCallbackRef,
|
|
41
|
+
useIsMounted,
|
|
42
|
+
useMergeRefs,
|
|
43
|
+
useSafeLayoutEffect,
|
|
44
|
+
useUnmountEffect,
|
|
45
|
+
useUpdateEffect
|
|
46
|
+
};
|
package/dist/string.d.ts
ADDED
package/dist/string.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/string.ts
|
|
21
|
+
var string_exports = {};
|
|
22
|
+
__export(string_exports, {
|
|
23
|
+
escape: () => escape
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(string_exports);
|
|
26
|
+
var escape = (value, replaceValue = "") => value.replace(/\s+/g, replaceValue);
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
escape
|
|
30
|
+
});
|
package/dist/string.mjs
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yamada-ui/utils",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Yamada UI utils",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"utils",
|
|
7
|
+
"utilities",
|
|
8
|
+
"yamada",
|
|
9
|
+
"yamada ui",
|
|
10
|
+
"react"
|
|
11
|
+
],
|
|
12
|
+
"author": "Hirotomo Yamada <hirotomo.yamada@avap.co.jp>",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"main": "dist/index.js",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/hirotomoyamada/yamada-ui",
|
|
25
|
+
"directory": "packages/utils"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/hirotomoyamada/yamada-ui/issues"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@ctrl/tinycolor": "^3.4.1"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"react": "^18.0.0",
|
|
35
|
+
"clean-package": "2.2.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"react": ">=18"
|
|
39
|
+
},
|
|
40
|
+
"clean-package": "../../clean-package.config.json",
|
|
41
|
+
"tsup": {
|
|
42
|
+
"clean": true,
|
|
43
|
+
"target": "es2019",
|
|
44
|
+
"format": [
|
|
45
|
+
"cjs",
|
|
46
|
+
"esm"
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
"module": "dist/index.mjs",
|
|
50
|
+
"types": "dist/index.d.ts",
|
|
51
|
+
"exports": {
|
|
52
|
+
".": {
|
|
53
|
+
"types": "./dist/index.d.ts",
|
|
54
|
+
"import": "./dist/index.mjs",
|
|
55
|
+
"require": "./dist/index.js"
|
|
56
|
+
},
|
|
57
|
+
"./package.json": "./package.json"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"dev": "pnpm build:fast -- --watch",
|
|
61
|
+
"build": "tsup src --dts",
|
|
62
|
+
"build:fast": "tsup src",
|
|
63
|
+
"clean": "rimraf dist .turbo",
|
|
64
|
+
"typecheck": "tsc --noEmit"
|
|
65
|
+
}
|
|
66
|
+
}
|