@yamada-ui/utils 0.0.0-dev-20230716162752 → 0.0.0-dev-20230716195657

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 };
@@ -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/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 };
@@ -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 };
@@ -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';
@@ -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) => (obj: Dict, path: string | number, fallback?: any, i?: number) => any;
15
+ declare const getMemoizedObject: (obj: Dict, path: string | number, fallback?: any, i?: number) => any;
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 };
@@ -0,0 +1,94 @@
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> = [
65
+ StateFromFunctionReturningPromise<T>,
66
+ T
67
+ ];
68
+ declare const useAsyncFunc: <T extends FunctionReturningPromise>(func: T, deps?: React.DependencyList, initialState?: StateFromFunctionReturningPromise<T>) => AsyncFnReturn<T>;
69
+ type AsyncStateRetry<T> = AsyncState<T> & {
70
+ retry(): void;
71
+ };
72
+ declare const useAsyncRetry: <T>(func: () => Promise<T>, deps?: React.DependencyList) => {
73
+ retry: () => void;
74
+ loading: boolean;
75
+ error?: undefined;
76
+ value?: undefined;
77
+ } | {
78
+ retry: () => void;
79
+ loading: false;
80
+ error: Error;
81
+ value?: undefined;
82
+ } | {
83
+ retry: () => void;
84
+ loading: true;
85
+ error?: Error | undefined;
86
+ value?: T | undefined;
87
+ } | {
88
+ retry: () => void;
89
+ loading: false;
90
+ error?: undefined;
91
+ value: T;
92
+ };
93
+
94
+ 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 };
@@ -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.0.0-dev-20230716162752",
3
+ "version": "0.0.0-dev-20230716195657",
4
4
  "description": "Yamada UI utils",
5
5
  "keywords": [
6
6
  "utils",