@yamada-ui/utils 0.2.1 → 0.3.1
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-ANJGKDOC.mjs → chunk-5OQGKXOK.mjs} +38 -18
- package/dist/color.d.mts +13 -11
- package/dist/color.d.ts +13 -11
- package/dist/color.js +33 -12
- package/dist/color.mjs +3 -1
- package/dist/function.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +39 -18
- package/dist/index.mjs +3 -1
- package/dist/index.types.d.mts +1 -4
- package/dist/index.types.d.ts +1 -4
- package/dist/object.d.mts +2 -2
- package/dist/object.d.ts +2 -2
- package/dist/object.js +6 -6
- package/dist/object.mjs +1 -1
- package/dist/react.mjs +1 -1
- package/package.json +1 -1
|
@@ -180,13 +180,32 @@ import {
|
|
|
180
180
|
darken,
|
|
181
181
|
lighten
|
|
182
182
|
} from "color2k";
|
|
183
|
+
var hues = [
|
|
184
|
+
50,
|
|
185
|
+
100,
|
|
186
|
+
200,
|
|
187
|
+
300,
|
|
188
|
+
400,
|
|
189
|
+
500,
|
|
190
|
+
600,
|
|
191
|
+
700,
|
|
192
|
+
800,
|
|
193
|
+
900,
|
|
194
|
+
950
|
|
195
|
+
];
|
|
183
196
|
var isGray = (colorScheme) => colorScheme === "gray" || colorScheme === "zinc" || colorScheme === "neutral" || colorScheme === "stone";
|
|
184
|
-
var getColor = (color, fallback) => (theme, colorMode) => {
|
|
197
|
+
var getColor = (color, fallback) => (theme = {}, colorMode) => {
|
|
198
|
+
var _a, _b, _c;
|
|
199
|
+
const [token, hue] = color.split(".");
|
|
200
|
+
const [, relatedToken] = (_c = Object.entries((_b = (_a = theme.semantics) == null ? void 0 : _a.colorSchemes) != null ? _b : {}).find(
|
|
201
|
+
([semanticToken]) => token === semanticToken
|
|
202
|
+
)) != null ? _c : [];
|
|
203
|
+
if (relatedToken)
|
|
204
|
+
color = `${relatedToken}.${hue}`;
|
|
185
205
|
const hex = getMemoizedObject(theme, `colors.${color}`, color);
|
|
186
206
|
try {
|
|
187
207
|
if (isArray(hex)) {
|
|
188
|
-
|
|
189
|
-
return toHex(String(colorMode !== "dark" ? lightHex : darkHex));
|
|
208
|
+
return toHex(String(colorMode !== "dark" ? hex[0] : hex[1]));
|
|
190
209
|
} else {
|
|
191
210
|
return toHex(String(hex));
|
|
192
211
|
}
|
|
@@ -195,30 +214,30 @@ var getColor = (color, fallback) => (theme, colorMode) => {
|
|
|
195
214
|
}
|
|
196
215
|
};
|
|
197
216
|
var lightenColor = (color, amount) => (theme, colorMode) => {
|
|
198
|
-
const raw =
|
|
217
|
+
const raw = getColor(color, color)(theme, colorMode);
|
|
199
218
|
return toHex(lighten(raw, amount / 100));
|
|
200
219
|
};
|
|
201
220
|
var darkenColor = (color, amount) => (theme, colorMode) => {
|
|
202
|
-
const raw =
|
|
221
|
+
const raw = getColor(color, color)(theme, colorMode);
|
|
203
222
|
return toHex(darken(raw, amount / 100));
|
|
204
223
|
};
|
|
205
224
|
var tintColor = (color, amount) => (theme, colorMode) => {
|
|
206
|
-
const raw =
|
|
225
|
+
const raw = getColor(color, color)(theme, colorMode);
|
|
207
226
|
return toHex(mix(raw, "#fff", amount));
|
|
208
227
|
};
|
|
209
228
|
var shadeColor = (color, amount) => (theme, colorMode) => {
|
|
210
|
-
const raw =
|
|
229
|
+
const raw = getColor(color, color)(theme, colorMode);
|
|
211
230
|
return toHex(mix(raw, "#000", amount / 100));
|
|
212
231
|
};
|
|
213
232
|
var transparentizeColor = (color, alpha) => (theme, colorMode) => {
|
|
214
|
-
const raw =
|
|
233
|
+
const raw = getColor(color, color)(theme, colorMode);
|
|
215
234
|
return transparentize(raw, 1 - alpha);
|
|
216
235
|
};
|
|
217
|
-
var toneColor = (color,
|
|
218
|
-
const raw =
|
|
219
|
-
if (
|
|
236
|
+
var toneColor = (color, hue) => (theme, colorMode) => {
|
|
237
|
+
const raw = getColor(color, color)(theme, colorMode);
|
|
238
|
+
if (hue < 50 || 950 < hue)
|
|
220
239
|
return color;
|
|
221
|
-
let n = (
|
|
240
|
+
let n = (hue - 500) / 10;
|
|
222
241
|
const isLighten = n <= 0;
|
|
223
242
|
if (isLighten)
|
|
224
243
|
n *= -1;
|
|
@@ -320,16 +339,16 @@ var filterObject = (obj, func) => {
|
|
|
320
339
|
return result;
|
|
321
340
|
};
|
|
322
341
|
var filterUndefined = (obj) => filterObject(obj, (_, val) => val !== null && val !== void 0);
|
|
323
|
-
var merge = (target, source,
|
|
342
|
+
var merge = (target, source, mergeArray = false) => {
|
|
324
343
|
let result = Object.assign({}, target);
|
|
325
344
|
if (isObject(source)) {
|
|
326
345
|
if (isObject(target)) {
|
|
327
346
|
for (const [sourceKey, sourceValue] of Object.entries(source)) {
|
|
328
347
|
const targetValue = target[sourceKey];
|
|
329
|
-
if (
|
|
348
|
+
if (mergeArray && isArray(sourceValue) && isArray(targetValue)) {
|
|
330
349
|
result[sourceKey] = targetValue.concat(...sourceValue);
|
|
331
350
|
} else if (!isFunction(sourceValue) && isObject(sourceValue) && target.hasOwnProperty(sourceKey)) {
|
|
332
|
-
result[sourceKey] = merge(targetValue, sourceValue,
|
|
351
|
+
result[sourceKey] = merge(targetValue, sourceValue, mergeArray);
|
|
333
352
|
} else {
|
|
334
353
|
Object.assign(result, { [sourceKey]: sourceValue });
|
|
335
354
|
}
|
|
@@ -340,12 +359,12 @@ var merge = (target, source, overrideArray = false) => {
|
|
|
340
359
|
}
|
|
341
360
|
return result;
|
|
342
361
|
};
|
|
343
|
-
var flattenObject = (obj, maxDepth = Infinity) => {
|
|
362
|
+
var flattenObject = (obj, maxDepth = Infinity, omitKeys = []) => {
|
|
344
363
|
if (!isObject(obj) && !isArray(obj) || !maxDepth)
|
|
345
364
|
return obj;
|
|
346
365
|
return Object.entries(obj).reduce((result, [key, value]) => {
|
|
347
|
-
if (isObject(value)) {
|
|
348
|
-
Object.entries(flattenObject(value, maxDepth - 1)).forEach(
|
|
366
|
+
if (isObject(value) && !Object.keys(value).some((key2) => omitKeys.includes(key2))) {
|
|
367
|
+
Object.entries(flattenObject(value, maxDepth - 1, omitKeys)).forEach(
|
|
349
368
|
([childKey, childValue]) => {
|
|
350
369
|
result[`${key}.${childKey}`] = childValue;
|
|
351
370
|
}
|
|
@@ -457,6 +476,7 @@ export {
|
|
|
457
476
|
useAsync,
|
|
458
477
|
useAsyncFunc,
|
|
459
478
|
useAsyncRetry,
|
|
479
|
+
hues,
|
|
460
480
|
isGray,
|
|
461
481
|
getColor,
|
|
462
482
|
lightenColor,
|
package/dist/color.d.mts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { Dict } from './index.types.mjs';
|
|
2
2
|
|
|
3
|
+
type ColorMode = 'light' | 'dark';
|
|
4
|
+
declare const hues: readonly [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
|
|
3
5
|
declare const isGray: (colorScheme: string) => boolean;
|
|
4
|
-
declare const getColor: (color: string, fallback?: string) => (theme
|
|
5
|
-
declare const lightenColor: (color: string, amount: number) => (theme?: Dict, colorMode?:
|
|
6
|
-
declare const darkenColor: (color: string, amount: number) => (theme?: Dict, colorMode?:
|
|
7
|
-
declare const tintColor: (color: string, amount: number) => (theme?: Dict, colorMode?:
|
|
8
|
-
declare const shadeColor: (color: string, amount: number) => (theme?: Dict, colorMode?:
|
|
9
|
-
declare const transparentizeColor: (color: string, alpha: number) => (theme?: Dict, colorMode?:
|
|
10
|
-
declare const toneColor: (color: string,
|
|
6
|
+
declare const getColor: (color: string, fallback?: string) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
7
|
+
declare const lightenColor: (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
8
|
+
declare const darkenColor: (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
9
|
+
declare const tintColor: (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
10
|
+
declare const shadeColor: (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
11
|
+
declare const transparentizeColor: (color: string, alpha: number) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
12
|
+
declare const toneColor: (color: string, hue: (typeof hues)[number]) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
11
13
|
declare const randomColor: ({ string, colors, }?: {
|
|
12
14
|
string?: string | undefined;
|
|
13
15
|
colors?: string[] | undefined;
|
|
14
16
|
}) => string;
|
|
15
|
-
declare const isTone: (color: string) => (theme?: Dict, colorMode?:
|
|
16
|
-
declare const isLight: (color: string) => (theme?: Dict, colorMode?:
|
|
17
|
-
declare const isDark: (color: string) => (theme?: Dict, colorMode?:
|
|
17
|
+
declare const isTone: (color: string) => (theme?: Dict, colorMode?: ColorMode) => "light" | "dark";
|
|
18
|
+
declare const isLight: (color: string) => (theme?: Dict, colorMode?: ColorMode) => boolean;
|
|
19
|
+
declare const isDark: (color: string) => (theme?: Dict, colorMode?: ColorMode) => boolean;
|
|
18
20
|
|
|
19
|
-
export { darkenColor, getColor, isDark, isGray, isLight, isTone, lightenColor, randomColor, shadeColor, tintColor, toneColor, transparentizeColor };
|
|
21
|
+
export { darkenColor, getColor, hues, isDark, isGray, isLight, isTone, lightenColor, randomColor, shadeColor, tintColor, toneColor, transparentizeColor };
|
package/dist/color.d.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { Dict } from './index.types.js';
|
|
2
2
|
|
|
3
|
+
type ColorMode = 'light' | 'dark';
|
|
4
|
+
declare const hues: readonly [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
|
|
3
5
|
declare const isGray: (colorScheme: string) => boolean;
|
|
4
|
-
declare const getColor: (color: string, fallback?: string) => (theme
|
|
5
|
-
declare const lightenColor: (color: string, amount: number) => (theme?: Dict, colorMode?:
|
|
6
|
-
declare const darkenColor: (color: string, amount: number) => (theme?: Dict, colorMode?:
|
|
7
|
-
declare const tintColor: (color: string, amount: number) => (theme?: Dict, colorMode?:
|
|
8
|
-
declare const shadeColor: (color: string, amount: number) => (theme?: Dict, colorMode?:
|
|
9
|
-
declare const transparentizeColor: (color: string, alpha: number) => (theme?: Dict, colorMode?:
|
|
10
|
-
declare const toneColor: (color: string,
|
|
6
|
+
declare const getColor: (color: string, fallback?: string) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
7
|
+
declare const lightenColor: (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
8
|
+
declare const darkenColor: (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
9
|
+
declare const tintColor: (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
10
|
+
declare const shadeColor: (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
11
|
+
declare const transparentizeColor: (color: string, alpha: number) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
12
|
+
declare const toneColor: (color: string, hue: (typeof hues)[number]) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
11
13
|
declare const randomColor: ({ string, colors, }?: {
|
|
12
14
|
string?: string | undefined;
|
|
13
15
|
colors?: string[] | undefined;
|
|
14
16
|
}) => string;
|
|
15
|
-
declare const isTone: (color: string) => (theme?: Dict, colorMode?:
|
|
16
|
-
declare const isLight: (color: string) => (theme?: Dict, colorMode?:
|
|
17
|
-
declare const isDark: (color: string) => (theme?: Dict, colorMode?:
|
|
17
|
+
declare const isTone: (color: string) => (theme?: Dict, colorMode?: ColorMode) => "light" | "dark";
|
|
18
|
+
declare const isLight: (color: string) => (theme?: Dict, colorMode?: ColorMode) => boolean;
|
|
19
|
+
declare const isDark: (color: string) => (theme?: Dict, colorMode?: ColorMode) => boolean;
|
|
18
20
|
|
|
19
|
-
export { darkenColor, getColor, isDark, isGray, isLight, isTone, lightenColor, randomColor, shadeColor, tintColor, toneColor, transparentizeColor };
|
|
21
|
+
export { darkenColor, getColor, hues, isDark, isGray, isLight, isTone, lightenColor, randomColor, shadeColor, tintColor, toneColor, transparentizeColor };
|
package/dist/color.js
CHANGED
|
@@ -22,6 +22,7 @@ var color_exports = {};
|
|
|
22
22
|
__export(color_exports, {
|
|
23
23
|
darkenColor: () => darkenColor,
|
|
24
24
|
getColor: () => getColor,
|
|
25
|
+
hues: () => hues,
|
|
25
26
|
isDark: () => isDark,
|
|
26
27
|
isGray: () => isGray,
|
|
27
28
|
isLight: () => isLight,
|
|
@@ -69,13 +70,32 @@ var memoizeObject = (func) => {
|
|
|
69
70
|
var getMemoizedObject = memoizeObject(getObject);
|
|
70
71
|
|
|
71
72
|
// src/color.ts
|
|
73
|
+
var hues = [
|
|
74
|
+
50,
|
|
75
|
+
100,
|
|
76
|
+
200,
|
|
77
|
+
300,
|
|
78
|
+
400,
|
|
79
|
+
500,
|
|
80
|
+
600,
|
|
81
|
+
700,
|
|
82
|
+
800,
|
|
83
|
+
900,
|
|
84
|
+
950
|
|
85
|
+
];
|
|
72
86
|
var isGray = (colorScheme) => colorScheme === "gray" || colorScheme === "zinc" || colorScheme === "neutral" || colorScheme === "stone";
|
|
73
|
-
var getColor = (color, fallback) => (theme, colorMode) => {
|
|
87
|
+
var getColor = (color, fallback) => (theme = {}, colorMode) => {
|
|
88
|
+
var _a, _b, _c;
|
|
89
|
+
const [token, hue] = color.split(".");
|
|
90
|
+
const [, relatedToken] = (_c = Object.entries((_b = (_a = theme.semantics) == null ? void 0 : _a.colorSchemes) != null ? _b : {}).find(
|
|
91
|
+
([semanticToken]) => token === semanticToken
|
|
92
|
+
)) != null ? _c : [];
|
|
93
|
+
if (relatedToken)
|
|
94
|
+
color = `${relatedToken}.${hue}`;
|
|
74
95
|
const hex = getMemoizedObject(theme, `colors.${color}`, color);
|
|
75
96
|
try {
|
|
76
97
|
if (isArray(hex)) {
|
|
77
|
-
|
|
78
|
-
return (0, import_color2k.toHex)(String(colorMode !== "dark" ? lightHex : darkHex));
|
|
98
|
+
return (0, import_color2k.toHex)(String(colorMode !== "dark" ? hex[0] : hex[1]));
|
|
79
99
|
} else {
|
|
80
100
|
return (0, import_color2k.toHex)(String(hex));
|
|
81
101
|
}
|
|
@@ -84,30 +104,30 @@ var getColor = (color, fallback) => (theme, colorMode) => {
|
|
|
84
104
|
}
|
|
85
105
|
};
|
|
86
106
|
var lightenColor = (color, amount) => (theme, colorMode) => {
|
|
87
|
-
const raw =
|
|
107
|
+
const raw = getColor(color, color)(theme, colorMode);
|
|
88
108
|
return (0, import_color2k.toHex)((0, import_color2k.lighten)(raw, amount / 100));
|
|
89
109
|
};
|
|
90
110
|
var darkenColor = (color, amount) => (theme, colorMode) => {
|
|
91
|
-
const raw =
|
|
111
|
+
const raw = getColor(color, color)(theme, colorMode);
|
|
92
112
|
return (0, import_color2k.toHex)((0, import_color2k.darken)(raw, amount / 100));
|
|
93
113
|
};
|
|
94
114
|
var tintColor = (color, amount) => (theme, colorMode) => {
|
|
95
|
-
const raw =
|
|
115
|
+
const raw = getColor(color, color)(theme, colorMode);
|
|
96
116
|
return (0, import_color2k.toHex)((0, import_color2k.mix)(raw, "#fff", amount));
|
|
97
117
|
};
|
|
98
118
|
var shadeColor = (color, amount) => (theme, colorMode) => {
|
|
99
|
-
const raw =
|
|
119
|
+
const raw = getColor(color, color)(theme, colorMode);
|
|
100
120
|
return (0, import_color2k.toHex)((0, import_color2k.mix)(raw, "#000", amount / 100));
|
|
101
121
|
};
|
|
102
122
|
var transparentizeColor = (color, alpha) => (theme, colorMode) => {
|
|
103
|
-
const raw =
|
|
123
|
+
const raw = getColor(color, color)(theme, colorMode);
|
|
104
124
|
return (0, import_color2k.transparentize)(raw, 1 - alpha);
|
|
105
125
|
};
|
|
106
|
-
var toneColor = (color,
|
|
107
|
-
const raw =
|
|
108
|
-
if (
|
|
126
|
+
var toneColor = (color, hue) => (theme, colorMode) => {
|
|
127
|
+
const raw = getColor(color, color)(theme, colorMode);
|
|
128
|
+
if (hue < 50 || 950 < hue)
|
|
109
129
|
return color;
|
|
110
|
-
let n = (
|
|
130
|
+
let n = (hue - 500) / 10;
|
|
111
131
|
const isLighten = n <= 0;
|
|
112
132
|
if (isLighten)
|
|
113
133
|
n *= -1;
|
|
@@ -172,6 +192,7 @@ var isDark = (color) => (theme, colorMode) => isTone(color)(theme, colorMode) ==
|
|
|
172
192
|
0 && (module.exports = {
|
|
173
193
|
darkenColor,
|
|
174
194
|
getColor,
|
|
195
|
+
hues,
|
|
175
196
|
isDark,
|
|
176
197
|
isGray,
|
|
177
198
|
isLight,
|
package/dist/color.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
darkenColor,
|
|
3
3
|
getColor,
|
|
4
|
+
hues,
|
|
4
5
|
isDark,
|
|
5
6
|
isGray,
|
|
6
7
|
isLight,
|
|
@@ -11,7 +12,7 @@ import {
|
|
|
11
12
|
tintColor,
|
|
12
13
|
toneColor,
|
|
13
14
|
transparentizeColor
|
|
14
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-5OQGKXOK.mjs";
|
|
15
16
|
import "./chunk-SLJ4M7XC.mjs";
|
|
16
17
|
import "./chunk-VYMGBE25.mjs";
|
|
17
18
|
import "./chunk-BZAW2D6U.mjs";
|
|
@@ -23,6 +24,7 @@ import "./chunk-G7Q2EDJF.mjs";
|
|
|
23
24
|
export {
|
|
24
25
|
darkenColor,
|
|
25
26
|
getColor,
|
|
27
|
+
hues,
|
|
26
28
|
isDark,
|
|
27
29
|
isGray,
|
|
28
30
|
isLight,
|
package/dist/function.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Dict,
|
|
1
|
+
export { Dict, Length, Path, StringLiteral, Union } from './index.types.mjs';
|
|
2
2
|
export { cast, isArray, isEmpty, isFunction, isNotNumber, isNull, isNumber, isNumeric, isObject, isString, isUndefined, isUnit } from './assertion.mjs';
|
|
3
3
|
export { assignAfter, filterObject, filterUndefined, flattenObject, getMemoizedObject, getObject, keysFormObject, memoizeObject, merge, objectFromEntries, omitObject, pickObject, replaceObject, splitObject } from './object.mjs';
|
|
4
4
|
export { funcAll, handlerAll, noop, runIfFunc } from './function.mjs';
|
|
@@ -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, isGray, isLight, isTone, lightenColor, randomColor, shadeColor, tintColor, toneColor, transparentizeColor } from './color.mjs';
|
|
9
|
+
export { darkenColor, getColor, hues, 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Dict,
|
|
1
|
+
export { Dict, Length, Path, StringLiteral, Union } from './index.types.js';
|
|
2
2
|
export { cast, isArray, isEmpty, isFunction, isNotNumber, isNull, isNumber, isNumeric, isObject, isString, isUndefined, isUnit } from './assertion.js';
|
|
3
3
|
export { assignAfter, filterObject, filterUndefined, flattenObject, getMemoizedObject, getObject, keysFormObject, memoizeObject, merge, objectFromEntries, omitObject, pickObject, replaceObject, splitObject } from './object.js';
|
|
4
4
|
export { funcAll, handlerAll, noop, runIfFunc } from './function.js';
|
|
@@ -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, isGray, isLight, isTone, lightenColor, randomColor, shadeColor, tintColor, toneColor, transparentizeColor } from './color.js';
|
|
9
|
+
export { darkenColor, getColor, hues, 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
|
@@ -66,6 +66,7 @@ __export(src_exports, {
|
|
|
66
66
|
handlerAll: () => handlerAll,
|
|
67
67
|
hasNegativeTabIndex: () => hasNegativeTabIndex,
|
|
68
68
|
hasTabIndex: () => hasTabIndex,
|
|
69
|
+
hues: () => hues,
|
|
69
70
|
includesChildren: () => includesChildren,
|
|
70
71
|
isActiveElement: () => isActiveElement,
|
|
71
72
|
isApple: () => isApple,
|
|
@@ -192,16 +193,16 @@ var filterObject = (obj, func) => {
|
|
|
192
193
|
return result;
|
|
193
194
|
};
|
|
194
195
|
var filterUndefined = (obj) => filterObject(obj, (_, val) => val !== null && val !== void 0);
|
|
195
|
-
var merge = (target, source,
|
|
196
|
+
var merge = (target, source, mergeArray = false) => {
|
|
196
197
|
let result = Object.assign({}, target);
|
|
197
198
|
if (isObject(source)) {
|
|
198
199
|
if (isObject(target)) {
|
|
199
200
|
for (const [sourceKey, sourceValue] of Object.entries(source)) {
|
|
200
201
|
const targetValue = target[sourceKey];
|
|
201
|
-
if (
|
|
202
|
+
if (mergeArray && isArray(sourceValue) && isArray(targetValue)) {
|
|
202
203
|
result[sourceKey] = targetValue.concat(...sourceValue);
|
|
203
204
|
} else if (!isFunction(sourceValue) && isObject(sourceValue) && target.hasOwnProperty(sourceKey)) {
|
|
204
|
-
result[sourceKey] = merge(targetValue, sourceValue,
|
|
205
|
+
result[sourceKey] = merge(targetValue, sourceValue, mergeArray);
|
|
205
206
|
} else {
|
|
206
207
|
Object.assign(result, { [sourceKey]: sourceValue });
|
|
207
208
|
}
|
|
@@ -212,12 +213,12 @@ var merge = (target, source, overrideArray = false) => {
|
|
|
212
213
|
}
|
|
213
214
|
return result;
|
|
214
215
|
};
|
|
215
|
-
var flattenObject = (obj, maxDepth = Infinity) => {
|
|
216
|
+
var flattenObject = (obj, maxDepth = Infinity, omitKeys = []) => {
|
|
216
217
|
if (!isObject(obj) && !isArray(obj) || !maxDepth)
|
|
217
218
|
return obj;
|
|
218
219
|
return Object.entries(obj).reduce((result, [key, value]) => {
|
|
219
|
-
if (isObject(value)) {
|
|
220
|
-
Object.entries(flattenObject(value, maxDepth - 1)).forEach(
|
|
220
|
+
if (isObject(value) && !Object.keys(value).some((key2) => omitKeys.includes(key2))) {
|
|
221
|
+
Object.entries(flattenObject(value, maxDepth - 1, omitKeys)).forEach(
|
|
221
222
|
([childKey, childValue]) => {
|
|
222
223
|
result[`${key}.${childKey}`] = childValue;
|
|
223
224
|
}
|
|
@@ -583,13 +584,32 @@ var calc = Object.assign(
|
|
|
583
584
|
|
|
584
585
|
// src/color.ts
|
|
585
586
|
var import_color2k = require("color2k");
|
|
587
|
+
var hues = [
|
|
588
|
+
50,
|
|
589
|
+
100,
|
|
590
|
+
200,
|
|
591
|
+
300,
|
|
592
|
+
400,
|
|
593
|
+
500,
|
|
594
|
+
600,
|
|
595
|
+
700,
|
|
596
|
+
800,
|
|
597
|
+
900,
|
|
598
|
+
950
|
|
599
|
+
];
|
|
586
600
|
var isGray = (colorScheme) => colorScheme === "gray" || colorScheme === "zinc" || colorScheme === "neutral" || colorScheme === "stone";
|
|
587
|
-
var getColor = (color, fallback) => (theme, colorMode) => {
|
|
601
|
+
var getColor = (color, fallback) => (theme = {}, colorMode) => {
|
|
602
|
+
var _a, _b, _c;
|
|
603
|
+
const [token, hue] = color.split(".");
|
|
604
|
+
const [, relatedToken] = (_c = Object.entries((_b = (_a = theme.semantics) == null ? void 0 : _a.colorSchemes) != null ? _b : {}).find(
|
|
605
|
+
([semanticToken]) => token === semanticToken
|
|
606
|
+
)) != null ? _c : [];
|
|
607
|
+
if (relatedToken)
|
|
608
|
+
color = `${relatedToken}.${hue}`;
|
|
588
609
|
const hex = getMemoizedObject(theme, `colors.${color}`, color);
|
|
589
610
|
try {
|
|
590
611
|
if (isArray(hex)) {
|
|
591
|
-
|
|
592
|
-
return (0, import_color2k.toHex)(String(colorMode !== "dark" ? lightHex : darkHex));
|
|
612
|
+
return (0, import_color2k.toHex)(String(colorMode !== "dark" ? hex[0] : hex[1]));
|
|
593
613
|
} else {
|
|
594
614
|
return (0, import_color2k.toHex)(String(hex));
|
|
595
615
|
}
|
|
@@ -598,30 +618,30 @@ var getColor = (color, fallback) => (theme, colorMode) => {
|
|
|
598
618
|
}
|
|
599
619
|
};
|
|
600
620
|
var lightenColor = (color, amount) => (theme, colorMode) => {
|
|
601
|
-
const raw =
|
|
621
|
+
const raw = getColor(color, color)(theme, colorMode);
|
|
602
622
|
return (0, import_color2k.toHex)((0, import_color2k.lighten)(raw, amount / 100));
|
|
603
623
|
};
|
|
604
624
|
var darkenColor = (color, amount) => (theme, colorMode) => {
|
|
605
|
-
const raw =
|
|
625
|
+
const raw = getColor(color, color)(theme, colorMode);
|
|
606
626
|
return (0, import_color2k.toHex)((0, import_color2k.darken)(raw, amount / 100));
|
|
607
627
|
};
|
|
608
628
|
var tintColor = (color, amount) => (theme, colorMode) => {
|
|
609
|
-
const raw =
|
|
629
|
+
const raw = getColor(color, color)(theme, colorMode);
|
|
610
630
|
return (0, import_color2k.toHex)((0, import_color2k.mix)(raw, "#fff", amount));
|
|
611
631
|
};
|
|
612
632
|
var shadeColor = (color, amount) => (theme, colorMode) => {
|
|
613
|
-
const raw =
|
|
633
|
+
const raw = getColor(color, color)(theme, colorMode);
|
|
614
634
|
return (0, import_color2k.toHex)((0, import_color2k.mix)(raw, "#000", amount / 100));
|
|
615
635
|
};
|
|
616
636
|
var transparentizeColor = (color, alpha) => (theme, colorMode) => {
|
|
617
|
-
const raw =
|
|
637
|
+
const raw = getColor(color, color)(theme, colorMode);
|
|
618
638
|
return (0, import_color2k.transparentize)(raw, 1 - alpha);
|
|
619
639
|
};
|
|
620
|
-
var toneColor = (color,
|
|
621
|
-
const raw =
|
|
622
|
-
if (
|
|
640
|
+
var toneColor = (color, hue) => (theme, colorMode) => {
|
|
641
|
+
const raw = getColor(color, color)(theme, colorMode);
|
|
642
|
+
if (hue < 50 || 950 < hue)
|
|
623
643
|
return color;
|
|
624
|
-
let n = (
|
|
644
|
+
let n = (hue - 500) / 10;
|
|
625
645
|
const isLighten = n <= 0;
|
|
626
646
|
if (isLighten)
|
|
627
647
|
n *= -1;
|
|
@@ -794,6 +814,7 @@ var addPointerEvent = (target, type, cb, options) => addDomEvent(target, type, w
|
|
|
794
814
|
handlerAll,
|
|
795
815
|
hasNegativeTabIndex,
|
|
796
816
|
hasTabIndex,
|
|
817
|
+
hues,
|
|
797
818
|
includesChildren,
|
|
798
819
|
isActiveElement,
|
|
799
820
|
isApple,
|
package/dist/index.mjs
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
getObject,
|
|
15
15
|
getValidChildren,
|
|
16
16
|
handlerAll,
|
|
17
|
+
hues,
|
|
17
18
|
includesChildren,
|
|
18
19
|
isDark,
|
|
19
20
|
isGray,
|
|
@@ -49,7 +50,7 @@ import {
|
|
|
49
50
|
useSafeLayoutEffect,
|
|
50
51
|
useUnmountEffect,
|
|
51
52
|
useUpdateEffect
|
|
52
|
-
} from "./chunk-
|
|
53
|
+
} from "./chunk-5OQGKXOK.mjs";
|
|
53
54
|
import "./chunk-SLJ4M7XC.mjs";
|
|
54
55
|
import {
|
|
55
56
|
clampNumber,
|
|
@@ -157,6 +158,7 @@ export {
|
|
|
157
158
|
handlerAll,
|
|
158
159
|
hasNegativeTabIndex,
|
|
159
160
|
hasTabIndex,
|
|
161
|
+
hues,
|
|
160
162
|
includesChildren,
|
|
161
163
|
isActiveElement,
|
|
162
164
|
isApple,
|
package/dist/index.types.d.mts
CHANGED
|
@@ -7,8 +7,5 @@ type Dict<T = any> = Record<string, T>;
|
|
|
7
7
|
type StringLiteral = string & {};
|
|
8
8
|
type Union<T> = T | StringLiteral;
|
|
9
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
10
|
|
|
14
|
-
export { Dict,
|
|
11
|
+
export { Dict, Length, Path, StringLiteral, Union };
|
package/dist/index.types.d.ts
CHANGED
|
@@ -7,8 +7,5 @@ type Dict<T = any> = Record<string, T>;
|
|
|
7
7
|
type StringLiteral = string & {};
|
|
8
8
|
type Union<T> = T | StringLiteral;
|
|
9
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
10
|
|
|
14
|
-
export { Dict,
|
|
11
|
+
export { Dict, Length, Path, StringLiteral, Union };
|
package/dist/object.d.mts
CHANGED
|
@@ -5,8 +5,8 @@ declare const pickObject: <T extends Dict, K extends keyof T>(obj: T, keys: K[])
|
|
|
5
5
|
declare const splitObject: <T extends Dict, K extends keyof T>(obj: T, keys: K[]) => [{ [P in K]: T[P]; }, Omit<T, K>];
|
|
6
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
7
|
declare const filterUndefined: <T extends Dict>(obj: T) => T;
|
|
8
|
-
declare const merge: <T extends Dict>(target: any, source: any,
|
|
9
|
-
declare const flattenObject: <T extends Dict>(obj: any, maxDepth?: number) => T;
|
|
8
|
+
declare const merge: <T extends Dict>(target: any, source: any, mergeArray?: boolean) => T;
|
|
9
|
+
declare const flattenObject: <T extends Dict>(obj: any, maxDepth?: number, omitKeys?: string[]) => T;
|
|
10
10
|
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;
|
package/dist/object.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ declare const pickObject: <T extends Dict, K extends keyof T>(obj: T, keys: K[])
|
|
|
5
5
|
declare const splitObject: <T extends Dict, K extends keyof T>(obj: T, keys: K[]) => [{ [P in K]: T[P]; }, Omit<T, K>];
|
|
6
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
7
|
declare const filterUndefined: <T extends Dict>(obj: T) => T;
|
|
8
|
-
declare const merge: <T extends Dict>(target: any, source: any,
|
|
9
|
-
declare const flattenObject: <T extends Dict>(obj: any, maxDepth?: number) => T;
|
|
8
|
+
declare const merge: <T extends Dict>(target: any, source: any, mergeArray?: boolean) => T;
|
|
9
|
+
declare const flattenObject: <T extends Dict>(obj: any, maxDepth?: number, omitKeys?: string[]) => T;
|
|
10
10
|
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;
|
package/dist/object.js
CHANGED
|
@@ -82,16 +82,16 @@ var filterObject = (obj, func) => {
|
|
|
82
82
|
return result;
|
|
83
83
|
};
|
|
84
84
|
var filterUndefined = (obj) => filterObject(obj, (_, val) => val !== null && val !== void 0);
|
|
85
|
-
var merge = (target, source,
|
|
85
|
+
var merge = (target, source, mergeArray = false) => {
|
|
86
86
|
let result = Object.assign({}, target);
|
|
87
87
|
if (isObject(source)) {
|
|
88
88
|
if (isObject(target)) {
|
|
89
89
|
for (const [sourceKey, sourceValue] of Object.entries(source)) {
|
|
90
90
|
const targetValue = target[sourceKey];
|
|
91
|
-
if (
|
|
91
|
+
if (mergeArray && isArray(sourceValue) && isArray(targetValue)) {
|
|
92
92
|
result[sourceKey] = targetValue.concat(...sourceValue);
|
|
93
93
|
} else if (!isFunction(sourceValue) && isObject(sourceValue) && target.hasOwnProperty(sourceKey)) {
|
|
94
|
-
result[sourceKey] = merge(targetValue, sourceValue,
|
|
94
|
+
result[sourceKey] = merge(targetValue, sourceValue, mergeArray);
|
|
95
95
|
} else {
|
|
96
96
|
Object.assign(result, { [sourceKey]: sourceValue });
|
|
97
97
|
}
|
|
@@ -102,12 +102,12 @@ var merge = (target, source, overrideArray = false) => {
|
|
|
102
102
|
}
|
|
103
103
|
return result;
|
|
104
104
|
};
|
|
105
|
-
var flattenObject = (obj, maxDepth = Infinity) => {
|
|
105
|
+
var flattenObject = (obj, maxDepth = Infinity, omitKeys = []) => {
|
|
106
106
|
if (!isObject(obj) && !isArray(obj) || !maxDepth)
|
|
107
107
|
return obj;
|
|
108
108
|
return Object.entries(obj).reduce((result, [key, value]) => {
|
|
109
|
-
if (isObject(value)) {
|
|
110
|
-
Object.entries(flattenObject(value, maxDepth - 1)).forEach(
|
|
109
|
+
if (isObject(value) && !Object.keys(value).some((key2) => omitKeys.includes(key2))) {
|
|
110
|
+
Object.entries(flattenObject(value, maxDepth - 1, omitKeys)).forEach(
|
|
111
111
|
([childKey, childValue]) => {
|
|
112
112
|
result[`${key}.${childKey}`] = childValue;
|
|
113
113
|
}
|
package/dist/object.mjs
CHANGED
package/dist/react.mjs
CHANGED