@yamada-ui/utils 0.1.3 → 0.1.5
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/dist/{chunk-FW7XS4NH.mjs → chunk-H5VMEQNO.mjs} +3 -1
- package/dist/{chunk-UUOSA3BW.mjs → chunk-XIDDMDVR.mjs} +53 -32
- package/dist/color.d.mts +3 -2
- package/dist/color.d.ts +3 -2
- package/dist/color.js +8 -6
- package/dist/color.mjs +4 -2
- package/dist/dom.js +3 -1
- package/dist/dom.mjs +1 -1
- package/dist/function.mjs +2 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +49 -32
- package/dist/index.mjs +4 -2
- package/dist/object.d.mts +2 -2
- package/dist/object.d.ts +2 -2
- package/dist/object.js +5 -3
- package/dist/object.mjs +2 -2
- package/dist/react.d.mts +1 -4
- package/dist/react.d.ts +1 -4
- package/dist/react.js +33 -22
- package/dist/react.mjs +2 -2
- package/package.json +1 -1
|
@@ -56,7 +56,9 @@ var focusableElList = [
|
|
|
56
56
|
];
|
|
57
57
|
var focusableElSelector = focusableElList.join();
|
|
58
58
|
var getAllFocusable = (container) => {
|
|
59
|
-
const focusableEls = Array.from(
|
|
59
|
+
const focusableEls = Array.from(
|
|
60
|
+
container.querySelectorAll(focusableElSelector)
|
|
61
|
+
);
|
|
60
62
|
focusableEls.unshift(container);
|
|
61
63
|
return focusableEls.filter((el) => isFocusable(el) && isVisible(el));
|
|
62
64
|
};
|
|
@@ -38,7 +38,11 @@ var createContext2 = ({
|
|
|
38
38
|
}
|
|
39
39
|
return context;
|
|
40
40
|
};
|
|
41
|
-
return [
|
|
41
|
+
return [
|
|
42
|
+
Context.Provider,
|
|
43
|
+
useContext2,
|
|
44
|
+
Context
|
|
45
|
+
];
|
|
42
46
|
};
|
|
43
47
|
var useSafeLayoutEffect = Boolean(globalThis == null ? void 0 : globalThis.document) ? React.useLayoutEffect : React.useEffect;
|
|
44
48
|
var useUnmountEffect = (callback) => (
|
|
@@ -96,10 +100,13 @@ var useCallbackRef = (callback, deps = []) => {
|
|
|
96
100
|
React.useEffect(() => {
|
|
97
101
|
callbackRef.current = callback;
|
|
98
102
|
});
|
|
99
|
-
return React.useCallback(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
return React.useCallback(
|
|
104
|
+
(...args) => {
|
|
105
|
+
var _a;
|
|
106
|
+
return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
|
|
107
|
+
},
|
|
108
|
+
deps
|
|
109
|
+
);
|
|
103
110
|
};
|
|
104
111
|
var useUpdateEffect = (callback, deps) => {
|
|
105
112
|
const renderCycleRef = React.useRef(false);
|
|
@@ -129,23 +136,27 @@ var useAsyncFunc = (func, deps = [], initialState = { loading: false }) => {
|
|
|
129
136
|
const lastCallId = React.useRef(0);
|
|
130
137
|
const isMounted = useIsMounted();
|
|
131
138
|
const [state, setState] = React.useState(initialState);
|
|
132
|
-
const callback = React.useCallback(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
139
|
+
const callback = React.useCallback(
|
|
140
|
+
(...args) => {
|
|
141
|
+
const callId = ++lastCallId.current;
|
|
142
|
+
if (!state.loading)
|
|
143
|
+
setState((prevState) => ({ ...prevState, loading: true }));
|
|
144
|
+
return func(...args).then(
|
|
145
|
+
(value) => {
|
|
146
|
+
if (isMounted.current && callId === lastCallId.current)
|
|
147
|
+
setState({ value, loading: false });
|
|
148
|
+
return value;
|
|
149
|
+
},
|
|
150
|
+
(error) => {
|
|
151
|
+
if (isMounted.current && callId === lastCallId.current)
|
|
152
|
+
setState({ error, loading: false });
|
|
153
|
+
return error;
|
|
154
|
+
}
|
|
155
|
+
);
|
|
156
|
+
},
|
|
157
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
158
|
+
deps
|
|
159
|
+
);
|
|
149
160
|
return [state, callback];
|
|
150
161
|
};
|
|
151
162
|
var useAsyncRetry = (func, deps = []) => {
|
|
@@ -161,13 +172,17 @@ var useAsyncRetry = (func, deps = []) => {
|
|
|
161
172
|
};
|
|
162
173
|
|
|
163
174
|
// src/color.ts
|
|
164
|
-
import {
|
|
175
|
+
import {
|
|
176
|
+
toHex,
|
|
177
|
+
parseToRgba,
|
|
178
|
+
transparentize,
|
|
179
|
+
mix,
|
|
180
|
+
darken,
|
|
181
|
+
lighten
|
|
182
|
+
} from "color2k";
|
|
183
|
+
var isGray = (colorScheme) => colorScheme === "gray" || colorScheme === "zinc" || colorScheme === "neutral" || colorScheme === "stone";
|
|
165
184
|
var getColor = (color, fallback) => (theme, colorMode) => {
|
|
166
|
-
const hex = getMemoizedObject(
|
|
167
|
-
theme,
|
|
168
|
-
`colors.${color}`,
|
|
169
|
-
color
|
|
170
|
-
);
|
|
185
|
+
const hex = getMemoizedObject(theme, `colors.${color}`, color);
|
|
171
186
|
try {
|
|
172
187
|
if (isArray(hex)) {
|
|
173
188
|
const [lightHex, darkHex] = hex;
|
|
@@ -211,7 +226,10 @@ var toneColor = (color, l) => (theme, colorMode) => {
|
|
|
211
226
|
n = n - 5 * (isLighten ? 1 : -1);
|
|
212
227
|
return toHex(isLighten ? lighten(raw, n / 100) : mix(raw, "#000", n / 100));
|
|
213
228
|
};
|
|
214
|
-
var randomColor = ({
|
|
229
|
+
var randomColor = ({
|
|
230
|
+
string,
|
|
231
|
+
colors
|
|
232
|
+
} = {}) => {
|
|
215
233
|
const fallback = randomHex();
|
|
216
234
|
if (string && colors)
|
|
217
235
|
return randomColorFromList(string, colors);
|
|
@@ -323,9 +341,11 @@ var flattenObject = (obj, maxDepth = Infinity) => {
|
|
|
323
341
|
return obj;
|
|
324
342
|
return Object.entries(obj).reduce((result, [key, value]) => {
|
|
325
343
|
if (isObject(value)) {
|
|
326
|
-
Object.entries(flattenObject(value, maxDepth - 1)).forEach(
|
|
327
|
-
|
|
328
|
-
|
|
344
|
+
Object.entries(flattenObject(value, maxDepth - 1)).forEach(
|
|
345
|
+
([childKey, childValue]) => {
|
|
346
|
+
result[`${key}.${childKey}`] = childValue;
|
|
347
|
+
}
|
|
348
|
+
);
|
|
329
349
|
} else {
|
|
330
350
|
result[key] = value;
|
|
331
351
|
}
|
|
@@ -433,6 +453,7 @@ export {
|
|
|
433
453
|
useAsync,
|
|
434
454
|
useAsyncFunc,
|
|
435
455
|
useAsyncRetry,
|
|
456
|
+
isGray,
|
|
436
457
|
getColor,
|
|
437
458
|
lightenColor,
|
|
438
459
|
darkenColor,
|
package/dist/color.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Dict } from './index.types.mjs';
|
|
2
2
|
|
|
3
|
+
declare const isGray: (colorScheme: string) => boolean;
|
|
3
4
|
declare const getColor: (color: string, fallback?: string) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
|
|
4
5
|
declare const lightenColor: (color: string, amount: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
|
|
5
6
|
declare const darkenColor: (color: string, amount: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
|
|
@@ -7,7 +8,7 @@ declare const tintColor: (color: string, amount: number) => (theme: Dict, colorM
|
|
|
7
8
|
declare const shadeColor: (color: string, amount: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
|
|
8
9
|
declare const transparentizeColor: (color: string, alpha: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
|
|
9
10
|
declare const toneColor: (color: string, l: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
|
|
10
|
-
declare const randomColor: ({ string, colors }?: {
|
|
11
|
+
declare const randomColor: ({ string, colors, }?: {
|
|
11
12
|
string?: string | undefined;
|
|
12
13
|
colors?: string[] | undefined;
|
|
13
14
|
}) => string;
|
|
@@ -15,4 +16,4 @@ declare const isTone: (color: string) => (theme: Dict, colorMode: 'light' | 'dar
|
|
|
15
16
|
declare const isLight: (color: string) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => boolean;
|
|
16
17
|
declare const isDark: (color: string) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => boolean;
|
|
17
18
|
|
|
18
|
-
export { darkenColor, getColor, isDark, isLight, isTone, lightenColor, randomColor, shadeColor, tintColor, toneColor, transparentizeColor };
|
|
19
|
+
export { darkenColor, getColor, isDark, isGray, isLight, isTone, lightenColor, randomColor, shadeColor, tintColor, toneColor, transparentizeColor };
|
package/dist/color.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Dict } from './index.types.js';
|
|
2
2
|
|
|
3
|
+
declare const isGray: (colorScheme: string) => boolean;
|
|
3
4
|
declare const getColor: (color: string, fallback?: string) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
|
|
4
5
|
declare const lightenColor: (color: string, amount: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
|
|
5
6
|
declare const darkenColor: (color: string, amount: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
|
|
@@ -7,7 +8,7 @@ declare const tintColor: (color: string, amount: number) => (theme: Dict, colorM
|
|
|
7
8
|
declare const shadeColor: (color: string, amount: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
|
|
8
9
|
declare const transparentizeColor: (color: string, alpha: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
|
|
9
10
|
declare const toneColor: (color: string, l: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
|
|
10
|
-
declare const randomColor: ({ string, colors }?: {
|
|
11
|
+
declare const randomColor: ({ string, colors, }?: {
|
|
11
12
|
string?: string | undefined;
|
|
12
13
|
colors?: string[] | undefined;
|
|
13
14
|
}) => string;
|
|
@@ -15,4 +16,4 @@ declare const isTone: (color: string) => (theme: Dict, colorMode: 'light' | 'dar
|
|
|
15
16
|
declare const isLight: (color: string) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => boolean;
|
|
16
17
|
declare const isDark: (color: string) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => boolean;
|
|
17
18
|
|
|
18
|
-
export { darkenColor, getColor, isDark, isLight, isTone, lightenColor, randomColor, shadeColor, tintColor, toneColor, transparentizeColor };
|
|
19
|
+
export { darkenColor, getColor, isDark, isGray, isLight, isTone, lightenColor, randomColor, shadeColor, tintColor, toneColor, transparentizeColor };
|
package/dist/color.js
CHANGED
|
@@ -23,6 +23,7 @@ __export(color_exports, {
|
|
|
23
23
|
darkenColor: () => darkenColor,
|
|
24
24
|
getColor: () => getColor,
|
|
25
25
|
isDark: () => isDark,
|
|
26
|
+
isGray: () => isGray,
|
|
26
27
|
isLight: () => isLight,
|
|
27
28
|
isTone: () => isTone,
|
|
28
29
|
lightenColor: () => lightenColor,
|
|
@@ -68,12 +69,9 @@ var memoizeObject = (func) => {
|
|
|
68
69
|
var getMemoizedObject = memoizeObject(getObject);
|
|
69
70
|
|
|
70
71
|
// src/color.ts
|
|
72
|
+
var isGray = (colorScheme) => colorScheme === "gray" || colorScheme === "zinc" || colorScheme === "neutral" || colorScheme === "stone";
|
|
71
73
|
var getColor = (color, fallback) => (theme, colorMode) => {
|
|
72
|
-
const hex = getMemoizedObject(
|
|
73
|
-
theme,
|
|
74
|
-
`colors.${color}`,
|
|
75
|
-
color
|
|
76
|
-
);
|
|
74
|
+
const hex = getMemoizedObject(theme, `colors.${color}`, color);
|
|
77
75
|
try {
|
|
78
76
|
if (isArray(hex)) {
|
|
79
77
|
const [lightHex, darkHex] = hex;
|
|
@@ -117,7 +115,10 @@ var toneColor = (color, l) => (theme, colorMode) => {
|
|
|
117
115
|
n = n - 5 * (isLighten ? 1 : -1);
|
|
118
116
|
return (0, import_color2k.toHex)(isLighten ? (0, import_color2k.lighten)(raw, n / 100) : (0, import_color2k.mix)(raw, "#000", n / 100));
|
|
119
117
|
};
|
|
120
|
-
var randomColor = ({
|
|
118
|
+
var randomColor = ({
|
|
119
|
+
string,
|
|
120
|
+
colors
|
|
121
|
+
} = {}) => {
|
|
121
122
|
const fallback = randomHex();
|
|
122
123
|
if (string && colors)
|
|
123
124
|
return randomColorFromList(string, colors);
|
|
@@ -172,6 +173,7 @@ var isDark = (color) => (theme, colorMode) => isTone(color)(theme, colorMode) ==
|
|
|
172
173
|
darkenColor,
|
|
173
174
|
getColor,
|
|
174
175
|
isDark,
|
|
176
|
+
isGray,
|
|
175
177
|
isLight,
|
|
176
178
|
isTone,
|
|
177
179
|
lightenColor,
|
package/dist/color.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
darkenColor,
|
|
3
3
|
getColor,
|
|
4
4
|
isDark,
|
|
5
|
+
isGray,
|
|
5
6
|
isLight,
|
|
6
7
|
isTone,
|
|
7
8
|
lightenColor,
|
|
@@ -10,19 +11,20 @@ import {
|
|
|
10
11
|
tintColor,
|
|
11
12
|
toneColor,
|
|
12
13
|
transparentizeColor
|
|
13
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-XIDDMDVR.mjs";
|
|
14
15
|
import "./chunk-SLJ4M7XC.mjs";
|
|
15
16
|
import "./chunk-VYMGBE25.mjs";
|
|
16
17
|
import "./chunk-BZAW2D6U.mjs";
|
|
17
18
|
import "./chunk-PURW64JE.mjs";
|
|
18
19
|
import "./chunk-IVGIIDMV.mjs";
|
|
19
20
|
import "./chunk-R5OUKGQ5.mjs";
|
|
20
|
-
import "./chunk-
|
|
21
|
+
import "./chunk-H5VMEQNO.mjs";
|
|
21
22
|
import "./chunk-PF7LRFIA.mjs";
|
|
22
23
|
export {
|
|
23
24
|
darkenColor,
|
|
24
25
|
getColor,
|
|
25
26
|
isDark,
|
|
27
|
+
isGray,
|
|
26
28
|
isLight,
|
|
27
29
|
isTone,
|
|
28
30
|
lightenColor,
|
package/dist/dom.js
CHANGED
|
@@ -104,7 +104,9 @@ var focusableElList = [
|
|
|
104
104
|
];
|
|
105
105
|
var focusableElSelector = focusableElList.join();
|
|
106
106
|
var getAllFocusable = (container) => {
|
|
107
|
-
const focusableEls = Array.from(
|
|
107
|
+
const focusableEls = Array.from(
|
|
108
|
+
container.querySelectorAll(focusableElSelector)
|
|
109
|
+
);
|
|
108
110
|
focusableEls.unshift(container);
|
|
109
111
|
return focusableEls.filter((el) => isFocusable(el) && isVisible(el));
|
|
110
112
|
};
|
package/dist/dom.mjs
CHANGED
package/dist/function.mjs
CHANGED
|
@@ -3,14 +3,14 @@ import {
|
|
|
3
3
|
handlerAll,
|
|
4
4
|
noop,
|
|
5
5
|
runIfFunc
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-XIDDMDVR.mjs";
|
|
7
7
|
import "./chunk-SLJ4M7XC.mjs";
|
|
8
8
|
import "./chunk-VYMGBE25.mjs";
|
|
9
9
|
import "./chunk-BZAW2D6U.mjs";
|
|
10
10
|
import "./chunk-PURW64JE.mjs";
|
|
11
11
|
import "./chunk-IVGIIDMV.mjs";
|
|
12
12
|
import "./chunk-R5OUKGQ5.mjs";
|
|
13
|
-
import "./chunk-
|
|
13
|
+
import "./chunk-H5VMEQNO.mjs";
|
|
14
14
|
import "./chunk-PF7LRFIA.mjs";
|
|
15
15
|
export {
|
|
16
16
|
funcAll,
|
package/dist/index.d.mts
CHANGED
|
@@ -6,7 +6,7 @@ export { AsyncFnReturn, AsyncState, AsyncStateRetry, DOMAttributes, FunctionRetu
|
|
|
6
6
|
export { FocusableElement, ariaAttr, createdDom, dataAttr, getActiveElement, getAllFocusable, getEventRelatedTarget, getOwnerDocument, getOwnerWindow, getPlatform, hasNegativeTabIndex, hasTabIndex, isActiveElement, isApple, isContains, isContentEditable, isDisabled, isElement, isFocusable, isHTMLElement, isHidden, isMac, isSafari, isTabbable, platform, vendor } from './dom.mjs';
|
|
7
7
|
export { escape } from './string.mjs';
|
|
8
8
|
export { Operand, calc } from './calc.mjs';
|
|
9
|
-
export { darkenColor, getColor, isDark, isLight, isTone, lightenColor, randomColor, shadeColor, tintColor, toneColor, transparentizeColor } from './color.mjs';
|
|
9
|
+
export { darkenColor, getColor, isDark, isGray, isLight, isTone, lightenColor, randomColor, shadeColor, tintColor, toneColor, transparentizeColor } from './color.mjs';
|
|
10
10
|
export { filterEmpty } from './array.mjs';
|
|
11
11
|
export { clampNumber, countDecimal, percentToValue, roundNumberToStep, toPrecision, valueToPercent } from './number.mjs';
|
|
12
12
|
export { AnyPointerEvent, MixedEventListener, Point, PointType, PointerEventInfo, addDomEvent, addPointerEvent, getEventPoint, getEventWindow, isMouseEvent, isMultiTouchEvent, isTouchEvent, pointFromMouse, pointFromTouch } from './event.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { AsyncFnReturn, AsyncState, AsyncStateRetry, DOMAttributes, FunctionRetu
|
|
|
6
6
|
export { FocusableElement, ariaAttr, createdDom, dataAttr, getActiveElement, getAllFocusable, getEventRelatedTarget, getOwnerDocument, getOwnerWindow, getPlatform, hasNegativeTabIndex, hasTabIndex, isActiveElement, isApple, isContains, isContentEditable, isDisabled, isElement, isFocusable, isHTMLElement, isHidden, isMac, isSafari, isTabbable, platform, vendor } from './dom.js';
|
|
7
7
|
export { escape } from './string.js';
|
|
8
8
|
export { Operand, calc } from './calc.js';
|
|
9
|
-
export { darkenColor, getColor, isDark, isLight, isTone, lightenColor, randomColor, shadeColor, tintColor, toneColor, transparentizeColor } from './color.js';
|
|
9
|
+
export { darkenColor, getColor, isDark, isGray, isLight, isTone, lightenColor, randomColor, shadeColor, tintColor, toneColor, transparentizeColor } from './color.js';
|
|
10
10
|
export { filterEmpty } from './array.js';
|
|
11
11
|
export { clampNumber, countDecimal, percentToValue, roundNumberToStep, toPrecision, valueToPercent } from './number.js';
|
|
12
12
|
export { AnyPointerEvent, MixedEventListener, Point, PointType, PointerEventInfo, addDomEvent, addPointerEvent, getEventPoint, getEventWindow, isMouseEvent, isMultiTouchEvent, isTouchEvent, pointFromMouse, pointFromTouch } from './event.js';
|
package/dist/index.js
CHANGED
|
@@ -78,6 +78,7 @@ __export(src_exports, {
|
|
|
78
78
|
isEmpty: () => isEmpty,
|
|
79
79
|
isFocusable: () => isFocusable,
|
|
80
80
|
isFunction: () => isFunction,
|
|
81
|
+
isGray: () => isGray,
|
|
81
82
|
isHTMLElement: () => isHTMLElement,
|
|
82
83
|
isHidden: () => isHidden,
|
|
83
84
|
isLight: () => isLight,
|
|
@@ -212,9 +213,11 @@ var flattenObject = (obj, maxDepth = Infinity) => {
|
|
|
212
213
|
return obj;
|
|
213
214
|
return Object.entries(obj).reduce((result, [key, value]) => {
|
|
214
215
|
if (isObject(value)) {
|
|
215
|
-
Object.entries(flattenObject(value, maxDepth - 1)).forEach(
|
|
216
|
-
|
|
217
|
-
|
|
216
|
+
Object.entries(flattenObject(value, maxDepth - 1)).forEach(
|
|
217
|
+
([childKey, childValue]) => {
|
|
218
|
+
result[`${key}.${childKey}`] = childValue;
|
|
219
|
+
}
|
|
220
|
+
);
|
|
218
221
|
} else {
|
|
219
222
|
result[key] = value;
|
|
220
223
|
}
|
|
@@ -315,7 +318,11 @@ var createContext2 = ({
|
|
|
315
318
|
}
|
|
316
319
|
return context;
|
|
317
320
|
};
|
|
318
|
-
return [
|
|
321
|
+
return [
|
|
322
|
+
Context.Provider,
|
|
323
|
+
useContext2,
|
|
324
|
+
Context
|
|
325
|
+
];
|
|
319
326
|
};
|
|
320
327
|
var useSafeLayoutEffect = Boolean(globalThis == null ? void 0 : globalThis.document) ? React.useLayoutEffect : React.useEffect;
|
|
321
328
|
var useUnmountEffect = (callback) => (
|
|
@@ -373,10 +380,13 @@ var useCallbackRef = (callback, deps = []) => {
|
|
|
373
380
|
React.useEffect(() => {
|
|
374
381
|
callbackRef.current = callback;
|
|
375
382
|
});
|
|
376
|
-
return React.useCallback(
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
383
|
+
return React.useCallback(
|
|
384
|
+
(...args) => {
|
|
385
|
+
var _a;
|
|
386
|
+
return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
|
|
387
|
+
},
|
|
388
|
+
deps
|
|
389
|
+
);
|
|
380
390
|
};
|
|
381
391
|
var useUpdateEffect = (callback, deps) => {
|
|
382
392
|
const renderCycleRef = React.useRef(false);
|
|
@@ -406,23 +416,27 @@ var useAsyncFunc = (func, deps = [], initialState = { loading: false }) => {
|
|
|
406
416
|
const lastCallId = React.useRef(0);
|
|
407
417
|
const isMounted = useIsMounted();
|
|
408
418
|
const [state, setState] = React.useState(initialState);
|
|
409
|
-
const callback = React.useCallback(
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
(
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
419
|
+
const callback = React.useCallback(
|
|
420
|
+
(...args) => {
|
|
421
|
+
const callId = ++lastCallId.current;
|
|
422
|
+
if (!state.loading)
|
|
423
|
+
setState((prevState) => ({ ...prevState, loading: true }));
|
|
424
|
+
return func(...args).then(
|
|
425
|
+
(value) => {
|
|
426
|
+
if (isMounted.current && callId === lastCallId.current)
|
|
427
|
+
setState({ value, loading: false });
|
|
428
|
+
return value;
|
|
429
|
+
},
|
|
430
|
+
(error) => {
|
|
431
|
+
if (isMounted.current && callId === lastCallId.current)
|
|
432
|
+
setState({ error, loading: false });
|
|
433
|
+
return error;
|
|
434
|
+
}
|
|
435
|
+
);
|
|
436
|
+
},
|
|
437
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
438
|
+
deps
|
|
439
|
+
);
|
|
426
440
|
return [state, callback];
|
|
427
441
|
};
|
|
428
442
|
var useAsyncRetry = (func, deps = []) => {
|
|
@@ -495,7 +509,9 @@ var focusableElList = [
|
|
|
495
509
|
];
|
|
496
510
|
var focusableElSelector = focusableElList.join();
|
|
497
511
|
var getAllFocusable = (container) => {
|
|
498
|
-
const focusableEls = Array.from(
|
|
512
|
+
const focusableEls = Array.from(
|
|
513
|
+
container.querySelectorAll(focusableElSelector)
|
|
514
|
+
);
|
|
499
515
|
focusableEls.unshift(container);
|
|
500
516
|
return focusableEls.filter((el) => isFocusable(el) && isVisible(el));
|
|
501
517
|
};
|
|
@@ -563,12 +579,9 @@ var calc = Object.assign(
|
|
|
563
579
|
|
|
564
580
|
// src/color.ts
|
|
565
581
|
var import_color2k = require("color2k");
|
|
582
|
+
var isGray = (colorScheme) => colorScheme === "gray" || colorScheme === "zinc" || colorScheme === "neutral" || colorScheme === "stone";
|
|
566
583
|
var getColor = (color, fallback) => (theme, colorMode) => {
|
|
567
|
-
const hex = getMemoizedObject(
|
|
568
|
-
theme,
|
|
569
|
-
`colors.${color}`,
|
|
570
|
-
color
|
|
571
|
-
);
|
|
584
|
+
const hex = getMemoizedObject(theme, `colors.${color}`, color);
|
|
572
585
|
try {
|
|
573
586
|
if (isArray(hex)) {
|
|
574
587
|
const [lightHex, darkHex] = hex;
|
|
@@ -612,7 +625,10 @@ var toneColor = (color, l) => (theme, colorMode) => {
|
|
|
612
625
|
n = n - 5 * (isLighten ? 1 : -1);
|
|
613
626
|
return (0, import_color2k.toHex)(isLighten ? (0, import_color2k.lighten)(raw, n / 100) : (0, import_color2k.mix)(raw, "#000", n / 100));
|
|
614
627
|
};
|
|
615
|
-
var randomColor = ({
|
|
628
|
+
var randomColor = ({
|
|
629
|
+
string,
|
|
630
|
+
colors
|
|
631
|
+
} = {}) => {
|
|
616
632
|
const fallback = randomHex();
|
|
617
633
|
if (string && colors)
|
|
618
634
|
return randomColorFromList(string, colors);
|
|
@@ -786,6 +802,7 @@ var addPointerEvent = (target, type, cb, options) => addDomEvent(target, type, w
|
|
|
786
802
|
isEmpty,
|
|
787
803
|
isFocusable,
|
|
788
804
|
isFunction,
|
|
805
|
+
isGray,
|
|
789
806
|
isHTMLElement,
|
|
790
807
|
isHidden,
|
|
791
808
|
isLight,
|
package/dist/index.mjs
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
handlerAll,
|
|
17
17
|
includesChildren,
|
|
18
18
|
isDark,
|
|
19
|
+
isGray,
|
|
19
20
|
isLight,
|
|
20
21
|
isRefObject,
|
|
21
22
|
isTone,
|
|
@@ -48,7 +49,7 @@ import {
|
|
|
48
49
|
useSafeLayoutEffect,
|
|
49
50
|
useUnmountEffect,
|
|
50
51
|
useUpdateEffect
|
|
51
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-XIDDMDVR.mjs";
|
|
52
53
|
import "./chunk-SLJ4M7XC.mjs";
|
|
53
54
|
import {
|
|
54
55
|
clampNumber,
|
|
@@ -107,7 +108,7 @@ import {
|
|
|
107
108
|
isTabbable,
|
|
108
109
|
platform,
|
|
109
110
|
vendor
|
|
110
|
-
} from "./chunk-
|
|
111
|
+
} from "./chunk-H5VMEQNO.mjs";
|
|
111
112
|
import {
|
|
112
113
|
addDomEvent,
|
|
113
114
|
addPointerEvent,
|
|
@@ -168,6 +169,7 @@ export {
|
|
|
168
169
|
isEmpty,
|
|
169
170
|
isFocusable,
|
|
170
171
|
isFunction,
|
|
172
|
+
isGray,
|
|
171
173
|
isHTMLElement,
|
|
172
174
|
isHidden,
|
|
173
175
|
isLight,
|
package/dist/object.d.mts
CHANGED
|
@@ -11,8 +11,8 @@ declare const objectFromEntries: <T extends Dict>(entries: any[][]) => T;
|
|
|
11
11
|
declare const keysFormObject: <T extends Dict>(obj: T) => (keyof T)[];
|
|
12
12
|
declare const replaceObject: <T extends unknown>(objOrArray: T, callBack: (value: any) => any) => T;
|
|
13
13
|
declare const getObject: (obj: Dict, path: string | number, fallback?: any, i?: number) => any;
|
|
14
|
-
declare const memoizeObject: (func: typeof getObject) => (obj: Dict, path: string | number, fallback?: any, i?: number) =>
|
|
15
|
-
declare const getMemoizedObject: (obj: Dict, path: string | number, fallback?: any, i?: number) =>
|
|
14
|
+
declare const memoizeObject: (func: typeof getObject) => <T extends unknown = any>(obj: Dict, path: string | number, fallback?: any, i?: number) => T;
|
|
15
|
+
declare const getMemoizedObject: <T extends unknown = any>(obj: Dict, path: string | number, fallback?: any, i?: number) => T;
|
|
16
16
|
declare const assignAfter: (target: Record<string, any>, ...sources: any[]) => Record<string, unknown>;
|
|
17
17
|
|
|
18
18
|
export { assignAfter, filterObject, filterUndefined, flattenObject, getMemoizedObject, getObject, keysFormObject, memoizeObject, merge, objectFromEntries, omitObject, pickObject, replaceObject, splitObject };
|
package/dist/object.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ declare const objectFromEntries: <T extends Dict>(entries: any[][]) => T;
|
|
|
11
11
|
declare const keysFormObject: <T extends Dict>(obj: T) => (keyof T)[];
|
|
12
12
|
declare const replaceObject: <T extends unknown>(objOrArray: T, callBack: (value: any) => any) => T;
|
|
13
13
|
declare const getObject: (obj: Dict, path: string | number, fallback?: any, i?: number) => any;
|
|
14
|
-
declare const memoizeObject: (func: typeof getObject) => (obj: Dict, path: string | number, fallback?: any, i?: number) =>
|
|
15
|
-
declare const getMemoizedObject: (obj: Dict, path: string | number, fallback?: any, i?: number) =>
|
|
14
|
+
declare const memoizeObject: (func: typeof getObject) => <T extends unknown = any>(obj: Dict, path: string | number, fallback?: any, i?: number) => T;
|
|
15
|
+
declare const getMemoizedObject: <T extends unknown = any>(obj: Dict, path: string | number, fallback?: any, i?: number) => T;
|
|
16
16
|
declare const assignAfter: (target: Record<string, any>, ...sources: any[]) => Record<string, unknown>;
|
|
17
17
|
|
|
18
18
|
export { assignAfter, filterObject, filterUndefined, flattenObject, getMemoizedObject, getObject, keysFormObject, memoizeObject, merge, objectFromEntries, omitObject, pickObject, replaceObject, splitObject };
|
package/dist/object.js
CHANGED
|
@@ -103,9 +103,11 @@ var flattenObject = (obj, maxDepth = Infinity) => {
|
|
|
103
103
|
return obj;
|
|
104
104
|
return Object.entries(obj).reduce((result, [key, value]) => {
|
|
105
105
|
if (isObject(value)) {
|
|
106
|
-
Object.entries(flattenObject(value, maxDepth - 1)).forEach(
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
Object.entries(flattenObject(value, maxDepth - 1)).forEach(
|
|
107
|
+
([childKey, childValue]) => {
|
|
108
|
+
result[`${key}.${childKey}`] = childValue;
|
|
109
|
+
}
|
|
110
|
+
);
|
|
109
111
|
} else {
|
|
110
112
|
result[key] = value;
|
|
111
113
|
}
|
package/dist/object.mjs
CHANGED
|
@@ -13,14 +13,14 @@ import {
|
|
|
13
13
|
pickObject,
|
|
14
14
|
replaceObject,
|
|
15
15
|
splitObject
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-XIDDMDVR.mjs";
|
|
17
17
|
import "./chunk-SLJ4M7XC.mjs";
|
|
18
18
|
import "./chunk-VYMGBE25.mjs";
|
|
19
19
|
import "./chunk-BZAW2D6U.mjs";
|
|
20
20
|
import "./chunk-PURW64JE.mjs";
|
|
21
21
|
import "./chunk-IVGIIDMV.mjs";
|
|
22
22
|
import "./chunk-R5OUKGQ5.mjs";
|
|
23
|
-
import "./chunk-
|
|
23
|
+
import "./chunk-H5VMEQNO.mjs";
|
|
24
24
|
import "./chunk-PF7LRFIA.mjs";
|
|
25
25
|
export {
|
|
26
26
|
assignAfter,
|
package/dist/react.d.mts
CHANGED
|
@@ -61,10 +61,7 @@ type AsyncState<T> = {
|
|
|
61
61
|
};
|
|
62
62
|
type PromiseType<P extends Promise<any>> = P extends Promise<infer T> ? T : never;
|
|
63
63
|
type StateFromFunctionReturningPromise<T extends FunctionReturningPromise> = AsyncState<PromiseType<ReturnType<T>>>;
|
|
64
|
-
type AsyncFnReturn<T extends FunctionReturningPromise = FunctionReturningPromise> = [
|
|
65
|
-
StateFromFunctionReturningPromise<T>,
|
|
66
|
-
T
|
|
67
|
-
];
|
|
64
|
+
type AsyncFnReturn<T extends FunctionReturningPromise = FunctionReturningPromise> = [StateFromFunctionReturningPromise<T>, T];
|
|
68
65
|
declare const useAsyncFunc: <T extends FunctionReturningPromise>(func: T, deps?: React.DependencyList, initialState?: StateFromFunctionReturningPromise<T>) => AsyncFnReturn<T>;
|
|
69
66
|
type AsyncStateRetry<T> = AsyncState<T> & {
|
|
70
67
|
retry(): void;
|
package/dist/react.d.ts
CHANGED
|
@@ -61,10 +61,7 @@ type AsyncState<T> = {
|
|
|
61
61
|
};
|
|
62
62
|
type PromiseType<P extends Promise<any>> = P extends Promise<infer T> ? T : never;
|
|
63
63
|
type StateFromFunctionReturningPromise<T extends FunctionReturningPromise> = AsyncState<PromiseType<ReturnType<T>>>;
|
|
64
|
-
type AsyncFnReturn<T extends FunctionReturningPromise = FunctionReturningPromise> = [
|
|
65
|
-
StateFromFunctionReturningPromise<T>,
|
|
66
|
-
T
|
|
67
|
-
];
|
|
64
|
+
type AsyncFnReturn<T extends FunctionReturningPromise = FunctionReturningPromise> = [StateFromFunctionReturningPromise<T>, T];
|
|
68
65
|
declare const useAsyncFunc: <T extends FunctionReturningPromise>(func: T, deps?: React.DependencyList, initialState?: StateFromFunctionReturningPromise<T>) => AsyncFnReturn<T>;
|
|
69
66
|
type AsyncStateRetry<T> = AsyncState<T> & {
|
|
70
67
|
retry(): void;
|
package/dist/react.js
CHANGED
|
@@ -77,7 +77,11 @@ var createContext2 = ({
|
|
|
77
77
|
}
|
|
78
78
|
return context;
|
|
79
79
|
};
|
|
80
|
-
return [
|
|
80
|
+
return [
|
|
81
|
+
Context.Provider,
|
|
82
|
+
useContext2,
|
|
83
|
+
Context
|
|
84
|
+
];
|
|
81
85
|
};
|
|
82
86
|
var useSafeLayoutEffect = Boolean(globalThis == null ? void 0 : globalThis.document) ? React.useLayoutEffect : React.useEffect;
|
|
83
87
|
var useUnmountEffect = (callback) => (
|
|
@@ -135,10 +139,13 @@ var useCallbackRef = (callback, deps = []) => {
|
|
|
135
139
|
React.useEffect(() => {
|
|
136
140
|
callbackRef.current = callback;
|
|
137
141
|
});
|
|
138
|
-
return React.useCallback(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
+
return React.useCallback(
|
|
143
|
+
(...args) => {
|
|
144
|
+
var _a;
|
|
145
|
+
return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
|
|
146
|
+
},
|
|
147
|
+
deps
|
|
148
|
+
);
|
|
142
149
|
};
|
|
143
150
|
var useUpdateEffect = (callback, deps) => {
|
|
144
151
|
const renderCycleRef = React.useRef(false);
|
|
@@ -168,23 +175,27 @@ var useAsyncFunc = (func, deps = [], initialState = { loading: false }) => {
|
|
|
168
175
|
const lastCallId = React.useRef(0);
|
|
169
176
|
const isMounted = useIsMounted();
|
|
170
177
|
const [state, setState] = React.useState(initialState);
|
|
171
|
-
const callback = React.useCallback(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
178
|
+
const callback = React.useCallback(
|
|
179
|
+
(...args) => {
|
|
180
|
+
const callId = ++lastCallId.current;
|
|
181
|
+
if (!state.loading)
|
|
182
|
+
setState((prevState) => ({ ...prevState, loading: true }));
|
|
183
|
+
return func(...args).then(
|
|
184
|
+
(value) => {
|
|
185
|
+
if (isMounted.current && callId === lastCallId.current)
|
|
186
|
+
setState({ value, loading: false });
|
|
187
|
+
return value;
|
|
188
|
+
},
|
|
189
|
+
(error) => {
|
|
190
|
+
if (isMounted.current && callId === lastCallId.current)
|
|
191
|
+
setState({ error, loading: false });
|
|
192
|
+
return error;
|
|
193
|
+
}
|
|
194
|
+
);
|
|
195
|
+
},
|
|
196
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
197
|
+
deps
|
|
198
|
+
);
|
|
188
199
|
return [state, callback];
|
|
189
200
|
};
|
|
190
201
|
var useAsyncRetry = (func, deps = []) => {
|
package/dist/react.mjs
CHANGED
|
@@ -19,14 +19,14 @@ import {
|
|
|
19
19
|
useSafeLayoutEffect,
|
|
20
20
|
useUnmountEffect,
|
|
21
21
|
useUpdateEffect
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-XIDDMDVR.mjs";
|
|
23
23
|
import "./chunk-SLJ4M7XC.mjs";
|
|
24
24
|
import "./chunk-VYMGBE25.mjs";
|
|
25
25
|
import "./chunk-BZAW2D6U.mjs";
|
|
26
26
|
import "./chunk-PURW64JE.mjs";
|
|
27
27
|
import "./chunk-IVGIIDMV.mjs";
|
|
28
28
|
import "./chunk-R5OUKGQ5.mjs";
|
|
29
|
-
import "./chunk-
|
|
29
|
+
import "./chunk-H5VMEQNO.mjs";
|
|
30
30
|
import "./chunk-PF7LRFIA.mjs";
|
|
31
31
|
export {
|
|
32
32
|
assignRef,
|