@zag-js/utils 2.0.0-next.0 → 2.0.0-next.2

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/equal.js CHANGED
@@ -23,36 +23,22 @@ __export(equal_exports, {
23
23
  isEqual: () => isEqual
24
24
  });
25
25
  module.exports = __toCommonJS(equal_exports);
26
- var isArrayLike = (value) => value?.constructor.name === "Array";
27
- var isArrayEqual = (a, b) => {
28
- if (a.length !== b.length) return false;
29
- for (let i = 0; i < a.length; i++) {
30
- if (!isEqual(a[i], b[i])) return false;
31
- }
32
- return true;
33
- };
26
+ var hasOwn = Object.prototype.hasOwnProperty;
34
27
  var isEqual = (a, b) => {
35
28
  if (Object.is(a, b)) return true;
36
- if (a == null && b != null || a != null && b == null) return false;
37
- if (typeof a?.isEqual === "function" && typeof b?.isEqual === "function") {
38
- return a.isEqual(b);
39
- }
40
- if (typeof a === "function" && typeof b === "function") {
41
- return a.toString() === b.toString();
42
- }
43
- if (isArrayLike(a) && isArrayLike(b)) {
44
- return isArrayEqual(Array.from(a), Array.from(b));
45
- }
46
- if (!(typeof a === "object") || !(typeof b === "object")) return false;
47
- const keys = Object.keys(b ?? /* @__PURE__ */ Object.create(null));
48
- const length = keys.length;
49
- for (let i = 0; i < length; i++) {
50
- const hasKey = Reflect.has(a, keys[i]);
51
- if (!hasKey) return false;
29
+ if (a == null || b == null) return false;
30
+ if (typeof a.isEqual === "function" && typeof b.isEqual === "function") return a.isEqual(b);
31
+ if (Array.isArray(a) && Array.isArray(b)) {
32
+ if (a.length !== b.length) return false;
33
+ for (let i = 0; i < a.length; i++) if (!isEqual(a[i], b[i])) return false;
34
+ return true;
52
35
  }
53
- for (let i = 0; i < length; i++) {
36
+ if (typeof a !== "object" || typeof b !== "object") return false;
37
+ const keys = Object.keys(b);
38
+ if (Object.keys(a).length !== keys.length) return false;
39
+ for (let i = 0; i < keys.length; i++) {
54
40
  const key = keys[i];
55
- if (!isEqual(a[key], b[key])) return false;
41
+ if (!hasOwn.call(a, key) || !isEqual(a[key], b[key])) return false;
56
42
  }
57
43
  return true;
58
44
  };
package/dist/equal.mjs CHANGED
@@ -1,36 +1,22 @@
1
1
  import "./chunk-MXGZDBDQ.mjs";
2
2
 
3
3
  // src/equal.ts
4
- var isArrayLike = (value) => value?.constructor.name === "Array";
5
- var isArrayEqual = (a, b) => {
6
- if (a.length !== b.length) return false;
7
- for (let i = 0; i < a.length; i++) {
8
- if (!isEqual(a[i], b[i])) return false;
9
- }
10
- return true;
11
- };
4
+ var hasOwn = Object.prototype.hasOwnProperty;
12
5
  var isEqual = (a, b) => {
13
6
  if (Object.is(a, b)) return true;
14
- if (a == null && b != null || a != null && b == null) return false;
15
- if (typeof a?.isEqual === "function" && typeof b?.isEqual === "function") {
16
- return a.isEqual(b);
17
- }
18
- if (typeof a === "function" && typeof b === "function") {
19
- return a.toString() === b.toString();
20
- }
21
- if (isArrayLike(a) && isArrayLike(b)) {
22
- return isArrayEqual(Array.from(a), Array.from(b));
23
- }
24
- if (!(typeof a === "object") || !(typeof b === "object")) return false;
25
- const keys = Object.keys(b ?? /* @__PURE__ */ Object.create(null));
26
- const length = keys.length;
27
- for (let i = 0; i < length; i++) {
28
- const hasKey = Reflect.has(a, keys[i]);
29
- if (!hasKey) return false;
7
+ if (a == null || b == null) return false;
8
+ if (typeof a.isEqual === "function" && typeof b.isEqual === "function") return a.isEqual(b);
9
+ if (Array.isArray(a) && Array.isArray(b)) {
10
+ if (a.length !== b.length) return false;
11
+ for (let i = 0; i < a.length; i++) if (!isEqual(a[i], b[i])) return false;
12
+ return true;
30
13
  }
31
- for (let i = 0; i < length; i++) {
14
+ if (typeof a !== "object" || typeof b !== "object") return false;
15
+ const keys = Object.keys(b);
16
+ if (Object.keys(a).length !== keys.length) return false;
17
+ for (let i = 0; i < keys.length; i++) {
32
18
  const key = keys[i];
33
- if (!isEqual(a[key], b[key])) return false;
19
+ if (!hasOwn.call(a, key) || !isEqual(a[key], b[key])) return false;
34
20
  }
35
21
  return true;
36
22
  };
package/dist/index.d.mts CHANGED
@@ -2,8 +2,9 @@ export { IndexOptions, add, addOrRemove, chunk, clear, diff, first, flatArray, f
2
2
  export { isEqual } from './equal.mjs';
3
3
  export { MaybeFunction, Nullable, callAll, cast, debounce, hash, identity, match, noop, runIfFn, throttle, tryCatch, uuid } from './functions.mjs';
4
4
  export { hasProp, isArray, isBoolean, isDev, isFunction, isNull, isNumber, isObject, isObjectLike, isPlainObject, isString } from './guard.mjs';
5
+ export { Teardown, TeardownReason } from './lifecycle.mjs';
5
6
  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, keys, omit, pick, splitProps } from './object.mjs';
7
+ export { MergeWithDefault, compact, createSplitProps, json, keys, mergeWithDefault, omit, pick, splitProps } from './object.mjs';
7
8
  export { Store, StoreCompareFn, StoreListener, createStore } from './store.mjs';
8
9
  export { Timer, TimerBaseContext, TimerContextFn, setRafInterval, setRafTimeout } from './timers.mjs';
9
10
  export { ensure, ensureProps, invariant, warn } from './warning.mjs';
package/dist/index.d.ts CHANGED
@@ -2,8 +2,9 @@ export { IndexOptions, add, addOrRemove, chunk, clear, diff, first, flatArray, f
2
2
  export { isEqual } from './equal.js';
3
3
  export { MaybeFunction, Nullable, callAll, cast, debounce, hash, identity, match, noop, runIfFn, throttle, tryCatch, uuid } from './functions.js';
4
4
  export { hasProp, isArray, isBoolean, isDev, isFunction, isNull, isNumber, isObject, isObjectLike, isPlainObject, isString } from './guard.js';
5
+ export { Teardown, TeardownReason } from './lifecycle.js';
5
6
  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, keys, omit, pick, splitProps } from './object.js';
7
+ export { MergeWithDefault, compact, createSplitProps, json, keys, mergeWithDefault, omit, pick, splitProps } from './object.js';
7
8
  export { Store, StoreCompareFn, StoreListener, createStore } from './store.js';
8
9
  export { Timer, TimerBaseContext, TimerContextFn, setRafInterval, setRafTimeout } from './timers.js';
9
10
  export { ensure, ensureProps, invariant, warn } from './warning.js';
package/dist/index.js CHANGED
@@ -21,6 +21,7 @@ __reExport(index_exports, require("./array.js"), module.exports);
21
21
  __reExport(index_exports, require("./equal.js"), module.exports);
22
22
  __reExport(index_exports, require("./functions.js"), module.exports);
23
23
  __reExport(index_exports, require("./guard.js"), module.exports);
24
+ __reExport(index_exports, require("./lifecycle.js"), module.exports);
24
25
  __reExport(index_exports, require("./number.js"), module.exports);
25
26
  __reExport(index_exports, require("./object.js"), module.exports);
26
27
  __reExport(index_exports, require("./store.js"), module.exports);
@@ -32,6 +33,7 @@ __reExport(index_exports, require("./warning.js"), module.exports);
32
33
  ...require("./equal.js"),
33
34
  ...require("./functions.js"),
34
35
  ...require("./guard.js"),
36
+ ...require("./lifecycle.js"),
35
37
  ...require("./number.js"),
36
38
  ...require("./object.js"),
37
39
  ...require("./store.js"),
package/dist/index.mjs CHANGED
@@ -3,6 +3,7 @@ export * from "./array.mjs";
3
3
  export * from "./equal.mjs";
4
4
  export * from "./functions.mjs";
5
5
  export * from "./guard.mjs";
6
+ export * from "./lifecycle.mjs";
6
7
  export * from "./number.mjs";
7
8
  export * from "./object.mjs";
8
9
  export * from "./store.mjs";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Why a cleanup is running: its inputs changed and it will be set up again, or it is being torn
3
+ * down for good. Lets a cleanup release resources gently on a restart, and fully on an exit.
4
+ */
5
+ type TeardownReason = "restart" | "exit";
6
+ /** A cleanup that may inspect why it was called. A plain `VoidFunction` is still valid. */
7
+ type Teardown = (reason: TeardownReason) => void;
8
+
9
+ export type { Teardown, TeardownReason };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Why a cleanup is running: its inputs changed and it will be set up again, or it is being torn
3
+ * down for good. Lets a cleanup release resources gently on a restart, and fully on an exit.
4
+ */
5
+ type TeardownReason = "restart" | "exit";
6
+ /** A cleanup that may inspect why it was called. A plain `VoidFunction` is still valid. */
7
+ type Teardown = (reason: TeardownReason) => void;
8
+
9
+ export type { Teardown, TeardownReason };
@@ -0,0 +1,18 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/lifecycle.ts
17
+ var lifecycle_exports = {};
18
+ module.exports = __toCommonJS(lifecycle_exports);
File without changes
package/dist/object.d.mts CHANGED
@@ -6,5 +6,12 @@ type Dict = Record<string | symbol, any>;
6
6
  declare function splitProps<T extends Dict>(props: T, keys: (keyof T)[]): Dict[];
7
7
  declare const createSplitProps: <T extends Dict>(keys: (keyof T)[]) => <Props extends T>(props: Props) => [T, Omit<Props, keyof T>];
8
8
  declare function omit<T extends Record<string, any>>(obj: T, keys: string[]): Omit<T, string | number>;
9
+ type Defined<T> = {
10
+ [K in keyof T]-?: Exclude<T[K], undefined>;
11
+ };
12
+ type MergeWithDefault<D, O = unknown> = Defined<D> & ([NonNullable<O>] extends [never] ? unknown : Omit<NonNullable<O>, keyof D>);
13
+ declare function mergeWithDefault<D extends object, O extends {
14
+ [K in keyof D]?: D[K] | undefined;
15
+ } | undefined>(defaults: D, overrides?: O): MergeWithDefault<D, O>;
9
16
 
10
- export { compact, createSplitProps, json, keys, omit, pick, splitProps };
17
+ export { type MergeWithDefault, compact, createSplitProps, json, keys, mergeWithDefault, omit, pick, splitProps };
package/dist/object.d.ts CHANGED
@@ -6,5 +6,12 @@ type Dict = Record<string | symbol, any>;
6
6
  declare function splitProps<T extends Dict>(props: T, keys: (keyof T)[]): Dict[];
7
7
  declare const createSplitProps: <T extends Dict>(keys: (keyof T)[]) => <Props extends T>(props: Props) => [T, Omit<Props, keyof T>];
8
8
  declare function omit<T extends Record<string, any>>(obj: T, keys: string[]): Omit<T, string | number>;
9
+ type Defined<T> = {
10
+ [K in keyof T]-?: Exclude<T[K], undefined>;
11
+ };
12
+ type MergeWithDefault<D, O = unknown> = Defined<D> & ([NonNullable<O>] extends [never] ? unknown : Omit<NonNullable<O>, keyof D>);
13
+ declare function mergeWithDefault<D extends object, O extends {
14
+ [K in keyof D]?: D[K] | undefined;
15
+ } | undefined>(defaults: D, overrides?: O): MergeWithDefault<D, O>;
9
16
 
10
- export { compact, createSplitProps, json, keys, omit, pick, splitProps };
17
+ export { type MergeWithDefault, compact, createSplitProps, json, keys, mergeWithDefault, omit, pick, splitProps };
package/dist/object.js CHANGED
@@ -24,6 +24,7 @@ __export(object_exports, {
24
24
  createSplitProps: () => createSplitProps,
25
25
  json: () => json,
26
26
  keys: () => keys,
27
+ mergeWithDefault: () => mergeWithDefault,
27
28
  omit: () => omit,
28
29
  pick: () => pick,
29
30
  splitProps: () => splitProps
@@ -76,12 +77,23 @@ var createSplitProps = (keys2) => {
76
77
  function omit(obj, keys2) {
77
78
  return createSplitProps(keys2)(obj)[1];
78
79
  }
80
+ function mergeWithDefault(defaults, overrides) {
81
+ if (!overrides) return defaults;
82
+ const result = { ...defaults };
83
+ const source = overrides;
84
+ for (const key in source) {
85
+ const value = source[key];
86
+ if (value !== void 0) result[key] = value;
87
+ }
88
+ return result;
89
+ }
79
90
  // Annotate the CommonJS export names for ESM import in node:
80
91
  0 && (module.exports = {
81
92
  compact,
82
93
  createSplitProps,
83
94
  json,
84
95
  keys,
96
+ mergeWithDefault,
85
97
  omit,
86
98
  pick,
87
99
  splitProps
package/dist/object.mjs CHANGED
@@ -48,11 +48,22 @@ var createSplitProps = (keys2) => {
48
48
  function omit(obj, keys2) {
49
49
  return createSplitProps(keys2)(obj)[1];
50
50
  }
51
+ function mergeWithDefault(defaults, overrides) {
52
+ if (!overrides) return defaults;
53
+ const result = { ...defaults };
54
+ const source = overrides;
55
+ for (const key in source) {
56
+ const value = source[key];
57
+ if (value !== void 0) result[key] = value;
58
+ }
59
+ return result;
60
+ }
51
61
  export {
52
62
  compact,
53
63
  createSplitProps,
54
64
  json,
55
65
  keys,
66
+ mergeWithDefault,
56
67
  omit,
57
68
  pick,
58
69
  splitProps
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/utils",
3
- "version": "2.0.0-next.0",
3
+ "version": "2.0.0-next.2",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "js",
@@ -10,7 +10,10 @@
10
10
  "author": "Segun Adebayo <sage@adebayosegun.com>",
11
11
  "homepage": "https://github.com/chakra-ui/zag#readme",
12
12
  "license": "MIT",
13
- "repository": "https://github.com/chakra-ui/zag/tree/main/packages/utilities/core",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/chakra-ui/zag/tree/main/packages/utilities/core"
16
+ },
14
17
  "sideEffects": false,
15
18
  "files": [
16
19
  "dist"
@@ -43,7 +46,7 @@
43
46
  },
44
47
  "scripts": {
45
48
  "build": "tsup",
46
- "lint": "eslint src",
49
+ "lint": "oxlint src",
47
50
  "typecheck": "tsc --noEmit"
48
51
  }
49
52
  }