@zag-js/number-input 0.1.6 → 0.1.9

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.mjs CHANGED
@@ -31,6 +31,13 @@ function raf(fn) {
31
31
  globalThis.cancelAnimationFrame(id);
32
32
  };
33
33
  }
34
+ var isDom = () => typeof window !== "undefined";
35
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
36
+ var isTouchDevice = isDom() && !!navigator.maxTouchPoints;
37
+ var runIfFn = (v, ...a) => {
38
+ const res = typeof v === "function" ? v(...a) : v;
39
+ return res != null ? res : void 0;
40
+ };
34
41
  var noop = () => {
35
42
  };
36
43
  var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
@@ -44,7 +51,7 @@ function getListenerCache() {
44
51
  globalThis.__listenerCache__ = globalThis.__listenerCache__ || /* @__PURE__ */ new Map();
45
52
  return globalThis.__listenerCache__;
46
53
  }
47
- function globalEventBus(node, type, handler, options) {
54
+ function addGlobalEventListener(node, type, handler, options) {
48
55
  var _a;
49
56
  if (!node)
50
57
  return noop;
@@ -96,28 +103,15 @@ function globalEventBus(node, type, handler, options) {
96
103
  }
97
104
  };
98
105
  }
99
- var t = (v) => Object.prototype.toString.call(v).slice(8, -1);
100
- var isRef = (v) => t(v) === "Object" && "current" in v;
101
- var runIfFn = (fn) => t(fn) === "Function" ? fn() : fn;
106
+ var isRef = (v) => hasProp(v, "current");
102
107
  function addDomEvent(target, event, listener, options) {
103
108
  const node = isRef(target) ? target.current : runIfFn(target);
104
- return globalEventBus(node, event, listener, options);
109
+ return addGlobalEventListener(node, event, listener, options);
105
110
  }
106
111
  var MAX_Z_INDEX = 2147483647;
107
- function getNativeEvent(event) {
112
+ function getNativeEvent(e) {
108
113
  var _a;
109
- return (_a = event.nativeEvent) != null ? _a : event;
110
- }
111
- var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
112
- var ARROW_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
113
- function getEventStep(event) {
114
- if (event.ctrlKey || event.metaKey) {
115
- return 0.1;
116
- } else {
117
- const isPageKey = PAGE_KEYS.has(event.key);
118
- const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.has(event.key);
119
- return isSkipKey ? 10 : 1;
120
- }
114
+ return (_a = e.nativeEvent) != null ? _a : e;
121
115
  }
122
116
  function observeAttributes(node, attributes, fn) {
123
117
  if (!node)
@@ -134,6 +128,17 @@ function observeAttributes(node, attributes, fn) {
134
128
  obs.observe(node, { attributes: true, attributeFilter: attrs });
135
129
  return () => obs.disconnect();
136
130
  }
131
+ var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
132
+ var ARROW_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
133
+ function getEventStep(event) {
134
+ if (event.ctrlKey || event.metaKey) {
135
+ return 0.1;
136
+ } else {
137
+ const isPageKey = PAGE_KEYS.has(event.key);
138
+ const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.has(event.key);
139
+ return isSkipKey ? 10 : 1;
140
+ }
141
+ }
137
142
  function itemById(v, id) {
138
143
  return v.find((node) => node.id === id);
139
144
  }
@@ -293,33 +298,46 @@ function decimalOperation(a, op, b) {
293
298
  var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
294
299
 
295
300
  // ../../utilities/rect/dist/index.mjs
301
+ var isDom2 = () => typeof window !== "undefined";
296
302
  var isArray = (v) => Array.isArray(v);
297
303
  var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
298
- var isTouchEvent = (v) => isObject(v) && "touches" in v;
304
+ var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
305
+ var isTouchDevice2 = isDom2() && !!navigator.maxTouchPoints;
306
+ var isTouchEvent = (v) => isObject(v) && hasProp2(v, "touches");
299
307
  var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
300
- function getEventPoint(e, t2 = "page") {
308
+ function getEventPoint(e, t = "page") {
301
309
  const p = isTouchEvent(e) ? e.touches[0] || e.changedTouches[0] || fallback : e;
302
- return { x: p[`${t2}X`], y: p[`${t2}Y`] };
310
+ return { x: p[`${t}X`], y: p[`${t}Y`] };
303
311
  }
304
312
 
305
313
  // ../../types/dist/index.mjs
306
314
  function createNormalizer(fn) {
307
- return { button: fn, label: fn, input: fn, output: fn, element: fn };
315
+ return new Proxy({}, {
316
+ get() {
317
+ return fn;
318
+ }
319
+ });
308
320
  }
309
321
  var normalizeProp = createNormalizer((v) => v);
310
322
 
311
323
  // ../../utilities/core/dist/index.mjs
312
- var pipe2 = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
313
- var platform = (v) => isDom() && v.test(navigator.platform);
314
- var ua = (v) => isDom() && v.test(navigator.userAgent);
315
- var isDom = () => !!(typeof window !== "undefined");
316
- var isMac = () => platform(/^Mac/);
317
- var isIPhone = () => platform(/^iPhone/);
318
- var isIPad = () => platform(/^iPad/) || isMac() && navigator.maxTouchPoints > 1;
319
- var isIos = () => isIPhone() || isIPad();
320
- var isSafari = () => ua(/^((?!chrome|android).)*safari/i);
321
- var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
324
+ var isDom3 = () => typeof window !== "undefined";
325
+ function getPlatform() {
326
+ var _a;
327
+ const agent = navigator.userAgentData;
328
+ return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
329
+ }
330
+ var pt = (v) => isDom3() && v.test(getPlatform());
331
+ var vn = (v) => isDom3() && v.test(navigator.vendor);
332
+ var isTouchDevice3 = isDom3() && !!navigator.maxTouchPoints;
333
+ var isMac = () => pt(/^Mac/) && !isTouchDevice3;
334
+ var isSafari = () => isApple() && vn(/apple/i);
335
+ var isApple = () => pt(/mac|iphone|ipad|ipod/i);
336
+ var isIos = () => isApple() && !isMac();
337
+ var supportsPointerEvent = () => isDom3() && window.onpointerdown === null;
338
+ var isLeftClick = (v) => v.button === 0;
322
339
  var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
340
+ var pipe2 = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
323
341
 
324
342
  // src/number-input.dom.ts
325
343
  var dom = {
@@ -583,7 +601,7 @@ function connect(state, send, normalize = normalizeProp) {
583
601
  onPointerDown(event) {
584
602
  if (isDecrementDisabled)
585
603
  return;
586
- send({ type: "PRESS_DOWN", hint: "decrement" });
604
+ send(isLeftClick(event) ? { type: "PRESS_DOWN", hint: "decrement" } : { type: "FOCUS" });
587
605
  event.preventDefault();
588
606
  },
589
607
  onPointerUp() {
@@ -606,10 +624,10 @@ function connect(state, send, normalize = normalizeProp) {
606
624
  tabIndex: -1,
607
625
  "aria-controls": dom.getInputId(state.context),
608
626
  onPointerDown(event) {
609
- event.preventDefault();
610
627
  if (isIncrementDisabled)
611
628
  return;
612
- send({ type: "PRESS_DOWN", hint: "increment" });
629
+ send(isLeftClick(event) ? { type: "PRESS_DOWN", hint: "increment" } : { type: "FOCUS" });
630
+ event.preventDefault();
613
631
  },
614
632
  onPointerUp() {
615
633
  send({ type: "PRESS_UP", hint: "increment" });
@@ -727,6 +745,7 @@ function machine(ctx = {}) {
727
745
  },
728
746
  focused: {
729
747
  tags: ["focus"],
748
+ entry: "focusInput",
730
749
  activities: "attachWheelListener",
731
750
  on: {
732
751
  PRESS_DOWN: {
@@ -765,7 +784,7 @@ function machine(ctx = {}) {
765
784
  },
766
785
  {
767
786
  target: "idle",
768
- actions: ["roundValue"]
787
+ actions: "roundValue"
769
788
  }
770
789
  ]
771
790
  }
@@ -820,7 +839,7 @@ function machine(ctx = {}) {
820
839
  on: {
821
840
  POINTER_UP_SCRUBBER: {
822
841
  target: "focused",
823
- actions: ["clearCursorPoint"]
842
+ actions: "clearCursorPoint"
824
843
  },
825
844
  POINTER_MOVE_SCRUBBER: [
826
845
  {