@zag-js/number-input 0.2.6 → 0.2.8

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.js CHANGED
@@ -39,14 +39,18 @@ var anatomy = (0, import_anatomy.createAnatomy)("numberInput").parts(
39
39
  );
40
40
  var parts = anatomy.build();
41
41
 
42
- // ../../utilities/dom/dist/index.mjs
42
+ // ../../utilities/dom/src/attrs.ts
43
43
  var dataAttr = (guard) => {
44
44
  return guard ? "" : void 0;
45
45
  };
46
46
  var ariaAttr = (guard) => {
47
47
  return guard ? "true" : void 0;
48
48
  };
49
+
50
+ // ../../utilities/dom/src/constants.ts
49
51
  var MAX_Z_INDEX = 2147483647;
52
+
53
+ // ../../utilities/core/src/functions.ts
50
54
  var runIfFn = (v, ...a) => {
51
55
  const res = typeof v === "function" ? v(...a) : v;
52
56
  return res != null ? res : void 0;
@@ -56,9 +60,22 @@ var callAll = (...fns) => (...a) => {
56
60
  fn == null ? void 0 : fn(...a);
57
61
  });
58
62
  };
63
+
64
+ // ../../utilities/core/src/guard.ts
59
65
  var isArray = (v) => Array.isArray(v);
60
66
  var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
61
67
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
68
+
69
+ // ../../utilities/core/src/object.ts
70
+ function compact(obj) {
71
+ if (obj === void 0)
72
+ return obj;
73
+ return Object.fromEntries(
74
+ Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
75
+ );
76
+ }
77
+
78
+ // ../../utilities/dom/src/platform.ts
62
79
  var isDom = () => typeof window !== "undefined";
63
80
  function getPlatform() {
64
81
  var _a;
@@ -69,6 +86,8 @@ var pt = (v) => isDom() && v.test(getPlatform());
69
86
  var vn = (v) => isDom() && v.test(navigator.vendor);
70
87
  var isSafari = () => isApple() && vn(/apple/i);
71
88
  var isApple = () => pt(/mac|iphone|ipad|ipod/i);
89
+
90
+ // ../../utilities/dom/src/query.ts
72
91
  function isDocument(el) {
73
92
  return el.nodeType === Node.DOCUMENT_NODE;
74
93
  }
@@ -83,6 +102,10 @@ function getDocument(el) {
83
102
  return el;
84
103
  return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
85
104
  }
105
+ function getWindow(el) {
106
+ var _a;
107
+ return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
108
+ }
86
109
  function defineDomHelpers(helpers) {
87
110
  const dom2 = {
88
111
  getRootNode: (ctx) => {
@@ -95,31 +118,15 @@ function defineDomHelpers(helpers) {
95
118
  return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
96
119
  },
97
120
  getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
98
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
99
- createEmitter: (ctx, target) => {
100
- const win = dom2.getWin(ctx);
101
- return function emit(evt, detail, options) {
102
- const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
103
- const eventName = `zag:${evt}`;
104
- const init = { bubbles, cancelable, composed, detail };
105
- const event = new win.CustomEvent(eventName, init);
106
- target.dispatchEvent(event);
107
- };
108
- },
109
- createListener: (target) => {
110
- return function listen(evt, handler) {
111
- const eventName = `zag:${evt}`;
112
- const listener = (e) => handler(e);
113
- target.addEventListener(eventName, listener);
114
- return () => target.removeEventListener(eventName, listener);
115
- };
116
- }
121
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
117
122
  };
118
123
  return {
119
124
  ...dom2,
120
125
  ...helpers
121
126
  };
122
127
  }
128
+
129
+ // ../../utilities/dom/src/event.ts
123
130
  function getNativeEvent(e) {
124
131
  var _a;
125
132
  return (_a = e.nativeEvent) != null ? _a : e;
@@ -128,6 +135,8 @@ var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
128
135
  var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
129
136
  var isLeftClick = (v) => v.button === 0;
130
137
  var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
138
+
139
+ // ../../utilities/dom/src/get-event-point.ts
131
140
  var fallback = {
132
141
  pageX: 0,
133
142
  pageY: 0,
@@ -139,6 +148,8 @@ function getEventPoint(event, type = "page") {
139
148
  const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event;
140
149
  return { x: point[`${type}X`], y: point[`${type}Y`] };
141
150
  }
151
+
152
+ // ../../utilities/dom/src/keyboard-event.ts
142
153
  var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
143
154
  var ARROW_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
144
155
  function getEventStep(event) {
@@ -150,6 +161,8 @@ function getEventStep(event) {
150
161
  return isSkipKey ? 10 : 1;
151
162
  }
152
163
  }
164
+
165
+ // ../../utilities/dom/src/listener.ts
153
166
  var isRef = (v) => hasProp(v, "current");
154
167
  function addDomEvent(target, eventName, handler, options) {
155
168
  const node = isRef(target) ? target.current : runIfFn(target);
@@ -158,6 +171,8 @@ function addDomEvent(target, eventName, handler, options) {
158
171
  node == null ? void 0 : node.removeEventListener(eventName, handler, options);
159
172
  };
160
173
  }
174
+
175
+ // ../../utilities/dom/src/mutation-observer.ts
161
176
  function observeAttributes(node, attributes, fn) {
162
177
  if (!node)
163
178
  return;
@@ -173,12 +188,16 @@ function observeAttributes(node, attributes, fn) {
173
188
  obs.observe(node, { attributes: true, attributeFilter: attrs });
174
189
  return () => obs.disconnect();
175
190
  }
191
+
192
+ // ../../utilities/dom/src/next-tick.ts
176
193
  function raf(fn) {
177
194
  const id = globalThis.requestAnimationFrame(fn);
178
195
  return function cleanup() {
179
196
  globalThis.cancelAnimationFrame(id);
180
197
  };
181
198
  }
199
+
200
+ // ../../utilities/dom/src/pointerlock.ts
182
201
  function addPointerlockChangeListener(doc, fn) {
183
202
  return addDomEvent(doc, "pointerlockchange", fn, false);
184
203
  }
@@ -210,7 +229,10 @@ function requestPointerLock(doc, handlers = {}) {
210
229
  }
211
230
  if (!supported)
212
231
  return;
213
- body.requestPointerLock();
232
+ try {
233
+ body.requestPointerLock();
234
+ } catch {
235
+ }
214
236
  const cleanup = callAll(
215
237
  addPointerlockChangeListener(doc, onPointerChange),
216
238
  addPointerlockErrorListener(doc, onPointerError)
@@ -223,7 +245,7 @@ function requestPointerLock(doc, handlers = {}) {
223
245
  };
224
246
  }
225
247
 
226
- // ../../utilities/number/dist/index.mjs
248
+ // ../../utilities/number/src/number.ts
227
249
  function wrap(num, max) {
228
250
  return (num % max + max) % max;
229
251
  }
@@ -285,7 +307,6 @@ function decimalOperation(a, op, b) {
285
307
  }
286
308
  return result;
287
309
  }
288
- var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
289
310
 
290
311
  // src/number-input.dom.ts
291
312
  var dom = defineDomHelpers({
@@ -640,27 +661,7 @@ function connect(state, send, normalize) {
640
661
  // src/number-input.machine.ts
641
662
  var import_core = require("@zag-js/core");
642
663
 
643
- // ../../utilities/core/dist/index.mjs
644
- var callAll2 = (...fns) => (...a) => {
645
- fns.forEach(function(fn) {
646
- fn == null ? void 0 : fn(...a);
647
- });
648
- };
649
- var isArray2 = (v) => Array.isArray(v);
650
- var isObject2 = (v) => !(v == null || typeof v !== "object" || isArray2(v));
651
- function compact(obj) {
652
- if (obj === void 0)
653
- return obj;
654
- return Object.fromEntries(
655
- Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject2(value) ? compact(value) : value])
656
- );
657
- }
658
-
659
- // ../../utilities/form-utils/dist/index.mjs
660
- function getWindow(el) {
661
- var _a;
662
- return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
663
- }
664
+ // ../../utilities/form-utils/src/input-event.ts
664
665
  function getDescriptor(el, options) {
665
666
  var _a;
666
667
  const { type, property = "value" } = options;
@@ -957,7 +958,7 @@ function machine(userContext) {
957
958
  function onMouseup() {
958
959
  send("POINTER_UP_SCRUBBER");
959
960
  }
960
- return callAll2(
961
+ return callAll(
961
962
  addDomEvent(doc, "mousemove", onMousemove, false),
962
963
  addDomEvent(doc, "mouseup", onMouseup, false)
963
964
  );