@yamada-ui/utils 1.5.0 → 1.5.1-dev-20240917064938
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/array.d.mts +1 -1
- package/dist/array.d.ts +1 -1
- package/dist/array.js +3 -1
- package/dist/array.js.map +1 -1
- package/dist/array.mjs +1 -1
- package/dist/assertion.d.mts +14 -14
- package/dist/assertion.d.ts +14 -14
- package/dist/assertion.js +44 -16
- package/dist/assertion.js.map +1 -1
- package/dist/assertion.mjs +1 -1
- package/dist/calc.d.mts +12 -7
- package/dist/calc.d.ts +12 -7
- package/dist/calc.js +17 -7
- package/dist/calc.js.map +1 -1
- package/dist/calc.mjs +1 -1
- package/dist/{chunk-ZFE4ZWCP.mjs → chunk-2AWPBKLQ.mjs} +68 -47
- package/dist/chunk-2AWPBKLQ.mjs.map +1 -0
- package/dist/chunk-5EG6NSMV.mjs +9 -0
- package/dist/chunk-5EG6NSMV.mjs.map +1 -0
- package/dist/{chunk-I5E5UXSE.mjs → chunk-7XL7BPER.mjs} +52 -44
- package/dist/chunk-7XL7BPER.mjs.map +1 -0
- package/dist/{chunk-KT4SLZO6.mjs → chunk-7XRVZGET.mjs} +18 -12
- package/dist/chunk-7XRVZGET.mjs.map +1 -0
- package/dist/{chunk-S35WPDIT.mjs → chunk-AF6MSVQN.mjs} +75 -41
- package/dist/chunk-AF6MSVQN.mjs.map +1 -0
- package/dist/chunk-APJY76CK.mjs +9 -0
- package/dist/chunk-APJY76CK.mjs.map +1 -0
- package/dist/{chunk-L56KWSQO.mjs → chunk-OM7WYVSS.mjs} +18 -8
- package/dist/chunk-OM7WYVSS.mjs.map +1 -0
- package/dist/chunk-QTCZ2LU5.mjs +65 -0
- package/dist/chunk-QTCZ2LU5.mjs.map +1 -0
- package/dist/chunk-RCW53QOG.mjs +31 -0
- package/dist/chunk-RCW53QOG.mjs.map +1 -0
- package/dist/chunk-TJ7CW2M5.mjs +365 -0
- package/dist/chunk-TJ7CW2M5.mjs.map +1 -0
- package/dist/{chunk-2AQWXBLU.mjs → chunk-WU6FTFUV.mjs} +15 -7
- package/dist/chunk-WU6FTFUV.mjs.map +1 -0
- package/dist/chunk-Z4AGSEWZ.mjs +63 -0
- package/dist/chunk-Z4AGSEWZ.mjs.map +1 -0
- package/dist/color.d.mts +24 -24
- package/dist/color.d.ts +24 -24
- package/dist/color.js +212 -158
- package/dist/color.js.map +1 -1
- package/dist/color.mjs +3 -3
- package/dist/dom.d.mts +29 -29
- package/dist/dom.d.ts +29 -29
- package/dist/dom.js +79 -41
- package/dist/dom.js.map +1 -1
- package/dist/dom.mjs +2 -2
- package/dist/event.d.mts +13 -13
- package/dist/event.d.ts +13 -13
- package/dist/event.js +37 -23
- package/dist/event.js.map +1 -1
- package/dist/event.mjs +1 -1
- package/dist/function.d.mts +3 -3
- package/dist/function.d.ts +3 -3
- package/dist/function.js +19 -9
- package/dist/function.js.map +1 -1
- package/dist/function.mjs +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +531 -346
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -12
- package/dist/index.types.d.mts +8 -4
- package/dist/index.types.d.ts +8 -4
- package/dist/index.types.js.map +1 -1
- package/dist/module.d.mts +1 -1
- package/dist/module.d.ts +1 -1
- package/dist/module.js +3 -1
- package/dist/module.js.map +1 -1
- package/dist/module.mjs +1 -1
- package/dist/number.d.mts +7 -7
- package/dist/number.d.ts +7 -7
- package/dist/number.js +17 -11
- package/dist/number.js.map +1 -1
- package/dist/number.mjs +1 -1
- package/dist/object.d.mts +19 -15
- package/dist/object.d.ts +19 -15
- package/dist/object.js +65 -47
- package/dist/object.js.map +1 -1
- package/dist/object.mjs +2 -2
- package/dist/react.d.mts +25 -35
- package/dist/react.d.ts +25 -35
- package/dist/react.js +78 -49
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +2 -2
- package/dist/string.d.mts +5 -5
- package/dist/string.d.ts +5 -5
- package/dist/string.js +14 -6
- package/dist/string.js.map +1 -1
- package/dist/string.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-2AQWXBLU.mjs.map +0 -1
- package/dist/chunk-5OUUTZYQ.mjs +0 -7
- package/dist/chunk-5OUUTZYQ.mjs.map +0 -1
- package/dist/chunk-I5E5UXSE.mjs.map +0 -1
- package/dist/chunk-KT4SLZO6.mjs.map +0 -1
- package/dist/chunk-L56KWSQO.mjs.map +0 -1
- package/dist/chunk-MMZ4T26E.mjs +0 -51
- package/dist/chunk-MMZ4T26E.mjs.map +0 -1
- package/dist/chunk-NBL5H4TH.mjs +0 -35
- package/dist/chunk-NBL5H4TH.mjs.map +0 -1
- package/dist/chunk-S35WPDIT.mjs.map +0 -1
- package/dist/chunk-VRHGQ632.mjs +0 -23
- package/dist/chunk-VRHGQ632.mjs.map +0 -1
- package/dist/chunk-WV6P7ZCI.mjs +0 -7
- package/dist/chunk-WV6P7ZCI.mjs.map +0 -1
- package/dist/chunk-ZFE4ZWCP.mjs.map +0 -1
- package/dist/chunk-ZMR5WZIP.mjs +0 -321
- package/dist/chunk-ZMR5WZIP.mjs.map +0 -1
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getMemoizedObject
|
|
3
|
+
} from "./chunk-7XL7BPER.mjs";
|
|
4
|
+
import {
|
|
5
|
+
isArray,
|
|
6
|
+
isNumber,
|
|
7
|
+
isObject
|
|
8
|
+
} from "./chunk-Z4AGSEWZ.mjs";
|
|
9
|
+
|
|
10
|
+
// src/color.ts
|
|
11
|
+
import * as c from "color2k";
|
|
12
|
+
var SEMANTIC_COLOR_SCHEMES = [
|
|
13
|
+
"mono",
|
|
14
|
+
"primary",
|
|
15
|
+
"secondary",
|
|
16
|
+
"info",
|
|
17
|
+
"success",
|
|
18
|
+
"warning",
|
|
19
|
+
"danger",
|
|
20
|
+
"link"
|
|
21
|
+
];
|
|
22
|
+
var COLOR_SCHEMES = [
|
|
23
|
+
"gray",
|
|
24
|
+
"neutral",
|
|
25
|
+
"red",
|
|
26
|
+
"rose",
|
|
27
|
+
"pink",
|
|
28
|
+
"flashy",
|
|
29
|
+
"orange",
|
|
30
|
+
"amber",
|
|
31
|
+
"yellow",
|
|
32
|
+
"lime",
|
|
33
|
+
"green",
|
|
34
|
+
"emerald",
|
|
35
|
+
"teal",
|
|
36
|
+
"cyan",
|
|
37
|
+
"sky",
|
|
38
|
+
"blue",
|
|
39
|
+
"indigo",
|
|
40
|
+
"violet",
|
|
41
|
+
"purple",
|
|
42
|
+
"fuchsia"
|
|
43
|
+
];
|
|
44
|
+
var TONES = [
|
|
45
|
+
50,
|
|
46
|
+
100,
|
|
47
|
+
200,
|
|
48
|
+
300,
|
|
49
|
+
400,
|
|
50
|
+
500,
|
|
51
|
+
600,
|
|
52
|
+
700,
|
|
53
|
+
800,
|
|
54
|
+
900,
|
|
55
|
+
950
|
|
56
|
+
];
|
|
57
|
+
function isGray(colorScheme) {
|
|
58
|
+
return colorScheme === "gray" || colorScheme === "neutral";
|
|
59
|
+
}
|
|
60
|
+
function isAccessible(colorScheme) {
|
|
61
|
+
return colorScheme === "yellow" || colorScheme === "cyan" || colorScheme === "lime";
|
|
62
|
+
}
|
|
63
|
+
function getColor(color, fallback = "#000000") {
|
|
64
|
+
return function(theme = {}, colorMode = "light", breakpoint = "base") {
|
|
65
|
+
var _a, _b, _c, _d, _e, _f;
|
|
66
|
+
const [token, tone] = color.split(".");
|
|
67
|
+
if (tone) {
|
|
68
|
+
const [, relatedToken] = (_c = Object.entries((_b = (_a = theme.semantics) == null ? void 0 : _a.colorSchemes) != null ? _b : {}).find(
|
|
69
|
+
([semanticToken]) => token === semanticToken
|
|
70
|
+
)) != null ? _c : [];
|
|
71
|
+
if (relatedToken) color = `${relatedToken}.${tone}`;
|
|
72
|
+
} else {
|
|
73
|
+
const [, relatedColor] = (_f = Object.entries((_e = (_d = theme.semantics) == null ? void 0 : _d.colors) != null ? _e : {}).find(
|
|
74
|
+
([semanticToken]) => token === semanticToken
|
|
75
|
+
)) != null ? _f : [];
|
|
76
|
+
if (relatedColor) color = relatedColor;
|
|
77
|
+
}
|
|
78
|
+
const hex = getMemoizedObject(
|
|
79
|
+
theme,
|
|
80
|
+
`colors.${color}`,
|
|
81
|
+
color
|
|
82
|
+
);
|
|
83
|
+
try {
|
|
84
|
+
if (isArray(hex)) {
|
|
85
|
+
return c.toHex(String(hex[colorMode !== "dark" ? 0 : 1]));
|
|
86
|
+
} else if (isObject(hex)) {
|
|
87
|
+
return c.toHex(String(hex[breakpoint]));
|
|
88
|
+
} else {
|
|
89
|
+
return c.toHex(String(hex));
|
|
90
|
+
}
|
|
91
|
+
} catch {
|
|
92
|
+
try {
|
|
93
|
+
return c.toHex(fallback);
|
|
94
|
+
} catch {
|
|
95
|
+
return "#000000";
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function lightenColor(color, amount) {
|
|
101
|
+
return function(theme, colorMode, breakpoint) {
|
|
102
|
+
const raw = getColor(color, color)(theme, colorMode, breakpoint);
|
|
103
|
+
return c.toHex(c.lighten(raw, amount / 100));
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function darkenColor(color, amount) {
|
|
107
|
+
return function(theme, colorMode, breakpoint) {
|
|
108
|
+
const raw = getColor(color, color)(theme, colorMode, breakpoint);
|
|
109
|
+
return c.toHex(c.darken(raw, amount / 100));
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function tintColor(color, amount) {
|
|
113
|
+
return function(theme, colorMode, breakpoint) {
|
|
114
|
+
const raw = getColor(color, color)(theme, colorMode, breakpoint);
|
|
115
|
+
return c.toHex(c.mix(raw, "#fff", amount / 100));
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function shadeColor(color, amount) {
|
|
119
|
+
return function(theme, colorMode, breakpoint) {
|
|
120
|
+
const raw = getColor(color, color)(theme, colorMode, breakpoint);
|
|
121
|
+
return c.toHex(c.mix(raw, "#000", amount / 100));
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function transparentizeColor(color, alpha) {
|
|
125
|
+
return function(theme, colorMode, breakpoint) {
|
|
126
|
+
const raw = getColor(color, color)(theme, colorMode, breakpoint);
|
|
127
|
+
return c.transparentize(raw, 1 - alpha);
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function randomColor({
|
|
131
|
+
string,
|
|
132
|
+
colors
|
|
133
|
+
} = {}) {
|
|
134
|
+
const fallback = randomHex();
|
|
135
|
+
if (string && colors) return randomColorFromList(string, colors);
|
|
136
|
+
if (string && !colors) return randomColorFromString(string);
|
|
137
|
+
if (colors && !string) return randomFromList(colors);
|
|
138
|
+
return fallback;
|
|
139
|
+
}
|
|
140
|
+
function randomHex() {
|
|
141
|
+
return `#${Math.floor(Math.random() * 16777215).toString(16).padEnd(6, "0")}`;
|
|
142
|
+
}
|
|
143
|
+
function randomColorFromString(str) {
|
|
144
|
+
let hash = 0;
|
|
145
|
+
if (str.length === 0) return hash.toString();
|
|
146
|
+
for (let i = 0; i < str.length; i += 1) {
|
|
147
|
+
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
148
|
+
hash = hash & hash;
|
|
149
|
+
}
|
|
150
|
+
let color = "#";
|
|
151
|
+
for (let j = 0; j < 3; j += 1) {
|
|
152
|
+
const value = hash >> j * 8 & 255;
|
|
153
|
+
color += `00${value.toString(16)}`.substr(-2);
|
|
154
|
+
}
|
|
155
|
+
return color;
|
|
156
|
+
}
|
|
157
|
+
function randomColorFromList(str, list) {
|
|
158
|
+
let index = 0;
|
|
159
|
+
if (str.length === 0) return list[0];
|
|
160
|
+
for (let i = 0; i < str.length; i += 1) {
|
|
161
|
+
index = str.charCodeAt(i) + ((index << 5) - index);
|
|
162
|
+
index = index & index;
|
|
163
|
+
}
|
|
164
|
+
index = (index % list.length + list.length) % list.length;
|
|
165
|
+
return list[index];
|
|
166
|
+
}
|
|
167
|
+
function randomFromList(list) {
|
|
168
|
+
return list[Math.floor(Math.random() * list.length)];
|
|
169
|
+
}
|
|
170
|
+
function getBrightness(color) {
|
|
171
|
+
const [r, g, b] = c.parseToRgba(color);
|
|
172
|
+
return (r * 299 + g * 587 + b * 114) / 1e3;
|
|
173
|
+
}
|
|
174
|
+
function isTone(color) {
|
|
175
|
+
return function(theme, colorMode, breakpoint) {
|
|
176
|
+
const raw = theme ? getColor(color)(theme, colorMode, breakpoint) : color;
|
|
177
|
+
const brightness = getBrightness(raw);
|
|
178
|
+
const isDark2 = brightness < 128;
|
|
179
|
+
return isDark2 ? "dark" : "light";
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function isLight(color) {
|
|
183
|
+
return function(theme, colorMode) {
|
|
184
|
+
return isTone(color)(theme, colorMode) === "dark";
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function isDark(color) {
|
|
188
|
+
return function(theme, colorMode) {
|
|
189
|
+
return isTone(color)(theme, colorMode) === "light";
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function convertColor(color, fallback) {
|
|
193
|
+
return function(format) {
|
|
194
|
+
try {
|
|
195
|
+
const isAlpha = format.endsWith("a");
|
|
196
|
+
if (/^[0-9a-fA-F]{6}$/.test(color)) color = "#" + color;
|
|
197
|
+
if (format.startsWith("hex")) {
|
|
198
|
+
let hexa = c.toHex(color);
|
|
199
|
+
if (isAlpha) {
|
|
200
|
+
if (hexa.length === 7) hexa += "ff";
|
|
201
|
+
} else {
|
|
202
|
+
hexa = hexa.replace(/(?<=^#([0-9a-fA-F]{6}))[0-9a-fA-F]{2}$/, "");
|
|
203
|
+
}
|
|
204
|
+
return hexa;
|
|
205
|
+
} else if (format.startsWith("hsl")) {
|
|
206
|
+
let hsla2 = c.toHsla(color);
|
|
207
|
+
if (!isAlpha) {
|
|
208
|
+
hsla2 = hsla2.replace(/hsla/, "hsl");
|
|
209
|
+
hsla2 = hsla2.replace(/,\s*\d+(\.\d+)?\)$/, ")");
|
|
210
|
+
}
|
|
211
|
+
return hsla2;
|
|
212
|
+
} else {
|
|
213
|
+
let rgba2 = c.toRgba(color);
|
|
214
|
+
if (!isAlpha) {
|
|
215
|
+
rgba2 = rgba2.replace(/rgba/, "rgb");
|
|
216
|
+
rgba2 = rgba2.replace(/,\s*\d+(\.\d+)?\)$/, ")");
|
|
217
|
+
}
|
|
218
|
+
return rgba2;
|
|
219
|
+
}
|
|
220
|
+
} catch {
|
|
221
|
+
if (fallback) return convertColor(fallback)(format);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
function calcFormat(color) {
|
|
226
|
+
if (color.startsWith("hsl")) {
|
|
227
|
+
return color.startsWith("hsla") ? "hsla" : "hsl";
|
|
228
|
+
} else if (color.startsWith("rgb")) {
|
|
229
|
+
return color.startsWith("rgba") ? "rgba" : "rgb";
|
|
230
|
+
} else {
|
|
231
|
+
return color.length === 9 ? "hexa" : "hex";
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function getAlpha(color) {
|
|
235
|
+
return c.parseToRgba(color)[3];
|
|
236
|
+
}
|
|
237
|
+
function alphaToHex(a) {
|
|
238
|
+
if (0 > a) a = 0;
|
|
239
|
+
if (1 < a) a = 1;
|
|
240
|
+
return Math.round(a * 255).toString(16).padStart(2, "0");
|
|
241
|
+
}
|
|
242
|
+
function parseToRgba2(color, fallback) {
|
|
243
|
+
try {
|
|
244
|
+
if (/^[0-9a-fA-F]{6}$/.test(color)) color = "#" + color;
|
|
245
|
+
return c.parseToRgba(color);
|
|
246
|
+
} catch {
|
|
247
|
+
if (fallback) return c.parseToRgba(fallback);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
function parseToHsla2(color, fallback) {
|
|
251
|
+
try {
|
|
252
|
+
if (/^[0-9a-fA-F]{6}$/.test(color)) color = "#" + color;
|
|
253
|
+
return c.parseToHsla(color);
|
|
254
|
+
} catch {
|
|
255
|
+
if (fallback) return c.parseToHsla(fallback);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
function parseToHsv(color, fallback) {
|
|
259
|
+
var _a;
|
|
260
|
+
let [r, g, b, a] = (_a = parseToRgba2(color, fallback)) != null ? _a : [255, 255, 255, 1];
|
|
261
|
+
r = r / 255;
|
|
262
|
+
g = g / 255;
|
|
263
|
+
b = b / 255;
|
|
264
|
+
const [min, max] = [Math.min(r, g, b), Math.max(r, g, b)];
|
|
265
|
+
const delta = max - min;
|
|
266
|
+
let [h, v, s] = [0, max, max == 0 ? 0 : delta / max];
|
|
267
|
+
switch (min) {
|
|
268
|
+
case max:
|
|
269
|
+
h = 0;
|
|
270
|
+
break;
|
|
271
|
+
case r:
|
|
272
|
+
h = 60 * ((b - g) / delta) + 180;
|
|
273
|
+
break;
|
|
274
|
+
case g:
|
|
275
|
+
h = 60 * ((r - b) / delta) + 300;
|
|
276
|
+
break;
|
|
277
|
+
case b:
|
|
278
|
+
h = 60 * ((g - r) / delta) + 60;
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
return [h, s, v, a];
|
|
282
|
+
}
|
|
283
|
+
function rgbaTo([r, g, b, a], fallback) {
|
|
284
|
+
return function(format = "hex") {
|
|
285
|
+
return convertColor(c.rgba(r, g, b, a), fallback)(format);
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
function hslaTo([h, s, l, a], fallback) {
|
|
289
|
+
return function(format = "hex") {
|
|
290
|
+
return convertColor(c.hsla(h, s, l, a), fallback)(format);
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
function hsvTo([h, s, v, a], fallback) {
|
|
294
|
+
return function(format = "hex") {
|
|
295
|
+
h = h / 60;
|
|
296
|
+
let rgb = [v, v, v];
|
|
297
|
+
let i = Math.floor(h);
|
|
298
|
+
let f = h - i;
|
|
299
|
+
let p = v * (1 - s);
|
|
300
|
+
let q = v * (1 - s * f);
|
|
301
|
+
let t = v * (1 - s * (1 - f));
|
|
302
|
+
switch (i) {
|
|
303
|
+
case 0:
|
|
304
|
+
case 6:
|
|
305
|
+
rgb = [v, t, p];
|
|
306
|
+
break;
|
|
307
|
+
case 1:
|
|
308
|
+
rgb = [q, v, p];
|
|
309
|
+
break;
|
|
310
|
+
case 2:
|
|
311
|
+
rgb = [p, v, t];
|
|
312
|
+
break;
|
|
313
|
+
case 3:
|
|
314
|
+
rgb = [p, q, v];
|
|
315
|
+
break;
|
|
316
|
+
case 4:
|
|
317
|
+
rgb = [t, p, v];
|
|
318
|
+
break;
|
|
319
|
+
case 5:
|
|
320
|
+
rgb = [v, p, q];
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
let color = `rgb(${rgb.map((v2) => Math.round(v2 * 255)).join(", ")})`;
|
|
324
|
+
if (isNumber(a)) color = color.replace(/\)$/, `, ${a})`);
|
|
325
|
+
return convertColor(color, fallback)(format);
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
function sameColor(color, comparison) {
|
|
329
|
+
var _a, _b;
|
|
330
|
+
if (!color) return false;
|
|
331
|
+
if (!comparison) return false;
|
|
332
|
+
const a = (_a = parseToRgba2(color)) != null ? _a : [];
|
|
333
|
+
const b = (_b = parseToRgba2(comparison)) != null ? _b : [];
|
|
334
|
+
return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export {
|
|
338
|
+
SEMANTIC_COLOR_SCHEMES,
|
|
339
|
+
COLOR_SCHEMES,
|
|
340
|
+
TONES,
|
|
341
|
+
isGray,
|
|
342
|
+
isAccessible,
|
|
343
|
+
getColor,
|
|
344
|
+
lightenColor,
|
|
345
|
+
darkenColor,
|
|
346
|
+
tintColor,
|
|
347
|
+
shadeColor,
|
|
348
|
+
transparentizeColor,
|
|
349
|
+
randomColor,
|
|
350
|
+
isTone,
|
|
351
|
+
isLight,
|
|
352
|
+
isDark,
|
|
353
|
+
convertColor,
|
|
354
|
+
calcFormat,
|
|
355
|
+
getAlpha,
|
|
356
|
+
alphaToHex,
|
|
357
|
+
parseToRgba2 as parseToRgba,
|
|
358
|
+
parseToHsla2 as parseToHsla,
|
|
359
|
+
parseToHsv,
|
|
360
|
+
rgbaTo,
|
|
361
|
+
hslaTo,
|
|
362
|
+
hsvTo,
|
|
363
|
+
sameColor
|
|
364
|
+
};
|
|
365
|
+
//# sourceMappingURL=chunk-TJ7CW2M5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/color.ts"],"sourcesContent":["import * as c from \"color2k\"\nimport { isArray, isNumber, isObject } from \"./assertion\"\nimport type { Dict, StringLiteral } from \"./index.types\"\nimport { getMemoizedObject as get } from \"./object\"\n\ntype ThemeValue = string | number\ntype Breakpoint = \"base\" | StringLiteral\ntype ColorMode = \"light\" | \"dark\"\n\nexport type ColorFormat = \"hex\" | \"hexa\" | \"rgba\" | \"rgb\" | \"hsl\" | \"hsla\"\n\nexport const SEMANTIC_COLOR_SCHEMES = [\n \"mono\",\n \"primary\",\n \"secondary\",\n \"info\",\n \"success\",\n \"warning\",\n \"danger\",\n \"link\",\n] as const\n\nexport const COLOR_SCHEMES = [\n \"gray\",\n \"neutral\",\n \"red\",\n \"rose\",\n \"pink\",\n \"flashy\",\n \"orange\",\n \"amber\",\n \"yellow\",\n \"lime\",\n \"green\",\n \"emerald\",\n \"teal\",\n \"cyan\",\n \"sky\",\n \"blue\",\n \"indigo\",\n \"violet\",\n \"purple\",\n \"fuchsia\",\n] as const\n\nexport type SemanticColorScheme =\n | (typeof SEMANTIC_COLOR_SCHEMES)[number]\n | StringLiteral\nexport type ColorScheme = (typeof COLOR_SCHEMES)[number] | StringLiteral\n\nexport const TONES = [\n 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950,\n] as const\n\nexport function isGray(colorScheme: string) {\n return colorScheme === \"gray\" || colorScheme === \"neutral\"\n}\n\nexport function isAccessible(colorScheme: string) {\n return (\n colorScheme === \"yellow\" || colorScheme === \"cyan\" || colorScheme === \"lime\"\n )\n}\n\nexport function getColor(color: string, fallback: string = \"#000000\") {\n return function (\n theme: Dict = {},\n colorMode: ColorMode = \"light\",\n breakpoint: Breakpoint = \"base\",\n ) {\n const [token, tone] = color.split(\".\")\n\n if (tone) {\n const [, relatedToken] =\n Object.entries<string>(theme.semantics?.colorSchemes ?? {}).find(\n ([semanticToken]) => token === semanticToken,\n ) ?? []\n\n if (relatedToken) color = `${relatedToken}.${tone}`\n } else {\n const [, relatedColor] =\n Object.entries<string>(theme.semantics?.colors ?? {}).find(\n ([semanticToken]) => token === semanticToken,\n ) ?? []\n\n if (relatedColor) color = relatedColor\n }\n\n const hex = get<ThemeValue | [ThemeValue, ThemeValue] | Dict<ThemeValue>>(\n theme,\n `colors.${color}`,\n color,\n )\n\n try {\n if (isArray(hex)) {\n return c.toHex(String(hex[colorMode !== \"dark\" ? 0 : 1]))\n } else if (isObject(hex)) {\n return c.toHex(String(hex[breakpoint]))\n } else {\n return c.toHex(String(hex))\n }\n } catch {\n try {\n return c.toHex(fallback)\n } catch {\n return \"#000000\"\n }\n }\n }\n}\n\nexport function lightenColor(color: string, amount: number) {\n return function (\n theme?: Dict,\n colorMode?: ColorMode,\n breakpoint?: Breakpoint,\n ) {\n const raw = getColor(color, color)(theme, colorMode, breakpoint)\n\n return c.toHex(c.lighten(raw, amount / 100))\n }\n}\n\nexport function darkenColor(color: string, amount: number) {\n return function (\n theme?: Dict,\n colorMode?: ColorMode,\n breakpoint?: Breakpoint,\n ) {\n const raw = getColor(color, color)(theme, colorMode, breakpoint)\n\n return c.toHex(c.darken(raw, amount / 100))\n }\n}\n\nexport function tintColor(color: string, amount: number) {\n return function (\n theme?: Dict,\n colorMode?: ColorMode,\n breakpoint?: Breakpoint,\n ) {\n const raw = getColor(color, color)(theme, colorMode, breakpoint)\n\n return c.toHex(c.mix(raw, \"#fff\", amount / 100))\n }\n}\n\nexport function shadeColor(color: string, amount: number) {\n return function (\n theme?: Dict,\n colorMode?: ColorMode,\n breakpoint?: Breakpoint,\n ) {\n const raw = getColor(color, color)(theme, colorMode, breakpoint)\n\n return c.toHex(c.mix(raw, \"#000\", amount / 100))\n }\n}\n\nexport function transparentizeColor(color: string, alpha: number) {\n return function (\n theme?: Dict,\n colorMode?: ColorMode,\n breakpoint?: Breakpoint,\n ) {\n const raw = getColor(color, color)(theme, colorMode, breakpoint)\n\n return c.transparentize(raw, 1 - alpha)\n }\n}\n\nexport function randomColor({\n string,\n colors,\n}: { string?: string; colors?: string[] } = {}) {\n const fallback = randomHex()\n\n if (string && colors) return randomColorFromList(string, colors)\n\n if (string && !colors) return randomColorFromString(string)\n\n if (colors && !string) return randomFromList(colors)\n\n return fallback\n}\n\nfunction randomHex() {\n return `#${Math.floor(Math.random() * 0xffffff)\n .toString(16)\n .padEnd(6, \"0\")}`\n}\n\nfunction randomColorFromString(str: string) {\n let hash = 0\n\n if (str.length === 0) return hash.toString()\n\n for (let i = 0; i < str.length; i += 1) {\n hash = str.charCodeAt(i) + ((hash << 5) - hash)\n hash = hash & hash\n }\n\n let color = \"#\"\n\n for (let j = 0; j < 3; j += 1) {\n const value = (hash >> (j * 8)) & 255\n\n color += `00${value.toString(16)}`.substr(-2)\n }\n\n return color\n}\n\nfunction randomColorFromList(str: string, list: string[]) {\n let index = 0\n\n if (str.length === 0) return list[0]\n\n for (let i = 0; i < str.length; i += 1) {\n index = str.charCodeAt(i) + ((index << 5) - index)\n\n index = index & index\n }\n\n index = ((index % list.length) + list.length) % list.length\n\n return list[index]\n}\n\nfunction randomFromList(list: string[]) {\n return list[Math.floor(Math.random() * list.length)]\n}\n\nfunction getBrightness(color: string) {\n const [r, g, b] = c.parseToRgba(color)\n\n return (r * 299 + g * 587 + b * 114) / 1000\n}\n\nexport function isTone(color: string) {\n return function (\n theme?: Dict,\n colorMode?: ColorMode,\n breakpoint?: Breakpoint,\n ) {\n const raw = theme ? getColor(color)(theme, colorMode, breakpoint) : color\n\n const brightness = getBrightness(raw)\n\n const isDark = brightness < 128\n\n return isDark ? \"dark\" : \"light\"\n }\n}\n\nexport function isLight(color: string) {\n return function (theme?: Dict, colorMode?: ColorMode) {\n return isTone(color)(theme, colorMode) === \"dark\"\n }\n}\n\nexport function isDark(color: string) {\n return function (theme?: Dict, colorMode?: ColorMode) {\n return isTone(color)(theme, colorMode) === \"light\"\n }\n}\n\nexport function convertColor(color: string, fallback?: string) {\n return function (format: ColorFormat): string | undefined {\n try {\n const isAlpha = format.endsWith(\"a\")\n\n if (/^[0-9a-fA-F]{6}$/.test(color)) color = \"#\" + color\n\n if (format.startsWith(\"hex\")) {\n let hexa = c.toHex(color)\n\n if (isAlpha) {\n if (hexa.length === 7) hexa += \"ff\"\n } else {\n hexa = hexa.replace(/(?<=^#([0-9a-fA-F]{6}))[0-9a-fA-F]{2}$/, \"\")\n }\n\n return hexa\n } else if (format.startsWith(\"hsl\")) {\n let hsla = c.toHsla(color)\n\n if (!isAlpha) {\n hsla = hsla.replace(/hsla/, \"hsl\")\n hsla = hsla.replace(/,\\s*\\d+(\\.\\d+)?\\)$/, \")\")\n }\n\n return hsla\n } else {\n let rgba = c.toRgba(color)\n\n if (!isAlpha) {\n rgba = rgba.replace(/rgba/, \"rgb\")\n rgba = rgba.replace(/,\\s*\\d+(\\.\\d+)?\\)$/, \")\")\n }\n\n return rgba\n }\n } catch {\n if (fallback) return convertColor(fallback)(format)\n }\n }\n}\n\nexport function calcFormat(color: string): ColorFormat {\n if (color.startsWith(\"hsl\")) {\n return color.startsWith(\"hsla\") ? \"hsla\" : \"hsl\"\n } else if (color.startsWith(\"rgb\")) {\n return color.startsWith(\"rgba\") ? \"rgba\" : \"rgb\"\n } else {\n return color.length === 9 ? \"hexa\" : \"hex\"\n }\n}\n\nexport function getAlpha(color: string) {\n return c.parseToRgba(color)[3]\n}\n\nexport function alphaToHex(a: number) {\n if (0 > a) a = 0\n if (1 < a) a = 1\n\n return Math.round(a * 255)\n .toString(16)\n .padStart(2, \"0\")\n}\n\nexport function parseToRgba(color: string, fallback?: string) {\n try {\n if (/^[0-9a-fA-F]{6}$/.test(color)) color = \"#\" + color\n\n return c.parseToRgba(color)\n } catch {\n if (fallback) return c.parseToRgba(fallback)\n }\n}\n\nexport function parseToHsla(color: string, fallback?: string) {\n try {\n if (/^[0-9a-fA-F]{6}$/.test(color)) color = \"#\" + color\n\n return c.parseToHsla(color)\n } catch {\n if (fallback) return c.parseToHsla(fallback)\n }\n}\n\nexport function parseToHsv(\n color: string,\n fallback?: string,\n): [number, number, number, number] {\n let [r, g, b, a] = parseToRgba(color, fallback) ?? [255, 255, 255, 1]\n\n r = r / 255\n g = g / 255\n b = b / 255\n\n const [min, max] = [Math.min(r, g, b), Math.max(r, g, b)]\n const delta = max - min\n\n let [h, v, s] = [0, max, max == 0 ? 0 : delta / max]\n\n switch (min) {\n case max:\n h = 0\n break\n\n case r:\n h = 60 * ((b - g) / delta) + 180\n break\n\n case g:\n h = 60 * ((r - b) / delta) + 300\n break\n\n case b:\n h = 60 * ((g - r) / delta) + 60\n break\n }\n\n return [h, s, v, a]\n}\n\nexport function rgbaTo(\n [r, g, b, a]: [number, number, number, number],\n fallback?: string,\n) {\n return function (format: ColorFormat = \"hex\") {\n return convertColor(c.rgba(r, g, b, a), fallback)(format)\n }\n}\n\nexport function hslaTo(\n [h, s, l, a]: [number, number, number, number],\n fallback?: string,\n) {\n return function (format: ColorFormat = \"hex\") {\n return convertColor(c.hsla(h, s, l, a), fallback)(format)\n }\n}\n\nexport function hsvTo(\n [h, s, v, a]: [number, number, number, number?],\n fallback?: string,\n) {\n return function (format: ColorFormat = \"hex\"): string | undefined {\n h = h / 60\n\n let rgb: [number, number, number] = [v, v, v]\n\n let i = Math.floor(h)\n let f = h - i\n let p = v * (1 - s)\n let q = v * (1 - s * f)\n let t = v * (1 - s * (1 - f))\n\n switch (i) {\n case 0:\n case 6:\n rgb = [v, t, p]\n break\n\n case 1:\n rgb = [q, v, p]\n break\n\n case 2:\n rgb = [p, v, t]\n break\n\n case 3:\n rgb = [p, q, v]\n break\n\n case 4:\n rgb = [t, p, v]\n break\n\n case 5:\n rgb = [v, p, q]\n break\n }\n\n let color = `rgb(${rgb.map((v) => Math.round(v * 255)).join(\", \")})`\n\n if (isNumber(a)) color = color.replace(/\\)$/, `, ${a})`)\n\n return convertColor(color, fallback)(format)\n }\n}\n\nexport function sameColor(\n color: string | undefined,\n comparison: string | undefined,\n) {\n if (!color) return false\n if (!comparison) return false\n\n const a = parseToRgba(color) ?? []\n const b = parseToRgba(comparison) ?? []\n\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3]\n}\n"],"mappings":";;;;;;;;;;AAAA,YAAY,OAAO;AAWZ,IAAM,yBAAyB;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,IAAM,gBAAgB;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAOO,IAAM,QAAQ;AAAA,EACnB;AAAA,EAAI;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AACnD;AAEO,SAAS,OAAO,aAAqB;AAC1C,SAAO,gBAAgB,UAAU,gBAAgB;AACnD;AAEO,SAAS,aAAa,aAAqB;AAChD,SACE,gBAAgB,YAAY,gBAAgB,UAAU,gBAAgB;AAE1E;AAEO,SAAS,SAAS,OAAe,WAAmB,WAAW;AACpE,SAAO,SACL,QAAc,CAAC,GACf,YAAuB,SACvB,aAAyB,QACzB;AArEJ;AAsEI,UAAM,CAAC,OAAO,IAAI,IAAI,MAAM,MAAM,GAAG;AAErC,QAAI,MAAM;AACR,YA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AAG,SAAQ,MAAM,QAAQ,OAAO,KAAK,CAAC,GAAG;AAEvD,WAAO,aAAa,OAAO,QAAQ,EAAE,MAAM;AAAA,EAC7C;AACF;AAEO,SAAS,UACd,OACA,YACA;AA5cF;AA6cE,MAAI,CAAC,MAAO,QAAO;AACnB,MAAI,CAAC,WAAY,QAAO;AAExB,QAAM,KAAI,KAAAF,aAAY,KAAK,MAAjB,YAAsB,CAAC;AACjC,QAAM,KAAI,KAAAA,aAAY,UAAU,MAAtB,YAA2B,CAAC;AAEtC,SAAO,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,CAAC;AACxE;","names":["isDark","hsla","rgba","parseToRgba","parseToHsla","v"]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// src/string.ts
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
function escape(value, replaceValue = "") {
|
|
3
|
+
return value.replace(/\s+/g, replaceValue);
|
|
4
|
+
}
|
|
5
|
+
function antonym(value) {
|
|
4
6
|
switch (value) {
|
|
5
7
|
case "top":
|
|
6
8
|
return "bottom";
|
|
@@ -37,10 +39,16 @@ var antonym = (value) => {
|
|
|
37
39
|
default:
|
|
38
40
|
return value;
|
|
39
41
|
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
}
|
|
43
|
+
function toCamelCase(value) {
|
|
44
|
+
return value.toLowerCase().replace(/[_-](.)/g, (_, val) => val.toUpperCase()).replace(/^(.)/, (_, val) => val.toUpperCase());
|
|
45
|
+
}
|
|
46
|
+
function toKebabCase(value) {
|
|
47
|
+
return value.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase().replace(/^-/, "");
|
|
48
|
+
}
|
|
49
|
+
function toTitleCase(value) {
|
|
50
|
+
return value.replace(/([A-Z])/g, " $1").replace(/[_-](.)/g, (_, val) => ` ${val.toUpperCase()}`).replace(/^./, (str) => str.toUpperCase()).trim();
|
|
51
|
+
}
|
|
44
52
|
|
|
45
53
|
export {
|
|
46
54
|
escape,
|
|
@@ -49,4 +57,4 @@ export {
|
|
|
49
57
|
toKebabCase,
|
|
50
58
|
toTitleCase
|
|
51
59
|
};
|
|
52
|
-
//# sourceMappingURL=chunk-
|
|
60
|
+
//# sourceMappingURL=chunk-WU6FTFUV.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/string.ts"],"sourcesContent":["import type { StringLiteral } from \"./index.types\"\n\nexport function escape(value: string, replaceValue: string = \"\"): string {\n return value.replace(/\\s+/g, replaceValue)\n}\n\nexport function antonym(value: string): string {\n switch (value) {\n case \"top\":\n return \"bottom\"\n\n case \"bottom\":\n return \"top\"\n\n case \"left\":\n return \"right\"\n\n case \"right\":\n return \"left\"\n\n case \"start\":\n return \"end\"\n\n case \"end\":\n return \"start\"\n\n case \"x\":\n return \"y\"\n\n case \"y\":\n return \"x\"\n\n case \"enter\":\n return \"exit\"\n\n case \"exit\":\n return \"enter\"\n\n case \"vertical\":\n return \"horizontal\"\n\n case \"horizontal\":\n return \"vertical\"\n\n case \"up\":\n return \"down\"\n\n case \"down\":\n return \"up\"\n\n case \"block\":\n return \"inline\"\n\n case \"inline\":\n return \"block\"\n\n default:\n return value\n }\n}\n\nexport function toCamelCase(value: StringLiteral): string {\n return value\n .toLowerCase()\n .replace(/[_-](.)/g, (_, val) => val.toUpperCase())\n .replace(/^(.)/, (_, val) => val.toUpperCase())\n}\n\nexport function toKebabCase(value: StringLiteral): string {\n return value\n .replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, \"$1-$2\")\n .toLowerCase()\n .replace(/^-/, \"\")\n}\n\nexport function toTitleCase(value: StringLiteral): string {\n return value\n .replace(/([A-Z])/g, \" $1\")\n .replace(/[_-](.)/g, (_, val) => ` ${val.toUpperCase()}`)\n .replace(/^./,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0 || 1 / x === 1 / y) || x !== x && y !== y;
|
|
4
|
+
}
|
|
5
|
+
function isNumber(value) {
|
|
6
|
+
return typeof value === "number";
|
|
7
|
+
}
|
|
8
|
+
function isNotNumber(value) {
|
|
9
|
+
return typeof value !== "number" || Number.isNaN(value) || !Number.isFinite(value);
|
|
10
|
+
}
|
|
11
|
+
function isNumeric(value) {
|
|
12
|
+
return !isNaN(parseFloat(String(value))) && isFinite(Number(value)) && /^-?\d*\.?\d+$/.test(String(value));
|
|
13
|
+
}
|
|
14
|
+
function isString(value) {
|
|
15
|
+
return Object.prototype.toString.call(value) === "[object String]";
|
|
16
|
+
}
|
|
17
|
+
function isBoolean(value) {
|
|
18
|
+
return typeof value === "boolean";
|
|
19
|
+
}
|
|
20
|
+
function isUndefined(value) {
|
|
21
|
+
return typeof value === "undefined" && value === void 0;
|
|
22
|
+
}
|
|
23
|
+
function isNull(value) {
|
|
24
|
+
return value === null;
|
|
25
|
+
}
|
|
26
|
+
function isObject(value) {
|
|
27
|
+
return value !== null && (typeof value === "object" || typeof value === "function") && !isArray(value);
|
|
28
|
+
}
|
|
29
|
+
function isArray(value) {
|
|
30
|
+
return Array.isArray(value);
|
|
31
|
+
}
|
|
32
|
+
function isEmpty(value) {
|
|
33
|
+
return !isArray(value) || !value.length || value.every((v) => v == null);
|
|
34
|
+
}
|
|
35
|
+
function isFunction(value) {
|
|
36
|
+
return typeof value === "function";
|
|
37
|
+
}
|
|
38
|
+
function isUnit(value) {
|
|
39
|
+
return /[0-9].*(em|rem|ex|rex|cap|rcap|ch|rch|ic|ric|lh|rlh|vw|svw|lvw|dvw|vh|svh|lvh|dvh|vi|svi|lvi|dvi|vb|svb|lvb|dvb|vmin|svmin|lvmin|dvmin|vmax|svmax|lvmax|dvmax|cm|mm|Q|in|pc|pt|px|%|cqw|cqh|cqi|cqb|cqmin|cqmax)$/.test(
|
|
40
|
+
value
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
function cast(value) {
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
is,
|
|
49
|
+
isNumber,
|
|
50
|
+
isNotNumber,
|
|
51
|
+
isNumeric,
|
|
52
|
+
isString,
|
|
53
|
+
isBoolean,
|
|
54
|
+
isUndefined,
|
|
55
|
+
isNull,
|
|
56
|
+
isObject,
|
|
57
|
+
isArray,
|
|
58
|
+
isEmpty,
|
|
59
|
+
isFunction,
|
|
60
|
+
isUnit,
|
|
61
|
+
cast
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=chunk-Z4AGSEWZ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/assertion.ts"],"sourcesContent":["import type { Dict } from \"./index.types\"\n\nexport function is(x: any, y: any) {\n return (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y)\n}\n\nexport function isNumber(value: any): value is number {\n return typeof value === \"number\"\n}\n\nexport function isNotNumber(value: any): boolean {\n return (\n typeof value !== \"number\" || Number.isNaN(value) || !Number.isFinite(value)\n )\n}\n\nexport function isNumeric(value: any): boolean {\n return (\n !isNaN(parseFloat(String(value))) &&\n isFinite(Number(value)) &&\n /^-?\\d*\\.?\\d+$/.test(String(value))\n )\n}\n\nexport function isString(value: any): value is string {\n return Object.prototype.toString.call(value) === \"[object String]\"\n}\n\nexport function isBoolean(value: any): value is boolean {\n return typeof value === \"boolean\"\n}\n\nexport function isUndefined(value: any): value is undefined {\n return typeof value === \"undefined\" && value === undefined\n}\n\nexport function isNull(value: any): value is null {\n return value === null\n}\n\nexport function isObject<T extends Dict>(value: any): value is T {\n return (\n value !== null &&\n (typeof value === \"object\" || typeof value === \"function\") &&\n !isArray(value)\n )\n}\n\nexport function isArray<T extends any[]>(value: any): value is T {\n return Array.isArray(value)\n}\n\nexport function isEmpty(value: any): boolean {\n return !isArray(value) || !value.length || value.every((v) => v == null)\n}\n\nexport function isFunction<T extends Function = Function>(\n value: any,\n): value is T {\n return typeof value === \"function\"\n}\n\nexport function isUnit(value: any): boolean {\n return /[0-9].*(em|rem|ex|rex|cap|rcap|ch|rch|ic|ric|lh|rlh|vw|svw|lvw|dvw|vh|svh|lvh|dvh|vi|svi|lvi|dvi|vb|svb|lvb|dvb|vmin|svmin|lvmin|dvmin|vmax|svmax|lvmax|dvmax|cm|mm|Q|in|pc|pt|px|%|cqw|cqh|cqi|cqb|cqmin|cqmax)$/.test(\n value,\n )\n}\n\nexport function cast<T>(value: any) {\n return value as T\n}\n"],"mappings":";AAEO,SAAS,GAAG,GAAQ,GAAQ;AACjC,SAAQ,MAAM,MAAM,MAAM,KAAK,IAAI,MAAM,IAAI,MAAQ,MAAM,KAAK,MAAM;AACxE;AAEO,SAAS,SAAS,OAA6B;AACpD,SAAO,OAAO,UAAU;AAC1B;AAEO,SAAS,YAAY,OAAqB;AAC/C,SACE,OAAO,UAAU,YAAY,OAAO,MAAM,KAAK,KAAK,CAAC,OAAO,SAAS,KAAK;AAE9E;AAEO,SAAS,UAAU,OAAqB;AAC7C,SACE,CAAC,MAAM,WAAW,OAAO,KAAK,CAAC,CAAC,KAChC,SAAS,OAAO,KAAK,CAAC,KACtB,gBAAgB,KAAK,OAAO,KAAK,CAAC;AAEtC;AAEO,SAAS,SAAS,OAA6B;AACpD,SAAO,OAAO,UAAU,SAAS,KAAK,KAAK,MAAM;AACnD;AAEO,SAAS,UAAU,OAA8B;AACtD,SAAO,OAAO,UAAU;AAC1B;AAEO,SAAS,YAAY,OAAgC;AAC1D,SAAO,OAAO,UAAU,eAAe,UAAU;AACnD;AAEO,SAAS,OAAO,OAA2B;AAChD,SAAO,UAAU;AACnB;AAEO,SAAS,SAAyB,OAAwB;AAC/D,SACE,UAAU,SACT,OAAO,UAAU,YAAY,OAAO,UAAU,eAC/C,CAAC,QAAQ,KAAK;AAElB;AAEO,SAAS,QAAyB,OAAwB;AAC/D,SAAO,MAAM,QAAQ,KAAK;AAC5B;AAEO,SAAS,QAAQ,OAAqB;AAC3C,SAAO,CAAC,QAAQ,KAAK,KAAK,CAAC,MAAM,UAAU,MAAM,MAAM,CAAC,MAAM,KAAK,IAAI;AACzE;AAEO,SAAS,WACd,OACY;AACZ,SAAO,OAAO,UAAU;AAC1B;AAEO,SAAS,OAAO,OAAqB;AAC1C,SAAO,oNAAoN;AAAA,IACzN;AAAA,EACF;AACF;AAEO,SAAS,KAAQ,OAAY;AAClC,SAAO;AACT;","names":[]}
|
package/dist/color.d.mts
CHANGED
|
@@ -8,31 +8,31 @@ declare const COLOR_SCHEMES: readonly ["gray", "neutral", "red", "rose", "pink",
|
|
|
8
8
|
type SemanticColorScheme = (typeof SEMANTIC_COLOR_SCHEMES)[number] | StringLiteral;
|
|
9
9
|
type ColorScheme = (typeof COLOR_SCHEMES)[number] | StringLiteral;
|
|
10
10
|
declare const TONES: readonly [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
|
|
11
|
-
declare
|
|
12
|
-
declare
|
|
13
|
-
declare
|
|
14
|
-
declare
|
|
15
|
-
declare
|
|
16
|
-
declare
|
|
17
|
-
declare
|
|
18
|
-
declare
|
|
19
|
-
declare
|
|
11
|
+
declare function isGray(colorScheme: string): colorScheme is "gray" | "neutral";
|
|
12
|
+
declare function isAccessible(colorScheme: string): colorScheme is "yellow" | "lime" | "cyan";
|
|
13
|
+
declare function getColor(color: string, fallback?: string): (theme?: Dict, colorMode?: ColorMode, breakpoint?: Breakpoint) => string;
|
|
14
|
+
declare function lightenColor(color: string, amount: number): (theme?: Dict, colorMode?: ColorMode, breakpoint?: Breakpoint) => string;
|
|
15
|
+
declare function darkenColor(color: string, amount: number): (theme?: Dict, colorMode?: ColorMode, breakpoint?: Breakpoint) => string;
|
|
16
|
+
declare function tintColor(color: string, amount: number): (theme?: Dict, colorMode?: ColorMode, breakpoint?: Breakpoint) => string;
|
|
17
|
+
declare function shadeColor(color: string, amount: number): (theme?: Dict, colorMode?: ColorMode, breakpoint?: Breakpoint) => string;
|
|
18
|
+
declare function transparentizeColor(color: string, alpha: number): (theme?: Dict, colorMode?: ColorMode, breakpoint?: Breakpoint) => string;
|
|
19
|
+
declare function randomColor({ string, colors, }?: {
|
|
20
20
|
string?: string;
|
|
21
21
|
colors?: string[];
|
|
22
|
-
})
|
|
23
|
-
declare
|
|
24
|
-
declare
|
|
25
|
-
declare
|
|
26
|
-
declare
|
|
27
|
-
declare
|
|
28
|
-
declare
|
|
29
|
-
declare
|
|
30
|
-
declare
|
|
31
|
-
declare
|
|
32
|
-
declare
|
|
33
|
-
declare
|
|
34
|
-
declare
|
|
35
|
-
declare
|
|
36
|
-
declare
|
|
22
|
+
}): string;
|
|
23
|
+
declare function isTone(color: string): (theme?: Dict, colorMode?: ColorMode, breakpoint?: Breakpoint) => "light" | "dark";
|
|
24
|
+
declare function isLight(color: string): (theme?: Dict, colorMode?: ColorMode) => boolean;
|
|
25
|
+
declare function isDark(color: string): (theme?: Dict, colorMode?: ColorMode) => boolean;
|
|
26
|
+
declare function convertColor(color: string, fallback?: string): (format: ColorFormat) => string | undefined;
|
|
27
|
+
declare function calcFormat(color: string): ColorFormat;
|
|
28
|
+
declare function getAlpha(color: string): number;
|
|
29
|
+
declare function alphaToHex(a: number): string;
|
|
30
|
+
declare function parseToRgba(color: string, fallback?: string): [number, number, number, number] | undefined;
|
|
31
|
+
declare function parseToHsla(color: string, fallback?: string): [number, number, number, number] | undefined;
|
|
32
|
+
declare function parseToHsv(color: string, fallback?: string): [number, number, number, number];
|
|
33
|
+
declare function rgbaTo([r, g, b, a]: [number, number, number, number], fallback?: string): (format?: ColorFormat) => string | undefined;
|
|
34
|
+
declare function hslaTo([h, s, l, a]: [number, number, number, number], fallback?: string): (format?: ColorFormat) => string | undefined;
|
|
35
|
+
declare function hsvTo([h, s, v, a]: [number, number, number, number?], fallback?: string): (format?: ColorFormat) => string | undefined;
|
|
36
|
+
declare function sameColor(color: string | undefined, comparison: string | undefined): boolean;
|
|
37
37
|
|
|
38
38
|
export { COLOR_SCHEMES, type ColorFormat, type ColorScheme, SEMANTIC_COLOR_SCHEMES, type SemanticColorScheme, TONES, alphaToHex, calcFormat, convertColor, darkenColor, getAlpha, getColor, hslaTo, hsvTo, isAccessible, isDark, isGray, isLight, isTone, lightenColor, parseToHsla, parseToHsv, parseToRgba, randomColor, rgbaTo, sameColor, shadeColor, tintColor, transparentizeColor };
|
package/dist/color.d.ts
CHANGED
|
@@ -8,31 +8,31 @@ declare const COLOR_SCHEMES: readonly ["gray", "neutral", "red", "rose", "pink",
|
|
|
8
8
|
type SemanticColorScheme = (typeof SEMANTIC_COLOR_SCHEMES)[number] | StringLiteral;
|
|
9
9
|
type ColorScheme = (typeof COLOR_SCHEMES)[number] | StringLiteral;
|
|
10
10
|
declare const TONES: readonly [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
|
|
11
|
-
declare
|
|
12
|
-
declare
|
|
13
|
-
declare
|
|
14
|
-
declare
|
|
15
|
-
declare
|
|
16
|
-
declare
|
|
17
|
-
declare
|
|
18
|
-
declare
|
|
19
|
-
declare
|
|
11
|
+
declare function isGray(colorScheme: string): colorScheme is "gray" | "neutral";
|
|
12
|
+
declare function isAccessible(colorScheme: string): colorScheme is "yellow" | "lime" | "cyan";
|
|
13
|
+
declare function getColor(color: string, fallback?: string): (theme?: Dict, colorMode?: ColorMode, breakpoint?: Breakpoint) => string;
|
|
14
|
+
declare function lightenColor(color: string, amount: number): (theme?: Dict, colorMode?: ColorMode, breakpoint?: Breakpoint) => string;
|
|
15
|
+
declare function darkenColor(color: string, amount: number): (theme?: Dict, colorMode?: ColorMode, breakpoint?: Breakpoint) => string;
|
|
16
|
+
declare function tintColor(color: string, amount: number): (theme?: Dict, colorMode?: ColorMode, breakpoint?: Breakpoint) => string;
|
|
17
|
+
declare function shadeColor(color: string, amount: number): (theme?: Dict, colorMode?: ColorMode, breakpoint?: Breakpoint) => string;
|
|
18
|
+
declare function transparentizeColor(color: string, alpha: number): (theme?: Dict, colorMode?: ColorMode, breakpoint?: Breakpoint) => string;
|
|
19
|
+
declare function randomColor({ string, colors, }?: {
|
|
20
20
|
string?: string;
|
|
21
21
|
colors?: string[];
|
|
22
|
-
})
|
|
23
|
-
declare
|
|
24
|
-
declare
|
|
25
|
-
declare
|
|
26
|
-
declare
|
|
27
|
-
declare
|
|
28
|
-
declare
|
|
29
|
-
declare
|
|
30
|
-
declare
|
|
31
|
-
declare
|
|
32
|
-
declare
|
|
33
|
-
declare
|
|
34
|
-
declare
|
|
35
|
-
declare
|
|
36
|
-
declare
|
|
22
|
+
}): string;
|
|
23
|
+
declare function isTone(color: string): (theme?: Dict, colorMode?: ColorMode, breakpoint?: Breakpoint) => "light" | "dark";
|
|
24
|
+
declare function isLight(color: string): (theme?: Dict, colorMode?: ColorMode) => boolean;
|
|
25
|
+
declare function isDark(color: string): (theme?: Dict, colorMode?: ColorMode) => boolean;
|
|
26
|
+
declare function convertColor(color: string, fallback?: string): (format: ColorFormat) => string | undefined;
|
|
27
|
+
declare function calcFormat(color: string): ColorFormat;
|
|
28
|
+
declare function getAlpha(color: string): number;
|
|
29
|
+
declare function alphaToHex(a: number): string;
|
|
30
|
+
declare function parseToRgba(color: string, fallback?: string): [number, number, number, number] | undefined;
|
|
31
|
+
declare function parseToHsla(color: string, fallback?: string): [number, number, number, number] | undefined;
|
|
32
|
+
declare function parseToHsv(color: string, fallback?: string): [number, number, number, number];
|
|
33
|
+
declare function rgbaTo([r, g, b, a]: [number, number, number, number], fallback?: string): (format?: ColorFormat) => string | undefined;
|
|
34
|
+
declare function hslaTo([h, s, l, a]: [number, number, number, number], fallback?: string): (format?: ColorFormat) => string | undefined;
|
|
35
|
+
declare function hsvTo([h, s, v, a]: [number, number, number, number?], fallback?: string): (format?: ColorFormat) => string | undefined;
|
|
36
|
+
declare function sameColor(color: string | undefined, comparison: string | undefined): boolean;
|
|
37
37
|
|
|
38
38
|
export { COLOR_SCHEMES, type ColorFormat, type ColorScheme, SEMANTIC_COLOR_SCHEMES, type SemanticColorScheme, TONES, alphaToHex, calcFormat, convertColor, darkenColor, getAlpha, getColor, hslaTo, hsvTo, isAccessible, isDark, isGray, isLight, isTone, lightenColor, parseToHsla, parseToHsv, parseToRgba, randomColor, rgbaTo, sameColor, shadeColor, tintColor, transparentizeColor };
|