@yamada-ui/utils 0.1.0
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/LICENSE +21 -0
- package/README.md +31 -0
- package/dist/array.d.ts +3 -0
- package/dist/array.js +30 -0
- package/dist/array.mjs +6 -0
- package/dist/assertion.d.ts +16 -0
- package/dist/assertion.js +63 -0
- package/dist/assertion.mjs +28 -0
- package/dist/calc.d.ts +17 -0
- package/dist/calc.js +55 -0
- package/dist/calc.mjs +6 -0
- package/dist/chunk-A6J4FUU7.mjs +401 -0
- package/dist/chunk-BZAW2D6U.mjs +6 -0
- package/dist/chunk-FW7XS4NH.mjs +120 -0
- package/dist/chunk-IVGIIDMV.mjs +28 -0
- package/dist/chunk-PF7LRFIA.mjs +51 -0
- package/dist/chunk-PURW64JE.mjs +6 -0
- package/dist/chunk-R5OUKGQ5.mjs +31 -0
- package/dist/chunk-SLJ4M7XC.mjs +0 -0
- package/dist/chunk-VYMGBE25.mjs +39 -0
- package/dist/color.d.ts +19 -0
- package/dist/color.js +181 -0
- package/dist/color.mjs +34 -0
- package/dist/dom.d.ts +33 -0
- package/dist/dom.js +168 -0
- package/dist/dom.mjs +54 -0
- package/dist/event.d.ts +30 -0
- package/dist/event.js +83 -0
- package/dist/event.mjs +22 -0
- package/dist/function.d.ts +6 -0
- package/dist/function.js +50 -0
- package/dist/function.mjs +20 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +796 -0
- package/dist/index.mjs +221 -0
- package/dist/index.types.d.ts +14 -0
- package/dist/index.types.js +18 -0
- package/dist/index.types.mjs +1 -0
- package/dist/number.d.ts +8 -0
- package/dist/number.js +68 -0
- package/dist/number.mjs +16 -0
- package/dist/object.d.ts +18 -0
- package/dist/object.js +192 -0
- package/dist/object.mjs +40 -0
- package/dist/react.d.ts +44 -0
- package/dist/react.js +176 -0
- package/dist/react.mjs +46 -0
- package/dist/string.d.ts +3 -0
- package/dist/string.js +30 -0
- package/dist/string.mjs +6 -0
- package/package.json +66 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,796 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
addDomEvent: () => addDomEvent,
|
|
34
|
+
addPointerEvent: () => addPointerEvent,
|
|
35
|
+
ariaAttr: () => ariaAttr,
|
|
36
|
+
assignAfter: () => assignAfter,
|
|
37
|
+
assignRef: () => assignRef,
|
|
38
|
+
brightenColor: () => brightenColor,
|
|
39
|
+
calc: () => calc,
|
|
40
|
+
cast: () => cast,
|
|
41
|
+
clampNumber: () => clampNumber,
|
|
42
|
+
countDecimal: () => countDecimal,
|
|
43
|
+
createContext: () => createContext2,
|
|
44
|
+
createdDom: () => createdDom,
|
|
45
|
+
cx: () => cx,
|
|
46
|
+
darkenColor: () => darkenColor,
|
|
47
|
+
dataAttr: () => dataAttr,
|
|
48
|
+
escape: () => escape,
|
|
49
|
+
filterEmpty: () => filterEmpty,
|
|
50
|
+
filterObject: () => filterObject,
|
|
51
|
+
filterUndefined: () => filterUndefined,
|
|
52
|
+
findChildren: () => findChildren,
|
|
53
|
+
flattenObject: () => flattenObject,
|
|
54
|
+
funcAll: () => funcAll,
|
|
55
|
+
getActiveElement: () => getActiveElement,
|
|
56
|
+
getAllFocusable: () => getAllFocusable,
|
|
57
|
+
getColor: () => getColor,
|
|
58
|
+
getEventPoint: () => getEventPoint,
|
|
59
|
+
getEventRelatedTarget: () => getEventRelatedTarget,
|
|
60
|
+
getEventWindow: () => getEventWindow,
|
|
61
|
+
getMemoizedObject: () => getMemoizedObject,
|
|
62
|
+
getObject: () => getObject,
|
|
63
|
+
getOwnerDocument: () => getOwnerDocument,
|
|
64
|
+
getOwnerWindow: () => getOwnerWindow,
|
|
65
|
+
getPlatform: () => getPlatform,
|
|
66
|
+
getValidChildren: () => getValidChildren,
|
|
67
|
+
handlerAll: () => handlerAll,
|
|
68
|
+
hasNegativeTabIndex: () => hasNegativeTabIndex,
|
|
69
|
+
hasTabIndex: () => hasTabIndex,
|
|
70
|
+
includesChildren: () => includesChildren,
|
|
71
|
+
isActiveElement: () => isActiveElement,
|
|
72
|
+
isApple: () => isApple,
|
|
73
|
+
isArray: () => isArray,
|
|
74
|
+
isContains: () => isContains,
|
|
75
|
+
isContentEditable: () => isContentEditable,
|
|
76
|
+
isDark: () => isDark,
|
|
77
|
+
isDisabled: () => isDisabled,
|
|
78
|
+
isElement: () => isElement,
|
|
79
|
+
isEmpty: () => isEmpty,
|
|
80
|
+
isFocusable: () => isFocusable,
|
|
81
|
+
isFunction: () => isFunction,
|
|
82
|
+
isHTMLElement: () => isHTMLElement,
|
|
83
|
+
isHidden: () => isHidden,
|
|
84
|
+
isLight: () => isLight,
|
|
85
|
+
isMac: () => isMac,
|
|
86
|
+
isMouseEvent: () => isMouseEvent,
|
|
87
|
+
isMultiTouchEvent: () => isMultiTouchEvent,
|
|
88
|
+
isNotNumber: () => isNotNumber,
|
|
89
|
+
isNull: () => isNull,
|
|
90
|
+
isNumber: () => isNumber,
|
|
91
|
+
isNumeric: () => isNumeric,
|
|
92
|
+
isObject: () => isObject,
|
|
93
|
+
isRefObject: () => isRefObject,
|
|
94
|
+
isSafari: () => isSafari,
|
|
95
|
+
isString: () => isString,
|
|
96
|
+
isTabbable: () => isTabbable,
|
|
97
|
+
isTouchEvent: () => isTouchEvent,
|
|
98
|
+
isUndefined: () => isUndefined,
|
|
99
|
+
isUnit: () => isUnit,
|
|
100
|
+
isValidElement: () => isValidElement2,
|
|
101
|
+
keysFormObject: () => keysFormObject,
|
|
102
|
+
lightenColor: () => lightenColor,
|
|
103
|
+
memoizeObject: () => memoizeObject,
|
|
104
|
+
merge: () => merge,
|
|
105
|
+
mergeRefs: () => mergeRefs,
|
|
106
|
+
noop: () => noop,
|
|
107
|
+
objectFromEntries: () => objectFromEntries,
|
|
108
|
+
omitChildren: () => omitChildren,
|
|
109
|
+
omitObject: () => omitObject,
|
|
110
|
+
percentToValue: () => percentToValue,
|
|
111
|
+
pickChildren: () => pickChildren,
|
|
112
|
+
pickObject: () => pickObject,
|
|
113
|
+
platform: () => platform,
|
|
114
|
+
pointFromMouse: () => pointFromMouse,
|
|
115
|
+
pointFromTouch: () => pointFromTouch,
|
|
116
|
+
randomColor: () => randomColor,
|
|
117
|
+
replaceObject: () => replaceObject,
|
|
118
|
+
roundNumberToStep: () => roundNumberToStep,
|
|
119
|
+
runIfFunc: () => runIfFunc,
|
|
120
|
+
shadeColor: () => shadeColor,
|
|
121
|
+
splitObject: () => splitObject,
|
|
122
|
+
tintColor: () => tintColor,
|
|
123
|
+
toPrecision: () => toPrecision,
|
|
124
|
+
toneColor: () => toneColor,
|
|
125
|
+
transparentizeColor: () => transparentizeColor,
|
|
126
|
+
useCallbackRef: () => useCallbackRef,
|
|
127
|
+
useIsMounted: () => useIsMounted,
|
|
128
|
+
useMergeRefs: () => useMergeRefs,
|
|
129
|
+
useSafeLayoutEffect: () => useSafeLayoutEffect,
|
|
130
|
+
useUnmountEffect: () => useUnmountEffect,
|
|
131
|
+
useUpdateEffect: () => useUpdateEffect,
|
|
132
|
+
valueToPercent: () => valueToPercent,
|
|
133
|
+
vendor: () => vendor
|
|
134
|
+
});
|
|
135
|
+
module.exports = __toCommonJS(src_exports);
|
|
136
|
+
|
|
137
|
+
// src/assertion.ts
|
|
138
|
+
var isNumber = (value) => typeof value === "number";
|
|
139
|
+
var isNotNumber = (value) => typeof value !== "number" || Number.isNaN(value) || !Number.isFinite(value);
|
|
140
|
+
var isNumeric = (value) => value != null && parseFloat(value.toString()) - parseFloat(value.toString()) + 1 >= 0;
|
|
141
|
+
var isString = (value) => Object.prototype.toString.call(value) === "[object String]";
|
|
142
|
+
var isUndefined = (value) => typeof value === "undefined" && value === void 0;
|
|
143
|
+
var isNull = (value) => value === null;
|
|
144
|
+
var isObject = (value) => value !== null && (typeof value === "object" || typeof value === "function") && !Array.isArray(value);
|
|
145
|
+
var isArray = (value) => Array.isArray(value);
|
|
146
|
+
var isEmpty = (value) => !Array.isArray(value) || !value.length || value.every((v) => v == null);
|
|
147
|
+
var isFunction = (value) => typeof value === "function";
|
|
148
|
+
var isUnit = (value) => /[0-9].*[px|rem|em|%|vw|vh]$/.test(value);
|
|
149
|
+
var cast = (value) => value;
|
|
150
|
+
|
|
151
|
+
// src/object.ts
|
|
152
|
+
var omitObject = (obj, keys) => {
|
|
153
|
+
const result = {};
|
|
154
|
+
Object.keys(obj).forEach((key) => {
|
|
155
|
+
if (keys.includes(key))
|
|
156
|
+
return;
|
|
157
|
+
result[key] = obj[key];
|
|
158
|
+
});
|
|
159
|
+
return result;
|
|
160
|
+
};
|
|
161
|
+
var pickObject = (obj, keys) => {
|
|
162
|
+
const result = {};
|
|
163
|
+
keys.forEach((key) => {
|
|
164
|
+
if (key in obj)
|
|
165
|
+
result[key] = obj[key];
|
|
166
|
+
});
|
|
167
|
+
return result;
|
|
168
|
+
};
|
|
169
|
+
var splitObject = (obj, keys) => {
|
|
170
|
+
const picked = {};
|
|
171
|
+
const omitted = {};
|
|
172
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
173
|
+
if (keys.includes(key)) {
|
|
174
|
+
picked[key] = value;
|
|
175
|
+
} else {
|
|
176
|
+
omitted[key] = value;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return [picked, omitted];
|
|
180
|
+
};
|
|
181
|
+
var filterObject = (obj, func) => {
|
|
182
|
+
const result = {};
|
|
183
|
+
Object.entries(obj).forEach(([key, value]) => {
|
|
184
|
+
const shouldPass = func(key, value, obj);
|
|
185
|
+
if (shouldPass)
|
|
186
|
+
result[key] = value;
|
|
187
|
+
});
|
|
188
|
+
return result;
|
|
189
|
+
};
|
|
190
|
+
var filterUndefined = (obj) => filterObject(obj, (_, val) => val !== null && val !== void 0);
|
|
191
|
+
var merge = (target, source, overrideArray = false) => {
|
|
192
|
+
let result = Object.assign({}, target);
|
|
193
|
+
if (isObject(target) && isObject(source)) {
|
|
194
|
+
for (const [sourceKey, sourceValue] of Object.entries(source)) {
|
|
195
|
+
const targetValue = target[sourceKey];
|
|
196
|
+
if (overrideArray && Array.isArray(sourceValue) && Array.isArray(targetValue)) {
|
|
197
|
+
result[sourceKey] = targetValue.concat(...sourceValue);
|
|
198
|
+
} else if (!isFunction(sourceValue) && isObject(sourceValue) && target.hasOwnProperty(sourceKey)) {
|
|
199
|
+
result[sourceKey] = merge(targetValue, sourceValue, overrideArray);
|
|
200
|
+
} else {
|
|
201
|
+
Object.assign(result, { [sourceKey]: sourceValue });
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return result;
|
|
206
|
+
};
|
|
207
|
+
var flattenObject = (obj, maxDepth = Infinity) => {
|
|
208
|
+
if (!isObject(obj) && !isArray(obj) || !maxDepth)
|
|
209
|
+
return obj;
|
|
210
|
+
return Object.entries(obj).reduce((result, [key, value]) => {
|
|
211
|
+
if (isObject(value)) {
|
|
212
|
+
Object.entries(flattenObject(value, maxDepth - 1)).forEach(([childKey, childValue]) => {
|
|
213
|
+
result[`${key}.${childKey}`] = childValue;
|
|
214
|
+
});
|
|
215
|
+
} else {
|
|
216
|
+
result[key] = value;
|
|
217
|
+
}
|
|
218
|
+
return result;
|
|
219
|
+
}, {});
|
|
220
|
+
};
|
|
221
|
+
var objectFromEntries = (entries) => entries.reduce((result, [key, value]) => {
|
|
222
|
+
result[key] = value;
|
|
223
|
+
return result;
|
|
224
|
+
}, {});
|
|
225
|
+
var keysFormObject = (obj) => Object.keys(obj);
|
|
226
|
+
var replaceObject = (objOrArray, callBack) => {
|
|
227
|
+
if (isArray(objOrArray)) {
|
|
228
|
+
return objOrArray.map(callBack);
|
|
229
|
+
} else if (isObject(objOrArray)) {
|
|
230
|
+
return Object.entries(objOrArray).reduce((obj, [key, value]) => {
|
|
231
|
+
obj[key] = callBack(value);
|
|
232
|
+
return obj;
|
|
233
|
+
}, {});
|
|
234
|
+
} else {
|
|
235
|
+
return callBack(objOrArray);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
var getObject = (obj, path, fallback, i) => {
|
|
239
|
+
const k = typeof path === "string" ? path.split(".") : [path];
|
|
240
|
+
for (i = 0; i < k.length; i += 1) {
|
|
241
|
+
if (!obj)
|
|
242
|
+
break;
|
|
243
|
+
obj = obj[k[i]];
|
|
244
|
+
}
|
|
245
|
+
return obj === void 0 ? fallback : obj;
|
|
246
|
+
};
|
|
247
|
+
var memoizeObject = (func) => {
|
|
248
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
249
|
+
const memoizedFunc = (obj, path, fallback, i) => {
|
|
250
|
+
if (typeof obj === "undefined") {
|
|
251
|
+
return func(obj, path, fallback);
|
|
252
|
+
}
|
|
253
|
+
if (!cache.has(obj))
|
|
254
|
+
cache.set(obj, /* @__PURE__ */ new Map());
|
|
255
|
+
const map = cache.get(obj);
|
|
256
|
+
if (map.has(path))
|
|
257
|
+
return map.get(path);
|
|
258
|
+
const value = func(obj, path, fallback, i);
|
|
259
|
+
map.set(path, value);
|
|
260
|
+
return value;
|
|
261
|
+
};
|
|
262
|
+
return memoizedFunc;
|
|
263
|
+
};
|
|
264
|
+
var getMemoizedObject = memoizeObject(getObject);
|
|
265
|
+
var assignAfter = (target, ...sources) => {
|
|
266
|
+
if (target == null)
|
|
267
|
+
throw new TypeError("Cannot convert undefined or null to object");
|
|
268
|
+
const result = { ...target };
|
|
269
|
+
for (const nextSource of sources) {
|
|
270
|
+
if (nextSource == null)
|
|
271
|
+
continue;
|
|
272
|
+
for (const nextKey in nextSource) {
|
|
273
|
+
if (!Object.prototype.hasOwnProperty.call(nextSource, nextKey))
|
|
274
|
+
continue;
|
|
275
|
+
if (nextKey in result)
|
|
276
|
+
delete result[nextKey];
|
|
277
|
+
result[nextKey] = nextSource[nextKey];
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return result;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
// src/function.ts
|
|
284
|
+
var noop = () => {
|
|
285
|
+
};
|
|
286
|
+
var runIfFunc = (valOrFunc, ...args) => isFunction(valOrFunc) ? valOrFunc(...args) : valOrFunc;
|
|
287
|
+
var handlerAll = (...funcs) => (event) => {
|
|
288
|
+
funcs.some((func) => {
|
|
289
|
+
func == null ? void 0 : func(event);
|
|
290
|
+
return event == null ? void 0 : event.defaultPrevented;
|
|
291
|
+
});
|
|
292
|
+
};
|
|
293
|
+
var funcAll = (...funcs) => (arg) => funcs.forEach((func) => func == null ? void 0 : func(arg));
|
|
294
|
+
|
|
295
|
+
// src/react.tsx
|
|
296
|
+
var React = __toESM(require("react"));
|
|
297
|
+
var createContext2 = ({
|
|
298
|
+
strict = true,
|
|
299
|
+
errorMessage = "useContext: `context` is undefined. Seems you forgot to wrap component within the Provider",
|
|
300
|
+
name
|
|
301
|
+
} = {}) => {
|
|
302
|
+
const Context = React.createContext(void 0);
|
|
303
|
+
Context.displayName = name;
|
|
304
|
+
const useContext2 = () => {
|
|
305
|
+
var _a;
|
|
306
|
+
const context = React.useContext(Context);
|
|
307
|
+
if (!context && strict) {
|
|
308
|
+
const error = new Error(errorMessage);
|
|
309
|
+
error.name = "ContextError";
|
|
310
|
+
(_a = Error.captureStackTrace) == null ? void 0 : _a.call(Error, error, useContext2);
|
|
311
|
+
throw error;
|
|
312
|
+
}
|
|
313
|
+
return context;
|
|
314
|
+
};
|
|
315
|
+
return [Context.Provider, useContext2, Context];
|
|
316
|
+
};
|
|
317
|
+
var useSafeLayoutEffect = Boolean(globalThis == null ? void 0 : globalThis.document) ? React.useLayoutEffect : React.useEffect;
|
|
318
|
+
var useUnmountEffect = (callback) => (
|
|
319
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
320
|
+
React.useEffect(() => () => callback(), [])
|
|
321
|
+
);
|
|
322
|
+
var useIsMounted = () => {
|
|
323
|
+
const isMounted = React.useRef(false);
|
|
324
|
+
useSafeLayoutEffect(() => {
|
|
325
|
+
isMounted.current = true;
|
|
326
|
+
return () => {
|
|
327
|
+
isMounted.current = false;
|
|
328
|
+
};
|
|
329
|
+
}, []);
|
|
330
|
+
return isMounted;
|
|
331
|
+
};
|
|
332
|
+
var getValidChildren = (children) => React.Children.toArray(children).filter(
|
|
333
|
+
(child) => React.isValidElement(child)
|
|
334
|
+
);
|
|
335
|
+
var isValidElement2 = (child) => React.isValidElement(child) || isString(child) || isNumber(child);
|
|
336
|
+
var findChildren = (children, ...types) => children.find((child) => types.some((type) => child.type === type)) ? children.sort(
|
|
337
|
+
(a, b) => types.some((type) => a.type === type) ? -1 : types.some((type) => b.type === type) ? 1 : 0
|
|
338
|
+
) : [void 0, ...children];
|
|
339
|
+
var includesChildren = (children, ...types) => children.some((child) => {
|
|
340
|
+
if (types.some((type) => child.type === type))
|
|
341
|
+
return true;
|
|
342
|
+
const children2 = getValidChildren(child.props.children);
|
|
343
|
+
return children2.length ? includesChildren(children2, ...types) : false;
|
|
344
|
+
});
|
|
345
|
+
var omitChildren = (children, ...types) => children.filter((child) => types.every((type) => child.type !== type));
|
|
346
|
+
var pickChildren = (children, ...types) => children.filter((child) => types.every((type) => child.type === type));
|
|
347
|
+
var cx = (...classNames) => classNames.filter(Boolean).join(" ");
|
|
348
|
+
var isRefObject = (val) => "current" in val;
|
|
349
|
+
var assignRef = (ref, value) => {
|
|
350
|
+
if (ref == null)
|
|
351
|
+
return;
|
|
352
|
+
if (typeof ref === "function") {
|
|
353
|
+
ref(value);
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
try {
|
|
357
|
+
ref.current = value;
|
|
358
|
+
} catch (error) {
|
|
359
|
+
throw new Error(`Cannot assign value '${value}' to ref '${ref}'`);
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
var mergeRefs = (...refs) => (node) => {
|
|
363
|
+
refs.forEach((ref) => {
|
|
364
|
+
assignRef(ref, node);
|
|
365
|
+
});
|
|
366
|
+
};
|
|
367
|
+
var useMergeRefs = (...refs) => React.useMemo(() => mergeRefs(...refs), [refs]);
|
|
368
|
+
var useCallbackRef = (callback, deps = []) => {
|
|
369
|
+
const callbackRef = React.useRef(callback);
|
|
370
|
+
React.useEffect(() => {
|
|
371
|
+
callbackRef.current = callback;
|
|
372
|
+
});
|
|
373
|
+
return React.useCallback((...args) => {
|
|
374
|
+
var _a;
|
|
375
|
+
return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
|
|
376
|
+
}, deps);
|
|
377
|
+
};
|
|
378
|
+
var useUpdateEffect = (callback, deps) => {
|
|
379
|
+
const renderCycleRef = React.useRef(false);
|
|
380
|
+
const effectCycleRef = React.useRef(false);
|
|
381
|
+
React.useEffect(() => {
|
|
382
|
+
const mounted = renderCycleRef.current;
|
|
383
|
+
const run = mounted && effectCycleRef.current;
|
|
384
|
+
if (run)
|
|
385
|
+
return callback();
|
|
386
|
+
effectCycleRef.current = true;
|
|
387
|
+
}, deps);
|
|
388
|
+
React.useEffect(() => {
|
|
389
|
+
renderCycleRef.current = true;
|
|
390
|
+
return () => {
|
|
391
|
+
renderCycleRef.current = false;
|
|
392
|
+
};
|
|
393
|
+
}, []);
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
// src/dom.ts
|
|
397
|
+
var createdDom = () => !!(typeof window !== "undefined" && window.document && window.document.createElement);
|
|
398
|
+
var getPlatform = () => {
|
|
399
|
+
var _a, _b;
|
|
400
|
+
return (_b = (_a = navigator.userAgentData) == null ? void 0 : _a.platform) != null ? _b : navigator.platform;
|
|
401
|
+
};
|
|
402
|
+
var vendor = (v) => createdDom() && v.test(navigator.vendor);
|
|
403
|
+
var platform = (v) => createdDom() && v.test(getPlatform());
|
|
404
|
+
var isMac = () => platform(/^mac/);
|
|
405
|
+
var isApple = () => platform(/mac|iphone|ipad|ipod/i);
|
|
406
|
+
var isSafari = () => isApple() && vendor(/apple/i);
|
|
407
|
+
var isElement = (el) => el != null && typeof el == "object" && "nodeType" in el && el.nodeType === Node.ELEMENT_NODE;
|
|
408
|
+
var isHTMLElement = (el) => {
|
|
409
|
+
var _a;
|
|
410
|
+
if (!isElement(el))
|
|
411
|
+
return false;
|
|
412
|
+
const win = (_a = el.ownerDocument.defaultView) != null ? _a : window;
|
|
413
|
+
return el instanceof win.HTMLElement;
|
|
414
|
+
};
|
|
415
|
+
var isHidden = (el) => {
|
|
416
|
+
if (el.parentElement && isHidden(el.parentElement))
|
|
417
|
+
return true;
|
|
418
|
+
return el.hidden;
|
|
419
|
+
};
|
|
420
|
+
var isDisabled = (el) => Boolean(el.getAttribute("disabled")) === true || Boolean(el.getAttribute("aria-disabled")) === true;
|
|
421
|
+
var isVisible = (el) => el.offsetWidth > 0 && el.offsetHeight > 0;
|
|
422
|
+
var hasTabIndex = (el) => el.hasAttribute("tabindex");
|
|
423
|
+
var isContentEditable = (el) => {
|
|
424
|
+
const value = el.getAttribute("contenteditable");
|
|
425
|
+
return value !== "false" && value != null;
|
|
426
|
+
};
|
|
427
|
+
var isContains = (parent, child) => {
|
|
428
|
+
return parent === child || (parent == null ? void 0 : parent.contains(child));
|
|
429
|
+
};
|
|
430
|
+
var getEventRelatedTarget = (ev) => {
|
|
431
|
+
var _a;
|
|
432
|
+
return (_a = ev.relatedTarget) != null ? _a : ev.currentTarget.ownerDocument.activeElement;
|
|
433
|
+
};
|
|
434
|
+
var dataAttr = (condition) => condition ? "" : void 0;
|
|
435
|
+
var ariaAttr = (condition) => condition ? true : void 0;
|
|
436
|
+
var focusableElList = [
|
|
437
|
+
"input:not(:disabled):not([disabled])",
|
|
438
|
+
"select:not(:disabled):not([disabled])",
|
|
439
|
+
"textarea:not(:disabled):not([disabled])",
|
|
440
|
+
"embed",
|
|
441
|
+
"iframe",
|
|
442
|
+
"object",
|
|
443
|
+
"a[href]",
|
|
444
|
+
"area[href]",
|
|
445
|
+
"button:not(:disabled):not([disabled])",
|
|
446
|
+
"[tabindex]",
|
|
447
|
+
"audio[controls]",
|
|
448
|
+
"video[controls]",
|
|
449
|
+
"*[tabindex]:not([aria-disabled])",
|
|
450
|
+
"*[contenteditable]"
|
|
451
|
+
];
|
|
452
|
+
var focusableElSelector = focusableElList.join();
|
|
453
|
+
var getAllFocusable = (container) => {
|
|
454
|
+
const focusableEls = Array.from(container.querySelectorAll(focusableElSelector));
|
|
455
|
+
focusableEls.unshift(container);
|
|
456
|
+
return focusableEls.filter((el) => isFocusable(el) && isVisible(el));
|
|
457
|
+
};
|
|
458
|
+
var isFocusable = (el) => {
|
|
459
|
+
if (!isHTMLElement(el) || isHidden(el) || isDisabled(el)) {
|
|
460
|
+
return false;
|
|
461
|
+
}
|
|
462
|
+
const { localName } = el;
|
|
463
|
+
const focusableTags = ["input", "select", "textarea", "button"];
|
|
464
|
+
if (focusableTags.indexOf(localName) >= 0)
|
|
465
|
+
return true;
|
|
466
|
+
const others = {
|
|
467
|
+
a: () => el.hasAttribute("href"),
|
|
468
|
+
audio: () => el.hasAttribute("controls"),
|
|
469
|
+
video: () => el.hasAttribute("controls")
|
|
470
|
+
};
|
|
471
|
+
if (localName in others)
|
|
472
|
+
return others[localName]();
|
|
473
|
+
if (isContentEditable(el))
|
|
474
|
+
return true;
|
|
475
|
+
return hasTabIndex(el);
|
|
476
|
+
};
|
|
477
|
+
var hasNegativeTabIndex = (el) => hasTabIndex(el) && el.tabIndex === -1;
|
|
478
|
+
var isTabbable = (el) => el ? isHTMLElement(el) && isFocusable(el) && !hasNegativeTabIndex(el) : false;
|
|
479
|
+
var getOwnerWindow = (node) => {
|
|
480
|
+
var _a, _b;
|
|
481
|
+
return (_b = (_a = getOwnerDocument(node)) == null ? void 0 : _a.defaultView) != null ? _b : window;
|
|
482
|
+
};
|
|
483
|
+
var getOwnerDocument = (el) => isElement(el) ? el.ownerDocument : document;
|
|
484
|
+
var getActiveElement = (el) => getOwnerDocument(el).activeElement;
|
|
485
|
+
var isActiveElement = (el) => {
|
|
486
|
+
return getActiveElement(el) === el;
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
// src/string.ts
|
|
490
|
+
var escape = (value, replaceValue = "") => value.replace(/\s+/g, replaceValue);
|
|
491
|
+
|
|
492
|
+
// src/calc.ts
|
|
493
|
+
var toExpression = (operator, ...args) => args.join(` ${operator} `).replace(/calc/g, "");
|
|
494
|
+
var add = (...args) => `calc(${toExpression("+", ...args)})`;
|
|
495
|
+
var subtract = (...args) => `calc(${toExpression("-", ...args)})`;
|
|
496
|
+
var multiply = (...args) => `calc(${toExpression("*", ...args)})`;
|
|
497
|
+
var divide = (...args) => `calc(${toExpression("/", ...args)})`;
|
|
498
|
+
var negate = (value) => {
|
|
499
|
+
if (value != null && !isNaN(parseFloat(value.toString())))
|
|
500
|
+
return String(value).startsWith("-") ? String(value).slice(1) : `-${value}`;
|
|
501
|
+
return multiply(value, -1);
|
|
502
|
+
};
|
|
503
|
+
var calc = Object.assign(
|
|
504
|
+
(x) => ({
|
|
505
|
+
add: (...args) => calc(add(x, ...args)),
|
|
506
|
+
subtract: (...args) => calc(subtract(x, ...args)),
|
|
507
|
+
multiply: (...args) => calc(multiply(x, ...args)),
|
|
508
|
+
divide: (...args) => calc(divide(x, ...args)),
|
|
509
|
+
negate: () => calc(negate(x))
|
|
510
|
+
}),
|
|
511
|
+
{
|
|
512
|
+
add,
|
|
513
|
+
subtract,
|
|
514
|
+
multiply,
|
|
515
|
+
divide,
|
|
516
|
+
negate
|
|
517
|
+
}
|
|
518
|
+
);
|
|
519
|
+
|
|
520
|
+
// src/color.ts
|
|
521
|
+
var import_tinycolor = require("@ctrl/tinycolor");
|
|
522
|
+
var getColor = (color, fallback) => (theme, colorMode) => {
|
|
523
|
+
const hex = getMemoizedObject(
|
|
524
|
+
theme,
|
|
525
|
+
`colors.${color}`,
|
|
526
|
+
color
|
|
527
|
+
);
|
|
528
|
+
if (isArray(hex)) {
|
|
529
|
+
const [lightHex, darkHex] = hex;
|
|
530
|
+
const { isValid, originalInput } = new import_tinycolor.TinyColor(colorMode !== "dark" ? lightHex : darkHex);
|
|
531
|
+
return isValid ? originalInput : fallback;
|
|
532
|
+
} else {
|
|
533
|
+
const { isValid, originalInput } = new import_tinycolor.TinyColor(hex);
|
|
534
|
+
return isValid ? originalInput : fallback;
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
var lightenColor = (color, amount) => (theme, colorMode) => {
|
|
538
|
+
const raw = getColor(color)(theme, colorMode);
|
|
539
|
+
return new import_tinycolor.TinyColor(raw).lighten(amount).toRgbString();
|
|
540
|
+
};
|
|
541
|
+
var darkenColor = (color, amount) => (theme, colorMode) => {
|
|
542
|
+
const raw = getColor(color)(theme, colorMode);
|
|
543
|
+
return new import_tinycolor.TinyColor(raw).darken(amount).toRgbString();
|
|
544
|
+
};
|
|
545
|
+
var brightenColor = (color, amount) => (theme, colorMode) => {
|
|
546
|
+
const raw = getColor(color)(theme, colorMode);
|
|
547
|
+
return new import_tinycolor.TinyColor(raw).brighten(amount).toRgbString();
|
|
548
|
+
};
|
|
549
|
+
var tintColor = (color, amount) => (theme, colorMode) => {
|
|
550
|
+
const raw = getColor(color)(theme, colorMode);
|
|
551
|
+
return new import_tinycolor.TinyColor(raw).tint(amount).toRgbString();
|
|
552
|
+
};
|
|
553
|
+
var shadeColor = (color, amount) => (theme, colorMode) => {
|
|
554
|
+
const raw = getColor(color)(theme, colorMode);
|
|
555
|
+
return new import_tinycolor.TinyColor(raw).shade(amount).toRgbString();
|
|
556
|
+
};
|
|
557
|
+
var transparentizeColor = (color, alpha) => (theme, colorMode) => {
|
|
558
|
+
const raw = getColor(color)(theme, colorMode);
|
|
559
|
+
return new import_tinycolor.TinyColor(raw).setAlpha(alpha).toRgbString();
|
|
560
|
+
};
|
|
561
|
+
var toneColor = (color, l) => (theme, colorMode) => {
|
|
562
|
+
const raw = getColor(color)(theme, colorMode);
|
|
563
|
+
if (l < 0 || 900 < l)
|
|
564
|
+
return color;
|
|
565
|
+
let n = (l - 500) / 10;
|
|
566
|
+
const isLighten = n <= 0;
|
|
567
|
+
if (isLighten)
|
|
568
|
+
n *= -1;
|
|
569
|
+
if (n !== 0)
|
|
570
|
+
n = n - 5 * (isLighten ? 1 : -1);
|
|
571
|
+
return new import_tinycolor.TinyColor(raw)[isLighten ? "lighten" : "shade"](n).toString();
|
|
572
|
+
};
|
|
573
|
+
var randomColor = ({ string, colors } = {}) => {
|
|
574
|
+
const fallback = randomHex();
|
|
575
|
+
if (string && colors)
|
|
576
|
+
return randomColorFromList(string, colors);
|
|
577
|
+
if (string && !colors)
|
|
578
|
+
return randomColorFromString(string);
|
|
579
|
+
if (colors && !string)
|
|
580
|
+
return randomFromList(colors);
|
|
581
|
+
return fallback;
|
|
582
|
+
};
|
|
583
|
+
var randomHex = () => `#${Math.floor(Math.random() * 16777215).toString(16).padEnd(6, "0")}`;
|
|
584
|
+
var randomColorFromString = (str) => {
|
|
585
|
+
let hash = 0;
|
|
586
|
+
if (str.length === 0)
|
|
587
|
+
return hash.toString();
|
|
588
|
+
for (let i = 0; i < str.length; i += 1) {
|
|
589
|
+
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
590
|
+
hash = hash & hash;
|
|
591
|
+
}
|
|
592
|
+
let color = "#";
|
|
593
|
+
for (let j = 0; j < 3; j += 1) {
|
|
594
|
+
const value = hash >> j * 8 & 255;
|
|
595
|
+
color += `00${value.toString(16)}`.substr(-2);
|
|
596
|
+
}
|
|
597
|
+
return color;
|
|
598
|
+
};
|
|
599
|
+
var randomColorFromList = (str, list) => {
|
|
600
|
+
let index = 0;
|
|
601
|
+
if (str.length === 0)
|
|
602
|
+
return list[0];
|
|
603
|
+
for (let i = 0; i < str.length; i += 1) {
|
|
604
|
+
index = str.charCodeAt(i) + ((index << 5) - index);
|
|
605
|
+
index = index & index;
|
|
606
|
+
}
|
|
607
|
+
index = (index % list.length + list.length) % list.length;
|
|
608
|
+
return list[index];
|
|
609
|
+
};
|
|
610
|
+
var randomFromList = (list) => list[Math.floor(Math.random() * list.length)];
|
|
611
|
+
var isLight = (color) => (theme, colorMode) => {
|
|
612
|
+
const raw = getColor(color)(theme, colorMode);
|
|
613
|
+
return new import_tinycolor.TinyColor(raw).isLight();
|
|
614
|
+
};
|
|
615
|
+
var isDark = (color) => (theme, colorMode) => {
|
|
616
|
+
const raw = getColor(color)(theme, colorMode);
|
|
617
|
+
return new import_tinycolor.TinyColor(raw).isDark();
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
// src/array.ts
|
|
621
|
+
var filterEmpty = (array) => array.filter((value) => value != null);
|
|
622
|
+
|
|
623
|
+
// src/number.ts
|
|
624
|
+
var toNumber = (n) => {
|
|
625
|
+
const num = parseFloat(n);
|
|
626
|
+
return typeof num !== "number" || Number.isNaN(num) ? 0 : num;
|
|
627
|
+
};
|
|
628
|
+
var toPrecision = (n, precision) => {
|
|
629
|
+
n = toNumber(n);
|
|
630
|
+
const scale = 10 ** (precision != null ? precision : 10);
|
|
631
|
+
n = Math.round(n * scale) / scale;
|
|
632
|
+
return precision ? n.toFixed(precision) : n.toString();
|
|
633
|
+
};
|
|
634
|
+
var countDecimal = (n) => {
|
|
635
|
+
if (!Number.isFinite(n))
|
|
636
|
+
return 0;
|
|
637
|
+
let e = 1;
|
|
638
|
+
let p = 0;
|
|
639
|
+
while (Math.round(n * e) / e !== n) {
|
|
640
|
+
e *= 10;
|
|
641
|
+
p += 1;
|
|
642
|
+
}
|
|
643
|
+
return p;
|
|
644
|
+
};
|
|
645
|
+
var roundNumberToStep = (n, from, step) => {
|
|
646
|
+
const nextValue = Math.round((n - from) / step) * step + from;
|
|
647
|
+
const precision = countDecimal(step);
|
|
648
|
+
return toPrecision(nextValue, precision);
|
|
649
|
+
};
|
|
650
|
+
var valueToPercent = (n, min, max) => (n - min) * 100 / (max - min);
|
|
651
|
+
var percentToValue = (n, min, max) => (max - min) * n + min;
|
|
652
|
+
var clampNumber = (n, min, max) => Math.min(Math.max(n, min), max);
|
|
653
|
+
|
|
654
|
+
// src/event.ts
|
|
655
|
+
var isMouseEvent = (ev) => {
|
|
656
|
+
const win = getEventWindow(ev);
|
|
657
|
+
if (typeof win.PointerEvent !== "undefined" && ev instanceof win.PointerEvent)
|
|
658
|
+
return !!(ev.pointerType === "mouse");
|
|
659
|
+
return ev instanceof win.MouseEvent;
|
|
660
|
+
};
|
|
661
|
+
var isTouchEvent = (ev) => !!ev.touches;
|
|
662
|
+
var isMultiTouchEvent = (ev) => isTouchEvent(ev) && ev.touches.length > 1;
|
|
663
|
+
var getEventWindow = (ev) => {
|
|
664
|
+
var _a;
|
|
665
|
+
return (_a = ev.view) != null ? _a : window;
|
|
666
|
+
};
|
|
667
|
+
var pointFromTouch = (e, type = "page") => {
|
|
668
|
+
const point = e.touches[0] || e.changedTouches[0];
|
|
669
|
+
return { x: point[`${type}X`], y: point[`${type}Y`] };
|
|
670
|
+
};
|
|
671
|
+
var pointFromMouse = (point, type = "page") => ({
|
|
672
|
+
x: point[`${type}X`],
|
|
673
|
+
y: point[`${type}Y`]
|
|
674
|
+
});
|
|
675
|
+
var getEventPoint = (ev, type = "page") => isTouchEvent(ev) ? pointFromTouch(ev, type) : pointFromMouse(ev, type);
|
|
676
|
+
var addDomEvent = (target, type, cb, options) => {
|
|
677
|
+
target.addEventListener(type, cb, options);
|
|
678
|
+
return () => {
|
|
679
|
+
target.removeEventListener(type, cb, options);
|
|
680
|
+
};
|
|
681
|
+
};
|
|
682
|
+
var filter = (cb) => (event) => {
|
|
683
|
+
const isMouse = isMouseEvent(event);
|
|
684
|
+
if (!isMouse || isMouse && event.button === 0)
|
|
685
|
+
cb(event);
|
|
686
|
+
};
|
|
687
|
+
var wrap = (cb, filterPrimary = false) => {
|
|
688
|
+
const listener = (event) => cb(event, { point: getEventPoint(event) });
|
|
689
|
+
const fn = filterPrimary ? filter(listener) : listener;
|
|
690
|
+
return fn;
|
|
691
|
+
};
|
|
692
|
+
var addPointerEvent = (target, type, cb, options) => addDomEvent(target, type, wrap(cb, type === "pointerdown"), options);
|
|
693
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
694
|
+
0 && (module.exports = {
|
|
695
|
+
addDomEvent,
|
|
696
|
+
addPointerEvent,
|
|
697
|
+
ariaAttr,
|
|
698
|
+
assignAfter,
|
|
699
|
+
assignRef,
|
|
700
|
+
brightenColor,
|
|
701
|
+
calc,
|
|
702
|
+
cast,
|
|
703
|
+
clampNumber,
|
|
704
|
+
countDecimal,
|
|
705
|
+
createContext,
|
|
706
|
+
createdDom,
|
|
707
|
+
cx,
|
|
708
|
+
darkenColor,
|
|
709
|
+
dataAttr,
|
|
710
|
+
escape,
|
|
711
|
+
filterEmpty,
|
|
712
|
+
filterObject,
|
|
713
|
+
filterUndefined,
|
|
714
|
+
findChildren,
|
|
715
|
+
flattenObject,
|
|
716
|
+
funcAll,
|
|
717
|
+
getActiveElement,
|
|
718
|
+
getAllFocusable,
|
|
719
|
+
getColor,
|
|
720
|
+
getEventPoint,
|
|
721
|
+
getEventRelatedTarget,
|
|
722
|
+
getEventWindow,
|
|
723
|
+
getMemoizedObject,
|
|
724
|
+
getObject,
|
|
725
|
+
getOwnerDocument,
|
|
726
|
+
getOwnerWindow,
|
|
727
|
+
getPlatform,
|
|
728
|
+
getValidChildren,
|
|
729
|
+
handlerAll,
|
|
730
|
+
hasNegativeTabIndex,
|
|
731
|
+
hasTabIndex,
|
|
732
|
+
includesChildren,
|
|
733
|
+
isActiveElement,
|
|
734
|
+
isApple,
|
|
735
|
+
isArray,
|
|
736
|
+
isContains,
|
|
737
|
+
isContentEditable,
|
|
738
|
+
isDark,
|
|
739
|
+
isDisabled,
|
|
740
|
+
isElement,
|
|
741
|
+
isEmpty,
|
|
742
|
+
isFocusable,
|
|
743
|
+
isFunction,
|
|
744
|
+
isHTMLElement,
|
|
745
|
+
isHidden,
|
|
746
|
+
isLight,
|
|
747
|
+
isMac,
|
|
748
|
+
isMouseEvent,
|
|
749
|
+
isMultiTouchEvent,
|
|
750
|
+
isNotNumber,
|
|
751
|
+
isNull,
|
|
752
|
+
isNumber,
|
|
753
|
+
isNumeric,
|
|
754
|
+
isObject,
|
|
755
|
+
isRefObject,
|
|
756
|
+
isSafari,
|
|
757
|
+
isString,
|
|
758
|
+
isTabbable,
|
|
759
|
+
isTouchEvent,
|
|
760
|
+
isUndefined,
|
|
761
|
+
isUnit,
|
|
762
|
+
isValidElement,
|
|
763
|
+
keysFormObject,
|
|
764
|
+
lightenColor,
|
|
765
|
+
memoizeObject,
|
|
766
|
+
merge,
|
|
767
|
+
mergeRefs,
|
|
768
|
+
noop,
|
|
769
|
+
objectFromEntries,
|
|
770
|
+
omitChildren,
|
|
771
|
+
omitObject,
|
|
772
|
+
percentToValue,
|
|
773
|
+
pickChildren,
|
|
774
|
+
pickObject,
|
|
775
|
+
platform,
|
|
776
|
+
pointFromMouse,
|
|
777
|
+
pointFromTouch,
|
|
778
|
+
randomColor,
|
|
779
|
+
replaceObject,
|
|
780
|
+
roundNumberToStep,
|
|
781
|
+
runIfFunc,
|
|
782
|
+
shadeColor,
|
|
783
|
+
splitObject,
|
|
784
|
+
tintColor,
|
|
785
|
+
toPrecision,
|
|
786
|
+
toneColor,
|
|
787
|
+
transparentizeColor,
|
|
788
|
+
useCallbackRef,
|
|
789
|
+
useIsMounted,
|
|
790
|
+
useMergeRefs,
|
|
791
|
+
useSafeLayoutEffect,
|
|
792
|
+
useUnmountEffect,
|
|
793
|
+
useUpdateEffect,
|
|
794
|
+
valueToPercent,
|
|
795
|
+
vendor
|
|
796
|
+
});
|