@zag-js/utils 1.34.0 → 1.35.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.
@@ -0,0 +1,14 @@
1
+ type AnyFunction = (...args: any[]) => any;
2
+ declare const isDev: () => boolean;
3
+ declare const isArray: (v: any) => v is any[];
4
+ declare const isBoolean: (v: any) => v is boolean;
5
+ declare const isObjectLike: (v: any) => v is Record<string, any>;
6
+ declare const isObject: (v: any) => v is Record<string, any>;
7
+ declare const isNumber: (v: any) => v is number;
8
+ declare const isString: (v: any) => v is string;
9
+ declare const isFunction: (v: any) => v is AnyFunction;
10
+ declare const isNull: (v: any) => v is null | undefined;
11
+ declare const hasProp: <T extends string>(obj: any, prop: T) => obj is Record<T, any>;
12
+ declare const isPlainObject: (v: any) => boolean;
13
+
14
+ export { hasProp, isArray, isBoolean, isDev, isFunction, isNull, isNumber, isObject, isObjectLike, isPlainObject, isString };
@@ -0,0 +1,14 @@
1
+ type AnyFunction = (...args: any[]) => any;
2
+ declare const isDev: () => boolean;
3
+ declare const isArray: (v: any) => v is any[];
4
+ declare const isBoolean: (v: any) => v is boolean;
5
+ declare const isObjectLike: (v: any) => v is Record<string, any>;
6
+ declare const isObject: (v: any) => v is Record<string, any>;
7
+ declare const isNumber: (v: any) => v is number;
8
+ declare const isString: (v: any) => v is string;
9
+ declare const isFunction: (v: any) => v is AnyFunction;
10
+ declare const isNull: (v: any) => v is null | undefined;
11
+ declare const hasProp: <T extends string>(obj: any, prop: T) => obj is Record<T, any>;
12
+ declare const isPlainObject: (v: any) => boolean;
13
+
14
+ export { hasProp, isArray, isBoolean, isDev, isFunction, isNull, isNumber, isObject, isObjectLike, isPlainObject, isString };
package/dist/guard.js ADDED
@@ -0,0 +1,72 @@
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/guard.ts
21
+ var guard_exports = {};
22
+ __export(guard_exports, {
23
+ hasProp: () => hasProp,
24
+ isArray: () => isArray,
25
+ isBoolean: () => isBoolean,
26
+ isDev: () => isDev,
27
+ isFunction: () => isFunction,
28
+ isNull: () => isNull,
29
+ isNumber: () => isNumber,
30
+ isObject: () => isObject,
31
+ isObjectLike: () => isObjectLike,
32
+ isPlainObject: () => isPlainObject,
33
+ isString: () => isString
34
+ });
35
+ module.exports = __toCommonJS(guard_exports);
36
+ var isDev = () => process.env.NODE_ENV !== "production";
37
+ var isArray = (v) => Array.isArray(v);
38
+ var isBoolean = (v) => v === true || v === false;
39
+ var isObjectLike = (v) => v != null && typeof v === "object";
40
+ var isObject = (v) => isObjectLike(v) && !isArray(v);
41
+ var isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
42
+ var isString = (v) => typeof v === "string";
43
+ var isFunction = (v) => typeof v === "function";
44
+ var isNull = (v) => v == null;
45
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
46
+ var baseGetTag = (v) => Object.prototype.toString.call(v);
47
+ var fnToString = Function.prototype.toString;
48
+ var objectCtorString = fnToString.call(Object);
49
+ var isPlainObject = (v) => {
50
+ if (!isObjectLike(v) || baseGetTag(v) != "[object Object]" || isFrameworkElement(v)) return false;
51
+ const proto = Object.getPrototypeOf(v);
52
+ if (proto === null) return true;
53
+ const Ctor = hasProp(proto, "constructor") && proto.constructor;
54
+ return typeof Ctor == "function" && Ctor instanceof Ctor && fnToString.call(Ctor) == objectCtorString;
55
+ };
56
+ var isReactElement = (x) => typeof x === "object" && x !== null && "$$typeof" in x && "props" in x;
57
+ var isVueElement = (x) => typeof x === "object" && x !== null && "__v_isVNode" in x;
58
+ var isFrameworkElement = (x) => isReactElement(x) || isVueElement(x);
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ hasProp,
62
+ isArray,
63
+ isBoolean,
64
+ isDev,
65
+ isFunction,
66
+ isNull,
67
+ isNumber,
68
+ isObject,
69
+ isObjectLike,
70
+ isPlainObject,
71
+ isString
72
+ });
package/dist/guard.mjs ADDED
@@ -0,0 +1,39 @@
1
+ import "./chunk-MXGZDBDQ.mjs";
2
+
3
+ // src/guard.ts
4
+ var isDev = () => process.env.NODE_ENV !== "production";
5
+ var isArray = (v) => Array.isArray(v);
6
+ var isBoolean = (v) => v === true || v === false;
7
+ var isObjectLike = (v) => v != null && typeof v === "object";
8
+ var isObject = (v) => isObjectLike(v) && !isArray(v);
9
+ var isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
10
+ var isString = (v) => typeof v === "string";
11
+ var isFunction = (v) => typeof v === "function";
12
+ var isNull = (v) => v == null;
13
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
14
+ var baseGetTag = (v) => Object.prototype.toString.call(v);
15
+ var fnToString = Function.prototype.toString;
16
+ var objectCtorString = fnToString.call(Object);
17
+ var isPlainObject = (v) => {
18
+ if (!isObjectLike(v) || baseGetTag(v) != "[object Object]" || isFrameworkElement(v)) return false;
19
+ const proto = Object.getPrototypeOf(v);
20
+ if (proto === null) return true;
21
+ const Ctor = hasProp(proto, "constructor") && proto.constructor;
22
+ return typeof Ctor == "function" && Ctor instanceof Ctor && fnToString.call(Ctor) == objectCtorString;
23
+ };
24
+ var isReactElement = (x) => typeof x === "object" && x !== null && "$$typeof" in x && "props" in x;
25
+ var isVueElement = (x) => typeof x === "object" && x !== null && "__v_isVNode" in x;
26
+ var isFrameworkElement = (x) => isReactElement(x) || isVueElement(x);
27
+ export {
28
+ hasProp,
29
+ isArray,
30
+ isBoolean,
31
+ isDev,
32
+ isFunction,
33
+ isNull,
34
+ isNumber,
35
+ isObject,
36
+ isObjectLike,
37
+ isPlainObject,
38
+ isString
39
+ };
package/dist/index.d.mts CHANGED
@@ -1,148 +1,9 @@
1
- declare function toArray<T>(v: T | T[] | undefined | null): T[];
2
- declare const fromLength: (length: number) => number[];
3
- declare const first: <T>(v: T[]) => T | undefined;
4
- declare const last: <T>(v: T[]) => T | undefined;
5
- declare const isEmpty: <T>(v: T[]) => boolean;
6
- declare const has: <T>(v: T[], t: T) => boolean;
7
- declare const add: <T>(v: T[], ...items: T[]) => T[];
8
- declare const remove: <T>(v: T[], ...items: T[]) => T[];
9
- declare const removeAt: <T>(v: T[], i: number) => T[];
10
- declare const insertAt: <T>(v: T[], i: number, ...items: T[]) => T[];
11
- declare const uniq: <T>(v: T[]) => T[];
12
- declare const diff: <T>(a: T[], b: T[]) => T[];
13
- declare const addOrRemove: <T>(v: T[], item: T) => T[];
14
- declare function clear<T>(v: T[]): T[];
15
- type IndexOptions = {
16
- step?: number | undefined;
17
- loop?: boolean | undefined;
18
- };
19
- declare function nextIndex<T>(v: T[], idx: number, opts?: IndexOptions): number;
20
- declare function next<T>(v: T[], idx: number, opts?: IndexOptions): T | undefined;
21
- declare function prevIndex<T>(v: T[], idx: number, opts?: IndexOptions): number;
22
- declare function prev<T>(v: T[], index: number, opts?: IndexOptions): T | undefined;
23
- declare function chunk<T>(v: T[], size: number): T[][];
24
- declare function flatArray<T>(arr: T[]): T[];
25
- declare function partition<T>(arr: T[], fn: (value: T) => boolean): [T[], T[]];
26
-
27
- declare const isEqual: (a: any, b: any) => boolean;
28
-
29
- type MaybeFunction<T> = T | (() => T);
30
- type Nullable<T> = T | null | undefined;
31
- declare const runIfFn: <T>(v: T | undefined, ...a: T extends (...a: any[]) => void ? Parameters<T> : never) => T extends (...a: any[]) => void ? NonNullable<ReturnType<T>> : NonNullable<T>;
32
- declare const cast: <T>(v: unknown) => T;
33
- declare const identity: (v: VoidFunction) => void;
34
- declare const noop: () => void;
35
- declare const callAll: <T extends (...a: any[]) => void>(...fns: (T | null | undefined)[]) => (...a: Parameters<T>) => void;
36
- declare const uuid: () => string;
37
- declare function match<V extends string | number = string, R = unknown>(key: V, record: Record<V, R | ((...args: any[]) => R)>, ...args: any[]): R;
38
- declare const tryCatch: <R>(fn: () => R, fallback: () => R) => R;
39
- declare function throttle<T extends (...args: any[]) => void>(fn: T, wait?: number): T;
40
- declare function debounce<T extends (...args: any[]) => void>(fn: T, wait?: number): T;
41
- declare const hash: (value: string) => string;
42
-
43
- type AnyFunction = (...args: any[]) => any;
44
- declare const isDev: () => boolean;
45
- declare const isArray: (v: any) => v is any[];
46
- declare const isBoolean: (v: any) => v is boolean;
47
- declare const isObjectLike: (v: any) => v is Record<string, any>;
48
- declare const isObject: (v: any) => v is Record<string, any>;
49
- declare const isNumber: (v: any) => v is number;
50
- declare const isString: (v: any) => v is string;
51
- declare const isFunction: (v: any) => v is AnyFunction;
52
- declare const isNull: (v: any) => v is null | undefined;
53
- declare const hasProp: <T extends string>(obj: any, prop: T) => obj is Record<T, any>;
54
- declare const isPlainObject: (v: any) => boolean;
55
-
56
- declare const isNaN: (v: number) => boolean;
57
- declare const nan: (v: number) => number;
58
- declare const mod: (v: number, m: number) => number;
59
- declare const wrap: (v: number, vmax: number) => number;
60
- declare const getMinValueAtIndex: (i: number, v: number[], vmin: number) => number;
61
- declare const getMaxValueAtIndex: (i: number, v: number[], vmax: number) => number;
62
- declare const isValueAtMax: (v: number, vmax: number) => boolean;
63
- declare const isValueAtMin: (v: number, vmin: number) => boolean;
64
- declare const isValueWithinRange: (v: number, vmin: number | null | undefined, vmax: number | null | undefined) => boolean;
65
- declare const roundValue: (v: number, vmin: number, step: number) => number;
66
- declare const clampValue: (v: number, vmin: number, vmax: number) => number;
67
- declare const clampPercent: (v: number) => number;
68
- declare const getValuePercent: (v: number, vmin: number, vmax: number) => number;
69
- declare const getPercentValue: (p: number, vmin: number, vmax: number, step: number) => number;
70
- declare const roundToStepPrecision: (v: number, step: number) => number;
71
- declare const roundToDpr: (v: number, dpr: unknown) => number;
72
- declare const snapValueToStep: (v: number, vmin: number | undefined, vmax: number | undefined, step: number) => number;
73
- declare const setValueAtIndex: <T>(vs: T[], i: number, v: T) => T[];
74
- interface RangeContext {
75
- min: number;
76
- max: number;
77
- step: number;
78
- values: number[];
79
- }
80
- declare function getValueSetterAtIndex(index: number, ctx: RangeContext): (value: number) => number[];
81
- declare function getNextStepValue(index: number, ctx: RangeContext): number[];
82
- declare function getPreviousStepValue(index: number, ctx: RangeContext): number[];
83
- declare const getClosestValueIndex: (vs: number[], t: number) => number;
84
- declare const getClosestValue: (vs: number[], t: number) => number;
85
- declare const getValueRanges: (vs: number[], vmin: number, vmax: number, gap: number) => {
86
- min: number;
87
- max: number;
88
- value: number;
89
- }[];
90
- declare const getValueTransformer: (va: number[], vb: number[]) => (v: number) => number;
91
- declare const toFixedNumber: (v: number, d?: number, b?: number) => number;
92
- declare const incrementValue: (v: number, s: number) => number;
93
- declare const decrementValue: (v: number, s: number) => number;
94
- declare const toPx: (v: number | string | undefined) => string | undefined;
95
-
96
- declare function compact<T extends Record<string, unknown> | undefined>(obj: T): T;
97
- declare const json: (v: any) => any;
98
- declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
99
- type Dict = Record<string | symbol, any>;
100
- declare function splitProps<T extends Dict>(props: T, keys: (keyof T)[]): Dict[];
101
- declare const createSplitProps: <T extends Dict>(keys: (keyof T)[]) => <Props extends T>(props: Props) => [T, Omit<Props, keyof T>];
102
- declare function omit<T extends Record<string, any>>(obj: T, keys: string[]): Omit<T, string | number>;
103
-
104
- type StoreListener = VoidFunction;
105
- type StoreCompareFn<T> = (a: T, b: T) => boolean;
106
- declare function createStore<T extends Record<string, any>>(initialState: T, compare?: StoreCompareFn<T>): Store<T>;
107
- interface Store<T extends Record<string, any>> {
108
- subscribe: (listener: StoreListener) => () => void;
109
- get: <K extends keyof T>(key: K) => T[K];
110
- set: <K extends keyof T>(key: K, value: T[K]) => void;
111
- update: (updates: Partial<T>) => void;
112
- snapshot: () => T;
113
- }
114
-
115
- interface TimerBaseContext {
116
- startMs: number;
117
- deltaMs: number;
118
- }
119
- interface TimerContext extends TimerBaseContext {
120
- now: number;
121
- }
122
- type TimerContextFn = (ctx: TimerContext) => boolean | void;
123
- declare class Timer {
124
- #private;
125
- private readonly onTick;
126
- private frameId;
127
- private pausedAtMs;
128
- private context;
129
- constructor(onTick: TimerContextFn);
130
- private cancelFrame;
131
- setStartMs: (startMs: number) => void;
132
- get elapsedMs(): number;
133
- start: () => void;
134
- pause: () => void;
135
- stop: () => void;
136
- }
137
- declare function setRafInterval(fn: (ctx: TimerBaseContext) => void, intervalMs: number): () => void;
138
- declare function setRafTimeout(fn: () => void, delayMs: number): () => void;
139
-
140
- declare function warn(m: string): void;
141
- declare function warn(c: boolean, m: string): void;
142
- declare function invariant(m: string): void;
143
- declare function invariant(c: boolean, m: string): void;
144
- declare function ensure<T>(c: T | null | undefined, m: () => string): asserts c is T;
145
- type RequiredBy<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
146
- declare function ensureProps<T, K extends keyof T>(props: T, keys: K[], scope?: string): asserts props is T & RequiredBy<T, K>;
147
-
148
- export { type IndexOptions, type MaybeFunction, type Nullable, type Store, type StoreCompareFn, type StoreListener, Timer, type TimerBaseContext, type TimerContextFn, add, addOrRemove, callAll, cast, chunk, clampPercent, clampValue, clear, compact, createSplitProps, createStore, debounce, decrementValue, diff, ensure, ensureProps, first, flatArray, fromLength, getClosestValue, getClosestValueIndex, getMaxValueAtIndex, getMinValueAtIndex, getNextStepValue, getPercentValue, getPreviousStepValue, getValuePercent, getValueRanges, getValueSetterAtIndex, getValueTransformer, has, hasProp, hash, identity, incrementValue, insertAt, invariant, isArray, isBoolean, isDev, isEmpty, isEqual, isFunction, isNaN, isNull, isNumber, isObject, isObjectLike, isPlainObject, isString, isValueAtMax, isValueAtMin, isValueWithinRange, json, last, match, mod, nan, next, nextIndex, noop, omit, partition, pick, prev, prevIndex, remove, removeAt, roundToDpr, roundToStepPrecision, roundValue, runIfFn, setRafInterval, setRafTimeout, setValueAtIndex, snapValueToStep, splitProps, throttle, toArray, toFixedNumber, toPx, tryCatch, uniq, uuid, warn, wrap };
1
+ export { IndexOptions, add, addOrRemove, chunk, clear, diff, first, flatArray, fromLength, has, insertAt, isEmpty, last, next, nextIndex, partition, prev, prevIndex, remove, removeAt, toArray, uniq } from './array.mjs';
2
+ export { isEqual } from './equal.mjs';
3
+ export { MaybeFunction, Nullable, callAll, cast, debounce, hash, identity, match, noop, runIfFn, throttle, tryCatch, uuid } from './functions.mjs';
4
+ export { hasProp, isArray, isBoolean, isDev, isFunction, isNull, isNumber, isObject, isObjectLike, isPlainObject, isString } from './guard.mjs';
5
+ export { clampPercent, clampValue, decrementValue, getClosestValue, getClosestValueIndex, getMaxValueAtIndex, getMinValueAtIndex, getNextStepValue, getPercentValue, getPreviousStepValue, getValuePercent, getValueRanges, getValueSetterAtIndex, getValueTransformer, incrementValue, isNaN, isValueAtMax, isValueAtMin, isValueWithinRange, mod, nan, roundToDpr, roundToStepPrecision, roundValue, setValueAtIndex, snapValueToStep, toFixedNumber, toPx, wrap } from './number.mjs';
6
+ export { compact, createSplitProps, json, omit, pick, splitProps } from './object.mjs';
7
+ export { Store, StoreCompareFn, StoreListener, createStore } from './store.mjs';
8
+ export { Timer, TimerBaseContext, TimerContextFn, setRafInterval, setRafTimeout } from './timers.mjs';
9
+ export { ensure, ensureProps, invariant, warn } from './warning.mjs';
package/dist/index.d.ts CHANGED
@@ -1,148 +1,9 @@
1
- declare function toArray<T>(v: T | T[] | undefined | null): T[];
2
- declare const fromLength: (length: number) => number[];
3
- declare const first: <T>(v: T[]) => T | undefined;
4
- declare const last: <T>(v: T[]) => T | undefined;
5
- declare const isEmpty: <T>(v: T[]) => boolean;
6
- declare const has: <T>(v: T[], t: T) => boolean;
7
- declare const add: <T>(v: T[], ...items: T[]) => T[];
8
- declare const remove: <T>(v: T[], ...items: T[]) => T[];
9
- declare const removeAt: <T>(v: T[], i: number) => T[];
10
- declare const insertAt: <T>(v: T[], i: number, ...items: T[]) => T[];
11
- declare const uniq: <T>(v: T[]) => T[];
12
- declare const diff: <T>(a: T[], b: T[]) => T[];
13
- declare const addOrRemove: <T>(v: T[], item: T) => T[];
14
- declare function clear<T>(v: T[]): T[];
15
- type IndexOptions = {
16
- step?: number | undefined;
17
- loop?: boolean | undefined;
18
- };
19
- declare function nextIndex<T>(v: T[], idx: number, opts?: IndexOptions): number;
20
- declare function next<T>(v: T[], idx: number, opts?: IndexOptions): T | undefined;
21
- declare function prevIndex<T>(v: T[], idx: number, opts?: IndexOptions): number;
22
- declare function prev<T>(v: T[], index: number, opts?: IndexOptions): T | undefined;
23
- declare function chunk<T>(v: T[], size: number): T[][];
24
- declare function flatArray<T>(arr: T[]): T[];
25
- declare function partition<T>(arr: T[], fn: (value: T) => boolean): [T[], T[]];
26
-
27
- declare const isEqual: (a: any, b: any) => boolean;
28
-
29
- type MaybeFunction<T> = T | (() => T);
30
- type Nullable<T> = T | null | undefined;
31
- declare const runIfFn: <T>(v: T | undefined, ...a: T extends (...a: any[]) => void ? Parameters<T> : never) => T extends (...a: any[]) => void ? NonNullable<ReturnType<T>> : NonNullable<T>;
32
- declare const cast: <T>(v: unknown) => T;
33
- declare const identity: (v: VoidFunction) => void;
34
- declare const noop: () => void;
35
- declare const callAll: <T extends (...a: any[]) => void>(...fns: (T | null | undefined)[]) => (...a: Parameters<T>) => void;
36
- declare const uuid: () => string;
37
- declare function match<V extends string | number = string, R = unknown>(key: V, record: Record<V, R | ((...args: any[]) => R)>, ...args: any[]): R;
38
- declare const tryCatch: <R>(fn: () => R, fallback: () => R) => R;
39
- declare function throttle<T extends (...args: any[]) => void>(fn: T, wait?: number): T;
40
- declare function debounce<T extends (...args: any[]) => void>(fn: T, wait?: number): T;
41
- declare const hash: (value: string) => string;
42
-
43
- type AnyFunction = (...args: any[]) => any;
44
- declare const isDev: () => boolean;
45
- declare const isArray: (v: any) => v is any[];
46
- declare const isBoolean: (v: any) => v is boolean;
47
- declare const isObjectLike: (v: any) => v is Record<string, any>;
48
- declare const isObject: (v: any) => v is Record<string, any>;
49
- declare const isNumber: (v: any) => v is number;
50
- declare const isString: (v: any) => v is string;
51
- declare const isFunction: (v: any) => v is AnyFunction;
52
- declare const isNull: (v: any) => v is null | undefined;
53
- declare const hasProp: <T extends string>(obj: any, prop: T) => obj is Record<T, any>;
54
- declare const isPlainObject: (v: any) => boolean;
55
-
56
- declare const isNaN: (v: number) => boolean;
57
- declare const nan: (v: number) => number;
58
- declare const mod: (v: number, m: number) => number;
59
- declare const wrap: (v: number, vmax: number) => number;
60
- declare const getMinValueAtIndex: (i: number, v: number[], vmin: number) => number;
61
- declare const getMaxValueAtIndex: (i: number, v: number[], vmax: number) => number;
62
- declare const isValueAtMax: (v: number, vmax: number) => boolean;
63
- declare const isValueAtMin: (v: number, vmin: number) => boolean;
64
- declare const isValueWithinRange: (v: number, vmin: number | null | undefined, vmax: number | null | undefined) => boolean;
65
- declare const roundValue: (v: number, vmin: number, step: number) => number;
66
- declare const clampValue: (v: number, vmin: number, vmax: number) => number;
67
- declare const clampPercent: (v: number) => number;
68
- declare const getValuePercent: (v: number, vmin: number, vmax: number) => number;
69
- declare const getPercentValue: (p: number, vmin: number, vmax: number, step: number) => number;
70
- declare const roundToStepPrecision: (v: number, step: number) => number;
71
- declare const roundToDpr: (v: number, dpr: unknown) => number;
72
- declare const snapValueToStep: (v: number, vmin: number | undefined, vmax: number | undefined, step: number) => number;
73
- declare const setValueAtIndex: <T>(vs: T[], i: number, v: T) => T[];
74
- interface RangeContext {
75
- min: number;
76
- max: number;
77
- step: number;
78
- values: number[];
79
- }
80
- declare function getValueSetterAtIndex(index: number, ctx: RangeContext): (value: number) => number[];
81
- declare function getNextStepValue(index: number, ctx: RangeContext): number[];
82
- declare function getPreviousStepValue(index: number, ctx: RangeContext): number[];
83
- declare const getClosestValueIndex: (vs: number[], t: number) => number;
84
- declare const getClosestValue: (vs: number[], t: number) => number;
85
- declare const getValueRanges: (vs: number[], vmin: number, vmax: number, gap: number) => {
86
- min: number;
87
- max: number;
88
- value: number;
89
- }[];
90
- declare const getValueTransformer: (va: number[], vb: number[]) => (v: number) => number;
91
- declare const toFixedNumber: (v: number, d?: number, b?: number) => number;
92
- declare const incrementValue: (v: number, s: number) => number;
93
- declare const decrementValue: (v: number, s: number) => number;
94
- declare const toPx: (v: number | string | undefined) => string | undefined;
95
-
96
- declare function compact<T extends Record<string, unknown> | undefined>(obj: T): T;
97
- declare const json: (v: any) => any;
98
- declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
99
- type Dict = Record<string | symbol, any>;
100
- declare function splitProps<T extends Dict>(props: T, keys: (keyof T)[]): Dict[];
101
- declare const createSplitProps: <T extends Dict>(keys: (keyof T)[]) => <Props extends T>(props: Props) => [T, Omit<Props, keyof T>];
102
- declare function omit<T extends Record<string, any>>(obj: T, keys: string[]): Omit<T, string | number>;
103
-
104
- type StoreListener = VoidFunction;
105
- type StoreCompareFn<T> = (a: T, b: T) => boolean;
106
- declare function createStore<T extends Record<string, any>>(initialState: T, compare?: StoreCompareFn<T>): Store<T>;
107
- interface Store<T extends Record<string, any>> {
108
- subscribe: (listener: StoreListener) => () => void;
109
- get: <K extends keyof T>(key: K) => T[K];
110
- set: <K extends keyof T>(key: K, value: T[K]) => void;
111
- update: (updates: Partial<T>) => void;
112
- snapshot: () => T;
113
- }
114
-
115
- interface TimerBaseContext {
116
- startMs: number;
117
- deltaMs: number;
118
- }
119
- interface TimerContext extends TimerBaseContext {
120
- now: number;
121
- }
122
- type TimerContextFn = (ctx: TimerContext) => boolean | void;
123
- declare class Timer {
124
- #private;
125
- private readonly onTick;
126
- private frameId;
127
- private pausedAtMs;
128
- private context;
129
- constructor(onTick: TimerContextFn);
130
- private cancelFrame;
131
- setStartMs: (startMs: number) => void;
132
- get elapsedMs(): number;
133
- start: () => void;
134
- pause: () => void;
135
- stop: () => void;
136
- }
137
- declare function setRafInterval(fn: (ctx: TimerBaseContext) => void, intervalMs: number): () => void;
138
- declare function setRafTimeout(fn: () => void, delayMs: number): () => void;
139
-
140
- declare function warn(m: string): void;
141
- declare function warn(c: boolean, m: string): void;
142
- declare function invariant(m: string): void;
143
- declare function invariant(c: boolean, m: string): void;
144
- declare function ensure<T>(c: T | null | undefined, m: () => string): asserts c is T;
145
- type RequiredBy<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
146
- declare function ensureProps<T, K extends keyof T>(props: T, keys: K[], scope?: string): asserts props is T & RequiredBy<T, K>;
147
-
148
- export { type IndexOptions, type MaybeFunction, type Nullable, type Store, type StoreCompareFn, type StoreListener, Timer, type TimerBaseContext, type TimerContextFn, add, addOrRemove, callAll, cast, chunk, clampPercent, clampValue, clear, compact, createSplitProps, createStore, debounce, decrementValue, diff, ensure, ensureProps, first, flatArray, fromLength, getClosestValue, getClosestValueIndex, getMaxValueAtIndex, getMinValueAtIndex, getNextStepValue, getPercentValue, getPreviousStepValue, getValuePercent, getValueRanges, getValueSetterAtIndex, getValueTransformer, has, hasProp, hash, identity, incrementValue, insertAt, invariant, isArray, isBoolean, isDev, isEmpty, isEqual, isFunction, isNaN, isNull, isNumber, isObject, isObjectLike, isPlainObject, isString, isValueAtMax, isValueAtMin, isValueWithinRange, json, last, match, mod, nan, next, nextIndex, noop, omit, partition, pick, prev, prevIndex, remove, removeAt, roundToDpr, roundToStepPrecision, roundValue, runIfFn, setRafInterval, setRafTimeout, setValueAtIndex, snapValueToStep, splitProps, throttle, toArray, toFixedNumber, toPx, tryCatch, uniq, uuid, warn, wrap };
1
+ export { IndexOptions, add, addOrRemove, chunk, clear, diff, first, flatArray, fromLength, has, insertAt, isEmpty, last, next, nextIndex, partition, prev, prevIndex, remove, removeAt, toArray, uniq } from './array.js';
2
+ export { isEqual } from './equal.js';
3
+ export { MaybeFunction, Nullable, callAll, cast, debounce, hash, identity, match, noop, runIfFn, throttle, tryCatch, uuid } from './functions.js';
4
+ export { hasProp, isArray, isBoolean, isDev, isFunction, isNull, isNumber, isObject, isObjectLike, isPlainObject, isString } from './guard.js';
5
+ export { clampPercent, clampValue, decrementValue, getClosestValue, getClosestValueIndex, getMaxValueAtIndex, getMinValueAtIndex, getNextStepValue, getPercentValue, getPreviousStepValue, getValuePercent, getValueRanges, getValueSetterAtIndex, getValueTransformer, incrementValue, isNaN, isValueAtMax, isValueAtMin, isValueWithinRange, mod, nan, roundToDpr, roundToStepPrecision, roundValue, setValueAtIndex, snapValueToStep, toFixedNumber, toPx, wrap } from './number.js';
6
+ export { compact, createSplitProps, json, omit, pick, splitProps } from './object.js';
7
+ export { Store, StoreCompareFn, StoreListener, createStore } from './store.js';
8
+ export { Timer, TimerBaseContext, TimerContextFn, setRafInterval, setRafTimeout } from './timers.js';
9
+ export { ensure, ensureProps, invariant, warn } from './warning.js';