@zag-js/number-input 0.1.19 → 0.2.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.ts CHANGED
@@ -234,6 +234,6 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
234
234
  scrubberProps: T["element"];
235
235
  };
236
236
 
237
- declare function machine(ctx: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
237
+ declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
238
238
 
239
239
  export { UserDefinedContext as Context, connect, machine };
package/dist/index.js CHANGED
@@ -35,7 +35,7 @@ var ariaAttr = (guard) => {
35
35
  var MAX_Z_INDEX = 2147483647;
36
36
  var runIfFn = (v, ...a) => {
37
37
  const res = typeof v === "function" ? v(...a) : v;
38
- return res ?? void 0;
38
+ return res != null ? res : void 0;
39
39
  };
40
40
  var callAll = (...fns) => (...a) => {
41
41
  fns.forEach(function(fn) {
@@ -47,8 +47,9 @@ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
47
47
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
48
48
  var isDom = () => typeof window !== "undefined";
49
49
  function getPlatform() {
50
+ var _a;
50
51
  const agent = navigator.userAgentData;
51
- return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
52
+ return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
52
53
  }
53
54
  var pt = (v) => isDom() && v.test(getPlatform());
54
55
  var vn = (v) => isDom() && v.test(navigator.vendor);
@@ -61,22 +62,44 @@ function isWindow(value) {
61
62
  return (value == null ? void 0 : value.toString()) === "[object Window]";
62
63
  }
63
64
  function getDocument(el) {
65
+ var _a;
64
66
  if (isWindow(el))
65
67
  return el.document;
66
68
  if (isDocument(el))
67
69
  return el;
68
- return (el == null ? void 0 : el.ownerDocument) ?? document;
70
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
69
71
  }
70
72
  function defineDomHelpers(helpers) {
71
73
  const dom2 = {
72
74
  getRootNode: (ctx) => {
73
- var _a;
74
- return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
75
+ var _a, _b;
76
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
75
77
  },
76
78
  getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
77
- getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
79
+ getWin: (ctx) => {
80
+ var _a;
81
+ return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
82
+ },
78
83
  getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
79
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
84
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
85
+ createEmitter: (ctx, target) => {
86
+ const win = dom2.getWin(ctx);
87
+ return function emit(evt, detail, options) {
88
+ const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
89
+ const eventName = `zag:${evt}`;
90
+ const init = { bubbles, cancelable, composed, detail };
91
+ const event = new win.CustomEvent(eventName, init);
92
+ target.dispatchEvent(event);
93
+ };
94
+ },
95
+ createListener: (target) => {
96
+ return function listen(evt, handler) {
97
+ const eventName = `zag:${evt}`;
98
+ const listener = (e) => handler(e);
99
+ target.addEventListener(eventName, listener);
100
+ return () => target.removeEventListener(eventName, listener);
101
+ };
102
+ }
80
103
  };
81
104
  return {
82
105
  ...dom2,
@@ -84,7 +107,8 @@ function defineDomHelpers(helpers) {
84
107
  };
85
108
  }
86
109
  function getNativeEvent(e) {
87
- return e.nativeEvent ?? e;
110
+ var _a;
111
+ return (_a = e.nativeEvent) != null ? _a : e;
88
112
  }
89
113
  var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
90
114
  var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
@@ -97,7 +121,8 @@ var fallback = {
97
121
  clientY: 0
98
122
  };
99
123
  function getEventPoint(event, type = "page") {
100
- const point = isTouchEvent(event) ? event.touches[0] ?? event.changedTouches[0] ?? fallback : event;
124
+ var _a, _b;
125
+ const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event;
101
126
  return { x: point[`${type}X`], y: point[`${type}Y`] };
102
127
  }
103
128
  var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
@@ -251,29 +276,29 @@ var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigit
251
276
  // src/number-input.dom.ts
252
277
  var dom = defineDomHelpers({
253
278
  getRootId: (ctx) => {
254
- var _a;
255
- return ((_a = ctx.ids) == null ? void 0 : _a.root) ?? `number-input:${ctx.id}`;
279
+ var _a, _b;
280
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `number-input:${ctx.id}`;
256
281
  },
257
282
  getInputId: (ctx) => {
258
- var _a;
259
- return ((_a = ctx.ids) == null ? void 0 : _a.input) ?? `number-input:${ctx.id}:input`;
283
+ var _a, _b;
284
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.input) != null ? _b : `number-input:${ctx.id}:input`;
260
285
  },
261
286
  getIncButtonId: (ctx) => {
262
- var _a;
263
- return ((_a = ctx.ids) == null ? void 0 : _a.incBtn) ?? `number-input:${ctx.id}:inc-btn`;
287
+ var _a, _b;
288
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.incBtn) != null ? _b : `number-input:${ctx.id}:inc-btn`;
264
289
  },
265
290
  getDecButtonId: (ctx) => {
266
- var _a;
267
- return ((_a = ctx.ids) == null ? void 0 : _a.decBtn) ?? `number-input:${ctx.id}:dec-btn`;
291
+ var _a, _b;
292
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.decBtn) != null ? _b : `number-input:${ctx.id}:dec-btn`;
268
293
  },
269
294
  getScrubberId: (ctx) => {
270
- var _a;
271
- return ((_a = ctx.ids) == null ? void 0 : _a.scrubber) ?? `number-input:${ctx.id}:scrubber`;
295
+ var _a, _b;
296
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.scrubber) != null ? _b : `number-input:${ctx.id}:scrubber`;
272
297
  },
273
298
  getCursorId: (ctx) => `number-input:${ctx.id}:cursor`,
274
299
  getLabelId: (ctx) => {
275
- var _a;
276
- return ((_a = ctx.ids) == null ? void 0 : _a.label) ?? `number-input:${ctx.id}:label`;
300
+ var _a, _b;
301
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `number-input:${ctx.id}:label`;
277
302
  },
278
303
  getInputEl: (ctx) => dom.getById(ctx, dom.getInputId(ctx)),
279
304
  getIncButtonEl: (ctx) => dom.getById(ctx, dom.getIncButtonId(ctx)),
@@ -366,38 +391,39 @@ var dom = defineDomHelpers({
366
391
  // src/number-input.utils.ts
367
392
  var utils = {
368
393
  isValidNumericEvent: (ctx, event) => {
369
- var _a;
394
+ var _a, _b;
370
395
  if (event.key == null)
371
396
  return true;
372
397
  const isModifier = isModifiedEvent(event);
373
398
  const isSingleKey = event.key.length === 1;
374
399
  if (isModifier || !isSingleKey)
375
400
  return true;
376
- return ((_a = ctx.validateCharacter) == null ? void 0 : _a.call(ctx, event.key)) ?? utils.isFloatingPoint(event.key);
401
+ return (_b = (_a = ctx.validateCharacter) == null ? void 0 : _a.call(ctx, event.key)) != null ? _b : utils.isFloatingPoint(event.key);
377
402
  },
378
403
  isFloatingPoint: (v) => /^[0-9+\-.]$/.test(v),
379
404
  sanitize: (ctx, value) => {
380
- return value.split("").filter(ctx.validateCharacter ?? utils.isFloatingPoint).join("");
405
+ var _a;
406
+ return value.split("").filter((_a = ctx.validateCharacter) != null ? _a : utils.isFloatingPoint).join("");
381
407
  },
382
408
  increment: (ctx, step) => {
383
- const value = increment(ctx.value, step ?? ctx.step);
409
+ const value = increment(ctx.value, step != null ? step : ctx.step);
384
410
  return formatDecimal(clamp(value, ctx), ctx);
385
411
  },
386
412
  decrement: (ctx, step) => {
387
- const value = decrement(ctx.value, step ?? ctx.step);
413
+ const value = decrement(ctx.value, step != null ? step : ctx.step);
388
414
  return formatDecimal(clamp(value, ctx), ctx);
389
415
  },
390
416
  clamp: (ctx) => {
391
417
  return formatDecimal(clamp(ctx.value, ctx), ctx);
392
418
  },
393
419
  parse: (ctx, value) => {
394
- var _a;
395
- return ((_a = ctx.parse) == null ? void 0 : _a.call(ctx, value)) ?? value;
420
+ var _a, _b;
421
+ return (_b = (_a = ctx.parse) == null ? void 0 : _a.call(ctx, value)) != null ? _b : value;
396
422
  },
397
423
  format: (ctx, value) => {
398
- var _a;
424
+ var _a, _b;
399
425
  const _val = value.toString();
400
- return ((_a = ctx.format) == null ? void 0 : _a.call(ctx, _val)) ?? _val;
426
+ return (_b = (_a = ctx.format) == null ? void 0 : _a.call(ctx, _val)) != null ? _b : _val;
401
427
  },
402
428
  round: (ctx) => {
403
429
  return formatDecimal(ctx.value, ctx);
@@ -607,15 +633,26 @@ var callAll2 = (...fns) => (...a) => {
607
633
  fn == null ? void 0 : fn(...a);
608
634
  });
609
635
  };
636
+ var isArray2 = (v) => Array.isArray(v);
637
+ var isObject2 = (v) => !(v == null || typeof v !== "object" || isArray2(v));
638
+ function compact(obj) {
639
+ if (obj === void 0)
640
+ return obj;
641
+ return Object.fromEntries(
642
+ Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject2(value) ? compact(value) : value])
643
+ );
644
+ }
610
645
 
611
646
  // ../../utilities/form-utils/dist/index.mjs
612
647
  function getWindow(el) {
613
- return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
648
+ var _a;
649
+ return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
614
650
  }
615
651
  function getDescriptor(el, options) {
652
+ var _a;
616
653
  const { type, property } = options;
617
654
  const proto = getWindow(el)[type].prototype;
618
- return Object.getOwnPropertyDescriptor(proto, property) ?? {};
655
+ return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
619
656
  }
620
657
  function dispatchInputValueEvent(el, value) {
621
658
  var _a;
@@ -632,7 +669,8 @@ function dispatchInputValueEvent(el, value) {
632
669
 
633
670
  // src/number-input.machine.ts
634
671
  var { not, and } = import_core.guards;
635
- function machine(ctx) {
672
+ function machine(userContext) {
673
+ const ctx = compact(userContext);
636
674
  return (0, import_core.createMachine)(
637
675
  {
638
676
  id: "number-input",
@@ -673,8 +711,8 @@ function machine(ctx) {
673
711
  return (_b = (_a = ctx2.translations).valueText) == null ? void 0 : _b.call(_a, ctx2.value);
674
712
  },
675
713
  formattedValue: (ctx2) => {
676
- var _a;
677
- return ((_a = ctx2.format) == null ? void 0 : _a.call(ctx2, ctx2.value).toString()) ?? ctx2.value;
714
+ var _a, _b;
715
+ return (_b = (_a = ctx2.format) == null ? void 0 : _a.call(ctx2, ctx2.value).toString()) != null ? _b : ctx2.value;
678
716
  }
679
717
  },
680
718
  watch: {
@@ -844,9 +882,15 @@ function machine(ctx) {
844
882
  spinOnPress: (ctx2) => !!ctx2.spinOnPress,
845
883
  isAtMax: (ctx2) => ctx2.isAtMax,
846
884
  isInRange: (ctx2) => !ctx2.isOutOfRange,
847
- isDecrementHint: (ctx2, evt) => (evt.hint ?? ctx2.hint) === "decrement",
885
+ isDecrementHint: (ctx2, evt) => {
886
+ var _a;
887
+ return ((_a = evt.hint) != null ? _a : ctx2.hint) === "decrement";
888
+ },
848
889
  isEmptyValue: (ctx2) => ctx2.isValueEmpty,
849
- isIncrementHint: (ctx2, evt) => (evt.hint ?? ctx2.hint) === "increment",
890
+ isIncrementHint: (ctx2, evt) => {
891
+ var _a;
892
+ return ((_a = evt.hint) != null ? _a : ctx2.hint) === "increment";
893
+ },
850
894
  isInvalidExponential: (ctx2) => ctx2.value.toString().startsWith("e")
851
895
  },
852
896
  activities: {
@@ -928,8 +972,8 @@ function machine(ctx) {
928
972
  }
929
973
  },
930
974
  setValue(ctx2, evt) {
931
- var _a;
932
- const value = ((_a = evt.target) == null ? void 0 : _a.value) ?? evt.value;
975
+ var _a, _b;
976
+ const value = (_b = (_a = evt.target) == null ? void 0 : _a.value) != null ? _b : evt.value;
933
977
  ctx2.value = utils.sanitize(ctx2, utils.parse(ctx2, value.toString()));
934
978
  },
935
979
  clearValue(ctx2) {
package/dist/index.mjs CHANGED
@@ -8,7 +8,7 @@ var ariaAttr = (guard) => {
8
8
  var MAX_Z_INDEX = 2147483647;
9
9
  var runIfFn = (v, ...a) => {
10
10
  const res = typeof v === "function" ? v(...a) : v;
11
- return res ?? void 0;
11
+ return res != null ? res : void 0;
12
12
  };
13
13
  var callAll = (...fns) => (...a) => {
14
14
  fns.forEach(function(fn) {
@@ -20,8 +20,9 @@ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
20
20
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
21
21
  var isDom = () => typeof window !== "undefined";
22
22
  function getPlatform() {
23
+ var _a;
23
24
  const agent = navigator.userAgentData;
24
- return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
25
+ return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
25
26
  }
26
27
  var pt = (v) => isDom() && v.test(getPlatform());
27
28
  var vn = (v) => isDom() && v.test(navigator.vendor);
@@ -34,22 +35,44 @@ function isWindow(value) {
34
35
  return (value == null ? void 0 : value.toString()) === "[object Window]";
35
36
  }
36
37
  function getDocument(el) {
38
+ var _a;
37
39
  if (isWindow(el))
38
40
  return el.document;
39
41
  if (isDocument(el))
40
42
  return el;
41
- return (el == null ? void 0 : el.ownerDocument) ?? document;
43
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
42
44
  }
43
45
  function defineDomHelpers(helpers) {
44
46
  const dom2 = {
45
47
  getRootNode: (ctx) => {
46
- var _a;
47
- return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
48
+ var _a, _b;
49
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
48
50
  },
49
51
  getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
50
- getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
52
+ getWin: (ctx) => {
53
+ var _a;
54
+ return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
55
+ },
51
56
  getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
52
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
57
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
58
+ createEmitter: (ctx, target) => {
59
+ const win = dom2.getWin(ctx);
60
+ return function emit(evt, detail, options) {
61
+ const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
62
+ const eventName = `zag:${evt}`;
63
+ const init = { bubbles, cancelable, composed, detail };
64
+ const event = new win.CustomEvent(eventName, init);
65
+ target.dispatchEvent(event);
66
+ };
67
+ },
68
+ createListener: (target) => {
69
+ return function listen(evt, handler) {
70
+ const eventName = `zag:${evt}`;
71
+ const listener = (e) => handler(e);
72
+ target.addEventListener(eventName, listener);
73
+ return () => target.removeEventListener(eventName, listener);
74
+ };
75
+ }
53
76
  };
54
77
  return {
55
78
  ...dom2,
@@ -57,7 +80,8 @@ function defineDomHelpers(helpers) {
57
80
  };
58
81
  }
59
82
  function getNativeEvent(e) {
60
- return e.nativeEvent ?? e;
83
+ var _a;
84
+ return (_a = e.nativeEvent) != null ? _a : e;
61
85
  }
62
86
  var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
63
87
  var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
@@ -70,7 +94,8 @@ var fallback = {
70
94
  clientY: 0
71
95
  };
72
96
  function getEventPoint(event, type = "page") {
73
- const point = isTouchEvent(event) ? event.touches[0] ?? event.changedTouches[0] ?? fallback : event;
97
+ var _a, _b;
98
+ const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event;
74
99
  return { x: point[`${type}X`], y: point[`${type}Y`] };
75
100
  }
76
101
  var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
@@ -224,29 +249,29 @@ var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigit
224
249
  // src/number-input.dom.ts
225
250
  var dom = defineDomHelpers({
226
251
  getRootId: (ctx) => {
227
- var _a;
228
- return ((_a = ctx.ids) == null ? void 0 : _a.root) ?? `number-input:${ctx.id}`;
252
+ var _a, _b;
253
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `number-input:${ctx.id}`;
229
254
  },
230
255
  getInputId: (ctx) => {
231
- var _a;
232
- return ((_a = ctx.ids) == null ? void 0 : _a.input) ?? `number-input:${ctx.id}:input`;
256
+ var _a, _b;
257
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.input) != null ? _b : `number-input:${ctx.id}:input`;
233
258
  },
234
259
  getIncButtonId: (ctx) => {
235
- var _a;
236
- return ((_a = ctx.ids) == null ? void 0 : _a.incBtn) ?? `number-input:${ctx.id}:inc-btn`;
260
+ var _a, _b;
261
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.incBtn) != null ? _b : `number-input:${ctx.id}:inc-btn`;
237
262
  },
238
263
  getDecButtonId: (ctx) => {
239
- var _a;
240
- return ((_a = ctx.ids) == null ? void 0 : _a.decBtn) ?? `number-input:${ctx.id}:dec-btn`;
264
+ var _a, _b;
265
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.decBtn) != null ? _b : `number-input:${ctx.id}:dec-btn`;
241
266
  },
242
267
  getScrubberId: (ctx) => {
243
- var _a;
244
- return ((_a = ctx.ids) == null ? void 0 : _a.scrubber) ?? `number-input:${ctx.id}:scrubber`;
268
+ var _a, _b;
269
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.scrubber) != null ? _b : `number-input:${ctx.id}:scrubber`;
245
270
  },
246
271
  getCursorId: (ctx) => `number-input:${ctx.id}:cursor`,
247
272
  getLabelId: (ctx) => {
248
- var _a;
249
- return ((_a = ctx.ids) == null ? void 0 : _a.label) ?? `number-input:${ctx.id}:label`;
273
+ var _a, _b;
274
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `number-input:${ctx.id}:label`;
250
275
  },
251
276
  getInputEl: (ctx) => dom.getById(ctx, dom.getInputId(ctx)),
252
277
  getIncButtonEl: (ctx) => dom.getById(ctx, dom.getIncButtonId(ctx)),
@@ -339,38 +364,39 @@ var dom = defineDomHelpers({
339
364
  // src/number-input.utils.ts
340
365
  var utils = {
341
366
  isValidNumericEvent: (ctx, event) => {
342
- var _a;
367
+ var _a, _b;
343
368
  if (event.key == null)
344
369
  return true;
345
370
  const isModifier = isModifiedEvent(event);
346
371
  const isSingleKey = event.key.length === 1;
347
372
  if (isModifier || !isSingleKey)
348
373
  return true;
349
- return ((_a = ctx.validateCharacter) == null ? void 0 : _a.call(ctx, event.key)) ?? utils.isFloatingPoint(event.key);
374
+ return (_b = (_a = ctx.validateCharacter) == null ? void 0 : _a.call(ctx, event.key)) != null ? _b : utils.isFloatingPoint(event.key);
350
375
  },
351
376
  isFloatingPoint: (v) => /^[0-9+\-.]$/.test(v),
352
377
  sanitize: (ctx, value) => {
353
- return value.split("").filter(ctx.validateCharacter ?? utils.isFloatingPoint).join("");
378
+ var _a;
379
+ return value.split("").filter((_a = ctx.validateCharacter) != null ? _a : utils.isFloatingPoint).join("");
354
380
  },
355
381
  increment: (ctx, step) => {
356
- const value = increment(ctx.value, step ?? ctx.step);
382
+ const value = increment(ctx.value, step != null ? step : ctx.step);
357
383
  return formatDecimal(clamp(value, ctx), ctx);
358
384
  },
359
385
  decrement: (ctx, step) => {
360
- const value = decrement(ctx.value, step ?? ctx.step);
386
+ const value = decrement(ctx.value, step != null ? step : ctx.step);
361
387
  return formatDecimal(clamp(value, ctx), ctx);
362
388
  },
363
389
  clamp: (ctx) => {
364
390
  return formatDecimal(clamp(ctx.value, ctx), ctx);
365
391
  },
366
392
  parse: (ctx, value) => {
367
- var _a;
368
- return ((_a = ctx.parse) == null ? void 0 : _a.call(ctx, value)) ?? value;
393
+ var _a, _b;
394
+ return (_b = (_a = ctx.parse) == null ? void 0 : _a.call(ctx, value)) != null ? _b : value;
369
395
  },
370
396
  format: (ctx, value) => {
371
- var _a;
397
+ var _a, _b;
372
398
  const _val = value.toString();
373
- return ((_a = ctx.format) == null ? void 0 : _a.call(ctx, _val)) ?? _val;
399
+ return (_b = (_a = ctx.format) == null ? void 0 : _a.call(ctx, _val)) != null ? _b : _val;
374
400
  },
375
401
  round: (ctx) => {
376
402
  return formatDecimal(ctx.value, ctx);
@@ -580,15 +606,26 @@ var callAll2 = (...fns) => (...a) => {
580
606
  fn == null ? void 0 : fn(...a);
581
607
  });
582
608
  };
609
+ var isArray2 = (v) => Array.isArray(v);
610
+ var isObject2 = (v) => !(v == null || typeof v !== "object" || isArray2(v));
611
+ function compact(obj) {
612
+ if (obj === void 0)
613
+ return obj;
614
+ return Object.fromEntries(
615
+ Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject2(value) ? compact(value) : value])
616
+ );
617
+ }
583
618
 
584
619
  // ../../utilities/form-utils/dist/index.mjs
585
620
  function getWindow(el) {
586
- return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
621
+ var _a;
622
+ return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
587
623
  }
588
624
  function getDescriptor(el, options) {
625
+ var _a;
589
626
  const { type, property } = options;
590
627
  const proto = getWindow(el)[type].prototype;
591
- return Object.getOwnPropertyDescriptor(proto, property) ?? {};
628
+ return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
592
629
  }
593
630
  function dispatchInputValueEvent(el, value) {
594
631
  var _a;
@@ -605,7 +642,8 @@ function dispatchInputValueEvent(el, value) {
605
642
 
606
643
  // src/number-input.machine.ts
607
644
  var { not, and } = guards;
608
- function machine(ctx) {
645
+ function machine(userContext) {
646
+ const ctx = compact(userContext);
609
647
  return createMachine(
610
648
  {
611
649
  id: "number-input",
@@ -646,8 +684,8 @@ function machine(ctx) {
646
684
  return (_b = (_a = ctx2.translations).valueText) == null ? void 0 : _b.call(_a, ctx2.value);
647
685
  },
648
686
  formattedValue: (ctx2) => {
649
- var _a;
650
- return ((_a = ctx2.format) == null ? void 0 : _a.call(ctx2, ctx2.value).toString()) ?? ctx2.value;
687
+ var _a, _b;
688
+ return (_b = (_a = ctx2.format) == null ? void 0 : _a.call(ctx2, ctx2.value).toString()) != null ? _b : ctx2.value;
651
689
  }
652
690
  },
653
691
  watch: {
@@ -817,9 +855,15 @@ function machine(ctx) {
817
855
  spinOnPress: (ctx2) => !!ctx2.spinOnPress,
818
856
  isAtMax: (ctx2) => ctx2.isAtMax,
819
857
  isInRange: (ctx2) => !ctx2.isOutOfRange,
820
- isDecrementHint: (ctx2, evt) => (evt.hint ?? ctx2.hint) === "decrement",
858
+ isDecrementHint: (ctx2, evt) => {
859
+ var _a;
860
+ return ((_a = evt.hint) != null ? _a : ctx2.hint) === "decrement";
861
+ },
821
862
  isEmptyValue: (ctx2) => ctx2.isValueEmpty,
822
- isIncrementHint: (ctx2, evt) => (evt.hint ?? ctx2.hint) === "increment",
863
+ isIncrementHint: (ctx2, evt) => {
864
+ var _a;
865
+ return ((_a = evt.hint) != null ? _a : ctx2.hint) === "increment";
866
+ },
823
867
  isInvalidExponential: (ctx2) => ctx2.value.toString().startsWith("e")
824
868
  },
825
869
  activities: {
@@ -901,8 +945,8 @@ function machine(ctx) {
901
945
  }
902
946
  },
903
947
  setValue(ctx2, evt) {
904
- var _a;
905
- const value = ((_a = evt.target) == null ? void 0 : _a.value) ?? evt.value;
948
+ var _a, _b;
949
+ const value = (_b = (_a = evt.target) == null ? void 0 : _a.value) != null ? _b : evt.value;
906
950
  ctx2.value = utils.sanitize(ctx2, utils.parse(ctx2, value.toString()));
907
951
  },
908
952
  clearValue(ctx2) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/number-input",
3
- "version": "0.1.19",
3
+ "version": "0.2.1",
4
4
  "description": "Core logic for the number-input widget implemented as a state machine",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -29,14 +29,14 @@
29
29
  "url": "https://github.com/chakra-ui/zag/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@zag-js/core": "0.1.12",
33
- "@zag-js/types": "0.2.7"
32
+ "@zag-js/core": "0.2.1",
33
+ "@zag-js/types": "0.3.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@zag-js/dom-utils": "0.1.13",
37
- "@zag-js/form-utils": "0.1.3",
38
- "@zag-js/number-utils": "0.1.6",
39
- "@zag-js/utils": "0.1.6"
36
+ "@zag-js/dom-utils": "0.2.0",
37
+ "@zag-js/form-utils": "0.2.0",
38
+ "@zag-js/number-utils": "0.2.0",
39
+ "@zag-js/utils": "0.3.0"
40
40
  },
41
41
  "scripts": {
42
42
  "build-fast": "tsup src/index.ts --format=esm,cjs",