@zag-js/utils 1.21.9 → 1.22.1
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 +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +44 -0
- package/dist/index.mjs +44 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -100,6 +100,17 @@ declare function splitProps<T extends Dict>(props: T, keys: (keyof T)[]): Dict[]
|
|
|
100
100
|
declare const createSplitProps: <T extends Dict>(keys: (keyof T)[]) => <Props extends T>(props: Props) => [T, Omit<Props, keyof T>];
|
|
101
101
|
declare function omit<T extends Record<string, any>>(obj: T, keys: string[]): Omit<T, string | number>;
|
|
102
102
|
|
|
103
|
+
type StoreListener = VoidFunction;
|
|
104
|
+
type StoreCompareFn<T> = (a: T, b: T) => boolean;
|
|
105
|
+
declare function createStore<T extends Record<string, any>>(initialState: T, compare?: StoreCompareFn<T>): Store<T>;
|
|
106
|
+
interface Store<T extends Record<string, any>> {
|
|
107
|
+
subscribe: (listener: StoreListener) => () => void;
|
|
108
|
+
get: <K extends keyof T>(key: K) => T[K];
|
|
109
|
+
set: <K extends keyof T>(key: K, value: T[K]) => void;
|
|
110
|
+
update: (updates: Partial<T>) => void;
|
|
111
|
+
snapshot: () => T;
|
|
112
|
+
}
|
|
113
|
+
|
|
103
114
|
interface RafIntervalOptions {
|
|
104
115
|
startMs: number;
|
|
105
116
|
deltaMs: number;
|
|
@@ -115,4 +126,4 @@ declare function ensure<T>(c: T | null | undefined, m: () => string): asserts c
|
|
|
115
126
|
type RequiredBy<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
116
127
|
declare function ensureProps<T, K extends keyof T>(props: T, keys: K[], scope?: string): asserts props is T & RequiredBy<T, K>;
|
|
117
128
|
|
|
118
|
-
export { type IndexOptions, type MaybeFunction, type Nullable, type RafIntervalOptions, add, addOrRemove, callAll, cast, chunk, clampPercent, clampValue, clear, compact, createSplitProps, debounce, decrementValue, diff, 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, partition, pick, prev, prevIndex, remove, removeAt, roundToDpr, roundToStepPrecision, roundValue, runIfFn, setRafInterval, setRafTimeout, setValueAtIndex, snapValueToStep, splitProps, throttle, toArray, toFixedNumber, toPx, tryCatch, uniq, uuid, warn, wrap };
|
|
129
|
+
export { type IndexOptions, type MaybeFunction, type Nullable, type RafIntervalOptions, type Store, type StoreCompareFn, type StoreListener, 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, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -100,6 +100,17 @@ declare function splitProps<T extends Dict>(props: T, keys: (keyof T)[]): Dict[]
|
|
|
100
100
|
declare const createSplitProps: <T extends Dict>(keys: (keyof T)[]) => <Props extends T>(props: Props) => [T, Omit<Props, keyof T>];
|
|
101
101
|
declare function omit<T extends Record<string, any>>(obj: T, keys: string[]): Omit<T, string | number>;
|
|
102
102
|
|
|
103
|
+
type StoreListener = VoidFunction;
|
|
104
|
+
type StoreCompareFn<T> = (a: T, b: T) => boolean;
|
|
105
|
+
declare function createStore<T extends Record<string, any>>(initialState: T, compare?: StoreCompareFn<T>): Store<T>;
|
|
106
|
+
interface Store<T extends Record<string, any>> {
|
|
107
|
+
subscribe: (listener: StoreListener) => () => void;
|
|
108
|
+
get: <K extends keyof T>(key: K) => T[K];
|
|
109
|
+
set: <K extends keyof T>(key: K, value: T[K]) => void;
|
|
110
|
+
update: (updates: Partial<T>) => void;
|
|
111
|
+
snapshot: () => T;
|
|
112
|
+
}
|
|
113
|
+
|
|
103
114
|
interface RafIntervalOptions {
|
|
104
115
|
startMs: number;
|
|
105
116
|
deltaMs: number;
|
|
@@ -115,4 +126,4 @@ declare function ensure<T>(c: T | null | undefined, m: () => string): asserts c
|
|
|
115
126
|
type RequiredBy<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
116
127
|
declare function ensureProps<T, K extends keyof T>(props: T, keys: K[], scope?: string): asserts props is T & RequiredBy<T, K>;
|
|
117
128
|
|
|
118
|
-
export { type IndexOptions, type MaybeFunction, type Nullable, type RafIntervalOptions, add, addOrRemove, callAll, cast, chunk, clampPercent, clampValue, clear, compact, createSplitProps, debounce, decrementValue, diff, 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, partition, pick, prev, prevIndex, remove, removeAt, roundToDpr, roundToStepPrecision, roundValue, runIfFn, setRafInterval, setRafTimeout, setValueAtIndex, snapValueToStep, splitProps, throttle, toArray, toFixedNumber, toPx, tryCatch, uniq, uuid, warn, wrap };
|
|
129
|
+
export { type IndexOptions, type MaybeFunction, type Nullable, type RafIntervalOptions, type Store, type StoreCompareFn, type StoreListener, 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, 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 };
|
package/dist/index.js
CHANGED
|
@@ -370,6 +370,49 @@ function omit(obj, keys) {
|
|
|
370
370
|
return createSplitProps(keys)(obj)[1];
|
|
371
371
|
}
|
|
372
372
|
|
|
373
|
+
// src/store.ts
|
|
374
|
+
function createStore(initialState, compare = Object.is) {
|
|
375
|
+
let state = { ...initialState };
|
|
376
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
377
|
+
const subscribe = (listener) => {
|
|
378
|
+
listeners.add(listener);
|
|
379
|
+
return () => listeners.delete(listener);
|
|
380
|
+
};
|
|
381
|
+
const publish = () => {
|
|
382
|
+
listeners.forEach((listener) => listener());
|
|
383
|
+
};
|
|
384
|
+
const get = (key) => {
|
|
385
|
+
return state[key];
|
|
386
|
+
};
|
|
387
|
+
const set = (key, value) => {
|
|
388
|
+
if (!compare(state[key], value)) {
|
|
389
|
+
state[key] = value;
|
|
390
|
+
publish();
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
const update = (updates) => {
|
|
394
|
+
let hasChanges = false;
|
|
395
|
+
for (const key in updates) {
|
|
396
|
+
const value = updates[key];
|
|
397
|
+
if (value !== void 0 && !compare(state[key], value)) {
|
|
398
|
+
state[key] = value;
|
|
399
|
+
hasChanges = true;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
if (hasChanges) {
|
|
403
|
+
publish();
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
const snapshot = () => ({ ...state });
|
|
407
|
+
return {
|
|
408
|
+
subscribe,
|
|
409
|
+
get,
|
|
410
|
+
set,
|
|
411
|
+
update,
|
|
412
|
+
snapshot
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
|
|
373
416
|
// src/timers.ts
|
|
374
417
|
function setRafInterval(callback, interval) {
|
|
375
418
|
let start = performance.now();
|
|
@@ -437,6 +480,7 @@ exports.clampValue = clampValue;
|
|
|
437
480
|
exports.clear = clear;
|
|
438
481
|
exports.compact = compact;
|
|
439
482
|
exports.createSplitProps = createSplitProps;
|
|
483
|
+
exports.createStore = createStore;
|
|
440
484
|
exports.debounce = debounce;
|
|
441
485
|
exports.decrementValue = decrementValue;
|
|
442
486
|
exports.diff = diff;
|
package/dist/index.mjs
CHANGED
|
@@ -368,6 +368,49 @@ function omit(obj, keys) {
|
|
|
368
368
|
return createSplitProps(keys)(obj)[1];
|
|
369
369
|
}
|
|
370
370
|
|
|
371
|
+
// src/store.ts
|
|
372
|
+
function createStore(initialState, compare = Object.is) {
|
|
373
|
+
let state = { ...initialState };
|
|
374
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
375
|
+
const subscribe = (listener) => {
|
|
376
|
+
listeners.add(listener);
|
|
377
|
+
return () => listeners.delete(listener);
|
|
378
|
+
};
|
|
379
|
+
const publish = () => {
|
|
380
|
+
listeners.forEach((listener) => listener());
|
|
381
|
+
};
|
|
382
|
+
const get = (key) => {
|
|
383
|
+
return state[key];
|
|
384
|
+
};
|
|
385
|
+
const set = (key, value) => {
|
|
386
|
+
if (!compare(state[key], value)) {
|
|
387
|
+
state[key] = value;
|
|
388
|
+
publish();
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
const update = (updates) => {
|
|
392
|
+
let hasChanges = false;
|
|
393
|
+
for (const key in updates) {
|
|
394
|
+
const value = updates[key];
|
|
395
|
+
if (value !== void 0 && !compare(state[key], value)) {
|
|
396
|
+
state[key] = value;
|
|
397
|
+
hasChanges = true;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
if (hasChanges) {
|
|
401
|
+
publish();
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
const snapshot = () => ({ ...state });
|
|
405
|
+
return {
|
|
406
|
+
subscribe,
|
|
407
|
+
get,
|
|
408
|
+
set,
|
|
409
|
+
update,
|
|
410
|
+
snapshot
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
|
|
371
414
|
// src/timers.ts
|
|
372
415
|
function setRafInterval(callback, interval) {
|
|
373
416
|
let start = performance.now();
|
|
@@ -425,4 +468,4 @@ function ensureProps(props, keys, scope) {
|
|
|
425
468
|
throw new Error(`[zag-js${scope ? ` > ${scope}` : ""}] missing required props: ${missingKeys.join(", ")}`);
|
|
426
469
|
}
|
|
427
470
|
|
|
428
|
-
export { add, addOrRemove, callAll, cast, chunk, clampPercent, clampValue, clear, compact, createSplitProps, debounce, decrementValue, diff, 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, partition, pick, prev, prevIndex, remove, removeAt, roundToDpr, roundToStepPrecision, roundValue, runIfFn, setRafInterval, setRafTimeout, setValueAtIndex, snapValueToStep, splitProps, throttle, toArray, toFixedNumber, toPx, tryCatch, uniq, uuid, warn, wrap };
|
|
471
|
+
export { 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, 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 };
|