@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
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// src/dom.ts
|
|
2
|
+
var createdDom = () => !!(typeof window !== "undefined" && window.document && window.document.createElement);
|
|
3
|
+
var getPlatform = () => {
|
|
4
|
+
var _a, _b;
|
|
5
|
+
return (_b = (_a = navigator.userAgentData) == null ? void 0 : _a.platform) != null ? _b : navigator.platform;
|
|
6
|
+
};
|
|
7
|
+
var vendor = (v) => createdDom() && v.test(navigator.vendor);
|
|
8
|
+
var platform = (v) => createdDom() && v.test(getPlatform());
|
|
9
|
+
var isMac = () => platform(/^mac/);
|
|
10
|
+
var isApple = () => platform(/mac|iphone|ipad|ipod/i);
|
|
11
|
+
var isSafari = () => isApple() && vendor(/apple/i);
|
|
12
|
+
var isElement = (el) => el != null && typeof el == "object" && "nodeType" in el && el.nodeType === Node.ELEMENT_NODE;
|
|
13
|
+
var isHTMLElement = (el) => {
|
|
14
|
+
var _a;
|
|
15
|
+
if (!isElement(el))
|
|
16
|
+
return false;
|
|
17
|
+
const win = (_a = el.ownerDocument.defaultView) != null ? _a : window;
|
|
18
|
+
return el instanceof win.HTMLElement;
|
|
19
|
+
};
|
|
20
|
+
var isHidden = (el) => {
|
|
21
|
+
if (el.parentElement && isHidden(el.parentElement))
|
|
22
|
+
return true;
|
|
23
|
+
return el.hidden;
|
|
24
|
+
};
|
|
25
|
+
var isDisabled = (el) => Boolean(el.getAttribute("disabled")) === true || Boolean(el.getAttribute("aria-disabled")) === true;
|
|
26
|
+
var isVisible = (el) => el.offsetWidth > 0 && el.offsetHeight > 0;
|
|
27
|
+
var hasTabIndex = (el) => el.hasAttribute("tabindex");
|
|
28
|
+
var isContentEditable = (el) => {
|
|
29
|
+
const value = el.getAttribute("contenteditable");
|
|
30
|
+
return value !== "false" && value != null;
|
|
31
|
+
};
|
|
32
|
+
var isContains = (parent, child) => {
|
|
33
|
+
return parent === child || (parent == null ? void 0 : parent.contains(child));
|
|
34
|
+
};
|
|
35
|
+
var getEventRelatedTarget = (ev) => {
|
|
36
|
+
var _a;
|
|
37
|
+
return (_a = ev.relatedTarget) != null ? _a : ev.currentTarget.ownerDocument.activeElement;
|
|
38
|
+
};
|
|
39
|
+
var dataAttr = (condition) => condition ? "" : void 0;
|
|
40
|
+
var ariaAttr = (condition) => condition ? true : void 0;
|
|
41
|
+
var focusableElList = [
|
|
42
|
+
"input:not(:disabled):not([disabled])",
|
|
43
|
+
"select:not(:disabled):not([disabled])",
|
|
44
|
+
"textarea:not(:disabled):not([disabled])",
|
|
45
|
+
"embed",
|
|
46
|
+
"iframe",
|
|
47
|
+
"object",
|
|
48
|
+
"a[href]",
|
|
49
|
+
"area[href]",
|
|
50
|
+
"button:not(:disabled):not([disabled])",
|
|
51
|
+
"[tabindex]",
|
|
52
|
+
"audio[controls]",
|
|
53
|
+
"video[controls]",
|
|
54
|
+
"*[tabindex]:not([aria-disabled])",
|
|
55
|
+
"*[contenteditable]"
|
|
56
|
+
];
|
|
57
|
+
var focusableElSelector = focusableElList.join();
|
|
58
|
+
var getAllFocusable = (container) => {
|
|
59
|
+
const focusableEls = Array.from(container.querySelectorAll(focusableElSelector));
|
|
60
|
+
focusableEls.unshift(container);
|
|
61
|
+
return focusableEls.filter((el) => isFocusable(el) && isVisible(el));
|
|
62
|
+
};
|
|
63
|
+
var isFocusable = (el) => {
|
|
64
|
+
if (!isHTMLElement(el) || isHidden(el) || isDisabled(el)) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
const { localName } = el;
|
|
68
|
+
const focusableTags = ["input", "select", "textarea", "button"];
|
|
69
|
+
if (focusableTags.indexOf(localName) >= 0)
|
|
70
|
+
return true;
|
|
71
|
+
const others = {
|
|
72
|
+
a: () => el.hasAttribute("href"),
|
|
73
|
+
audio: () => el.hasAttribute("controls"),
|
|
74
|
+
video: () => el.hasAttribute("controls")
|
|
75
|
+
};
|
|
76
|
+
if (localName in others)
|
|
77
|
+
return others[localName]();
|
|
78
|
+
if (isContentEditable(el))
|
|
79
|
+
return true;
|
|
80
|
+
return hasTabIndex(el);
|
|
81
|
+
};
|
|
82
|
+
var hasNegativeTabIndex = (el) => hasTabIndex(el) && el.tabIndex === -1;
|
|
83
|
+
var isTabbable = (el) => el ? isHTMLElement(el) && isFocusable(el) && !hasNegativeTabIndex(el) : false;
|
|
84
|
+
var getOwnerWindow = (node) => {
|
|
85
|
+
var _a, _b;
|
|
86
|
+
return (_b = (_a = getOwnerDocument(node)) == null ? void 0 : _a.defaultView) != null ? _b : window;
|
|
87
|
+
};
|
|
88
|
+
var getOwnerDocument = (el) => isElement(el) ? el.ownerDocument : document;
|
|
89
|
+
var getActiveElement = (el) => getOwnerDocument(el).activeElement;
|
|
90
|
+
var isActiveElement = (el) => {
|
|
91
|
+
return getActiveElement(el) === el;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export {
|
|
95
|
+
createdDom,
|
|
96
|
+
getPlatform,
|
|
97
|
+
vendor,
|
|
98
|
+
platform,
|
|
99
|
+
isMac,
|
|
100
|
+
isApple,
|
|
101
|
+
isSafari,
|
|
102
|
+
isElement,
|
|
103
|
+
isHTMLElement,
|
|
104
|
+
isHidden,
|
|
105
|
+
isDisabled,
|
|
106
|
+
hasTabIndex,
|
|
107
|
+
isContentEditable,
|
|
108
|
+
isContains,
|
|
109
|
+
getEventRelatedTarget,
|
|
110
|
+
dataAttr,
|
|
111
|
+
ariaAttr,
|
|
112
|
+
getAllFocusable,
|
|
113
|
+
isFocusable,
|
|
114
|
+
hasNegativeTabIndex,
|
|
115
|
+
isTabbable,
|
|
116
|
+
getOwnerWindow,
|
|
117
|
+
getOwnerDocument,
|
|
118
|
+
getActiveElement,
|
|
119
|
+
isActiveElement
|
|
120
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// src/assertion.ts
|
|
2
|
+
var isNumber = (value) => typeof value === "number";
|
|
3
|
+
var isNotNumber = (value) => typeof value !== "number" || Number.isNaN(value) || !Number.isFinite(value);
|
|
4
|
+
var isNumeric = (value) => value != null && parseFloat(value.toString()) - parseFloat(value.toString()) + 1 >= 0;
|
|
5
|
+
var isString = (value) => Object.prototype.toString.call(value) === "[object String]";
|
|
6
|
+
var isUndefined = (value) => typeof value === "undefined" && value === void 0;
|
|
7
|
+
var isNull = (value) => value === null;
|
|
8
|
+
var isObject = (value) => value !== null && (typeof value === "object" || typeof value === "function") && !Array.isArray(value);
|
|
9
|
+
var isArray = (value) => Array.isArray(value);
|
|
10
|
+
var isEmpty = (value) => !Array.isArray(value) || !value.length || value.every((v) => v == null);
|
|
11
|
+
var isFunction = (value) => typeof value === "function";
|
|
12
|
+
var isUnit = (value) => /[0-9].*[px|rem|em|%|vw|vh]$/.test(value);
|
|
13
|
+
var cast = (value) => value;
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
isNumber,
|
|
17
|
+
isNotNumber,
|
|
18
|
+
isNumeric,
|
|
19
|
+
isString,
|
|
20
|
+
isUndefined,
|
|
21
|
+
isNull,
|
|
22
|
+
isObject,
|
|
23
|
+
isArray,
|
|
24
|
+
isEmpty,
|
|
25
|
+
isFunction,
|
|
26
|
+
isUnit,
|
|
27
|
+
cast
|
|
28
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// src/event.ts
|
|
2
|
+
var isMouseEvent = (ev) => {
|
|
3
|
+
const win = getEventWindow(ev);
|
|
4
|
+
if (typeof win.PointerEvent !== "undefined" && ev instanceof win.PointerEvent)
|
|
5
|
+
return !!(ev.pointerType === "mouse");
|
|
6
|
+
return ev instanceof win.MouseEvent;
|
|
7
|
+
};
|
|
8
|
+
var isTouchEvent = (ev) => !!ev.touches;
|
|
9
|
+
var isMultiTouchEvent = (ev) => isTouchEvent(ev) && ev.touches.length > 1;
|
|
10
|
+
var getEventWindow = (ev) => {
|
|
11
|
+
var _a;
|
|
12
|
+
return (_a = ev.view) != null ? _a : window;
|
|
13
|
+
};
|
|
14
|
+
var pointFromTouch = (e, type = "page") => {
|
|
15
|
+
const point = e.touches[0] || e.changedTouches[0];
|
|
16
|
+
return { x: point[`${type}X`], y: point[`${type}Y`] };
|
|
17
|
+
};
|
|
18
|
+
var pointFromMouse = (point, type = "page") => ({
|
|
19
|
+
x: point[`${type}X`],
|
|
20
|
+
y: point[`${type}Y`]
|
|
21
|
+
});
|
|
22
|
+
var getEventPoint = (ev, type = "page") => isTouchEvent(ev) ? pointFromTouch(ev, type) : pointFromMouse(ev, type);
|
|
23
|
+
var addDomEvent = (target, type, cb, options) => {
|
|
24
|
+
target.addEventListener(type, cb, options);
|
|
25
|
+
return () => {
|
|
26
|
+
target.removeEventListener(type, cb, options);
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
var filter = (cb) => (event) => {
|
|
30
|
+
const isMouse = isMouseEvent(event);
|
|
31
|
+
if (!isMouse || isMouse && event.button === 0)
|
|
32
|
+
cb(event);
|
|
33
|
+
};
|
|
34
|
+
var wrap = (cb, filterPrimary = false) => {
|
|
35
|
+
const listener = (event) => cb(event, { point: getEventPoint(event) });
|
|
36
|
+
const fn = filterPrimary ? filter(listener) : listener;
|
|
37
|
+
return fn;
|
|
38
|
+
};
|
|
39
|
+
var addPointerEvent = (target, type, cb, options) => addDomEvent(target, type, wrap(cb, type === "pointerdown"), options);
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
isMouseEvent,
|
|
43
|
+
isTouchEvent,
|
|
44
|
+
isMultiTouchEvent,
|
|
45
|
+
getEventWindow,
|
|
46
|
+
pointFromTouch,
|
|
47
|
+
pointFromMouse,
|
|
48
|
+
getEventPoint,
|
|
49
|
+
addDomEvent,
|
|
50
|
+
addPointerEvent
|
|
51
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// src/calc.ts
|
|
2
|
+
var toExpression = (operator, ...args) => args.join(` ${operator} `).replace(/calc/g, "");
|
|
3
|
+
var add = (...args) => `calc(${toExpression("+", ...args)})`;
|
|
4
|
+
var subtract = (...args) => `calc(${toExpression("-", ...args)})`;
|
|
5
|
+
var multiply = (...args) => `calc(${toExpression("*", ...args)})`;
|
|
6
|
+
var divide = (...args) => `calc(${toExpression("/", ...args)})`;
|
|
7
|
+
var negate = (value) => {
|
|
8
|
+
if (value != null && !isNaN(parseFloat(value.toString())))
|
|
9
|
+
return String(value).startsWith("-") ? String(value).slice(1) : `-${value}`;
|
|
10
|
+
return multiply(value, -1);
|
|
11
|
+
};
|
|
12
|
+
var calc = Object.assign(
|
|
13
|
+
(x) => ({
|
|
14
|
+
add: (...args) => calc(add(x, ...args)),
|
|
15
|
+
subtract: (...args) => calc(subtract(x, ...args)),
|
|
16
|
+
multiply: (...args) => calc(multiply(x, ...args)),
|
|
17
|
+
divide: (...args) => calc(divide(x, ...args)),
|
|
18
|
+
negate: () => calc(negate(x))
|
|
19
|
+
}),
|
|
20
|
+
{
|
|
21
|
+
add,
|
|
22
|
+
subtract,
|
|
23
|
+
multiply,
|
|
24
|
+
divide,
|
|
25
|
+
negate
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
calc
|
|
31
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/number.ts
|
|
2
|
+
var toNumber = (n) => {
|
|
3
|
+
const num = parseFloat(n);
|
|
4
|
+
return typeof num !== "number" || Number.isNaN(num) ? 0 : num;
|
|
5
|
+
};
|
|
6
|
+
var toPrecision = (n, precision) => {
|
|
7
|
+
n = toNumber(n);
|
|
8
|
+
const scale = 10 ** (precision != null ? precision : 10);
|
|
9
|
+
n = Math.round(n * scale) / scale;
|
|
10
|
+
return precision ? n.toFixed(precision) : n.toString();
|
|
11
|
+
};
|
|
12
|
+
var countDecimal = (n) => {
|
|
13
|
+
if (!Number.isFinite(n))
|
|
14
|
+
return 0;
|
|
15
|
+
let e = 1;
|
|
16
|
+
let p = 0;
|
|
17
|
+
while (Math.round(n * e) / e !== n) {
|
|
18
|
+
e *= 10;
|
|
19
|
+
p += 1;
|
|
20
|
+
}
|
|
21
|
+
return p;
|
|
22
|
+
};
|
|
23
|
+
var roundNumberToStep = (n, from, step) => {
|
|
24
|
+
const nextValue = Math.round((n - from) / step) * step + from;
|
|
25
|
+
const precision = countDecimal(step);
|
|
26
|
+
return toPrecision(nextValue, precision);
|
|
27
|
+
};
|
|
28
|
+
var valueToPercent = (n, min, max) => (n - min) * 100 / (max - min);
|
|
29
|
+
var percentToValue = (n, min, max) => (max - min) * n + min;
|
|
30
|
+
var clampNumber = (n, min, max) => Math.min(Math.max(n, min), max);
|
|
31
|
+
|
|
32
|
+
export {
|
|
33
|
+
toPrecision,
|
|
34
|
+
countDecimal,
|
|
35
|
+
roundNumberToStep,
|
|
36
|
+
valueToPercent,
|
|
37
|
+
percentToValue,
|
|
38
|
+
clampNumber
|
|
39
|
+
};
|
package/dist/color.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as _ctrl_tinycolor from '@ctrl/tinycolor';
|
|
2
|
+
import { Dict } from './index.types.js';
|
|
3
|
+
|
|
4
|
+
declare const getColor: (color: string, fallback?: string) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string | number | _ctrl_tinycolor.RGB | _ctrl_tinycolor.HSL | _ctrl_tinycolor.HSV | undefined;
|
|
5
|
+
declare const lightenColor: (color: string, amount: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
|
|
6
|
+
declare const darkenColor: (color: string, amount: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
|
|
7
|
+
declare const brightenColor: (color: string, amount: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
|
|
8
|
+
declare const tintColor: (color: string, amount: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
|
|
9
|
+
declare const shadeColor: (color: string, amount: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
|
|
10
|
+
declare const transparentizeColor: (color: string, alpha: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
|
|
11
|
+
declare const toneColor: (color: string, l: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
|
|
12
|
+
declare const randomColor: ({ string, colors }?: {
|
|
13
|
+
string?: string | undefined;
|
|
14
|
+
colors?: string[] | undefined;
|
|
15
|
+
}) => string;
|
|
16
|
+
declare const isLight: (color: string) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => boolean;
|
|
17
|
+
declare const isDark: (color: string) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => boolean;
|
|
18
|
+
|
|
19
|
+
export { brightenColor, darkenColor, getColor, isDark, isLight, lightenColor, randomColor, shadeColor, tintColor, toneColor, transparentizeColor };
|
package/dist/color.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/color.ts
|
|
21
|
+
var color_exports = {};
|
|
22
|
+
__export(color_exports, {
|
|
23
|
+
brightenColor: () => brightenColor,
|
|
24
|
+
darkenColor: () => darkenColor,
|
|
25
|
+
getColor: () => getColor,
|
|
26
|
+
isDark: () => isDark,
|
|
27
|
+
isLight: () => isLight,
|
|
28
|
+
lightenColor: () => lightenColor,
|
|
29
|
+
randomColor: () => randomColor,
|
|
30
|
+
shadeColor: () => shadeColor,
|
|
31
|
+
tintColor: () => tintColor,
|
|
32
|
+
toneColor: () => toneColor,
|
|
33
|
+
transparentizeColor: () => transparentizeColor
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(color_exports);
|
|
36
|
+
var import_tinycolor = require("@ctrl/tinycolor");
|
|
37
|
+
|
|
38
|
+
// src/assertion.ts
|
|
39
|
+
var isArray = (value) => Array.isArray(value);
|
|
40
|
+
|
|
41
|
+
// src/object.ts
|
|
42
|
+
var getObject = (obj, path, fallback, i) => {
|
|
43
|
+
const k = typeof path === "string" ? path.split(".") : [path];
|
|
44
|
+
for (i = 0; i < k.length; i += 1) {
|
|
45
|
+
if (!obj)
|
|
46
|
+
break;
|
|
47
|
+
obj = obj[k[i]];
|
|
48
|
+
}
|
|
49
|
+
return obj === void 0 ? fallback : obj;
|
|
50
|
+
};
|
|
51
|
+
var memoizeObject = (func) => {
|
|
52
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
53
|
+
const memoizedFunc = (obj, path, fallback, i) => {
|
|
54
|
+
if (typeof obj === "undefined") {
|
|
55
|
+
return func(obj, path, fallback);
|
|
56
|
+
}
|
|
57
|
+
if (!cache.has(obj))
|
|
58
|
+
cache.set(obj, /* @__PURE__ */ new Map());
|
|
59
|
+
const map = cache.get(obj);
|
|
60
|
+
if (map.has(path))
|
|
61
|
+
return map.get(path);
|
|
62
|
+
const value = func(obj, path, fallback, i);
|
|
63
|
+
map.set(path, value);
|
|
64
|
+
return value;
|
|
65
|
+
};
|
|
66
|
+
return memoizedFunc;
|
|
67
|
+
};
|
|
68
|
+
var getMemoizedObject = memoizeObject(getObject);
|
|
69
|
+
|
|
70
|
+
// src/color.ts
|
|
71
|
+
var getColor = (color, fallback) => (theme, colorMode) => {
|
|
72
|
+
const hex = getMemoizedObject(
|
|
73
|
+
theme,
|
|
74
|
+
`colors.${color}`,
|
|
75
|
+
color
|
|
76
|
+
);
|
|
77
|
+
if (isArray(hex)) {
|
|
78
|
+
const [lightHex, darkHex] = hex;
|
|
79
|
+
const { isValid, originalInput } = new import_tinycolor.TinyColor(colorMode !== "dark" ? lightHex : darkHex);
|
|
80
|
+
return isValid ? originalInput : fallback;
|
|
81
|
+
} else {
|
|
82
|
+
const { isValid, originalInput } = new import_tinycolor.TinyColor(hex);
|
|
83
|
+
return isValid ? originalInput : fallback;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var lightenColor = (color, amount) => (theme, colorMode) => {
|
|
87
|
+
const raw = getColor(color)(theme, colorMode);
|
|
88
|
+
return new import_tinycolor.TinyColor(raw).lighten(amount).toRgbString();
|
|
89
|
+
};
|
|
90
|
+
var darkenColor = (color, amount) => (theme, colorMode) => {
|
|
91
|
+
const raw = getColor(color)(theme, colorMode);
|
|
92
|
+
return new import_tinycolor.TinyColor(raw).darken(amount).toRgbString();
|
|
93
|
+
};
|
|
94
|
+
var brightenColor = (color, amount) => (theme, colorMode) => {
|
|
95
|
+
const raw = getColor(color)(theme, colorMode);
|
|
96
|
+
return new import_tinycolor.TinyColor(raw).brighten(amount).toRgbString();
|
|
97
|
+
};
|
|
98
|
+
var tintColor = (color, amount) => (theme, colorMode) => {
|
|
99
|
+
const raw = getColor(color)(theme, colorMode);
|
|
100
|
+
return new import_tinycolor.TinyColor(raw).tint(amount).toRgbString();
|
|
101
|
+
};
|
|
102
|
+
var shadeColor = (color, amount) => (theme, colorMode) => {
|
|
103
|
+
const raw = getColor(color)(theme, colorMode);
|
|
104
|
+
return new import_tinycolor.TinyColor(raw).shade(amount).toRgbString();
|
|
105
|
+
};
|
|
106
|
+
var transparentizeColor = (color, alpha) => (theme, colorMode) => {
|
|
107
|
+
const raw = getColor(color)(theme, colorMode);
|
|
108
|
+
return new import_tinycolor.TinyColor(raw).setAlpha(alpha).toRgbString();
|
|
109
|
+
};
|
|
110
|
+
var toneColor = (color, l) => (theme, colorMode) => {
|
|
111
|
+
const raw = getColor(color)(theme, colorMode);
|
|
112
|
+
if (l < 0 || 900 < l)
|
|
113
|
+
return color;
|
|
114
|
+
let n = (l - 500) / 10;
|
|
115
|
+
const isLighten = n <= 0;
|
|
116
|
+
if (isLighten)
|
|
117
|
+
n *= -1;
|
|
118
|
+
if (n !== 0)
|
|
119
|
+
n = n - 5 * (isLighten ? 1 : -1);
|
|
120
|
+
return new import_tinycolor.TinyColor(raw)[isLighten ? "lighten" : "shade"](n).toString();
|
|
121
|
+
};
|
|
122
|
+
var randomColor = ({ string, colors } = {}) => {
|
|
123
|
+
const fallback = randomHex();
|
|
124
|
+
if (string && colors)
|
|
125
|
+
return randomColorFromList(string, colors);
|
|
126
|
+
if (string && !colors)
|
|
127
|
+
return randomColorFromString(string);
|
|
128
|
+
if (colors && !string)
|
|
129
|
+
return randomFromList(colors);
|
|
130
|
+
return fallback;
|
|
131
|
+
};
|
|
132
|
+
var randomHex = () => `#${Math.floor(Math.random() * 16777215).toString(16).padEnd(6, "0")}`;
|
|
133
|
+
var randomColorFromString = (str) => {
|
|
134
|
+
let hash = 0;
|
|
135
|
+
if (str.length === 0)
|
|
136
|
+
return hash.toString();
|
|
137
|
+
for (let i = 0; i < str.length; i += 1) {
|
|
138
|
+
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
139
|
+
hash = hash & hash;
|
|
140
|
+
}
|
|
141
|
+
let color = "#";
|
|
142
|
+
for (let j = 0; j < 3; j += 1) {
|
|
143
|
+
const value = hash >> j * 8 & 255;
|
|
144
|
+
color += `00${value.toString(16)}`.substr(-2);
|
|
145
|
+
}
|
|
146
|
+
return color;
|
|
147
|
+
};
|
|
148
|
+
var randomColorFromList = (str, list) => {
|
|
149
|
+
let index = 0;
|
|
150
|
+
if (str.length === 0)
|
|
151
|
+
return list[0];
|
|
152
|
+
for (let i = 0; i < str.length; i += 1) {
|
|
153
|
+
index = str.charCodeAt(i) + ((index << 5) - index);
|
|
154
|
+
index = index & index;
|
|
155
|
+
}
|
|
156
|
+
index = (index % list.length + list.length) % list.length;
|
|
157
|
+
return list[index];
|
|
158
|
+
};
|
|
159
|
+
var randomFromList = (list) => list[Math.floor(Math.random() * list.length)];
|
|
160
|
+
var isLight = (color) => (theme, colorMode) => {
|
|
161
|
+
const raw = getColor(color)(theme, colorMode);
|
|
162
|
+
return new import_tinycolor.TinyColor(raw).isLight();
|
|
163
|
+
};
|
|
164
|
+
var isDark = (color) => (theme, colorMode) => {
|
|
165
|
+
const raw = getColor(color)(theme, colorMode);
|
|
166
|
+
return new import_tinycolor.TinyColor(raw).isDark();
|
|
167
|
+
};
|
|
168
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
169
|
+
0 && (module.exports = {
|
|
170
|
+
brightenColor,
|
|
171
|
+
darkenColor,
|
|
172
|
+
getColor,
|
|
173
|
+
isDark,
|
|
174
|
+
isLight,
|
|
175
|
+
lightenColor,
|
|
176
|
+
randomColor,
|
|
177
|
+
shadeColor,
|
|
178
|
+
tintColor,
|
|
179
|
+
toneColor,
|
|
180
|
+
transparentizeColor
|
|
181
|
+
});
|
package/dist/color.mjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
brightenColor,
|
|
3
|
+
darkenColor,
|
|
4
|
+
getColor,
|
|
5
|
+
isDark,
|
|
6
|
+
isLight,
|
|
7
|
+
lightenColor,
|
|
8
|
+
randomColor,
|
|
9
|
+
shadeColor,
|
|
10
|
+
tintColor,
|
|
11
|
+
toneColor,
|
|
12
|
+
transparentizeColor
|
|
13
|
+
} from "./chunk-A6J4FUU7.mjs";
|
|
14
|
+
import "./chunk-SLJ4M7XC.mjs";
|
|
15
|
+
import "./chunk-VYMGBE25.mjs";
|
|
16
|
+
import "./chunk-BZAW2D6U.mjs";
|
|
17
|
+
import "./chunk-PURW64JE.mjs";
|
|
18
|
+
import "./chunk-IVGIIDMV.mjs";
|
|
19
|
+
import "./chunk-R5OUKGQ5.mjs";
|
|
20
|
+
import "./chunk-FW7XS4NH.mjs";
|
|
21
|
+
import "./chunk-PF7LRFIA.mjs";
|
|
22
|
+
export {
|
|
23
|
+
brightenColor,
|
|
24
|
+
darkenColor,
|
|
25
|
+
getColor,
|
|
26
|
+
isDark,
|
|
27
|
+
isLight,
|
|
28
|
+
lightenColor,
|
|
29
|
+
randomColor,
|
|
30
|
+
shadeColor,
|
|
31
|
+
tintColor,
|
|
32
|
+
toneColor,
|
|
33
|
+
transparentizeColor
|
|
34
|
+
};
|
package/dist/dom.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
2
|
+
|
|
3
|
+
declare const createdDom: () => boolean;
|
|
4
|
+
declare const getPlatform: () => string;
|
|
5
|
+
declare const vendor: (v: RegExp) => boolean;
|
|
6
|
+
declare const platform: (v: RegExp) => boolean;
|
|
7
|
+
declare const isMac: () => boolean;
|
|
8
|
+
declare const isApple: () => boolean;
|
|
9
|
+
declare const isSafari: () => boolean;
|
|
10
|
+
declare const isElement: (el: any) => el is Element;
|
|
11
|
+
declare const isHTMLElement: (el: any) => el is HTMLElement;
|
|
12
|
+
declare const isHidden: (el: HTMLElement) => boolean;
|
|
13
|
+
declare const isDisabled: (el: HTMLElement) => boolean;
|
|
14
|
+
declare const hasTabIndex: (el: HTMLElement) => boolean;
|
|
15
|
+
declare const isContentEditable: (el: HTMLElement) => boolean;
|
|
16
|
+
declare const isContains: (parent: HTMLElement | null, child: HTMLElement | null) => boolean | undefined;
|
|
17
|
+
declare const getEventRelatedTarget: (ev: React__default.FocusEvent | React__default.MouseEvent) => HTMLElement | null;
|
|
18
|
+
type Booleanish = boolean | 'true' | 'false';
|
|
19
|
+
declare const dataAttr: (condition: boolean | undefined) => Booleanish;
|
|
20
|
+
declare const ariaAttr: (condition: boolean | undefined) => boolean | undefined;
|
|
21
|
+
type FocusableElement = {
|
|
22
|
+
focus: (options?: FocusOptions) => void;
|
|
23
|
+
};
|
|
24
|
+
declare const getAllFocusable: <T extends HTMLElement>(container: T) => T[];
|
|
25
|
+
declare const isFocusable: (el: HTMLElement) => boolean;
|
|
26
|
+
declare const hasNegativeTabIndex: (el: HTMLElement) => boolean;
|
|
27
|
+
declare const isTabbable: (el?: HTMLElement | null) => boolean;
|
|
28
|
+
declare const getOwnerWindow: (node?: Element | null) => Window & typeof globalThis;
|
|
29
|
+
declare const getOwnerDocument: (el?: Element | null) => Document;
|
|
30
|
+
declare const getActiveElement: (el?: HTMLElement) => HTMLElement;
|
|
31
|
+
declare const isActiveElement: (el: HTMLElement) => boolean;
|
|
32
|
+
|
|
33
|
+
export { FocusableElement, ariaAttr, createdDom, dataAttr, getActiveElement, getAllFocusable, getEventRelatedTarget, getOwnerDocument, getOwnerWindow, getPlatform, hasNegativeTabIndex, hasTabIndex, isActiveElement, isApple, isContains, isContentEditable, isDisabled, isElement, isFocusable, isHTMLElement, isHidden, isMac, isSafari, isTabbable, platform, vendor };
|