@yamada-ui/utils 1.5.2 → 1.5.3-dev-20241006032009
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/assertion.d.mts +2 -1
- package/dist/assertion.d.ts +2 -1
- package/dist/assertion.js +6 -1
- package/dist/assertion.js.map +1 -1
- package/dist/assertion.mjs +3 -1
- package/dist/calc.d.mts +5 -5
- package/dist/calc.d.ts +5 -5
- package/dist/calc.js +6 -6
- package/dist/calc.js.map +1 -1
- package/dist/calc.mjs +1 -1
- package/dist/{chunk-RCW53QOG.mjs → chunk-23I7TQOH.mjs} +2 -2
- package/dist/chunk-23I7TQOH.mjs.map +1 -0
- package/dist/{chunk-AF6MSVQN.mjs → chunk-47Z7BHBJ.mjs} +9 -7
- package/dist/chunk-47Z7BHBJ.mjs.map +1 -0
- package/dist/{chunk-OM7WYVSS.mjs → chunk-5J34UVTP.mjs} +7 -7
- package/dist/chunk-5J34UVTP.mjs.map +1 -0
- package/dist/{chunk-C3VXOUDJ.mjs → chunk-CCLWFJAZ.mjs} +11 -16
- package/dist/chunk-CCLWFJAZ.mjs.map +1 -0
- package/dist/{chunk-7XL7BPER.mjs → chunk-EJPLJ6FG.mjs} +9 -10
- package/dist/chunk-EJPLJ6FG.mjs.map +1 -0
- package/dist/{chunk-TJ7CW2M5.mjs → chunk-K4FGNB3Y.mjs} +8 -7
- package/dist/chunk-K4FGNB3Y.mjs.map +1 -0
- package/dist/{chunk-WU6FTFUV.mjs → chunk-MBMGLDTD.mjs} +1 -1
- package/dist/chunk-MBMGLDTD.mjs.map +1 -0
- package/dist/{chunk-Z4AGSEWZ.mjs → chunk-QWVYBC6R.mjs} +6 -2
- package/dist/chunk-QWVYBC6R.mjs.map +1 -0
- package/dist/{chunk-QTCZ2LU5.mjs → chunk-SAYAT2RG.mjs} +4 -3
- package/dist/chunk-SAYAT2RG.mjs.map +1 -0
- package/dist/color.d.mts +5 -5
- package/dist/color.d.ts +5 -5
- package/dist/color.js +10 -8
- package/dist/color.js.map +1 -1
- package/dist/color.mjs +3 -3
- package/dist/dom.d.mts +4 -4
- package/dist/dom.d.ts +4 -4
- package/dist/dom.js +8 -6
- package/dist/dom.js.map +1 -1
- package/dist/dom.mjs +2 -2
- package/dist/event.d.mts +2 -2
- package/dist/event.d.ts +2 -2
- package/dist/event.js +3 -2
- package/dist/event.js.map +1 -1
- package/dist/event.mjs +1 -1
- package/dist/function.d.mts +1 -1
- package/dist/function.d.ts +1 -1
- package/dist/function.js.map +1 -1
- package/dist/function.mjs +2 -2
- package/dist/index.d.mts +9 -9
- package/dist/index.d.ts +9 -9
- package/dist/index.js +688 -683
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -10
- package/dist/index.types.d.mts +5 -5
- package/dist/index.types.d.ts +5 -5
- package/dist/index.types.js.map +1 -1
- package/dist/index.types.mjs +0 -1
- package/dist/object.d.mts +3 -3
- package/dist/object.d.ts +3 -3
- package/dist/object.js +8 -9
- package/dist/object.js.map +1 -1
- package/dist/object.mjs +2 -2
- package/dist/react.d.mts +40 -35
- package/dist/react.d.ts +40 -35
- package/dist/react.js +9 -14
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +2 -2
- package/dist/string.js.map +1 -1
- package/dist/string.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-7XL7BPER.mjs.map +0 -1
- package/dist/chunk-AF6MSVQN.mjs.map +0 -1
- package/dist/chunk-C3VXOUDJ.mjs.map +0 -1
- package/dist/chunk-OM7WYVSS.mjs.map +0 -1
- package/dist/chunk-QTCZ2LU5.mjs.map +0 -1
- package/dist/chunk-RCW53QOG.mjs.map +0 -1
- package/dist/chunk-RSDBT4DI.mjs +0 -1
- package/dist/chunk-RSDBT4DI.mjs.map +0 -1
- package/dist/chunk-TJ7CW2M5.mjs.map +0 -1
- package/dist/chunk-WU6FTFUV.mjs.map +0 -1
- package/dist/chunk-Z4AGSEWZ.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -93,6 +93,7 @@ __export(src_exports, {
|
|
|
93
93
|
isDisabled: () => isDisabled,
|
|
94
94
|
isElement: () => isElement,
|
|
95
95
|
isEmpty: () => isEmpty,
|
|
96
|
+
isEmptyObject: () => isEmptyObject,
|
|
96
97
|
isFocusable: () => isFocusable,
|
|
97
98
|
isFunction: () => isFunction,
|
|
98
99
|
isGray: () => isGray,
|
|
@@ -165,6 +166,11 @@ __export(src_exports, {
|
|
|
165
166
|
});
|
|
166
167
|
module.exports = __toCommonJS(src_exports);
|
|
167
168
|
|
|
169
|
+
// src/array.ts
|
|
170
|
+
function filterEmpty(array) {
|
|
171
|
+
return array.filter((value) => value != null);
|
|
172
|
+
}
|
|
173
|
+
|
|
168
174
|
// src/assertion.ts
|
|
169
175
|
function is(x, y) {
|
|
170
176
|
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
|
|
@@ -185,7 +191,7 @@ function isBoolean(value) {
|
|
|
185
191
|
return typeof value === "boolean";
|
|
186
192
|
}
|
|
187
193
|
function isUndefined(value) {
|
|
188
|
-
return typeof value === "undefined"
|
|
194
|
+
return typeof value === "undefined";
|
|
189
195
|
}
|
|
190
196
|
function isNull(value) {
|
|
191
197
|
return value === null;
|
|
@@ -199,6 +205,9 @@ function isArray(value) {
|
|
|
199
205
|
function isEmpty(value) {
|
|
200
206
|
return !isArray(value) || !value.length || value.every((v) => v == null);
|
|
201
207
|
}
|
|
208
|
+
function isEmptyObject(value) {
|
|
209
|
+
return isObject(value) && !Object.keys(value).length;
|
|
210
|
+
}
|
|
202
211
|
function isFunction(value) {
|
|
203
212
|
return typeof value === "function";
|
|
204
213
|
}
|
|
@@ -211,15 +220,57 @@ function cast(value) {
|
|
|
211
220
|
return value;
|
|
212
221
|
}
|
|
213
222
|
|
|
223
|
+
// src/calc.ts
|
|
224
|
+
function toExpression(operator, ...args) {
|
|
225
|
+
return args.join(` ${operator} `).replace(/calc/g, "");
|
|
226
|
+
}
|
|
227
|
+
function add(...args) {
|
|
228
|
+
return `calc(${toExpression("+", ...args)})`;
|
|
229
|
+
}
|
|
230
|
+
function subtract(...args) {
|
|
231
|
+
return `calc(${toExpression("-", ...args)})`;
|
|
232
|
+
}
|
|
233
|
+
function multiply(...args) {
|
|
234
|
+
return `calc(${toExpression("*", ...args)})`;
|
|
235
|
+
}
|
|
236
|
+
function divide(...args) {
|
|
237
|
+
return `calc(${toExpression("/", ...args)})`;
|
|
238
|
+
}
|
|
239
|
+
function negate(value) {
|
|
240
|
+
if (!isNaN(parseFloat(value.toString())))
|
|
241
|
+
return String(value).startsWith("-") ? String(value).slice(1) : `-${value}`;
|
|
242
|
+
return multiply(value, -1);
|
|
243
|
+
}
|
|
244
|
+
var calc = Object.assign(
|
|
245
|
+
(x) => ({
|
|
246
|
+
add: (...args) => calc(add(x, ...args)),
|
|
247
|
+
divide: (...args) => calc(divide(x, ...args)),
|
|
248
|
+
multiply: (...args) => calc(multiply(x, ...args)),
|
|
249
|
+
negate: () => calc(negate(x)),
|
|
250
|
+
subtract: (...args) => calc(subtract(x, ...args)),
|
|
251
|
+
toString: () => x.toString()
|
|
252
|
+
}),
|
|
253
|
+
{
|
|
254
|
+
add,
|
|
255
|
+
divide,
|
|
256
|
+
multiply,
|
|
257
|
+
negate,
|
|
258
|
+
subtract
|
|
259
|
+
}
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
// src/color.ts
|
|
263
|
+
var c = __toESM(require("color2k"));
|
|
264
|
+
|
|
214
265
|
// src/object.ts
|
|
215
266
|
function omitObjectHelper(obj, path) {
|
|
216
267
|
if (!path.length) return obj;
|
|
217
268
|
const [primaryKey, ...restKeys] = path;
|
|
218
|
-
if (restKeys.length === 0 && primaryKey in obj) {
|
|
269
|
+
if (restKeys.length === 0 && primaryKey && primaryKey in obj) {
|
|
219
270
|
const { [primaryKey]: _, ...rest } = obj;
|
|
220
271
|
return rest;
|
|
221
272
|
}
|
|
222
|
-
if (obj[primaryKey] && isObject(obj[primaryKey])) {
|
|
273
|
+
if (primaryKey && obj[primaryKey] && isObject(obj[primaryKey])) {
|
|
223
274
|
return {
|
|
224
275
|
...obj,
|
|
225
276
|
[primaryKey]: omitObjectHelper(obj[primaryKey], restKeys)
|
|
@@ -298,7 +349,7 @@ function flattenObject(obj, { maxDepth, omitKeys, separator, shouldProcess } = {
|
|
|
298
349
|
separator != null ? separator : separator = ".";
|
|
299
350
|
if (!isObject(obj) && !isArray(obj) || !maxDepth) return obj;
|
|
300
351
|
return Object.entries(obj).reduce((result, [key, value]) => {
|
|
301
|
-
if (isObject(value) && !Object.keys(value).some((key2) => omitKeys
|
|
352
|
+
if (isObject(value) && !Object.keys(value).some((key2) => omitKeys.includes(key2)) && (!shouldProcess || shouldProcess(value))) {
|
|
302
353
|
Object.entries(
|
|
303
354
|
flattenObject(value, {
|
|
304
355
|
maxDepth: maxDepth - 1,
|
|
@@ -337,10 +388,11 @@ function replaceObject(objOrArray, callBack) {
|
|
|
337
388
|
}
|
|
338
389
|
}
|
|
339
390
|
function getObject(obj, path, fallback, i) {
|
|
340
|
-
const
|
|
341
|
-
for (i = 0; i <
|
|
391
|
+
const keys = isString(path) ? path.split(/\[(.*?)\]|\./).filter(Boolean) : [path];
|
|
392
|
+
for (i = 0; i < keys.length; i += 1) {
|
|
342
393
|
if (!obj) break;
|
|
343
|
-
|
|
394
|
+
const key = keys[i];
|
|
395
|
+
obj = key ? obj[key] : void 0;
|
|
344
396
|
}
|
|
345
397
|
return obj === void 0 ? fallback : obj;
|
|
346
398
|
}
|
|
@@ -359,8 +411,6 @@ function memoizeObject(func) {
|
|
|
359
411
|
}
|
|
360
412
|
var getMemoizedObject = memoizeObject(getObject);
|
|
361
413
|
function assignAfter(target, ...sources) {
|
|
362
|
-
if (target == null)
|
|
363
|
-
throw new TypeError("Cannot convert undefined or null to object");
|
|
364
414
|
const result = { ...target };
|
|
365
415
|
for (const nextSource of sources) {
|
|
366
416
|
if (nextSource == null) continue;
|
|
@@ -373,251 +423,338 @@ function assignAfter(target, ...sources) {
|
|
|
373
423
|
return result;
|
|
374
424
|
}
|
|
375
425
|
|
|
376
|
-
// src/
|
|
377
|
-
var
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
426
|
+
// src/color.ts
|
|
427
|
+
var SEMANTIC_COLOR_SCHEMES = [
|
|
428
|
+
"mono",
|
|
429
|
+
"primary",
|
|
430
|
+
"secondary",
|
|
431
|
+
"info",
|
|
432
|
+
"success",
|
|
433
|
+
"warning",
|
|
434
|
+
"danger",
|
|
435
|
+
"link"
|
|
436
|
+
];
|
|
437
|
+
var COLOR_SCHEMES = [
|
|
438
|
+
"gray",
|
|
439
|
+
"neutral",
|
|
440
|
+
"red",
|
|
441
|
+
"rose",
|
|
442
|
+
"pink",
|
|
443
|
+
"flashy",
|
|
444
|
+
"orange",
|
|
445
|
+
"amber",
|
|
446
|
+
"yellow",
|
|
447
|
+
"lime",
|
|
448
|
+
"green",
|
|
449
|
+
"emerald",
|
|
450
|
+
"teal",
|
|
451
|
+
"cyan",
|
|
452
|
+
"sky",
|
|
453
|
+
"blue",
|
|
454
|
+
"indigo",
|
|
455
|
+
"violet",
|
|
456
|
+
"purple",
|
|
457
|
+
"fuchsia"
|
|
458
|
+
];
|
|
459
|
+
var TONES = [
|
|
460
|
+
50,
|
|
461
|
+
100,
|
|
462
|
+
200,
|
|
463
|
+
300,
|
|
464
|
+
400,
|
|
465
|
+
500,
|
|
466
|
+
600,
|
|
467
|
+
700,
|
|
468
|
+
800,
|
|
469
|
+
900,
|
|
470
|
+
950
|
|
471
|
+
];
|
|
472
|
+
function isGray(colorScheme) {
|
|
473
|
+
return colorScheme === "gray" || colorScheme === "neutral";
|
|
381
474
|
}
|
|
382
|
-
function
|
|
383
|
-
return
|
|
384
|
-
funcs.some((func) => {
|
|
385
|
-
func == null ? void 0 : func(event, ...args);
|
|
386
|
-
return event == null ? void 0 : event.defaultPrevented;
|
|
387
|
-
});
|
|
388
|
-
};
|
|
475
|
+
function isAccessible(colorScheme) {
|
|
476
|
+
return colorScheme === "yellow" || colorScheme === "cyan" || colorScheme === "lime";
|
|
389
477
|
}
|
|
390
|
-
function
|
|
391
|
-
return function(
|
|
392
|
-
|
|
478
|
+
function getColor(color, fallback = "#000000") {
|
|
479
|
+
return function(theme = {}, colorMode = "light", breakpoint = "base") {
|
|
480
|
+
var _a, _b, _c, _d, _e, _f;
|
|
481
|
+
const [token, tone] = color.split(".");
|
|
482
|
+
if (tone) {
|
|
483
|
+
const [, relatedToken] = (_c = Object.entries((_b = (_a = theme.semantics) == null ? void 0 : _a.colorSchemes) != null ? _b : {}).find(
|
|
484
|
+
([semanticToken]) => token === semanticToken
|
|
485
|
+
)) != null ? _c : [];
|
|
486
|
+
if (relatedToken) color = `${relatedToken}.${tone}`;
|
|
487
|
+
} else {
|
|
488
|
+
const [, relatedColor] = (_f = Object.entries((_e = (_d = theme.semantics) == null ? void 0 : _d.colors) != null ? _e : {}).find(
|
|
489
|
+
([semanticToken]) => token === semanticToken
|
|
490
|
+
)) != null ? _f : [];
|
|
491
|
+
if (relatedColor) color = relatedColor;
|
|
492
|
+
}
|
|
493
|
+
const hex = getMemoizedObject(
|
|
494
|
+
theme,
|
|
495
|
+
`colors.${color}`,
|
|
496
|
+
color
|
|
497
|
+
);
|
|
498
|
+
try {
|
|
499
|
+
if (isArray(hex)) {
|
|
500
|
+
return c.toHex(String(hex[colorMode !== "dark" ? 0 : 1]));
|
|
501
|
+
} else if (isObject(hex)) {
|
|
502
|
+
return c.toHex(String(hex[breakpoint]));
|
|
503
|
+
} else {
|
|
504
|
+
return c.toHex(String(hex));
|
|
505
|
+
}
|
|
506
|
+
} catch {
|
|
507
|
+
try {
|
|
508
|
+
return c.toHex(fallback);
|
|
509
|
+
} catch {
|
|
510
|
+
return "#000000";
|
|
511
|
+
}
|
|
512
|
+
}
|
|
393
513
|
};
|
|
394
514
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
strict = true,
|
|
400
|
-
errorMessage = "useContext: `context` is undefined. Seems you forgot to wrap component within the Provider",
|
|
401
|
-
name,
|
|
402
|
-
defaultValue
|
|
403
|
-
} = {}) {
|
|
404
|
-
const Context = React.createContext(defaultValue);
|
|
405
|
-
Context.displayName = name;
|
|
406
|
-
const useContext2 = () => {
|
|
407
|
-
var _a;
|
|
408
|
-
const context = React.useContext(Context);
|
|
409
|
-
if (!context && strict) {
|
|
410
|
-
const error = new Error(errorMessage);
|
|
411
|
-
error.name = "ContextError";
|
|
412
|
-
(_a = Error.captureStackTrace) == null ? void 0 : _a.call(Error, error, useContext2);
|
|
413
|
-
throw error;
|
|
414
|
-
}
|
|
415
|
-
return context;
|
|
515
|
+
function lightenColor(color, amount) {
|
|
516
|
+
return function(theme, colorMode, breakpoint) {
|
|
517
|
+
const raw = getColor(color, color)(theme, colorMode, breakpoint);
|
|
518
|
+
return c.toHex(c.lighten(raw, amount / 100));
|
|
416
519
|
};
|
|
417
|
-
return [
|
|
418
|
-
Context.Provider,
|
|
419
|
-
useContext2,
|
|
420
|
-
Context
|
|
421
|
-
];
|
|
422
520
|
}
|
|
423
|
-
|
|
424
|
-
function
|
|
425
|
-
|
|
521
|
+
function darkenColor(color, amount) {
|
|
522
|
+
return function(theme, colorMode, breakpoint) {
|
|
523
|
+
const raw = getColor(color, color)(theme, colorMode, breakpoint);
|
|
524
|
+
return c.toHex(c.darken(raw, amount / 100));
|
|
525
|
+
};
|
|
426
526
|
}
|
|
427
|
-
function
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
const [isMounted, setIsMounted] = React.useState(false);
|
|
433
|
-
useSafeLayoutEffect(() => {
|
|
434
|
-
isMountedRef.current = true;
|
|
435
|
-
let timeoutId = null;
|
|
436
|
-
if (rerender) {
|
|
437
|
-
if (delay > 0) {
|
|
438
|
-
timeoutId = setTimeout(() => setIsMounted(true), delay);
|
|
439
|
-
} else {
|
|
440
|
-
setIsMounted(true);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
return () => {
|
|
444
|
-
isMountedRef.current = false;
|
|
445
|
-
if (rerender) setIsMounted(false);
|
|
446
|
-
if (timeoutId) clearTimeout(timeoutId);
|
|
447
|
-
};
|
|
448
|
-
}, [delay, rerender]);
|
|
449
|
-
return [React.useCallback(() => isMountedRef.current, []), isMounted];
|
|
527
|
+
function tintColor(color, amount) {
|
|
528
|
+
return function(theme, colorMode, breakpoint) {
|
|
529
|
+
const raw = getColor(color, color)(theme, colorMode, breakpoint);
|
|
530
|
+
return c.toHex(c.mix(raw, "#fff", amount / 100));
|
|
531
|
+
};
|
|
450
532
|
}
|
|
451
|
-
function
|
|
452
|
-
return
|
|
453
|
-
(
|
|
454
|
-
|
|
533
|
+
function shadeColor(color, amount) {
|
|
534
|
+
return function(theme, colorMode, breakpoint) {
|
|
535
|
+
const raw = getColor(color, color)(theme, colorMode, breakpoint);
|
|
536
|
+
return c.toHex(c.mix(raw, "#000", amount / 100));
|
|
537
|
+
};
|
|
455
538
|
}
|
|
456
|
-
function
|
|
457
|
-
return
|
|
539
|
+
function transparentizeColor(color, alpha) {
|
|
540
|
+
return function(theme, colorMode, breakpoint) {
|
|
541
|
+
const raw = getColor(color, color)(theme, colorMode, breakpoint);
|
|
542
|
+
return c.transparentize(raw, 1 - alpha);
|
|
543
|
+
};
|
|
458
544
|
}
|
|
459
|
-
function
|
|
545
|
+
function randomColor({
|
|
546
|
+
colors,
|
|
547
|
+
string
|
|
548
|
+
} = {}) {
|
|
460
549
|
var _a, _b;
|
|
461
|
-
|
|
462
|
-
if (
|
|
463
|
-
|
|
550
|
+
const fallback = randomHex();
|
|
551
|
+
if (string && colors) return (_a = randomColorFromList(string, colors)) != null ? _a : fallback;
|
|
552
|
+
if (string && !colors) return randomColorFromString(string);
|
|
553
|
+
if (colors && !string) return (_b = randomFromList(colors)) != null ? _b : fallback;
|
|
554
|
+
return fallback;
|
|
555
|
+
}
|
|
556
|
+
function randomHex() {
|
|
557
|
+
return `#${Math.floor(Math.random() * 16777215).toString(16).padEnd(6, "0")}`;
|
|
558
|
+
}
|
|
559
|
+
function randomColorFromString(str) {
|
|
560
|
+
let hash = 0;
|
|
561
|
+
if (str.length === 0) return hash.toString();
|
|
562
|
+
for (let i = 0; i < str.length; i += 1) {
|
|
563
|
+
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
564
|
+
hash = hash & hash;
|
|
464
565
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
566
|
+
let color = "#";
|
|
567
|
+
for (let j = 0; j < 3; j += 1) {
|
|
568
|
+
const value = hash >> j * 8 & 255;
|
|
569
|
+
color += `00${value.toString(16)}`.substr(-2);
|
|
468
570
|
}
|
|
469
|
-
return
|
|
470
|
-
}
|
|
471
|
-
function findChild(children, ...types) {
|
|
472
|
-
const child = children.find(
|
|
473
|
-
(child2) => types.some((type) => isSomeElement(child2, type))
|
|
474
|
-
);
|
|
475
|
-
return child;
|
|
571
|
+
return color;
|
|
476
572
|
}
|
|
477
|
-
function
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
)
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
if (types.some((type) => isSomeElement(a, type))) {
|
|
484
|
-
return -1;
|
|
485
|
-
} else if (types.some((type) => isSomeElement(b, type))) {
|
|
486
|
-
return 1;
|
|
487
|
-
} else {
|
|
488
|
-
return 0;
|
|
489
|
-
}
|
|
490
|
-
});
|
|
491
|
-
} else {
|
|
492
|
-
return [void 0, ...children];
|
|
573
|
+
function randomColorFromList(str, list) {
|
|
574
|
+
let index = 0;
|
|
575
|
+
if (str.length === 0) return list[0];
|
|
576
|
+
for (let i = 0; i < str.length; i += 1) {
|
|
577
|
+
index = str.charCodeAt(i) + ((index << 5) - index);
|
|
578
|
+
index = index & index;
|
|
493
579
|
}
|
|
580
|
+
index = (index % list.length + list.length) % list.length;
|
|
581
|
+
return list[index];
|
|
494
582
|
}
|
|
495
|
-
function
|
|
496
|
-
return
|
|
497
|
-
if (types.some((type) => isSomeElement(child, type))) return true;
|
|
498
|
-
const children2 = getValidChildren(child.props.children);
|
|
499
|
-
return children2.length ? includesChildren(children2, ...types) : false;
|
|
500
|
-
});
|
|
583
|
+
function randomFromList(list) {
|
|
584
|
+
return list[Math.floor(Math.random() * list.length)];
|
|
501
585
|
}
|
|
502
|
-
function
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
);
|
|
586
|
+
function getBrightness(color) {
|
|
587
|
+
const [r, g, b] = c.parseToRgba(color);
|
|
588
|
+
return (r * 299 + g * 587 + b * 114) / 1e3;
|
|
506
589
|
}
|
|
507
|
-
function
|
|
508
|
-
return
|
|
509
|
-
|
|
510
|
-
|
|
590
|
+
function isTone(color) {
|
|
591
|
+
return function(theme, colorMode, breakpoint) {
|
|
592
|
+
const raw = theme ? getColor(color)(theme, colorMode, breakpoint) : color;
|
|
593
|
+
const brightness = getBrightness(raw);
|
|
594
|
+
const isDark2 = brightness < 128;
|
|
595
|
+
return isDark2 ? "dark" : "light";
|
|
596
|
+
};
|
|
511
597
|
}
|
|
512
|
-
function
|
|
513
|
-
return
|
|
598
|
+
function isLight(color) {
|
|
599
|
+
return function(theme, colorMode) {
|
|
600
|
+
return isTone(color)(theme, colorMode) === "dark";
|
|
601
|
+
};
|
|
514
602
|
}
|
|
515
|
-
function
|
|
516
|
-
return
|
|
603
|
+
function isDark(color) {
|
|
604
|
+
return function(theme, colorMode) {
|
|
605
|
+
return isTone(color)(theme, colorMode) === "light";
|
|
606
|
+
};
|
|
517
607
|
}
|
|
518
|
-
function
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
608
|
+
function convertColor(color, fallback) {
|
|
609
|
+
return function(format) {
|
|
610
|
+
try {
|
|
611
|
+
const isAlpha = format.endsWith("a");
|
|
612
|
+
if (/^[0-9a-fA-F]{6}$/.test(color)) color = "#" + color;
|
|
613
|
+
if (format.startsWith("hex")) {
|
|
614
|
+
let hexa = c.toHex(color);
|
|
615
|
+
if (isAlpha) {
|
|
616
|
+
if (hexa.length === 7) hexa += "ff";
|
|
617
|
+
} else {
|
|
618
|
+
hexa = hexa.replace(/(?<=^#([0-9a-fA-F]{6}))[0-9a-fA-F]{2}$/, "");
|
|
619
|
+
}
|
|
620
|
+
return hexa;
|
|
621
|
+
} else if (format.startsWith("hsl")) {
|
|
622
|
+
let hsla2 = c.toHsla(color);
|
|
623
|
+
if (!isAlpha) {
|
|
624
|
+
hsla2 = hsla2.replace(/hsla/, "hsl");
|
|
625
|
+
hsla2 = hsla2.replace(/,\s*\d+(\.\d+)?\)$/, ")");
|
|
626
|
+
}
|
|
627
|
+
return hsla2;
|
|
628
|
+
} else {
|
|
629
|
+
let rgba2 = c.toRgba(color);
|
|
630
|
+
if (!isAlpha) {
|
|
631
|
+
rgba2 = rgba2.replace(/rgba/, "rgb");
|
|
632
|
+
rgba2 = rgba2.replace(/,\s*\d+(\.\d+)?\)$/, ")");
|
|
633
|
+
}
|
|
634
|
+
return rgba2;
|
|
635
|
+
}
|
|
636
|
+
} catch {
|
|
637
|
+
if (fallback) return convertColor(fallback)(format);
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
function calcFormat(color) {
|
|
642
|
+
if (color.startsWith("hsl")) {
|
|
643
|
+
return color.startsWith("hsla") ? "hsla" : "hsl";
|
|
644
|
+
} else if (color.startsWith("rgb")) {
|
|
645
|
+
return color.startsWith("rgba") ? "rgba" : "rgb";
|
|
646
|
+
} else {
|
|
647
|
+
return color.length === 9 ? "hexa" : "hex";
|
|
523
648
|
}
|
|
649
|
+
}
|
|
650
|
+
function getAlpha(color) {
|
|
651
|
+
return c.parseToRgba(color)[3];
|
|
652
|
+
}
|
|
653
|
+
function alphaToHex(a) {
|
|
654
|
+
if (0 > a) a = 0;
|
|
655
|
+
if (1 < a) a = 1;
|
|
656
|
+
return Math.round(a * 255).toString(16).padStart(2, "0");
|
|
657
|
+
}
|
|
658
|
+
function parseToRgba2(color, fallback) {
|
|
524
659
|
try {
|
|
525
|
-
|
|
660
|
+
if (/^[0-9a-fA-F]{6}$/.test(color)) color = "#" + color;
|
|
661
|
+
return c.parseToRgba(color);
|
|
526
662
|
} catch {
|
|
527
|
-
|
|
663
|
+
if (fallback) return c.parseToRgba(fallback);
|
|
528
664
|
}
|
|
529
665
|
}
|
|
530
|
-
function
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
}
|
|
537
|
-
function useMergeRefs(...refs) {
|
|
538
|
-
return React.useMemo(() => mergeRefs(...refs), [refs]);
|
|
539
|
-
}
|
|
540
|
-
function useCallbackRef(callback, deps = []) {
|
|
541
|
-
const callbackRef = React.useRef(callback);
|
|
542
|
-
React.useEffect(() => {
|
|
543
|
-
callbackRef.current = callback;
|
|
544
|
-
});
|
|
545
|
-
return React.useCallback(
|
|
546
|
-
(...args) => {
|
|
547
|
-
var _a;
|
|
548
|
-
return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
|
|
549
|
-
},
|
|
550
|
-
deps
|
|
551
|
-
);
|
|
666
|
+
function parseToHsla2(color, fallback) {
|
|
667
|
+
try {
|
|
668
|
+
if (/^[0-9a-fA-F]{6}$/.test(color)) color = "#" + color;
|
|
669
|
+
return c.parseToHsla(color);
|
|
670
|
+
} catch {
|
|
671
|
+
if (fallback) return c.parseToHsla(fallback);
|
|
672
|
+
}
|
|
552
673
|
}
|
|
553
|
-
function
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
674
|
+
function parseToHsv(color, fallback) {
|
|
675
|
+
var _a;
|
|
676
|
+
let [r, g, b, a] = (_a = parseToRgba2(color, fallback)) != null ? _a : [255, 255, 255, 1];
|
|
677
|
+
r = r / 255;
|
|
678
|
+
g = g / 255;
|
|
679
|
+
b = b / 255;
|
|
680
|
+
const [min, max] = [Math.min(r, g, b), Math.max(r, g, b)];
|
|
681
|
+
const delta = max - min;
|
|
682
|
+
let [h, v, s] = [0, max, max == 0 ? 0 : delta / max];
|
|
683
|
+
switch (min) {
|
|
684
|
+
case max:
|
|
685
|
+
h = 0;
|
|
686
|
+
break;
|
|
687
|
+
case r:
|
|
688
|
+
h = 60 * ((b - g) / delta) + 180;
|
|
689
|
+
break;
|
|
690
|
+
case g:
|
|
691
|
+
h = 60 * ((r - b) / delta) + 300;
|
|
692
|
+
break;
|
|
693
|
+
case b:
|
|
694
|
+
h = 60 * ((g - r) / delta) + 60;
|
|
695
|
+
break;
|
|
696
|
+
}
|
|
697
|
+
return [h, s, v, a];
|
|
568
698
|
}
|
|
569
|
-
function
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
}, [callback]);
|
|
574
|
-
return state;
|
|
699
|
+
function rgbaTo([r, g, b, a], fallback) {
|
|
700
|
+
return function(format = "hex") {
|
|
701
|
+
return convertColor(c.rgba(r, g, b, a), fallback)(format);
|
|
702
|
+
};
|
|
575
703
|
}
|
|
576
|
-
function
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
const callback = React.useCallback(
|
|
581
|
-
(...args) => {
|
|
582
|
-
const callId = ++lastCallId.current;
|
|
583
|
-
if (!state.loading)
|
|
584
|
-
setState((prevState) => ({ ...prevState, loading: true }));
|
|
585
|
-
return func(...args).then(
|
|
586
|
-
(value) => {
|
|
587
|
-
if (isMounted() && callId === lastCallId.current)
|
|
588
|
-
setState({ value, loading: false });
|
|
589
|
-
return value;
|
|
590
|
-
},
|
|
591
|
-
(error) => {
|
|
592
|
-
if (isMounted() && callId === lastCallId.current)
|
|
593
|
-
setState({ error, loading: false });
|
|
594
|
-
return error;
|
|
595
|
-
}
|
|
596
|
-
);
|
|
597
|
-
},
|
|
598
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
599
|
-
deps
|
|
600
|
-
);
|
|
601
|
-
return [state, callback];
|
|
704
|
+
function hslaTo([h, s, l, a], fallback) {
|
|
705
|
+
return function(format = "hex") {
|
|
706
|
+
return convertColor(c.hsla(h, s, l, a), fallback)(format);
|
|
707
|
+
};
|
|
602
708
|
}
|
|
603
|
-
function
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
709
|
+
function hsvTo([h, s, v, a], fallback) {
|
|
710
|
+
return function(format = "hex") {
|
|
711
|
+
h = h / 60;
|
|
712
|
+
let rgb = [v, v, v];
|
|
713
|
+
let i = Math.floor(h);
|
|
714
|
+
let f = h - i;
|
|
715
|
+
let p = v * (1 - s);
|
|
716
|
+
let q = v * (1 - s * f);
|
|
717
|
+
let t = v * (1 - s * (1 - f));
|
|
718
|
+
switch (i) {
|
|
719
|
+
case 0:
|
|
720
|
+
case 6:
|
|
721
|
+
rgb = [v, t, p];
|
|
722
|
+
break;
|
|
723
|
+
case 1:
|
|
724
|
+
rgb = [q, v, p];
|
|
725
|
+
break;
|
|
726
|
+
case 2:
|
|
727
|
+
rgb = [p, v, t];
|
|
728
|
+
break;
|
|
729
|
+
case 3:
|
|
730
|
+
rgb = [p, q, v];
|
|
731
|
+
break;
|
|
732
|
+
case 4:
|
|
733
|
+
rgb = [t, p, v];
|
|
734
|
+
break;
|
|
735
|
+
case 5:
|
|
736
|
+
rgb = [v, p, q];
|
|
737
|
+
break;
|
|
738
|
+
}
|
|
739
|
+
let color = `rgb(${rgb.map((v2) => Math.round(v2 * 255)).join(", ")})`;
|
|
740
|
+
if (isNumber(a)) color = color.replace(/\)$/, `, ${a})`);
|
|
741
|
+
return convertColor(color, fallback)(format);
|
|
742
|
+
};
|
|
612
743
|
}
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
744
|
+
function sameColor(color, comparison) {
|
|
745
|
+
var _a, _b;
|
|
746
|
+
if (!color) return false;
|
|
747
|
+
if (!comparison) return false;
|
|
748
|
+
const a = (_a = parseToRgba2(color)) != null ? _a : [];
|
|
749
|
+
const b = (_b = parseToRgba2(comparison)) != null ? _b : [];
|
|
750
|
+
return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];
|
|
616
751
|
}
|
|
617
752
|
|
|
618
753
|
// src/dom.ts
|
|
619
754
|
function createdDom() {
|
|
620
|
-
|
|
755
|
+
var _a;
|
|
756
|
+
return !!(typeof window !== "undefined" && // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
757
|
+
((_a = window.document) == null ? void 0 : _a.createElement));
|
|
621
758
|
}
|
|
622
759
|
function getPlatform() {
|
|
623
760
|
var _a, _b;
|
|
@@ -652,7 +789,7 @@ function isHidden(el) {
|
|
|
652
789
|
return el.hidden;
|
|
653
790
|
}
|
|
654
791
|
function isDisabled(el) {
|
|
655
|
-
return Boolean(el.getAttribute("disabled"))
|
|
792
|
+
return Boolean(el.getAttribute("disabled")) || Boolean(el.getAttribute("data-disabled")) || Boolean(el.getAttribute("aria-disabled"));
|
|
656
793
|
}
|
|
657
794
|
function isVisible(el) {
|
|
658
795
|
return el.offsetWidth > 0 && el.offsetHeight > 0;
|
|
@@ -720,7 +857,7 @@ function isFocusable(el) {
|
|
|
720
857
|
}
|
|
721
858
|
const { localName } = el;
|
|
722
859
|
const focusableTags = ["input", "select", "textarea", "button"];
|
|
723
|
-
if (focusableTags.
|
|
860
|
+
if (focusableTags.includes(localName)) return true;
|
|
724
861
|
const others = {
|
|
725
862
|
a: () => el.hasAttribute("href"),
|
|
726
863
|
audio: () => el.hasAttribute("controls"),
|
|
@@ -740,8 +877,8 @@ function isTouchDevice() {
|
|
|
740
877
|
return "ontouchstart" in window;
|
|
741
878
|
}
|
|
742
879
|
function getOwnerWindow(node) {
|
|
743
|
-
var _a
|
|
744
|
-
return (
|
|
880
|
+
var _a;
|
|
881
|
+
return (_a = getOwnerDocument(node).defaultView) != null ? _a : window;
|
|
745
882
|
}
|
|
746
883
|
function getOwnerDocument(el) {
|
|
747
884
|
return isElement(el) ? el.ownerDocument : document;
|
|
@@ -753,521 +890,388 @@ function isActiveElement(el) {
|
|
|
753
890
|
return getActiveElement(el) === el;
|
|
754
891
|
}
|
|
755
892
|
|
|
756
|
-
// src/
|
|
757
|
-
function
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
case "top":
|
|
763
|
-
return "bottom";
|
|
764
|
-
case "bottom":
|
|
765
|
-
return "top";
|
|
766
|
-
case "left":
|
|
767
|
-
return "right";
|
|
768
|
-
case "right":
|
|
769
|
-
return "left";
|
|
770
|
-
case "start":
|
|
771
|
-
return "end";
|
|
772
|
-
case "end":
|
|
773
|
-
return "start";
|
|
774
|
-
case "x":
|
|
775
|
-
return "y";
|
|
776
|
-
case "y":
|
|
777
|
-
return "x";
|
|
778
|
-
case "enter":
|
|
779
|
-
return "exit";
|
|
780
|
-
case "exit":
|
|
781
|
-
return "enter";
|
|
782
|
-
case "vertical":
|
|
783
|
-
return "horizontal";
|
|
784
|
-
case "horizontal":
|
|
785
|
-
return "vertical";
|
|
786
|
-
case "up":
|
|
787
|
-
return "down";
|
|
788
|
-
case "down":
|
|
789
|
-
return "up";
|
|
790
|
-
case "block":
|
|
791
|
-
return "inline";
|
|
792
|
-
case "inline":
|
|
793
|
-
return "block";
|
|
794
|
-
default:
|
|
795
|
-
return value;
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
function toCamelCase(value) {
|
|
799
|
-
return value.toLowerCase().replace(/[_-](.)/g, (_, val) => val.toUpperCase()).replace(/^(.)/, (_, val) => val.toUpperCase());
|
|
800
|
-
}
|
|
801
|
-
function toKebabCase(value) {
|
|
802
|
-
return value.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase().replace(/^-/, "");
|
|
803
|
-
}
|
|
804
|
-
function toTitleCase(value) {
|
|
805
|
-
return value.replace(/([A-Z])/g, " $1").replace(/[_-](.)/g, (_, val) => ` ${val.toUpperCase()}`).replace(/^./, (str) => str.toUpperCase()).trim();
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
// src/calc.ts
|
|
809
|
-
function toExpression(operator, ...args) {
|
|
810
|
-
return args.join(` ${operator} `).replace(/calc/g, "");
|
|
811
|
-
}
|
|
812
|
-
function add(...args) {
|
|
813
|
-
return `calc(${toExpression("+", ...args)})`;
|
|
814
|
-
}
|
|
815
|
-
function subtract(...args) {
|
|
816
|
-
return `calc(${toExpression("-", ...args)})`;
|
|
817
|
-
}
|
|
818
|
-
function multiply(...args) {
|
|
819
|
-
return `calc(${toExpression("*", ...args)})`;
|
|
820
|
-
}
|
|
821
|
-
function divide(...args) {
|
|
822
|
-
return `calc(${toExpression("/", ...args)})`;
|
|
823
|
-
}
|
|
824
|
-
function negate(value) {
|
|
825
|
-
if (value != null && !isNaN(parseFloat(value.toString())))
|
|
826
|
-
return String(value).startsWith("-") ? String(value).slice(1) : `-${value}`;
|
|
827
|
-
return multiply(value, -1);
|
|
893
|
+
// src/event.ts
|
|
894
|
+
function isMouseEvent(ev) {
|
|
895
|
+
const win = getEventWindow(ev);
|
|
896
|
+
if (typeof win.PointerEvent !== "undefined" && ev instanceof win.PointerEvent)
|
|
897
|
+
return !!(ev.pointerType === "mouse");
|
|
898
|
+
return ev instanceof win.MouseEvent;
|
|
828
899
|
}
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
add: (...args) => calc(add(x, ...args)),
|
|
832
|
-
subtract: (...args) => calc(subtract(x, ...args)),
|
|
833
|
-
multiply: (...args) => calc(multiply(x, ...args)),
|
|
834
|
-
divide: (...args) => calc(divide(x, ...args)),
|
|
835
|
-
negate: () => calc(negate(x)),
|
|
836
|
-
toString: () => x.toString()
|
|
837
|
-
}),
|
|
838
|
-
{
|
|
839
|
-
add,
|
|
840
|
-
subtract,
|
|
841
|
-
multiply,
|
|
842
|
-
divide,
|
|
843
|
-
negate
|
|
844
|
-
}
|
|
845
|
-
);
|
|
846
|
-
|
|
847
|
-
// src/color.ts
|
|
848
|
-
var c = __toESM(require("color2k"));
|
|
849
|
-
var SEMANTIC_COLOR_SCHEMES = [
|
|
850
|
-
"mono",
|
|
851
|
-
"primary",
|
|
852
|
-
"secondary",
|
|
853
|
-
"info",
|
|
854
|
-
"success",
|
|
855
|
-
"warning",
|
|
856
|
-
"danger",
|
|
857
|
-
"link"
|
|
858
|
-
];
|
|
859
|
-
var COLOR_SCHEMES = [
|
|
860
|
-
"gray",
|
|
861
|
-
"neutral",
|
|
862
|
-
"red",
|
|
863
|
-
"rose",
|
|
864
|
-
"pink",
|
|
865
|
-
"flashy",
|
|
866
|
-
"orange",
|
|
867
|
-
"amber",
|
|
868
|
-
"yellow",
|
|
869
|
-
"lime",
|
|
870
|
-
"green",
|
|
871
|
-
"emerald",
|
|
872
|
-
"teal",
|
|
873
|
-
"cyan",
|
|
874
|
-
"sky",
|
|
875
|
-
"blue",
|
|
876
|
-
"indigo",
|
|
877
|
-
"violet",
|
|
878
|
-
"purple",
|
|
879
|
-
"fuchsia"
|
|
880
|
-
];
|
|
881
|
-
var TONES = [
|
|
882
|
-
50,
|
|
883
|
-
100,
|
|
884
|
-
200,
|
|
885
|
-
300,
|
|
886
|
-
400,
|
|
887
|
-
500,
|
|
888
|
-
600,
|
|
889
|
-
700,
|
|
890
|
-
800,
|
|
891
|
-
900,
|
|
892
|
-
950
|
|
893
|
-
];
|
|
894
|
-
function isGray(colorScheme) {
|
|
895
|
-
return colorScheme === "gray" || colorScheme === "neutral";
|
|
900
|
+
function isTouchEvent(ev) {
|
|
901
|
+
return !!ev.touches;
|
|
896
902
|
}
|
|
897
|
-
function
|
|
898
|
-
return
|
|
903
|
+
function isMultiTouchEvent(ev) {
|
|
904
|
+
return isTouchEvent(ev) && ev.touches.length > 1;
|
|
899
905
|
}
|
|
900
|
-
function
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
const [token, tone] = color.split(".");
|
|
904
|
-
if (tone) {
|
|
905
|
-
const [, relatedToken] = (_c = Object.entries((_b = (_a = theme.semantics) == null ? void 0 : _a.colorSchemes) != null ? _b : {}).find(
|
|
906
|
-
([semanticToken]) => token === semanticToken
|
|
907
|
-
)) != null ? _c : [];
|
|
908
|
-
if (relatedToken) color = `${relatedToken}.${tone}`;
|
|
909
|
-
} else {
|
|
910
|
-
const [, relatedColor] = (_f = Object.entries((_e = (_d = theme.semantics) == null ? void 0 : _d.colors) != null ? _e : {}).find(
|
|
911
|
-
([semanticToken]) => token === semanticToken
|
|
912
|
-
)) != null ? _f : [];
|
|
913
|
-
if (relatedColor) color = relatedColor;
|
|
914
|
-
}
|
|
915
|
-
const hex = getMemoizedObject(
|
|
916
|
-
theme,
|
|
917
|
-
`colors.${color}`,
|
|
918
|
-
color
|
|
919
|
-
);
|
|
920
|
-
try {
|
|
921
|
-
if (isArray(hex)) {
|
|
922
|
-
return c.toHex(String(hex[colorMode !== "dark" ? 0 : 1]));
|
|
923
|
-
} else if (isObject(hex)) {
|
|
924
|
-
return c.toHex(String(hex[breakpoint]));
|
|
925
|
-
} else {
|
|
926
|
-
return c.toHex(String(hex));
|
|
927
|
-
}
|
|
928
|
-
} catch {
|
|
929
|
-
try {
|
|
930
|
-
return c.toHex(fallback);
|
|
931
|
-
} catch {
|
|
932
|
-
return "#000000";
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
};
|
|
906
|
+
function getEventWindow(ev) {
|
|
907
|
+
var _a;
|
|
908
|
+
return (_a = ev.view) != null ? _a : window;
|
|
936
909
|
}
|
|
937
|
-
function
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
};
|
|
910
|
+
function pointFromTouch(e, type = "page") {
|
|
911
|
+
var _a, _b;
|
|
912
|
+
const point = e.touches[0] || e.changedTouches[0];
|
|
913
|
+
return { x: (_a = point == null ? void 0 : point[`${type}X`]) != null ? _a : 0, y: (_b = point == null ? void 0 : point[`${type}Y`]) != null ? _b : 0 };
|
|
942
914
|
}
|
|
943
|
-
function
|
|
944
|
-
return
|
|
945
|
-
|
|
946
|
-
|
|
915
|
+
function pointFromMouse(point, type = "page") {
|
|
916
|
+
return {
|
|
917
|
+
x: point[`${type}X`],
|
|
918
|
+
y: point[`${type}Y`]
|
|
947
919
|
};
|
|
948
920
|
}
|
|
949
|
-
function
|
|
950
|
-
return
|
|
951
|
-
const raw = getColor(color, color)(theme, colorMode, breakpoint);
|
|
952
|
-
return c.toHex(c.mix(raw, "#fff", amount / 100));
|
|
953
|
-
};
|
|
921
|
+
function getEventPoint(ev, type = "page") {
|
|
922
|
+
return isTouchEvent(ev) ? pointFromTouch(ev, type) : pointFromMouse(ev, type);
|
|
954
923
|
}
|
|
955
|
-
function
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
924
|
+
function addDomEvent(target, type, cb, options) {
|
|
925
|
+
target.addEventListener(type, cb, options);
|
|
926
|
+
return () => {
|
|
927
|
+
target.removeEventListener(type, cb, options);
|
|
959
928
|
};
|
|
960
929
|
}
|
|
961
|
-
function
|
|
962
|
-
return function(
|
|
963
|
-
const
|
|
964
|
-
|
|
930
|
+
function filter(cb) {
|
|
931
|
+
return function(ev) {
|
|
932
|
+
const isMouse = isMouseEvent(ev);
|
|
933
|
+
if (!isMouse || ev.button === 0) cb(ev);
|
|
965
934
|
};
|
|
966
935
|
}
|
|
967
|
-
function
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
} = {}) {
|
|
971
|
-
const fallback = randomHex();
|
|
972
|
-
if (string && colors) return randomColorFromList(string, colors);
|
|
973
|
-
if (string && !colors) return randomColorFromString(string);
|
|
974
|
-
if (colors && !string) return randomFromList(colors);
|
|
975
|
-
return fallback;
|
|
976
|
-
}
|
|
977
|
-
function randomHex() {
|
|
978
|
-
return `#${Math.floor(Math.random() * 16777215).toString(16).padEnd(6, "0")}`;
|
|
979
|
-
}
|
|
980
|
-
function randomColorFromString(str) {
|
|
981
|
-
let hash = 0;
|
|
982
|
-
if (str.length === 0) return hash.toString();
|
|
983
|
-
for (let i = 0; i < str.length; i += 1) {
|
|
984
|
-
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
985
|
-
hash = hash & hash;
|
|
986
|
-
}
|
|
987
|
-
let color = "#";
|
|
988
|
-
for (let j = 0; j < 3; j += 1) {
|
|
989
|
-
const value = hash >> j * 8 & 255;
|
|
990
|
-
color += `00${value.toString(16)}`.substr(-2);
|
|
991
|
-
}
|
|
992
|
-
return color;
|
|
993
|
-
}
|
|
994
|
-
function randomColorFromList(str, list) {
|
|
995
|
-
let index = 0;
|
|
996
|
-
if (str.length === 0) return list[0];
|
|
997
|
-
for (let i = 0; i < str.length; i += 1) {
|
|
998
|
-
index = str.charCodeAt(i) + ((index << 5) - index);
|
|
999
|
-
index = index & index;
|
|
936
|
+
function wrap(cb, filterPrimary = false) {
|
|
937
|
+
function listener(ev) {
|
|
938
|
+
return cb(ev, { point: getEventPoint(ev) });
|
|
1000
939
|
}
|
|
1001
|
-
|
|
1002
|
-
return
|
|
940
|
+
const fn = filterPrimary ? filter(listener) : listener;
|
|
941
|
+
return fn;
|
|
1003
942
|
}
|
|
1004
|
-
function
|
|
1005
|
-
return
|
|
943
|
+
function addPointerEvent(target, type, cb, options) {
|
|
944
|
+
return addDomEvent(target, type, wrap(cb, type === "pointerdown"), options);
|
|
1006
945
|
}
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
946
|
+
|
|
947
|
+
// src/function.ts
|
|
948
|
+
var noop = () => {
|
|
949
|
+
};
|
|
950
|
+
function runIfFunc(valOrFunc, ...args) {
|
|
951
|
+
return isFunction(valOrFunc) ? valOrFunc(...args) : valOrFunc;
|
|
1010
952
|
}
|
|
1011
|
-
function
|
|
1012
|
-
return function(
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
953
|
+
function handlerAll(...funcs) {
|
|
954
|
+
return function(event, ...args) {
|
|
955
|
+
funcs.some((func) => {
|
|
956
|
+
func == null ? void 0 : func(event, ...args);
|
|
957
|
+
return event == null ? void 0 : event.defaultPrevented;
|
|
958
|
+
});
|
|
1017
959
|
};
|
|
1018
960
|
}
|
|
1019
|
-
function
|
|
1020
|
-
return function(
|
|
1021
|
-
return
|
|
961
|
+
function funcAll(...funcs) {
|
|
962
|
+
return function(...args) {
|
|
963
|
+
return funcs.forEach((func) => func == null ? void 0 : func(...args));
|
|
1022
964
|
};
|
|
1023
965
|
}
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
966
|
+
|
|
967
|
+
// src/module.ts
|
|
968
|
+
function interopDefault(module2) {
|
|
969
|
+
return module2.default || module2;
|
|
1028
970
|
}
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
if (format.startsWith("hex")) {
|
|
1035
|
-
let hexa = c.toHex(color);
|
|
1036
|
-
if (isAlpha) {
|
|
1037
|
-
if (hexa.length === 7) hexa += "ff";
|
|
1038
|
-
} else {
|
|
1039
|
-
hexa = hexa.replace(/(?<=^#([0-9a-fA-F]{6}))[0-9a-fA-F]{2}$/, "");
|
|
1040
|
-
}
|
|
1041
|
-
return hexa;
|
|
1042
|
-
} else if (format.startsWith("hsl")) {
|
|
1043
|
-
let hsla2 = c.toHsla(color);
|
|
1044
|
-
if (!isAlpha) {
|
|
1045
|
-
hsla2 = hsla2.replace(/hsla/, "hsl");
|
|
1046
|
-
hsla2 = hsla2.replace(/,\s*\d+(\.\d+)?\)$/, ")");
|
|
1047
|
-
}
|
|
1048
|
-
return hsla2;
|
|
1049
|
-
} else {
|
|
1050
|
-
let rgba2 = c.toRgba(color);
|
|
1051
|
-
if (!isAlpha) {
|
|
1052
|
-
rgba2 = rgba2.replace(/rgba/, "rgb");
|
|
1053
|
-
rgba2 = rgba2.replace(/,\s*\d+(\.\d+)?\)$/, ")");
|
|
1054
|
-
}
|
|
1055
|
-
return rgba2;
|
|
1056
|
-
}
|
|
1057
|
-
} catch {
|
|
1058
|
-
if (fallback) return convertColor(fallback)(format);
|
|
1059
|
-
}
|
|
1060
|
-
};
|
|
971
|
+
|
|
972
|
+
// src/number.ts
|
|
973
|
+
function toNumber(n) {
|
|
974
|
+
const num = parseFloat(n);
|
|
975
|
+
return typeof num !== "number" || Number.isNaN(num) ? 0 : num;
|
|
1061
976
|
}
|
|
1062
|
-
function
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
} else {
|
|
1068
|
-
return color.length === 9 ? "hexa" : "hex";
|
|
1069
|
-
}
|
|
977
|
+
function toPrecision(n, precision) {
|
|
978
|
+
n = toNumber(n);
|
|
979
|
+
const scale = 10 ** (precision != null ? precision : 10);
|
|
980
|
+
n = Math.round(n * scale) / scale;
|
|
981
|
+
return precision ? n.toFixed(precision) : n.toString();
|
|
1070
982
|
}
|
|
1071
|
-
function
|
|
1072
|
-
|
|
983
|
+
function countDecimal(n) {
|
|
984
|
+
if (!Number.isFinite(n)) return 0;
|
|
985
|
+
let e = 1;
|
|
986
|
+
let p = 0;
|
|
987
|
+
while (Math.round(n * e) / e !== n) {
|
|
988
|
+
e *= 10;
|
|
989
|
+
p += 1;
|
|
990
|
+
}
|
|
991
|
+
return p;
|
|
1073
992
|
}
|
|
1074
|
-
function
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
return
|
|
993
|
+
function roundNumberToStep(n, from, step) {
|
|
994
|
+
const nextValue = Math.round((n - from) / step) * step + from;
|
|
995
|
+
const precision = countDecimal(step);
|
|
996
|
+
return toPrecision(nextValue, precision);
|
|
1078
997
|
}
|
|
1079
|
-
function
|
|
1080
|
-
|
|
1081
|
-
if (/^[0-9a-fA-F]{6}$/.test(color)) color = "#" + color;
|
|
1082
|
-
return c.parseToRgba(color);
|
|
1083
|
-
} catch {
|
|
1084
|
-
if (fallback) return c.parseToRgba(fallback);
|
|
1085
|
-
}
|
|
998
|
+
function valueToPercent(n, min, max) {
|
|
999
|
+
return (n - min) * 100 / (max - min);
|
|
1086
1000
|
}
|
|
1087
|
-
function
|
|
1088
|
-
|
|
1089
|
-
if (/^[0-9a-fA-F]{6}$/.test(color)) color = "#" + color;
|
|
1090
|
-
return c.parseToHsla(color);
|
|
1091
|
-
} catch {
|
|
1092
|
-
if (fallback) return c.parseToHsla(fallback);
|
|
1093
|
-
}
|
|
1001
|
+
function percentToValue(n, min, max) {
|
|
1002
|
+
return (max - min) * n + min;
|
|
1094
1003
|
}
|
|
1095
|
-
function
|
|
1096
|
-
|
|
1097
|
-
let [r, g, b, a] = (_a = parseToRgba2(color, fallback)) != null ? _a : [255, 255, 255, 1];
|
|
1098
|
-
r = r / 255;
|
|
1099
|
-
g = g / 255;
|
|
1100
|
-
b = b / 255;
|
|
1101
|
-
const [min, max] = [Math.min(r, g, b), Math.max(r, g, b)];
|
|
1102
|
-
const delta = max - min;
|
|
1103
|
-
let [h, v, s] = [0, max, max == 0 ? 0 : delta / max];
|
|
1104
|
-
switch (min) {
|
|
1105
|
-
case max:
|
|
1106
|
-
h = 0;
|
|
1107
|
-
break;
|
|
1108
|
-
case r:
|
|
1109
|
-
h = 60 * ((b - g) / delta) + 180;
|
|
1110
|
-
break;
|
|
1111
|
-
case g:
|
|
1112
|
-
h = 60 * ((r - b) / delta) + 300;
|
|
1113
|
-
break;
|
|
1114
|
-
case b:
|
|
1115
|
-
h = 60 * ((g - r) / delta) + 60;
|
|
1116
|
-
break;
|
|
1117
|
-
}
|
|
1118
|
-
return [h, s, v, a];
|
|
1004
|
+
function clampNumber(n, min, max) {
|
|
1005
|
+
return Math.min(Math.max(n, min), max);
|
|
1119
1006
|
}
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1007
|
+
|
|
1008
|
+
// src/react.tsx
|
|
1009
|
+
var React = __toESM(require("react"));
|
|
1010
|
+
function createContext2({
|
|
1011
|
+
name,
|
|
1012
|
+
defaultValue,
|
|
1013
|
+
errorMessage = "useContext: `context` is undefined. Seems you forgot to wrap component within the Provider",
|
|
1014
|
+
strict = true
|
|
1015
|
+
} = {}) {
|
|
1016
|
+
const Context = React.createContext(defaultValue);
|
|
1017
|
+
Context.displayName = name;
|
|
1018
|
+
const useContext2 = () => {
|
|
1019
|
+
const context = React.useContext(Context);
|
|
1020
|
+
if (!context && strict) {
|
|
1021
|
+
const error = new Error(errorMessage);
|
|
1022
|
+
error.name = "ContextError";
|
|
1023
|
+
Error.captureStackTrace(error, useContext2);
|
|
1024
|
+
throw error;
|
|
1025
|
+
}
|
|
1026
|
+
return context;
|
|
1123
1027
|
};
|
|
1028
|
+
return [Context.Provider, useContext2, Context];
|
|
1124
1029
|
}
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
};
|
|
1030
|
+
var useSafeLayoutEffect = Boolean(globalThis.document) ? React.useLayoutEffect : React.useEffect;
|
|
1031
|
+
function useUnmountEffect(callback) {
|
|
1032
|
+
return React.useEffect(() => () => callback(), []);
|
|
1129
1033
|
}
|
|
1130
|
-
function
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
let
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
rgb = [q, v, p];
|
|
1146
|
-
break;
|
|
1147
|
-
case 2:
|
|
1148
|
-
rgb = [p, v, t];
|
|
1149
|
-
break;
|
|
1150
|
-
case 3:
|
|
1151
|
-
rgb = [p, q, v];
|
|
1152
|
-
break;
|
|
1153
|
-
case 4:
|
|
1154
|
-
rgb = [t, p, v];
|
|
1155
|
-
break;
|
|
1156
|
-
case 5:
|
|
1157
|
-
rgb = [v, p, q];
|
|
1158
|
-
break;
|
|
1034
|
+
function useIsMounted({
|
|
1035
|
+
delay = 0,
|
|
1036
|
+
rerender = false
|
|
1037
|
+
} = {}) {
|
|
1038
|
+
const isMountedRef = React.useRef(false);
|
|
1039
|
+
const [isMounted, setIsMounted] = React.useState(false);
|
|
1040
|
+
useSafeLayoutEffect(() => {
|
|
1041
|
+
isMountedRef.current = true;
|
|
1042
|
+
let timeoutId = null;
|
|
1043
|
+
if (rerender) {
|
|
1044
|
+
if (delay > 0) {
|
|
1045
|
+
timeoutId = setTimeout(() => setIsMounted(true), delay);
|
|
1046
|
+
} else {
|
|
1047
|
+
setIsMounted(true);
|
|
1048
|
+
}
|
|
1159
1049
|
}
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1050
|
+
return () => {
|
|
1051
|
+
isMountedRef.current = false;
|
|
1052
|
+
if (rerender) setIsMounted(false);
|
|
1053
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
1054
|
+
};
|
|
1055
|
+
}, [delay, rerender]);
|
|
1056
|
+
return [React.useCallback(() => isMountedRef.current, []), isMounted];
|
|
1164
1057
|
}
|
|
1165
|
-
function
|
|
1058
|
+
function getValidChildren(children) {
|
|
1059
|
+
return React.Children.toArray(children).filter(
|
|
1060
|
+
(child) => React.isValidElement(child)
|
|
1061
|
+
);
|
|
1062
|
+
}
|
|
1063
|
+
function isValidElement2(child) {
|
|
1064
|
+
return React.isValidElement(child) || isString(child) || isNumber(child);
|
|
1065
|
+
}
|
|
1066
|
+
function isSomeElement(child, type) {
|
|
1166
1067
|
var _a, _b;
|
|
1167
|
-
if (
|
|
1168
|
-
if (
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1068
|
+
if (child.type === type) return true;
|
|
1069
|
+
if (!!child.__ui__ && !!type.__ui__) {
|
|
1070
|
+
if (child.__ui__ === type.__ui__) return true;
|
|
1071
|
+
}
|
|
1072
|
+
const payload = child.type._payload;
|
|
1073
|
+
if (!!((_a = payload == null ? void 0 : payload.value) == null ? void 0 : _a.__ui__) && !!type.__ui__) {
|
|
1074
|
+
if (((_b = payload == null ? void 0 : payload.value) == null ? void 0 : _b.__ui__) === type.__ui__) return true;
|
|
1075
|
+
}
|
|
1076
|
+
return false;
|
|
1172
1077
|
}
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1078
|
+
function findChild(children, ...types) {
|
|
1079
|
+
const child = children.find(
|
|
1080
|
+
(child2) => types.some((type) => isSomeElement(child2, type))
|
|
1081
|
+
);
|
|
1082
|
+
return child;
|
|
1177
1083
|
}
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1084
|
+
function findChildren(children, ...types) {
|
|
1085
|
+
const child = children.find(
|
|
1086
|
+
(child2) => types.some((type) => isSomeElement(child2, type))
|
|
1087
|
+
);
|
|
1088
|
+
if (child) {
|
|
1089
|
+
return children.sort((a, b) => {
|
|
1090
|
+
if (types.some((type) => isSomeElement(a, type))) {
|
|
1091
|
+
return -1;
|
|
1092
|
+
} else if (types.some((type) => isSomeElement(b, type))) {
|
|
1093
|
+
return 1;
|
|
1094
|
+
} else {
|
|
1095
|
+
return 0;
|
|
1096
|
+
}
|
|
1097
|
+
});
|
|
1098
|
+
} else {
|
|
1099
|
+
return [void 0, ...children];
|
|
1100
|
+
}
|
|
1183
1101
|
}
|
|
1184
|
-
function
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1102
|
+
function includesChildren(children, ...types) {
|
|
1103
|
+
return children.some((child) => {
|
|
1104
|
+
if (types.some((type) => isSomeElement(child, type))) return true;
|
|
1105
|
+
const children2 = getValidChildren(child.props.children);
|
|
1106
|
+
return children2.length ? includesChildren(children2, ...types) : false;
|
|
1107
|
+
});
|
|
1189
1108
|
}
|
|
1190
|
-
function
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
while (Math.round(n * e) / e !== n) {
|
|
1195
|
-
e *= 10;
|
|
1196
|
-
p += 1;
|
|
1197
|
-
}
|
|
1198
|
-
return p;
|
|
1109
|
+
function omitChildren(children, ...types) {
|
|
1110
|
+
return children.filter(
|
|
1111
|
+
(child) => types.every((type) => !isSomeElement(child, type))
|
|
1112
|
+
);
|
|
1199
1113
|
}
|
|
1200
|
-
function
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1114
|
+
function pickChildren(children, ...types) {
|
|
1115
|
+
return children.filter(
|
|
1116
|
+
(child) => types.every((type) => isSomeElement(child, type))
|
|
1117
|
+
);
|
|
1204
1118
|
}
|
|
1205
|
-
function
|
|
1206
|
-
return (
|
|
1119
|
+
function cx(...classNames) {
|
|
1120
|
+
return classNames.filter(Boolean).join(" ");
|
|
1207
1121
|
}
|
|
1208
|
-
function
|
|
1209
|
-
return (
|
|
1122
|
+
function isRefObject(val) {
|
|
1123
|
+
return isObject(val) && "current" in val;
|
|
1210
1124
|
}
|
|
1211
|
-
function
|
|
1212
|
-
|
|
1125
|
+
function assignRef(ref, value) {
|
|
1126
|
+
if (ref == null) return;
|
|
1127
|
+
if (typeof ref === "function") {
|
|
1128
|
+
ref(value);
|
|
1129
|
+
return;
|
|
1130
|
+
}
|
|
1131
|
+
try {
|
|
1132
|
+
ref.current = value;
|
|
1133
|
+
} catch {
|
|
1134
|
+
throw new Error(`Cannot assign value '${value}' to ref '${ref}'`);
|
|
1135
|
+
}
|
|
1213
1136
|
}
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
return ev instanceof win.MouseEvent;
|
|
1137
|
+
function mergeRefs(...refs) {
|
|
1138
|
+
return function(node) {
|
|
1139
|
+
return refs.forEach((ref) => {
|
|
1140
|
+
assignRef(ref, node);
|
|
1141
|
+
});
|
|
1142
|
+
};
|
|
1221
1143
|
}
|
|
1222
|
-
function
|
|
1223
|
-
return
|
|
1144
|
+
function useMergeRefs(...refs) {
|
|
1145
|
+
return React.useMemo(() => mergeRefs(...refs), [refs]);
|
|
1224
1146
|
}
|
|
1225
|
-
function
|
|
1226
|
-
|
|
1147
|
+
function useCallbackRef(callback, deps = []) {
|
|
1148
|
+
const callbackRef = React.useRef(callback);
|
|
1149
|
+
React.useEffect(() => {
|
|
1150
|
+
callbackRef.current = callback;
|
|
1151
|
+
});
|
|
1152
|
+
return React.useCallback(
|
|
1153
|
+
(...args) => {
|
|
1154
|
+
var _a;
|
|
1155
|
+
return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
|
|
1156
|
+
},
|
|
1157
|
+
deps
|
|
1158
|
+
);
|
|
1227
1159
|
}
|
|
1228
|
-
function
|
|
1229
|
-
|
|
1230
|
-
|
|
1160
|
+
function useUpdateEffect(callback, deps) {
|
|
1161
|
+
const renderCycleRef = React.useRef(false);
|
|
1162
|
+
const effectCycleRef = React.useRef(false);
|
|
1163
|
+
React.useEffect(() => {
|
|
1164
|
+
const mounted = renderCycleRef.current;
|
|
1165
|
+
const run = mounted && effectCycleRef.current;
|
|
1166
|
+
if (run) return callback();
|
|
1167
|
+
effectCycleRef.current = true;
|
|
1168
|
+
}, deps);
|
|
1169
|
+
React.useEffect(() => {
|
|
1170
|
+
renderCycleRef.current = true;
|
|
1171
|
+
return () => {
|
|
1172
|
+
renderCycleRef.current = false;
|
|
1173
|
+
};
|
|
1174
|
+
}, []);
|
|
1231
1175
|
}
|
|
1232
|
-
function
|
|
1233
|
-
const
|
|
1234
|
-
|
|
1176
|
+
function useAsync(func, deps = []) {
|
|
1177
|
+
const [state, callback] = useAsyncFunc(func, deps, { loading: true });
|
|
1178
|
+
React.useEffect(() => {
|
|
1179
|
+
callback();
|
|
1180
|
+
}, [callback]);
|
|
1181
|
+
return state;
|
|
1235
1182
|
}
|
|
1236
|
-
function
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1183
|
+
function useAsyncFunc(func, deps = [], initialState = { loading: false }) {
|
|
1184
|
+
const lastCallId = React.useRef(0);
|
|
1185
|
+
const [isMounted] = useIsMounted();
|
|
1186
|
+
const [state, setState] = React.useState(initialState);
|
|
1187
|
+
const callback = React.useCallback(
|
|
1188
|
+
(...args) => {
|
|
1189
|
+
const callId = ++lastCallId.current;
|
|
1190
|
+
if (!state.loading)
|
|
1191
|
+
setState((prevState) => ({ ...prevState, loading: true }));
|
|
1192
|
+
return func(...args).then(
|
|
1193
|
+
(value) => {
|
|
1194
|
+
if (isMounted() && callId === lastCallId.current)
|
|
1195
|
+
setState({ loading: false, value });
|
|
1196
|
+
return value;
|
|
1197
|
+
},
|
|
1198
|
+
(error) => {
|
|
1199
|
+
if (isMounted() && callId === lastCallId.current)
|
|
1200
|
+
setState({ error, loading: false });
|
|
1201
|
+
return error;
|
|
1202
|
+
}
|
|
1203
|
+
);
|
|
1204
|
+
},
|
|
1205
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1206
|
+
deps
|
|
1207
|
+
);
|
|
1208
|
+
return [state, callback];
|
|
1241
1209
|
}
|
|
1242
|
-
function
|
|
1243
|
-
|
|
1210
|
+
function useAsyncRetry(func, deps = []) {
|
|
1211
|
+
const [attempt, setAttempt] = React.useState(0);
|
|
1212
|
+
const state = useAsync(func, [...deps, attempt]);
|
|
1213
|
+
const stateLoading = state.loading;
|
|
1214
|
+
const retry = React.useCallback(() => {
|
|
1215
|
+
if (stateLoading) return;
|
|
1216
|
+
setAttempt((currentAttempt) => currentAttempt + 1);
|
|
1217
|
+
}, [...deps, stateLoading]);
|
|
1218
|
+
return { ...state, retry };
|
|
1244
1219
|
}
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
return (
|
|
1248
|
-
target.removeEventListener(type, cb, options);
|
|
1249
|
-
};
|
|
1220
|
+
var createIdCounter = 0;
|
|
1221
|
+
function createId(prefix) {
|
|
1222
|
+
return `${prefix}-${++createIdCounter}-${(/* @__PURE__ */ new Date()).getTime()}`;
|
|
1250
1223
|
}
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
};
|
|
1224
|
+
|
|
1225
|
+
// src/string.ts
|
|
1226
|
+
function escape(value, replaceValue = "") {
|
|
1227
|
+
return value.replace(/\s+/g, replaceValue);
|
|
1256
1228
|
}
|
|
1257
|
-
function
|
|
1258
|
-
|
|
1259
|
-
|
|
1229
|
+
function antonym(value) {
|
|
1230
|
+
switch (value) {
|
|
1231
|
+
case "top":
|
|
1232
|
+
return "bottom";
|
|
1233
|
+
case "bottom":
|
|
1234
|
+
return "top";
|
|
1235
|
+
case "left":
|
|
1236
|
+
return "right";
|
|
1237
|
+
case "right":
|
|
1238
|
+
return "left";
|
|
1239
|
+
case "start":
|
|
1240
|
+
return "end";
|
|
1241
|
+
case "end":
|
|
1242
|
+
return "start";
|
|
1243
|
+
case "x":
|
|
1244
|
+
return "y";
|
|
1245
|
+
case "y":
|
|
1246
|
+
return "x";
|
|
1247
|
+
case "enter":
|
|
1248
|
+
return "exit";
|
|
1249
|
+
case "exit":
|
|
1250
|
+
return "enter";
|
|
1251
|
+
case "vertical":
|
|
1252
|
+
return "horizontal";
|
|
1253
|
+
case "horizontal":
|
|
1254
|
+
return "vertical";
|
|
1255
|
+
case "up":
|
|
1256
|
+
return "down";
|
|
1257
|
+
case "down":
|
|
1258
|
+
return "up";
|
|
1259
|
+
case "block":
|
|
1260
|
+
return "inline";
|
|
1261
|
+
case "inline":
|
|
1262
|
+
return "block";
|
|
1263
|
+
default:
|
|
1264
|
+
return value;
|
|
1260
1265
|
}
|
|
1261
|
-
const fn = filterPrimary ? filter(listener) : listener;
|
|
1262
|
-
return fn;
|
|
1263
1266
|
}
|
|
1264
|
-
function
|
|
1265
|
-
return
|
|
1267
|
+
function toCamelCase(value) {
|
|
1268
|
+
return value.toLowerCase().replace(/[_-](.)/g, (_, val) => val.toUpperCase()).replace(/^(.)/, (_, val) => val.toUpperCase());
|
|
1266
1269
|
}
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1270
|
+
function toKebabCase(value) {
|
|
1271
|
+
return value.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase().replace(/^-/, "");
|
|
1272
|
+
}
|
|
1273
|
+
function toTitleCase(value) {
|
|
1274
|
+
return value.replace(/([A-Z])/g, " $1").replace(/[_-](.)/g, (_, val) => ` ${val.toUpperCase()}`).replace(/^./, (str) => str.toUpperCase()).trim();
|
|
1271
1275
|
}
|
|
1272
1276
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1273
1277
|
0 && (module.exports = {
|
|
@@ -1334,6 +1338,7 @@ function interopDefault(module2) {
|
|
|
1334
1338
|
isDisabled,
|
|
1335
1339
|
isElement,
|
|
1336
1340
|
isEmpty,
|
|
1341
|
+
isEmptyObject,
|
|
1337
1342
|
isFocusable,
|
|
1338
1343
|
isFunction,
|
|
1339
1344
|
isGray,
|