@zag-js/utils 1.12.1 → 1.12.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -35,6 +35,7 @@ declare const uuid: () => string;
35
35
  declare function match<V extends string | number = string, R = unknown>(key: V, record: Record<V, R | ((...args: any[]) => R)>, ...args: any[]): R;
36
36
  declare const tryCatch: <R>(fn: () => R, fallback: () => R) => R;
37
37
  declare function throttle<T extends (...args: any[]) => void>(fn: T, wait?: number): T;
38
+ declare function debounce<T extends (...args: any[]) => void>(fn: T, wait?: number): T;
38
39
 
39
40
  type AnyFunction = (...args: any[]) => any;
40
41
  declare const isDev: () => boolean;
@@ -112,4 +113,4 @@ declare function ensure<T>(c: T | null | undefined, m: () => string): asserts c
112
113
  type RequiredBy<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
113
114
  declare function ensureProps<T, K extends keyof T>(props: T, keys: K[], scope?: string): asserts props is T & RequiredBy<T, K>;
114
115
 
115
- export { type IndexOptions, type MaybeFunction, type Nullable, type RafIntervalOptions, add, addOrRemove, callAll, cast, chunk, clampPercent, clampValue, clear, compact, createSplitProps, decrementValue, ensure, ensureProps, first, flatArray, fromLength, getClosestValue, getClosestValueIndex, getMaxValueAtIndex, getMinValueAtIndex, getNextStepValue, getPercentValue, getPreviousStepValue, getValuePercent, getValueRanges, getValueSetterAtIndex, getValueTransformer, has, hasProp, 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, pick, prev, prevIndex, remove, removeAt, roundToDpr, roundToStepPrecision, roundValue, runIfFn, setRafInterval, setRafTimeout, setValueAtIndex, snapValueToStep, splitProps, throttle, toArray, toFixedNumber, toPx, tryCatch, uniq, uuid, warn, wrap };
116
+ export { type IndexOptions, type MaybeFunction, type Nullable, type RafIntervalOptions, add, addOrRemove, callAll, cast, chunk, clampPercent, clampValue, clear, compact, createSplitProps, debounce, decrementValue, ensure, ensureProps, first, flatArray, fromLength, getClosestValue, getClosestValueIndex, getMaxValueAtIndex, getMinValueAtIndex, getNextStepValue, getPercentValue, getPreviousStepValue, getValuePercent, getValueRanges, getValueSetterAtIndex, getValueTransformer, has, hasProp, 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, pick, prev, prevIndex, remove, removeAt, roundToDpr, roundToStepPrecision, roundValue, runIfFn, setRafInterval, setRafTimeout, setValueAtIndex, snapValueToStep, splitProps, throttle, toArray, toFixedNumber, toPx, tryCatch, uniq, uuid, warn, wrap };
package/dist/index.d.ts CHANGED
@@ -35,6 +35,7 @@ declare const uuid: () => string;
35
35
  declare function match<V extends string | number = string, R = unknown>(key: V, record: Record<V, R | ((...args: any[]) => R)>, ...args: any[]): R;
36
36
  declare const tryCatch: <R>(fn: () => R, fallback: () => R) => R;
37
37
  declare function throttle<T extends (...args: any[]) => void>(fn: T, wait?: number): T;
38
+ declare function debounce<T extends (...args: any[]) => void>(fn: T, wait?: number): T;
38
39
 
39
40
  type AnyFunction = (...args: any[]) => any;
40
41
  declare const isDev: () => boolean;
@@ -112,4 +113,4 @@ declare function ensure<T>(c: T | null | undefined, m: () => string): asserts c
112
113
  type RequiredBy<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
113
114
  declare function ensureProps<T, K extends keyof T>(props: T, keys: K[], scope?: string): asserts props is T & RequiredBy<T, K>;
114
115
 
115
- export { type IndexOptions, type MaybeFunction, type Nullable, type RafIntervalOptions, add, addOrRemove, callAll, cast, chunk, clampPercent, clampValue, clear, compact, createSplitProps, decrementValue, ensure, ensureProps, first, flatArray, fromLength, getClosestValue, getClosestValueIndex, getMaxValueAtIndex, getMinValueAtIndex, getNextStepValue, getPercentValue, getPreviousStepValue, getValuePercent, getValueRanges, getValueSetterAtIndex, getValueTransformer, has, hasProp, 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, pick, prev, prevIndex, remove, removeAt, roundToDpr, roundToStepPrecision, roundValue, runIfFn, setRafInterval, setRafTimeout, setValueAtIndex, snapValueToStep, splitProps, throttle, toArray, toFixedNumber, toPx, tryCatch, uniq, uuid, warn, wrap };
116
+ export { type IndexOptions, type MaybeFunction, type Nullable, type RafIntervalOptions, add, addOrRemove, callAll, cast, chunk, clampPercent, clampValue, clear, compact, createSplitProps, debounce, decrementValue, ensure, ensureProps, first, flatArray, fromLength, getClosestValue, getClosestValueIndex, getMaxValueAtIndex, getMinValueAtIndex, getNextStepValue, getPercentValue, getPreviousStepValue, getValuePercent, getValueRanges, getValueSetterAtIndex, getValueTransformer, has, hasProp, 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, pick, prev, prevIndex, remove, removeAt, roundToDpr, roundToStepPrecision, roundValue, runIfFn, setRafInterval, setRafTimeout, setValueAtIndex, snapValueToStep, splitProps, throttle, toArray, toFixedNumber, toPx, tryCatch, uniq, uuid, warn, wrap };
package/dist/index.js CHANGED
@@ -179,6 +179,18 @@ function throttle(fn, wait = 0) {
179
179
  }
180
180
  };
181
181
  }
182
+ function debounce(fn, wait = 0) {
183
+ let timeout = null;
184
+ return (...args) => {
185
+ if (timeout) {
186
+ clearTimeout(timeout);
187
+ timeout = null;
188
+ }
189
+ timeout = setTimeout(() => {
190
+ fn(...args);
191
+ }, wait);
192
+ };
193
+ }
182
194
 
183
195
  // src/number.ts
184
196
  var { floor, abs, round, min, max, pow, sign } = Math;
@@ -413,6 +425,7 @@ exports.clampValue = clampValue;
413
425
  exports.clear = clear;
414
426
  exports.compact = compact;
415
427
  exports.createSplitProps = createSplitProps;
428
+ exports.debounce = debounce;
416
429
  exports.decrementValue = decrementValue;
417
430
  exports.ensure = ensure;
418
431
  exports.ensureProps = ensureProps;
package/dist/index.mjs CHANGED
@@ -177,6 +177,18 @@ function throttle(fn, wait = 0) {
177
177
  }
178
178
  };
179
179
  }
180
+ function debounce(fn, wait = 0) {
181
+ let timeout = null;
182
+ return (...args) => {
183
+ if (timeout) {
184
+ clearTimeout(timeout);
185
+ timeout = null;
186
+ }
187
+ timeout = setTimeout(() => {
188
+ fn(...args);
189
+ }, wait);
190
+ };
191
+ }
180
192
 
181
193
  // src/number.ts
182
194
  var { floor, abs, round, min, max, pow, sign } = Math;
@@ -401,4 +413,4 @@ function ensureProps(props, keys, scope) {
401
413
  throw new Error(`[zag-js${scope ? ` > ${scope}` : ""}] missing required props: ${missingKeys.join(", ")}`);
402
414
  }
403
415
 
404
- export { add, addOrRemove, callAll, cast, chunk, clampPercent, clampValue, clear, compact, createSplitProps, decrementValue, ensure, ensureProps, first, flatArray, fromLength, getClosestValue, getClosestValueIndex, getMaxValueAtIndex, getMinValueAtIndex, getNextStepValue, getPercentValue, getPreviousStepValue, getValuePercent, getValueRanges, getValueSetterAtIndex, getValueTransformer, has, hasProp, 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, pick, prev, prevIndex, remove, removeAt, roundToDpr, roundToStepPrecision, roundValue, runIfFn, setRafInterval, setRafTimeout, setValueAtIndex, snapValueToStep, splitProps, throttle, toArray, toFixedNumber, toPx, tryCatch, uniq, uuid, warn, wrap };
416
+ export { add, addOrRemove, callAll, cast, chunk, clampPercent, clampValue, clear, compact, createSplitProps, debounce, decrementValue, ensure, ensureProps, first, flatArray, fromLength, getClosestValue, getClosestValueIndex, getMaxValueAtIndex, getMinValueAtIndex, getNextStepValue, getPercentValue, getPreviousStepValue, getValuePercent, getValueRanges, getValueSetterAtIndex, getValueTransformer, has, hasProp, 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, pick, prev, prevIndex, remove, removeAt, roundToDpr, roundToStepPrecision, roundValue, runIfFn, setRafInterval, setRafTimeout, setValueAtIndex, snapValueToStep, splitProps, throttle, toArray, toFixedNumber, toPx, tryCatch, uniq, uuid, warn, wrap };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/utils",
3
- "version": "1.12.1",
3
+ "version": "1.12.3",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "js",