@yamada-ui/utils 0.0.0-dev-20230606151107

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.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +31 -0
  3. package/dist/array.d.ts +3 -0
  4. package/dist/array.js +30 -0
  5. package/dist/array.mjs +6 -0
  6. package/dist/assertion.d.ts +16 -0
  7. package/dist/assertion.js +63 -0
  8. package/dist/assertion.mjs +28 -0
  9. package/dist/calc.d.ts +17 -0
  10. package/dist/calc.js +55 -0
  11. package/dist/calc.mjs +6 -0
  12. package/dist/chunk-BZAW2D6U.mjs +6 -0
  13. package/dist/chunk-FW7XS4NH.mjs +120 -0
  14. package/dist/chunk-HUEOJZVC.mjs +403 -0
  15. package/dist/chunk-IVGIIDMV.mjs +28 -0
  16. package/dist/chunk-PF7LRFIA.mjs +51 -0
  17. package/dist/chunk-PURW64JE.mjs +6 -0
  18. package/dist/chunk-R5OUKGQ5.mjs +31 -0
  19. package/dist/chunk-SLJ4M7XC.mjs +0 -0
  20. package/dist/chunk-VYMGBE25.mjs +39 -0
  21. package/dist/color.d.ts +18 -0
  22. package/dist/color.js +183 -0
  23. package/dist/color.mjs +34 -0
  24. package/dist/dom.d.ts +33 -0
  25. package/dist/dom.js +168 -0
  26. package/dist/dom.mjs +54 -0
  27. package/dist/event.d.ts +30 -0
  28. package/dist/event.js +83 -0
  29. package/dist/event.mjs +22 -0
  30. package/dist/function.d.ts +6 -0
  31. package/dist/function.js +50 -0
  32. package/dist/function.mjs +20 -0
  33. package/dist/index.d.ts +13 -0
  34. package/dist/index.js +798 -0
  35. package/dist/index.mjs +221 -0
  36. package/dist/index.types.d.ts +14 -0
  37. package/dist/index.types.js +18 -0
  38. package/dist/index.types.mjs +1 -0
  39. package/dist/number.d.ts +8 -0
  40. package/dist/number.js +68 -0
  41. package/dist/number.mjs +16 -0
  42. package/dist/object.d.ts +18 -0
  43. package/dist/object.js +192 -0
  44. package/dist/object.mjs +40 -0
  45. package/dist/react.d.ts +44 -0
  46. package/dist/react.js +176 -0
  47. package/dist/react.mjs +46 -0
  48. package/dist/string.d.ts +3 -0
  49. package/dist/string.js +30 -0
  50. package/dist/string.mjs +6 -0
  51. package/package.json +66 -0
@@ -0,0 +1,403 @@
1
+ import {
2
+ isArray,
3
+ isFunction,
4
+ isNumber,
5
+ isObject,
6
+ isString
7
+ } from "./chunk-IVGIIDMV.mjs";
8
+
9
+ // src/function.ts
10
+ var noop = () => {
11
+ };
12
+ var runIfFunc = (valOrFunc, ...args) => isFunction(valOrFunc) ? valOrFunc(...args) : valOrFunc;
13
+ var handlerAll = (...funcs) => (event) => {
14
+ funcs.some((func) => {
15
+ func == null ? void 0 : func(event);
16
+ return event == null ? void 0 : event.defaultPrevented;
17
+ });
18
+ };
19
+ var funcAll = (...funcs) => (arg) => funcs.forEach((func) => func == null ? void 0 : func(arg));
20
+
21
+ // src/react.tsx
22
+ import * as React from "react";
23
+ var createContext2 = ({
24
+ strict = true,
25
+ errorMessage = "useContext: `context` is undefined. Seems you forgot to wrap component within the Provider",
26
+ name
27
+ } = {}) => {
28
+ const Context = React.createContext(void 0);
29
+ Context.displayName = name;
30
+ const useContext2 = () => {
31
+ var _a;
32
+ const context = React.useContext(Context);
33
+ if (!context && strict) {
34
+ const error = new Error(errorMessage);
35
+ error.name = "ContextError";
36
+ (_a = Error.captureStackTrace) == null ? void 0 : _a.call(Error, error, useContext2);
37
+ throw error;
38
+ }
39
+ return context;
40
+ };
41
+ return [Context.Provider, useContext2, Context];
42
+ };
43
+ var useSafeLayoutEffect = Boolean(globalThis == null ? void 0 : globalThis.document) ? React.useLayoutEffect : React.useEffect;
44
+ var useUnmountEffect = (callback) => (
45
+ // eslint-disable-next-line react-hooks/exhaustive-deps
46
+ React.useEffect(() => () => callback(), [])
47
+ );
48
+ var useIsMounted = () => {
49
+ const isMounted = React.useRef(false);
50
+ useSafeLayoutEffect(() => {
51
+ isMounted.current = true;
52
+ return () => {
53
+ isMounted.current = false;
54
+ };
55
+ }, []);
56
+ return isMounted;
57
+ };
58
+ var getValidChildren = (children) => React.Children.toArray(children).filter(
59
+ (child) => React.isValidElement(child)
60
+ );
61
+ var isValidElement2 = (child) => React.isValidElement(child) || isString(child) || isNumber(child);
62
+ var findChildren = (children, ...types) => children.find((child) => types.some((type) => child.type === type)) ? children.sort(
63
+ (a, b) => types.some((type) => a.type === type) ? -1 : types.some((type) => b.type === type) ? 1 : 0
64
+ ) : [void 0, ...children];
65
+ var includesChildren = (children, ...types) => children.some((child) => {
66
+ if (types.some((type) => child.type === type))
67
+ return true;
68
+ const children2 = getValidChildren(child.props.children);
69
+ return children2.length ? includesChildren(children2, ...types) : false;
70
+ });
71
+ var omitChildren = (children, ...types) => children.filter((child) => types.every((type) => child.type !== type));
72
+ var pickChildren = (children, ...types) => children.filter((child) => types.every((type) => child.type === type));
73
+ var cx = (...classNames) => classNames.filter(Boolean).join(" ");
74
+ var isRefObject = (val) => "current" in val;
75
+ var assignRef = (ref, value) => {
76
+ if (ref == null)
77
+ return;
78
+ if (typeof ref === "function") {
79
+ ref(value);
80
+ return;
81
+ }
82
+ try {
83
+ ref.current = value;
84
+ } catch (error) {
85
+ throw new Error(`Cannot assign value '${value}' to ref '${ref}'`);
86
+ }
87
+ };
88
+ var mergeRefs = (...refs) => (node) => {
89
+ refs.forEach((ref) => {
90
+ assignRef(ref, node);
91
+ });
92
+ };
93
+ var useMergeRefs = (...refs) => React.useMemo(() => mergeRefs(...refs), [refs]);
94
+ var useCallbackRef = (callback, deps = []) => {
95
+ const callbackRef = React.useRef(callback);
96
+ React.useEffect(() => {
97
+ callbackRef.current = callback;
98
+ });
99
+ return React.useCallback((...args) => {
100
+ var _a;
101
+ return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
102
+ }, deps);
103
+ };
104
+ var useUpdateEffect = (callback, deps) => {
105
+ const renderCycleRef = React.useRef(false);
106
+ const effectCycleRef = React.useRef(false);
107
+ React.useEffect(() => {
108
+ const mounted = renderCycleRef.current;
109
+ const run = mounted && effectCycleRef.current;
110
+ if (run)
111
+ return callback();
112
+ effectCycleRef.current = true;
113
+ }, deps);
114
+ React.useEffect(() => {
115
+ renderCycleRef.current = true;
116
+ return () => {
117
+ renderCycleRef.current = false;
118
+ };
119
+ }, []);
120
+ };
121
+
122
+ // src/color.ts
123
+ import { toHex, parseToRgba, transparentize, mix, darken, lighten } from "color2k";
124
+ var getColor = (color, fallback) => (theme, colorMode) => {
125
+ const hex = getMemoizedObject(
126
+ theme,
127
+ `colors.${color}`,
128
+ color
129
+ );
130
+ try {
131
+ if (isArray(hex)) {
132
+ const [lightHex, darkHex] = hex;
133
+ return toHex(String(colorMode !== "dark" ? lightHex : darkHex));
134
+ } else {
135
+ return toHex(String(hex));
136
+ }
137
+ } catch {
138
+ return fallback != null ? fallback : "#000000";
139
+ }
140
+ };
141
+ var lightenColor = (color, amount) => (theme, colorMode) => {
142
+ const raw = getColor(color)(theme, colorMode);
143
+ return toHex(lighten(raw, amount / 100));
144
+ };
145
+ var darkenColor = (color, amount) => (theme, colorMode) => {
146
+ const raw = getColor(color)(theme, colorMode);
147
+ return toHex(darken(raw, amount / 100));
148
+ };
149
+ var tintColor = (color, amount) => (theme, colorMode) => {
150
+ const raw = getColor(color)(theme, colorMode);
151
+ return toHex(mix(raw, "#fff", amount));
152
+ };
153
+ var shadeColor = (color, amount) => (theme, colorMode) => {
154
+ const raw = getColor(color)(theme, colorMode);
155
+ return toHex(mix(raw, "#000", amount / 100));
156
+ };
157
+ var transparentizeColor = (color, alpha) => (theme, colorMode) => {
158
+ const raw = getColor(color)(theme, colorMode);
159
+ return transparentize(raw, 1 - alpha);
160
+ };
161
+ var toneColor = (color, l) => (theme, colorMode) => {
162
+ const raw = getColor(color)(theme, colorMode);
163
+ if (l < 0 || 900 < l)
164
+ return color;
165
+ let n = (l - 500) / 10;
166
+ const isLighten = n <= 0;
167
+ if (isLighten)
168
+ n *= -1;
169
+ if (n !== 0)
170
+ n = n - 5 * (isLighten ? 1 : -1);
171
+ return toHex(isLighten ? lighten(raw, n / 100) : mix(raw, "#000", n / 100));
172
+ };
173
+ var randomColor = ({ string, colors } = {}) => {
174
+ const fallback = randomHex();
175
+ if (string && colors)
176
+ return randomColorFromList(string, colors);
177
+ if (string && !colors)
178
+ return randomColorFromString(string);
179
+ if (colors && !string)
180
+ return randomFromList(colors);
181
+ return fallback;
182
+ };
183
+ var randomHex = () => `#${Math.floor(Math.random() * 16777215).toString(16).padEnd(6, "0")}`;
184
+ var randomColorFromString = (str) => {
185
+ let hash = 0;
186
+ if (str.length === 0)
187
+ return hash.toString();
188
+ for (let i = 0; i < str.length; i += 1) {
189
+ hash = str.charCodeAt(i) + ((hash << 5) - hash);
190
+ hash = hash & hash;
191
+ }
192
+ let color = "#";
193
+ for (let j = 0; j < 3; j += 1) {
194
+ const value = hash >> j * 8 & 255;
195
+ color += `00${value.toString(16)}`.substr(-2);
196
+ }
197
+ return color;
198
+ };
199
+ var randomColorFromList = (str, list) => {
200
+ let index = 0;
201
+ if (str.length === 0)
202
+ return list[0];
203
+ for (let i = 0; i < str.length; i += 1) {
204
+ index = str.charCodeAt(i) + ((index << 5) - index);
205
+ index = index & index;
206
+ }
207
+ index = (index % list.length + list.length) % list.length;
208
+ return list[index];
209
+ };
210
+ var randomFromList = (list) => list[Math.floor(Math.random() * list.length)];
211
+ var getBrightness = (color) => {
212
+ const [r, g, b] = parseToRgba(color);
213
+ return (r * 299 + g * 587 + b * 114) / 1e3;
214
+ };
215
+ var isTone = (color) => (theme, colorMode) => {
216
+ const raw = getColor(color)(theme, colorMode);
217
+ const brightness = getBrightness(raw);
218
+ const isDark2 = brightness < 128;
219
+ return isDark2 ? "dark" : "light";
220
+ };
221
+ var isLight = (color) => (theme, colorMode) => isTone(color)(theme, colorMode) === "dark";
222
+ var isDark = (color) => (theme, colorMode) => isTone(color)(theme, colorMode) === "light";
223
+
224
+ // src/object.ts
225
+ var omitObject = (obj, keys) => {
226
+ const result = {};
227
+ Object.keys(obj).forEach((key) => {
228
+ if (keys.includes(key))
229
+ return;
230
+ result[key] = obj[key];
231
+ });
232
+ return result;
233
+ };
234
+ var pickObject = (obj, keys) => {
235
+ const result = {};
236
+ keys.forEach((key) => {
237
+ if (key in obj)
238
+ result[key] = obj[key];
239
+ });
240
+ return result;
241
+ };
242
+ var splitObject = (obj, keys) => {
243
+ const picked = {};
244
+ const omitted = {};
245
+ for (const [key, value] of Object.entries(obj)) {
246
+ if (keys.includes(key)) {
247
+ picked[key] = value;
248
+ } else {
249
+ omitted[key] = value;
250
+ }
251
+ }
252
+ return [picked, omitted];
253
+ };
254
+ var filterObject = (obj, func) => {
255
+ const result = {};
256
+ Object.entries(obj).forEach(([key, value]) => {
257
+ const shouldPass = func(key, value, obj);
258
+ if (shouldPass)
259
+ result[key] = value;
260
+ });
261
+ return result;
262
+ };
263
+ var filterUndefined = (obj) => filterObject(obj, (_, val) => val !== null && val !== void 0);
264
+ var merge = (target, source, overrideArray = false) => {
265
+ let result = Object.assign({}, target);
266
+ if (isObject(target) && isObject(source)) {
267
+ for (const [sourceKey, sourceValue] of Object.entries(source)) {
268
+ const targetValue = target[sourceKey];
269
+ if (overrideArray && Array.isArray(sourceValue) && Array.isArray(targetValue)) {
270
+ result[sourceKey] = targetValue.concat(...sourceValue);
271
+ } else if (!isFunction(sourceValue) && isObject(sourceValue) && target.hasOwnProperty(sourceKey)) {
272
+ result[sourceKey] = merge(targetValue, sourceValue, overrideArray);
273
+ } else {
274
+ Object.assign(result, { [sourceKey]: sourceValue });
275
+ }
276
+ }
277
+ }
278
+ return result;
279
+ };
280
+ var flattenObject = (obj, maxDepth = Infinity) => {
281
+ if (!isObject(obj) && !isArray(obj) || !maxDepth)
282
+ return obj;
283
+ return Object.entries(obj).reduce((result, [key, value]) => {
284
+ if (isObject(value)) {
285
+ Object.entries(flattenObject(value, maxDepth - 1)).forEach(([childKey, childValue]) => {
286
+ result[`${key}.${childKey}`] = childValue;
287
+ });
288
+ } else {
289
+ result[key] = value;
290
+ }
291
+ return result;
292
+ }, {});
293
+ };
294
+ var objectFromEntries = (entries) => entries.reduce((result, [key, value]) => {
295
+ result[key] = value;
296
+ return result;
297
+ }, {});
298
+ var keysFormObject = (obj) => Object.keys(obj);
299
+ var replaceObject = (objOrArray, callBack) => {
300
+ if (isArray(objOrArray)) {
301
+ return objOrArray.map(callBack);
302
+ } else if (isObject(objOrArray)) {
303
+ return Object.entries(objOrArray).reduce((obj, [key, value]) => {
304
+ obj[key] = callBack(value);
305
+ return obj;
306
+ }, {});
307
+ } else {
308
+ return callBack(objOrArray);
309
+ }
310
+ };
311
+ var getObject = (obj, path, fallback, i) => {
312
+ const k = typeof path === "string" ? path.split(".") : [path];
313
+ for (i = 0; i < k.length; i += 1) {
314
+ if (!obj)
315
+ break;
316
+ obj = obj[k[i]];
317
+ }
318
+ return obj === void 0 ? fallback : obj;
319
+ };
320
+ var memoizeObject = (func) => {
321
+ const cache = /* @__PURE__ */ new WeakMap();
322
+ const memoizedFunc = (obj, path, fallback, i) => {
323
+ if (typeof obj === "undefined") {
324
+ return func(obj, path, fallback);
325
+ }
326
+ if (!cache.has(obj))
327
+ cache.set(obj, /* @__PURE__ */ new Map());
328
+ const map = cache.get(obj);
329
+ if (map.has(path))
330
+ return map.get(path);
331
+ const value = func(obj, path, fallback, i);
332
+ map.set(path, value);
333
+ return value;
334
+ };
335
+ return memoizedFunc;
336
+ };
337
+ var getMemoizedObject = memoizeObject(getObject);
338
+ var assignAfter = (target, ...sources) => {
339
+ if (target == null)
340
+ throw new TypeError("Cannot convert undefined or null to object");
341
+ const result = { ...target };
342
+ for (const nextSource of sources) {
343
+ if (nextSource == null)
344
+ continue;
345
+ for (const nextKey in nextSource) {
346
+ if (!Object.prototype.hasOwnProperty.call(nextSource, nextKey))
347
+ continue;
348
+ if (nextKey in result)
349
+ delete result[nextKey];
350
+ result[nextKey] = nextSource[nextKey];
351
+ }
352
+ }
353
+ return result;
354
+ };
355
+
356
+ export {
357
+ omitObject,
358
+ pickObject,
359
+ splitObject,
360
+ filterObject,
361
+ filterUndefined,
362
+ merge,
363
+ flattenObject,
364
+ objectFromEntries,
365
+ keysFormObject,
366
+ replaceObject,
367
+ getObject,
368
+ memoizeObject,
369
+ getMemoizedObject,
370
+ assignAfter,
371
+ noop,
372
+ runIfFunc,
373
+ handlerAll,
374
+ funcAll,
375
+ createContext2 as createContext,
376
+ useSafeLayoutEffect,
377
+ useUnmountEffect,
378
+ useIsMounted,
379
+ getValidChildren,
380
+ isValidElement2 as isValidElement,
381
+ findChildren,
382
+ includesChildren,
383
+ omitChildren,
384
+ pickChildren,
385
+ cx,
386
+ isRefObject,
387
+ assignRef,
388
+ mergeRefs,
389
+ useMergeRefs,
390
+ useCallbackRef,
391
+ useUpdateEffect,
392
+ getColor,
393
+ lightenColor,
394
+ darkenColor,
395
+ tintColor,
396
+ shadeColor,
397
+ transparentizeColor,
398
+ toneColor,
399
+ randomColor,
400
+ isTone,
401
+ isLight,
402
+ isDark
403
+ };
@@ -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,6 @@
1
+ // src/array.ts
2
+ var filterEmpty = (array) => array.filter((value) => value != null);
3
+
4
+ export {
5
+ filterEmpty
6
+ };
@@ -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
+ };
@@ -0,0 +1,18 @@
1
+ import { Dict } from './index.types.js';
2
+
3
+ declare const getColor: (color: string, fallback?: string) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
4
+ declare const lightenColor: (color: string, amount: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
5
+ declare const darkenColor: (color: string, amount: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
6
+ declare const tintColor: (color: string, amount: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
7
+ declare const shadeColor: (color: string, amount: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
8
+ declare const transparentizeColor: (color: string, alpha: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
9
+ declare const toneColor: (color: string, l: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
10
+ declare const randomColor: ({ string, colors }?: {
11
+ string?: string | undefined;
12
+ colors?: string[] | undefined;
13
+ }) => string;
14
+ declare const isTone: (color: string) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => "light" | "dark";
15
+ declare const isLight: (color: string) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => boolean;
16
+ declare const isDark: (color: string) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => boolean;
17
+
18
+ export { darkenColor, getColor, isDark, isLight, isTone, lightenColor, randomColor, shadeColor, tintColor, toneColor, transparentizeColor };