@yamada-ui/utils 0.1.2 → 0.1.4

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.
@@ -0,0 +1,3 @@
1
+ declare const filterEmpty: <T extends any[]>(array: T) => any[];
2
+
3
+ export { filterEmpty };
@@ -0,0 +1,16 @@
1
+ import { Dict } from './index.types.mjs';
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>(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,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 };
@@ -38,7 +38,11 @@ var createContext2 = ({
38
38
  }
39
39
  return context;
40
40
  };
41
- return [Context.Provider, useContext2, Context];
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((...args) => {
100
- var _a;
101
- return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
102
- }, deps);
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,24 +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((...args) => {
133
- const callId = ++lastCallId.current;
134
- if (!state.loading) {
135
- setState((prevState) => ({ ...prevState, loading: true }));
136
- }
137
- return func(...args).then(
138
- (value) => {
139
- if (isMounted.current && callId === lastCallId.current)
140
- setState({ value, loading: false });
141
- return value;
142
- },
143
- (error) => {
144
- if (isMounted.current && callId === lastCallId.current)
145
- setState({ error, loading: false });
146
- return error;
147
- }
148
- );
149
- }, deps);
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
+ );
150
160
  return [state, callback];
151
161
  };
152
162
  var useAsyncRetry = (func, deps = []) => {
@@ -162,13 +172,16 @@ var useAsyncRetry = (func, deps = []) => {
162
172
  };
163
173
 
164
174
  // src/color.ts
165
- import { toHex, parseToRgba, transparentize, mix, darken, lighten } from "color2k";
175
+ import {
176
+ toHex,
177
+ parseToRgba,
178
+ transparentize,
179
+ mix,
180
+ darken,
181
+ lighten
182
+ } from "color2k";
166
183
  var getColor = (color, fallback) => (theme, colorMode) => {
167
- const hex = getMemoizedObject(
168
- theme,
169
- `colors.${color}`,
170
- color
171
- );
184
+ const hex = getMemoizedObject(theme, `colors.${color}`, color);
172
185
  try {
173
186
  if (isArray(hex)) {
174
187
  const [lightHex, darkHex] = hex;
@@ -212,7 +225,10 @@ var toneColor = (color, l) => (theme, colorMode) => {
212
225
  n = n - 5 * (isLighten ? 1 : -1);
213
226
  return toHex(isLighten ? lighten(raw, n / 100) : mix(raw, "#000", n / 100));
214
227
  };
215
- var randomColor = ({ string, colors } = {}) => {
228
+ var randomColor = ({
229
+ string,
230
+ colors
231
+ } = {}) => {
216
232
  const fallback = randomHex();
217
233
  if (string && colors)
218
234
  return randomColorFromList(string, colors);
@@ -324,9 +340,11 @@ var flattenObject = (obj, maxDepth = Infinity) => {
324
340
  return obj;
325
341
  return Object.entries(obj).reduce((result, [key, value]) => {
326
342
  if (isObject(value)) {
327
- Object.entries(flattenObject(value, maxDepth - 1)).forEach(([childKey, childValue]) => {
328
- result[`${key}.${childKey}`] = childValue;
329
- });
343
+ Object.entries(flattenObject(value, maxDepth - 1)).forEach(
344
+ ([childKey, childValue]) => {
345
+ result[`${key}.${childKey}`] = childValue;
346
+ }
347
+ );
330
348
  } else {
331
349
  result[key] = value;
332
350
  }
@@ -56,7 +56,9 @@ var focusableElList = [
56
56
  ];
57
57
  var focusableElSelector = focusableElList.join();
58
58
  var getAllFocusable = (container) => {
59
- const focusableEls = Array.from(container.querySelectorAll(focusableElSelector));
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
  };
@@ -0,0 +1,18 @@
1
+ import { Dict } from './index.types.mjs';
2
+
3
+ declare const getColor: (color: string, fallback?: string) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
4
+ declare const lightenColor: (color: string, amount: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
5
+ declare const darkenColor: (color: string, amount: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
6
+ declare const tintColor: (color: string, amount: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
7
+ declare const shadeColor: (color: string, amount: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
8
+ declare const transparentizeColor: (color: string, alpha: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
9
+ declare const toneColor: (color: string, l: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
10
+ declare const randomColor: ({ string, colors, }?: {
11
+ string?: string | undefined;
12
+ colors?: string[] | undefined;
13
+ }) => string;
14
+ declare const isTone: (color: string) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => "light" | "dark";
15
+ declare const isLight: (color: string) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => boolean;
16
+ declare const isDark: (color: string) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => boolean;
17
+
18
+ export { darkenColor, getColor, isDark, isLight, isTone, lightenColor, randomColor, shadeColor, tintColor, toneColor, transparentizeColor };
package/dist/color.d.ts CHANGED
@@ -7,7 +7,7 @@ declare const tintColor: (color: string, amount: number) => (theme: Dict, colorM
7
7
  declare const shadeColor: (color: string, amount: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
8
8
  declare const transparentizeColor: (color: string, alpha: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
9
9
  declare const toneColor: (color: string, l: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
10
- declare const randomColor: ({ string, colors }?: {
10
+ declare const randomColor: ({ string, colors, }?: {
11
11
  string?: string | undefined;
12
12
  colors?: string[] | undefined;
13
13
  }) => string;
package/dist/color.js CHANGED
@@ -69,11 +69,7 @@ var getMemoizedObject = memoizeObject(getObject);
69
69
 
70
70
  // src/color.ts
71
71
  var getColor = (color, fallback) => (theme, colorMode) => {
72
- const hex = getMemoizedObject(
73
- theme,
74
- `colors.${color}`,
75
- color
76
- );
72
+ const hex = getMemoizedObject(theme, `colors.${color}`, color);
77
73
  try {
78
74
  if (isArray(hex)) {
79
75
  const [lightHex, darkHex] = hex;
@@ -117,7 +113,10 @@ var toneColor = (color, l) => (theme, colorMode) => {
117
113
  n = n - 5 * (isLighten ? 1 : -1);
118
114
  return (0, import_color2k.toHex)(isLighten ? (0, import_color2k.lighten)(raw, n / 100) : (0, import_color2k.mix)(raw, "#000", n / 100));
119
115
  };
120
- var randomColor = ({ string, colors } = {}) => {
116
+ var randomColor = ({
117
+ string,
118
+ colors
119
+ } = {}) => {
121
120
  const fallback = randomHex();
122
121
  if (string && colors)
123
122
  return randomColorFromList(string, colors);
package/dist/color.mjs CHANGED
@@ -10,14 +10,14 @@ import {
10
10
  tintColor,
11
11
  toneColor,
12
12
  transparentizeColor
13
- } from "./chunk-VPOQGCMS.mjs";
13
+ } from "./chunk-EUA3L3L6.mjs";
14
14
  import "./chunk-SLJ4M7XC.mjs";
15
15
  import "./chunk-VYMGBE25.mjs";
16
16
  import "./chunk-BZAW2D6U.mjs";
17
17
  import "./chunk-PURW64JE.mjs";
18
18
  import "./chunk-IVGIIDMV.mjs";
19
19
  import "./chunk-R5OUKGQ5.mjs";
20
- import "./chunk-FW7XS4NH.mjs";
20
+ import "./chunk-H5VMEQNO.mjs";
21
21
  import "./chunk-PF7LRFIA.mjs";
22
22
  export {
23
23
  darkenColor,
package/dist/dom.d.mts ADDED
@@ -0,0 +1,33 @@
1
+ import React__default from 'react';
2
+
3
+ declare const createdDom: () => boolean;
4
+ declare const getPlatform: () => string;
5
+ declare const vendor: (v: RegExp) => boolean;
6
+ declare const platform: (v: RegExp) => boolean;
7
+ declare const isMac: () => boolean;
8
+ declare const isApple: () => boolean;
9
+ declare const isSafari: () => boolean;
10
+ declare const isElement: (el: any) => el is Element;
11
+ declare const isHTMLElement: (el: any) => el is HTMLElement;
12
+ declare const isHidden: (el: HTMLElement) => boolean;
13
+ declare const isDisabled: (el: HTMLElement) => boolean;
14
+ declare const hasTabIndex: (el: HTMLElement) => boolean;
15
+ declare const isContentEditable: (el: HTMLElement) => boolean;
16
+ declare const isContains: (parent: HTMLElement | null, child: HTMLElement | null) => boolean | undefined;
17
+ declare const getEventRelatedTarget: (ev: React__default.FocusEvent | React__default.MouseEvent) => HTMLElement | null;
18
+ type Booleanish = boolean | 'true' | 'false';
19
+ declare const dataAttr: (condition: boolean | undefined) => Booleanish;
20
+ declare const ariaAttr: (condition: boolean | undefined) => boolean | undefined;
21
+ type FocusableElement = {
22
+ focus: (options?: FocusOptions) => void;
23
+ };
24
+ declare const getAllFocusable: <T extends HTMLElement>(container: T) => T[];
25
+ declare const isFocusable: (el: HTMLElement) => boolean;
26
+ declare const hasNegativeTabIndex: (el: HTMLElement) => boolean;
27
+ declare const isTabbable: (el?: HTMLElement | null) => boolean;
28
+ declare const getOwnerWindow: (node?: Element | null) => Window & typeof globalThis;
29
+ declare const getOwnerDocument: (el?: Element | null) => Document;
30
+ declare const getActiveElement: (el?: HTMLElement) => HTMLElement;
31
+ declare const isActiveElement: (el: HTMLElement) => boolean;
32
+
33
+ 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 };
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(container.querySelectorAll(focusableElSelector));
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
@@ -24,7 +24,7 @@ import {
24
24
  isTabbable,
25
25
  platform,
26
26
  vendor
27
- } from "./chunk-FW7XS4NH.mjs";
27
+ } from "./chunk-H5VMEQNO.mjs";
28
28
  export {
29
29
  ariaAttr,
30
30
  createdDom,
@@ -0,0 +1,30 @@
1
+ type AnyPointerEvent = MouseEvent | TouchEvent | PointerEvent;
2
+ type PointType = 'page' | 'client';
3
+ type Point = {
4
+ x: number;
5
+ y: number;
6
+ };
7
+ type PointerEventInfo = {
8
+ point: Point;
9
+ };
10
+ type MixedEventListener = (e: AnyPointerEvent, info: PointerEventInfo) => void;
11
+ declare const isMouseEvent: (ev: any) => ev is MouseEvent;
12
+ declare const isTouchEvent: (ev: AnyPointerEvent) => ev is TouchEvent;
13
+ declare const isMultiTouchEvent: (ev: AnyPointerEvent) => boolean;
14
+ declare const getEventWindow: (ev: Event) => typeof globalThis;
15
+ declare const pointFromTouch: (e: TouchEvent, type?: PointType) => {
16
+ x: number;
17
+ y: number;
18
+ };
19
+ declare const pointFromMouse: (point: MouseEvent | PointerEvent, type?: PointType) => {
20
+ x: number;
21
+ y: number;
22
+ };
23
+ declare const getEventPoint: (ev: AnyPointerEvent, type?: PointType) => {
24
+ x: number;
25
+ y: number;
26
+ };
27
+ declare const addDomEvent: (target: EventTarget, type: string, cb: EventListener, options?: AddEventListenerOptions) => () => void;
28
+ declare const addPointerEvent: (target: EventTarget, type: string, cb: MixedEventListener, options?: AddEventListenerOptions) => () => void;
29
+
30
+ export { AnyPointerEvent, MixedEventListener, Point, PointType, PointerEventInfo, addDomEvent, addPointerEvent, getEventPoint, getEventWindow, isMouseEvent, isMultiTouchEvent, isTouchEvent, pointFromMouse, pointFromTouch };
@@ -0,0 +1,6 @@
1
+ declare const noop: () => void;
2
+ declare const runIfFunc: <T, U extends any[]>(valOrFunc: T | ((...funcArgs: U) => T), ...args: U) => T;
3
+ declare const handlerAll: <T extends (event: any) => void>(...funcs: (T | undefined)[]) => (event: (T extends (...args: infer R) => any ? R : never)[0]) => void;
4
+ declare const funcAll: <T extends (...args: any[]) => any>(...funcs: (T | undefined)[]) => (arg: (T extends (...args: infer R) => any ? R : never)[0]) => void;
5
+
6
+ export { funcAll, handlerAll, noop, runIfFunc };
package/dist/function.mjs CHANGED
@@ -3,14 +3,14 @@ import {
3
3
  handlerAll,
4
4
  noop,
5
5
  runIfFunc
6
- } from "./chunk-VPOQGCMS.mjs";
6
+ } from "./chunk-EUA3L3L6.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-FW7XS4NH.mjs";
13
+ import "./chunk-H5VMEQNO.mjs";
14
14
  import "./chunk-PF7LRFIA.mjs";
15
15
  export {
16
16
  funcAll,
@@ -0,0 +1,13 @@
1
+ export { Dict, DynamicRecord, Length, Path, StringLiteral, Union } from './index.types.mjs';
2
+ export { cast, isArray, isEmpty, isFunction, isNotNumber, isNull, isNumber, isNumeric, isObject, isString, isUndefined, isUnit } from './assertion.mjs';
3
+ export { assignAfter, filterObject, filterUndefined, flattenObject, getMemoizedObject, getObject, keysFormObject, memoizeObject, merge, objectFromEntries, omitObject, pickObject, replaceObject, splitObject } from './object.mjs';
4
+ export { funcAll, handlerAll, noop, runIfFunc } from './function.mjs';
5
+ export { AsyncFnReturn, AsyncState, AsyncStateRetry, DOMAttributes, FunctionReturningPromise, MaybeRenderProp, PromiseType, PropGetter, RequiredPropGetter, assignRef, createContext, cx, findChildren, getValidChildren, includesChildren, isRefObject, isValidElement, mergeRefs, omitChildren, pickChildren, useAsync, useAsyncFunc, useAsyncRetry, useCallbackRef, useIsMounted, useMergeRefs, useSafeLayoutEffect, useUnmountEffect, useUpdateEffect } from './react.mjs';
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
+ export { escape } from './string.mjs';
8
+ export { Operand, calc } from './calc.mjs';
9
+ export { darkenColor, getColor, isDark, isLight, isTone, lightenColor, randomColor, shadeColor, tintColor, toneColor, transparentizeColor } from './color.mjs';
10
+ export { filterEmpty } from './array.mjs';
11
+ export { clampNumber, countDecimal, percentToValue, roundNumberToStep, toPrecision, valueToPercent } from './number.mjs';
12
+ export { AnyPointerEvent, MixedEventListener, Point, PointType, PointerEventInfo, addDomEvent, addPointerEvent, getEventPoint, getEventWindow, isMouseEvent, isMultiTouchEvent, isTouchEvent, pointFromMouse, pointFromTouch } from './event.mjs';
13
+ import 'react';
package/dist/index.js CHANGED
@@ -212,9 +212,11 @@ var flattenObject = (obj, maxDepth = Infinity) => {
212
212
  return obj;
213
213
  return Object.entries(obj).reduce((result, [key, value]) => {
214
214
  if (isObject(value)) {
215
- Object.entries(flattenObject(value, maxDepth - 1)).forEach(([childKey, childValue]) => {
216
- result[`${key}.${childKey}`] = childValue;
217
- });
215
+ Object.entries(flattenObject(value, maxDepth - 1)).forEach(
216
+ ([childKey, childValue]) => {
217
+ result[`${key}.${childKey}`] = childValue;
218
+ }
219
+ );
218
220
  } else {
219
221
  result[key] = value;
220
222
  }
@@ -315,7 +317,11 @@ var createContext2 = ({
315
317
  }
316
318
  return context;
317
319
  };
318
- return [Context.Provider, useContext2, Context];
320
+ return [
321
+ Context.Provider,
322
+ useContext2,
323
+ Context
324
+ ];
319
325
  };
320
326
  var useSafeLayoutEffect = Boolean(globalThis == null ? void 0 : globalThis.document) ? React.useLayoutEffect : React.useEffect;
321
327
  var useUnmountEffect = (callback) => (
@@ -373,10 +379,13 @@ var useCallbackRef = (callback, deps = []) => {
373
379
  React.useEffect(() => {
374
380
  callbackRef.current = callback;
375
381
  });
376
- return React.useCallback((...args) => {
377
- var _a;
378
- return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
379
- }, deps);
382
+ return React.useCallback(
383
+ (...args) => {
384
+ var _a;
385
+ return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
386
+ },
387
+ deps
388
+ );
380
389
  };
381
390
  var useUpdateEffect = (callback, deps) => {
382
391
  const renderCycleRef = React.useRef(false);
@@ -406,24 +415,27 @@ var useAsyncFunc = (func, deps = [], initialState = { loading: false }) => {
406
415
  const lastCallId = React.useRef(0);
407
416
  const isMounted = useIsMounted();
408
417
  const [state, setState] = React.useState(initialState);
409
- const callback = React.useCallback((...args) => {
410
- const callId = ++lastCallId.current;
411
- if (!state.loading) {
412
- setState((prevState) => ({ ...prevState, loading: true }));
413
- }
414
- return func(...args).then(
415
- (value) => {
416
- if (isMounted.current && callId === lastCallId.current)
417
- setState({ value, loading: false });
418
- return value;
419
- },
420
- (error) => {
421
- if (isMounted.current && callId === lastCallId.current)
422
- setState({ error, loading: false });
423
- return error;
424
- }
425
- );
426
- }, deps);
418
+ const callback = React.useCallback(
419
+ (...args) => {
420
+ const callId = ++lastCallId.current;
421
+ if (!state.loading)
422
+ setState((prevState) => ({ ...prevState, loading: true }));
423
+ return func(...args).then(
424
+ (value) => {
425
+ if (isMounted.current && callId === lastCallId.current)
426
+ setState({ value, loading: false });
427
+ return value;
428
+ },
429
+ (error) => {
430
+ if (isMounted.current && callId === lastCallId.current)
431
+ setState({ error, loading: false });
432
+ return error;
433
+ }
434
+ );
435
+ },
436
+ // eslint-disable-next-line react-hooks/exhaustive-deps
437
+ deps
438
+ );
427
439
  return [state, callback];
428
440
  };
429
441
  var useAsyncRetry = (func, deps = []) => {
@@ -496,7 +508,9 @@ var focusableElList = [
496
508
  ];
497
509
  var focusableElSelector = focusableElList.join();
498
510
  var getAllFocusable = (container) => {
499
- const focusableEls = Array.from(container.querySelectorAll(focusableElSelector));
511
+ const focusableEls = Array.from(
512
+ container.querySelectorAll(focusableElSelector)
513
+ );
500
514
  focusableEls.unshift(container);
501
515
  return focusableEls.filter((el) => isFocusable(el) && isVisible(el));
502
516
  };
@@ -565,11 +579,7 @@ var calc = Object.assign(
565
579
  // src/color.ts
566
580
  var import_color2k = require("color2k");
567
581
  var getColor = (color, fallback) => (theme, colorMode) => {
568
- const hex = getMemoizedObject(
569
- theme,
570
- `colors.${color}`,
571
- color
572
- );
582
+ const hex = getMemoizedObject(theme, `colors.${color}`, color);
573
583
  try {
574
584
  if (isArray(hex)) {
575
585
  const [lightHex, darkHex] = hex;
@@ -613,7 +623,10 @@ var toneColor = (color, l) => (theme, colorMode) => {
613
623
  n = n - 5 * (isLighten ? 1 : -1);
614
624
  return (0, import_color2k.toHex)(isLighten ? (0, import_color2k.lighten)(raw, n / 100) : (0, import_color2k.mix)(raw, "#000", n / 100));
615
625
  };
616
- var randomColor = ({ string, colors } = {}) => {
626
+ var randomColor = ({
627
+ string,
628
+ colors
629
+ } = {}) => {
617
630
  const fallback = randomHex();
618
631
  if (string && colors)
619
632
  return randomColorFromList(string, colors);
package/dist/index.mjs CHANGED
@@ -48,7 +48,7 @@ import {
48
48
  useSafeLayoutEffect,
49
49
  useUnmountEffect,
50
50
  useUpdateEffect
51
- } from "./chunk-VPOQGCMS.mjs";
51
+ } from "./chunk-EUA3L3L6.mjs";
52
52
  import "./chunk-SLJ4M7XC.mjs";
53
53
  import {
54
54
  clampNumber,
@@ -107,7 +107,7 @@ import {
107
107
  isTabbable,
108
108
  platform,
109
109
  vendor
110
- } from "./chunk-FW7XS4NH.mjs";
110
+ } from "./chunk-H5VMEQNO.mjs";
111
111
  import {
112
112
  addDomEvent,
113
113
  addPointerEvent,
@@ -0,0 +1,14 @@
1
+ type Primitive = null | undefined | string | number | boolean | symbol | bigint;
2
+ type PathImpl<K extends string | number | symbol, V> = K extends string | number ? V extends Primitive ? `${K}` : `${K}.${Path<V>}` : ``;
3
+ type Path<T> = {
4
+ [K in keyof T]-?: PathImpl<K, T[K]>;
5
+ }[keyof T];
6
+ type Dict<T = any> = Record<string, T>;
7
+ type StringLiteral = string & {};
8
+ type Union<T> = T | StringLiteral;
9
+ type Length = string | 0 | number;
10
+ type DynamicRecord<T> = {
11
+ [K in keyof T]-?: T[K] extends Primitive ? string | number : DynamicRecord<T[K]>;
12
+ };
13
+
14
+ export { Dict, DynamicRecord, Length, Path, StringLiteral, Union };
@@ -0,0 +1,8 @@
1
+ declare const toPrecision: (n: number, precision?: number) => string;
2
+ declare const countDecimal: (n: number) => number;
3
+ declare const roundNumberToStep: (n: number, from: number, step: number) => string;
4
+ declare const valueToPercent: (n: number, min: number, max: number) => number;
5
+ declare const percentToValue: (n: number, min: number, max: number) => number;
6
+ declare const clampNumber: (n: number, min: number, max: number) => number;
7
+
8
+ export { clampNumber, countDecimal, percentToValue, roundNumberToStep, toPrecision, valueToPercent };
@@ -0,0 +1,18 @@
1
+ import { Dict } from './index.types.mjs';
2
+
3
+ declare const omitObject: <T extends Dict, K extends keyof T>(obj: T, keys: K[]) => Omit<T, K>;
4
+ declare const pickObject: <T extends Dict, K extends keyof T>(obj: T, keys: K[]) => { [P in K]: T[P]; };
5
+ declare const splitObject: <T extends Dict, K extends keyof T>(obj: T, keys: K[]) => [{ [P in K]: T[P]; }, Omit<T, K>];
6
+ declare const filterObject: <T extends Dict, K extends Dict>(obj: T, func: (key: keyof T, value: T[keyof T], obj: T) => boolean) => K;
7
+ declare const filterUndefined: <T extends Dict>(obj: T) => T;
8
+ declare const merge: <T extends Dict>(target: any, source: any, overrideArray?: boolean) => T;
9
+ declare const flattenObject: <T extends Dict>(obj: any, maxDepth?: number) => T;
10
+ declare const objectFromEntries: <T extends Dict>(entries: any[][]) => T;
11
+ declare const keysFormObject: <T extends Dict>(obj: T) => (keyof T)[];
12
+ declare const replaceObject: <T extends unknown>(objOrArray: T, callBack: (value: any) => any) => T;
13
+ declare const getObject: (obj: Dict, path: string | number, fallback?: any, i?: number) => any;
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
+ declare const assignAfter: (target: Record<string, any>, ...sources: any[]) => Record<string, unknown>;
17
+
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) => any;
15
- declare const getMemoizedObject: (obj: Dict, path: string | number, fallback?: any, i?: number) => any;
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(([childKey, childValue]) => {
107
- result[`${key}.${childKey}`] = childValue;
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-VPOQGCMS.mjs";
16
+ } from "./chunk-EUA3L3L6.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-FW7XS4NH.mjs";
23
+ import "./chunk-H5VMEQNO.mjs";
24
24
  import "./chunk-PF7LRFIA.mjs";
25
25
  export {
26
26
  assignAfter,
@@ -0,0 +1,91 @@
1
+ import * as React from 'react';
2
+
3
+ type DOMElement = Element & HTMLOrSVGElement;
4
+ type DataAttributes = {
5
+ [dataAttr: string]: any;
6
+ };
7
+ type DOMAttributes<Y = DOMElement> = React.AriaAttributes & React.DOMAttributes<Y> & DataAttributes & {
8
+ id?: string;
9
+ role?: React.AriaRole;
10
+ tabIndex?: number;
11
+ style?: React.CSSProperties;
12
+ };
13
+ type Merge<Y, M> = M extends Record<string, unknown> ? Y : Omit<Y, keyof M> & M;
14
+ type PropGetter<Y = Record<string, unknown>, M = DOMAttributes> = (props?: Merge<DOMAttributes, Y>, ref?: React.Ref<any>) => M & React.RefAttributes<any>;
15
+ type RequiredPropGetter<Y = Record<string, unknown>, M = DOMAttributes> = (props: Merge<DOMAttributes, Y>, ref?: React.Ref<any>) => M & React.RefAttributes<any>;
16
+ type MaybeRenderProp<Y> = React.ReactNode | ((props: Y) => React.ReactNode);
17
+ type Options = {
18
+ strict?: boolean;
19
+ errorMessage?: string;
20
+ name?: string;
21
+ };
22
+ type CreateContextReturn<T> = [React.Provider<T>, () => T, React.Context<T>];
23
+ declare const createContext: <ContextType extends unknown = any>({ strict, errorMessage, name, }?: Options) => CreateContextReturn<ContextType>;
24
+ declare const useSafeLayoutEffect: typeof React.useLayoutEffect;
25
+ declare const useUnmountEffect: (callback: () => void) => void;
26
+ declare const useIsMounted: () => React.MutableRefObject<boolean>;
27
+ declare const getValidChildren: (children: React.ReactNode) => React.ReactElement[];
28
+ declare const isValidElement: (child: any) => child is React.ReactNode;
29
+ declare const findChildren: (children: React.ReactElement<any, string | React.JSXElementConstructor<any>>[], ...types: React.JSXElementConstructor<any>[]) => [React.ReactElement | undefined, ...React.ReactElement[]];
30
+ declare const includesChildren: (children: React.ReactElement<any, string | React.JSXElementConstructor<any>>[], ...types: React.JSXElementConstructor<any>[]) => boolean;
31
+ declare const omitChildren: (children: React.ReactElement<any, string | React.JSXElementConstructor<any>>[], ...types: React.JSXElementConstructor<any>[]) => React.ReactElement[];
32
+ declare const pickChildren: (children: React.ReactElement<any, string | React.JSXElementConstructor<any>>[], ...types: React.JSXElementConstructor<any>[]) => React.ReactElement[];
33
+ declare const cx: (...classNames: (string | undefined)[]) => string;
34
+ type ReactRef<T> = React.Ref<T> | React.MutableRefObject<T>;
35
+ declare const isRefObject: (val: any) => val is {
36
+ current: any;
37
+ };
38
+ declare const assignRef: <T extends unknown = any>(ref: ReactRef<T> | undefined, value: T) => void;
39
+ declare const mergeRefs: <T extends unknown = any>(...refs: (ReactRef<T> | undefined)[]) => (node: T | null) => void;
40
+ declare const useMergeRefs: <T extends unknown = any>(...refs: (ReactRef<T> | undefined)[]) => (node: T | null) => void;
41
+ declare const useCallbackRef: <T extends (...args: any[]) => any>(callback: T | undefined, deps?: React.DependencyList) => T;
42
+ declare const useUpdateEffect: (callback: React.EffectCallback, deps: React.DependencyList) => void;
43
+ type FunctionReturningPromise = (...args: any[]) => Promise<any>;
44
+ declare const useAsync: <T extends FunctionReturningPromise>(func: T, deps?: React.DependencyList) => StateFromFunctionReturningPromise<T>;
45
+ type AsyncState<T> = {
46
+ loading: boolean;
47
+ error?: undefined;
48
+ value?: undefined;
49
+ } | {
50
+ loading: true;
51
+ error?: Error | undefined;
52
+ value?: T;
53
+ } | {
54
+ loading: false;
55
+ error: Error;
56
+ value?: undefined;
57
+ } | {
58
+ loading: false;
59
+ error?: undefined;
60
+ value: T;
61
+ };
62
+ type PromiseType<P extends Promise<any>> = P extends Promise<infer T> ? T : never;
63
+ type StateFromFunctionReturningPromise<T extends FunctionReturningPromise> = AsyncState<PromiseType<ReturnType<T>>>;
64
+ type AsyncFnReturn<T extends FunctionReturningPromise = FunctionReturningPromise> = [StateFromFunctionReturningPromise<T>, T];
65
+ declare const useAsyncFunc: <T extends FunctionReturningPromise>(func: T, deps?: React.DependencyList, initialState?: StateFromFunctionReturningPromise<T>) => AsyncFnReturn<T>;
66
+ type AsyncStateRetry<T> = AsyncState<T> & {
67
+ retry(): void;
68
+ };
69
+ declare const useAsyncRetry: <T>(func: () => Promise<T>, deps?: React.DependencyList) => {
70
+ retry: () => void;
71
+ loading: boolean;
72
+ error?: undefined;
73
+ value?: undefined;
74
+ } | {
75
+ retry: () => void;
76
+ loading: false;
77
+ error: Error;
78
+ value?: undefined;
79
+ } | {
80
+ retry: () => void;
81
+ loading: true;
82
+ error?: Error | undefined;
83
+ value?: T | undefined;
84
+ } | {
85
+ retry: () => void;
86
+ loading: false;
87
+ error?: undefined;
88
+ value: T;
89
+ };
90
+
91
+ export { AsyncFnReturn, AsyncState, AsyncStateRetry, DOMAttributes, FunctionReturningPromise, MaybeRenderProp, PromiseType, PropGetter, RequiredPropGetter, assignRef, createContext, cx, findChildren, getValidChildren, includesChildren, isRefObject, isValidElement, mergeRefs, omitChildren, pickChildren, useAsync, useAsyncFunc, useAsyncRetry, useCallbackRef, useIsMounted, useMergeRefs, useSafeLayoutEffect, useUnmountEffect, useUpdateEffect };
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 [Context.Provider, useContext2, Context];
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((...args) => {
139
- var _a;
140
- return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
141
- }, deps);
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,24 +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((...args) => {
172
- const callId = ++lastCallId.current;
173
- if (!state.loading) {
174
- setState((prevState) => ({ ...prevState, loading: true }));
175
- }
176
- return func(...args).then(
177
- (value) => {
178
- if (isMounted.current && callId === lastCallId.current)
179
- setState({ value, loading: false });
180
- return value;
181
- },
182
- (error) => {
183
- if (isMounted.current && callId === lastCallId.current)
184
- setState({ error, loading: false });
185
- return error;
186
- }
187
- );
188
- }, deps);
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
+ );
189
199
  return [state, callback];
190
200
  };
191
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-VPOQGCMS.mjs";
22
+ } from "./chunk-EUA3L3L6.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-FW7XS4NH.mjs";
29
+ import "./chunk-H5VMEQNO.mjs";
30
30
  import "./chunk-PF7LRFIA.mjs";
31
31
  export {
32
32
  assignRef,
@@ -0,0 +1,3 @@
1
+ declare const escape: (value: string, replaceValue?: string) => string;
2
+
3
+ export { escape };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yamada-ui/utils",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Yamada UI utils",
5
5
  "keywords": [
6
6
  "utils",