@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.
@@ -0,0 +1,543 @@
1
+ import {
2
+ dom
3
+ } from "./chunk-EUVYGWZ6.mjs";
4
+ import {
5
+ utils
6
+ } from "./chunk-HP6F2HUY.mjs";
7
+ import {
8
+ getWindow,
9
+ hasProp,
10
+ isAtMax,
11
+ isAtMin,
12
+ isObject,
13
+ isSafari,
14
+ isWithinRange,
15
+ supportsPointerEvent,
16
+ valueOf
17
+ } from "./chunk-VCZUWKJT.mjs";
18
+
19
+ // src/number-input.machine.ts
20
+ import { choose, createMachine, guards } from "@zag-js/core";
21
+
22
+ // ../../utilities/core/src/functions.ts
23
+ var runIfFn = (v, ...a) => {
24
+ const res = typeof v === "function" ? v(...a) : v;
25
+ return res != null ? res : void 0;
26
+ };
27
+ var callAll = (...fns) => (...a) => {
28
+ fns.forEach(function(fn) {
29
+ fn == null ? void 0 : fn(...a);
30
+ });
31
+ };
32
+
33
+ // ../../utilities/core/src/object.ts
34
+ function compact(obj) {
35
+ if (obj === void 0)
36
+ return obj;
37
+ return Object.fromEntries(
38
+ Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
39
+ );
40
+ }
41
+
42
+ // ../../utilities/dom/src/listener.ts
43
+ var isRef = (v) => hasProp(v, "current");
44
+ function addDomEvent(target, eventName, handler, options) {
45
+ const node = isRef(target) ? target.current : runIfFn(target);
46
+ node == null ? void 0 : node.addEventListener(eventName, handler, options);
47
+ return () => {
48
+ node == null ? void 0 : node.removeEventListener(eventName, handler, options);
49
+ };
50
+ }
51
+
52
+ // ../../utilities/dom/src/mutation-observer.ts
53
+ function observeAttributes(node, attributes, fn) {
54
+ if (!node)
55
+ return;
56
+ const attrs = Array.isArray(attributes) ? attributes : [attributes];
57
+ const win = node.ownerDocument.defaultView || window;
58
+ const obs = new win.MutationObserver((changes) => {
59
+ for (const change of changes) {
60
+ if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
61
+ fn(change);
62
+ }
63
+ }
64
+ });
65
+ obs.observe(node, { attributes: true, attributeFilter: attrs });
66
+ return () => obs.disconnect();
67
+ }
68
+
69
+ // ../../utilities/dom/src/next-tick.ts
70
+ function raf(fn) {
71
+ const id = globalThis.requestAnimationFrame(fn);
72
+ return function cleanup() {
73
+ globalThis.cancelAnimationFrame(id);
74
+ };
75
+ }
76
+
77
+ // ../../utilities/dom/src/pointerlock.ts
78
+ function addPointerlockChangeListener(doc, fn) {
79
+ return addDomEvent(doc, "pointerlockchange", fn, false);
80
+ }
81
+ function addPointerlockErrorListener(doc, fn) {
82
+ doc.addEventListener("pointerlockerror", fn, false);
83
+ return function cleanup() {
84
+ doc.removeEventListener("pointerlockerror", fn, false);
85
+ };
86
+ }
87
+ function requestPointerLock(doc, handlers = {}) {
88
+ const { onPointerLock, onPointerUnlock } = handlers;
89
+ const body = doc.body;
90
+ const supported = "pointerLockElement" in doc || "mozPointerLockElement" in doc;
91
+ const locked = !!doc.pointerLockElement;
92
+ function onPointerChange() {
93
+ if (locked)
94
+ onPointerLock == null ? void 0 : onPointerLock();
95
+ else
96
+ onPointerUnlock == null ? void 0 : onPointerUnlock();
97
+ }
98
+ function onPointerError(event) {
99
+ if (locked)
100
+ onPointerUnlock == null ? void 0 : onPointerUnlock();
101
+ console.error("PointerLock error occured:", event);
102
+ exit();
103
+ }
104
+ function exit() {
105
+ doc.exitPointerLock();
106
+ }
107
+ if (!supported)
108
+ return;
109
+ try {
110
+ body.requestPointerLock();
111
+ } catch {
112
+ }
113
+ const cleanup = callAll(
114
+ addPointerlockChangeListener(doc, onPointerChange),
115
+ addPointerlockErrorListener(doc, onPointerError)
116
+ );
117
+ return function dispose() {
118
+ if (!supported)
119
+ return;
120
+ cleanup();
121
+ exit();
122
+ };
123
+ }
124
+
125
+ // ../../utilities/form-utils/src/input-event.ts
126
+ function getDescriptor(el, options) {
127
+ var _a;
128
+ const { type, property = "value" } = options;
129
+ const proto = getWindow(el)[type].prototype;
130
+ return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
131
+ }
132
+ function dispatchInputValueEvent(el, value) {
133
+ var _a;
134
+ if (!el)
135
+ return;
136
+ const win = getWindow(el);
137
+ if (!(el instanceof win.HTMLInputElement))
138
+ return;
139
+ const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
140
+ (_a = desc.set) == null ? void 0 : _a.call(el, value);
141
+ const event = new win.Event("input", { bubbles: true });
142
+ el.dispatchEvent(event);
143
+ }
144
+
145
+ // src/number-input.machine.ts
146
+ var { not, and } = guards;
147
+ function machine(userContext) {
148
+ const ctx = compact(userContext);
149
+ return createMachine(
150
+ {
151
+ id: "number-input",
152
+ initial: "unknown",
153
+ context: {
154
+ dir: "ltr",
155
+ focusInputOnChange: true,
156
+ clampValueOnBlur: true,
157
+ allowOverflow: false,
158
+ inputMode: "decimal",
159
+ pattern: "[0-9]*(.[0-9]+)?",
160
+ hint: null,
161
+ value: "",
162
+ step: 1,
163
+ min: Number.MIN_SAFE_INTEGER,
164
+ max: Number.MAX_SAFE_INTEGER,
165
+ scrubberCursorPoint: null,
166
+ invalid: false,
167
+ spinOnPress: true,
168
+ ...ctx,
169
+ translations: {
170
+ incrementLabel: "increment value",
171
+ decrementLabel: "decrease value",
172
+ ...ctx.translations
173
+ }
174
+ },
175
+ computed: {
176
+ isRtl: (ctx2) => ctx2.dir === "rtl",
177
+ valueAsNumber: (ctx2) => valueOf(ctx2.value),
178
+ isAtMin: (ctx2) => isAtMin(ctx2.value, ctx2),
179
+ isAtMax: (ctx2) => isAtMax(ctx2.value, ctx2),
180
+ isOutOfRange: (ctx2) => !isWithinRange(ctx2.value, ctx2),
181
+ isValueEmpty: (ctx2) => ctx2.value === "",
182
+ canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
183
+ canDecrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMin,
184
+ valueText: (ctx2) => {
185
+ var _a, _b;
186
+ return (_b = (_a = ctx2.translations).valueText) == null ? void 0 : _b.call(_a, ctx2.value);
187
+ },
188
+ formattedValue: (ctx2) => {
189
+ var _a, _b;
190
+ return (_b = (_a = ctx2.format) == null ? void 0 : _a.call(ctx2, ctx2.value).toString()) != null ? _b : ctx2.value;
191
+ }
192
+ },
193
+ watch: {
194
+ value: ["invokeOnChange", "dispatchChangeEvent"],
195
+ isOutOfRange: ["invokeOnInvalid"],
196
+ scrubberCursorPoint: ["setVirtualCursorPosition"]
197
+ },
198
+ on: {
199
+ SET_VALUE: [
200
+ {
201
+ guard: "clampOnBlur",
202
+ actions: ["setValue", "clampValue", "setHintToSet"]
203
+ },
204
+ {
205
+ actions: ["setValue", "setHintToSet"]
206
+ }
207
+ ],
208
+ CLEAR_VALUE: {
209
+ actions: ["clearValue"]
210
+ },
211
+ INCREMENT: {
212
+ actions: ["increment"]
213
+ },
214
+ DECREMENT: {
215
+ actions: ["decrement"]
216
+ }
217
+ },
218
+ states: {
219
+ unknown: {
220
+ on: {
221
+ SETUP: {
222
+ target: "idle",
223
+ actions: "syncInputValue"
224
+ }
225
+ }
226
+ },
227
+ idle: {
228
+ exit: "invokeOnFocus",
229
+ on: {
230
+ PRESS_DOWN: {
231
+ target: "before:spin",
232
+ actions: ["focusInput", "setHint"]
233
+ },
234
+ PRESS_DOWN_SCRUBBER: {
235
+ target: "scrubbing",
236
+ actions: ["focusInput", "setHint", "setCursorPoint"]
237
+ },
238
+ FOCUS: "focused"
239
+ }
240
+ },
241
+ focused: {
242
+ tags: "focus",
243
+ entry: "focusInput",
244
+ activities: "attachWheelListener",
245
+ on: {
246
+ PRESS_DOWN: {
247
+ target: "before:spin",
248
+ actions: ["focusInput", "setHint"]
249
+ },
250
+ PRESS_DOWN_SCRUBBER: {
251
+ target: "scrubbing",
252
+ actions: ["focusInput", "setHint", "setCursorPoint"]
253
+ },
254
+ ARROW_UP: {
255
+ actions: "increment"
256
+ },
257
+ ARROW_DOWN: {
258
+ actions: "decrement"
259
+ },
260
+ HOME: {
261
+ actions: "setToMin"
262
+ },
263
+ END: {
264
+ actions: "setToMax"
265
+ },
266
+ CHANGE: {
267
+ actions: ["setValue", "setHint"]
268
+ },
269
+ BLUR: [
270
+ {
271
+ guard: "isInvalidExponential",
272
+ target: "idle",
273
+ actions: ["clearValue", "clearHint", "invokeOnBlur"]
274
+ },
275
+ {
276
+ guard: and("clampOnBlur", not("isInRange"), not("isEmptyValue")),
277
+ target: "idle",
278
+ actions: ["clampValue", "clearHint", "invokeOnBlur"]
279
+ },
280
+ {
281
+ target: "idle",
282
+ actions: ["roundValue", "invokeOnBlur"]
283
+ }
284
+ ]
285
+ }
286
+ },
287
+ "before:spin": {
288
+ tags: "focus",
289
+ activities: "trackButtonDisabled",
290
+ entry: choose([
291
+ { guard: "isIncrementHint", actions: "increment" },
292
+ { guard: "isDecrementHint", actions: "decrement" }
293
+ ]),
294
+ after: {
295
+ CHANGE_DELAY: {
296
+ target: "spinning",
297
+ guard: and("isInRange", "spinOnPress")
298
+ }
299
+ },
300
+ on: {
301
+ PRESS_UP: {
302
+ target: "focused",
303
+ actions: "clearHint"
304
+ }
305
+ }
306
+ },
307
+ spinning: {
308
+ tags: "focus",
309
+ activities: "trackButtonDisabled",
310
+ every: [
311
+ {
312
+ delay: "CHANGE_INTERVAL",
313
+ guard: and(not("isAtMin"), "isIncrementHint"),
314
+ actions: "increment"
315
+ },
316
+ {
317
+ delay: "CHANGE_INTERVAL",
318
+ guard: and(not("isAtMax"), "isDecrementHint"),
319
+ actions: "decrement"
320
+ }
321
+ ],
322
+ on: {
323
+ PRESS_UP: {
324
+ target: "focused",
325
+ actions: "clearHint"
326
+ }
327
+ }
328
+ },
329
+ scrubbing: {
330
+ tags: "focus",
331
+ exit: "clearCursorPoint",
332
+ activities: ["activatePointerLock", "trackMousemove", "setupVirtualCursor", "preventTextSelection"],
333
+ on: {
334
+ POINTER_UP_SCRUBBER: "focused",
335
+ POINTER_MOVE_SCRUBBER: [
336
+ {
337
+ guard: "isIncrementHint",
338
+ actions: ["increment", "setCursorPoint"]
339
+ },
340
+ {
341
+ guard: "isDecrementHint",
342
+ actions: ["decrement", "setCursorPoint"]
343
+ }
344
+ ]
345
+ }
346
+ }
347
+ }
348
+ },
349
+ {
350
+ delays: {
351
+ CHANGE_INTERVAL: 50,
352
+ CHANGE_DELAY: 300
353
+ },
354
+ guards: {
355
+ clampOnBlur: (ctx2) => !!ctx2.clampValueOnBlur,
356
+ isAtMin: (ctx2) => ctx2.isAtMin,
357
+ spinOnPress: (ctx2) => !!ctx2.spinOnPress,
358
+ isAtMax: (ctx2) => ctx2.isAtMax,
359
+ isInRange: (ctx2) => !ctx2.isOutOfRange,
360
+ isDecrementHint: (ctx2, evt) => {
361
+ var _a;
362
+ return ((_a = evt.hint) != null ? _a : ctx2.hint) === "decrement";
363
+ },
364
+ isEmptyValue: (ctx2) => ctx2.isValueEmpty,
365
+ isIncrementHint: (ctx2, evt) => {
366
+ var _a;
367
+ return ((_a = evt.hint) != null ? _a : ctx2.hint) === "increment";
368
+ },
369
+ isInvalidExponential: (ctx2) => ctx2.value.toString().startsWith("e")
370
+ },
371
+ activities: {
372
+ setupVirtualCursor(ctx2) {
373
+ return dom.setupVirtualCursor(ctx2);
374
+ },
375
+ preventTextSelection(ctx2) {
376
+ return dom.preventTextSelection(ctx2);
377
+ },
378
+ trackButtonDisabled(ctx2, _evt, { send }) {
379
+ const btn = dom.getPressedTriggerEl(ctx2, ctx2.hint);
380
+ return observeAttributes(btn, "disabled", () => send("PRESS_UP"));
381
+ },
382
+ attachWheelListener(ctx2, _evt, { send }) {
383
+ const input = dom.getInputEl(ctx2);
384
+ if (!input)
385
+ return;
386
+ function onWheel(event) {
387
+ const isInputFocused = dom.getDoc(ctx2).activeElement === input;
388
+ if (!ctx2.allowMouseWheel || !isInputFocused)
389
+ return;
390
+ event.preventDefault();
391
+ const dir = Math.sign(event.deltaY) * -1;
392
+ if (dir === 1) {
393
+ send("INCREMENT");
394
+ } else if (dir === -1) {
395
+ send("DECREMENT");
396
+ }
397
+ }
398
+ return addDomEvent(input, "wheel", onWheel, { passive: false });
399
+ },
400
+ activatePointerLock(ctx2) {
401
+ if (isSafari() || !supportsPointerEvent())
402
+ return;
403
+ return requestPointerLock(dom.getDoc(ctx2));
404
+ },
405
+ trackMousemove(ctx2, _evt, { send }) {
406
+ const doc = dom.getDoc(ctx2);
407
+ function onMousemove(event) {
408
+ if (!ctx2.scrubberCursorPoint)
409
+ return;
410
+ const value = dom.getMousementValue(ctx2, event);
411
+ if (!value.hint)
412
+ return;
413
+ send({
414
+ type: "POINTER_MOVE_SCRUBBER",
415
+ hint: value.hint,
416
+ point: value.point
417
+ });
418
+ }
419
+ function onMouseup() {
420
+ send("POINTER_UP_SCRUBBER");
421
+ }
422
+ return callAll(
423
+ addDomEvent(doc, "mousemove", onMousemove, false),
424
+ addDomEvent(doc, "mouseup", onMouseup, false)
425
+ );
426
+ }
427
+ },
428
+ actions: {
429
+ focusInput(ctx2) {
430
+ if (!ctx2.focusInputOnChange)
431
+ return;
432
+ const input = dom.getInputEl(ctx2);
433
+ raf(() => input == null ? void 0 : input.focus());
434
+ },
435
+ increment(ctx2, evt) {
436
+ ctx2.value = utils.increment(ctx2, evt.step);
437
+ },
438
+ decrement(ctx2, evt) {
439
+ ctx2.value = utils.decrement(ctx2, evt.step);
440
+ },
441
+ clampValue(ctx2) {
442
+ ctx2.value = utils.clamp(ctx2);
443
+ },
444
+ roundValue(ctx2) {
445
+ if (ctx2.value !== "") {
446
+ ctx2.value = utils.round(ctx2);
447
+ }
448
+ },
449
+ setValue(ctx2, evt) {
450
+ var _a, _b;
451
+ const value = (_b = (_a = evt.target) == null ? void 0 : _a.value) != null ? _b : evt.value;
452
+ ctx2.value = utils.sanitize(ctx2, utils.parse(ctx2, value.toString()));
453
+ },
454
+ clearValue(ctx2) {
455
+ ctx2.value = "";
456
+ },
457
+ setToMax(ctx2) {
458
+ ctx2.value = ctx2.max.toString();
459
+ },
460
+ setToMin(ctx2) {
461
+ ctx2.value = ctx2.min.toString();
462
+ },
463
+ setHint(ctx2, evt) {
464
+ ctx2.hint = evt.hint;
465
+ },
466
+ clearHint(ctx2) {
467
+ ctx2.hint = null;
468
+ },
469
+ setHintToSet(ctx2) {
470
+ ctx2.hint = "set";
471
+ },
472
+ invokeOnChange(ctx2) {
473
+ var _a;
474
+ (_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, {
475
+ value: ctx2.value,
476
+ valueAsNumber: ctx2.valueAsNumber
477
+ });
478
+ },
479
+ invokeOnFocus(ctx2, evt) {
480
+ var _a;
481
+ let srcElement = null;
482
+ if (evt.type === "PRESS_DOWN") {
483
+ srcElement = dom.getPressedTriggerEl(ctx2, evt.hint);
484
+ } else if (evt.type === "FOCUS") {
485
+ srcElement = dom.getInputEl(ctx2);
486
+ } else if (evt.type === "PRESS_DOWN_SCRUBBER") {
487
+ srcElement = dom.getScrubberEl(ctx2);
488
+ }
489
+ (_a = ctx2.onFocus) == null ? void 0 : _a.call(ctx2, {
490
+ value: ctx2.value,
491
+ valueAsNumber: ctx2.valueAsNumber,
492
+ srcElement
493
+ });
494
+ },
495
+ invokeOnBlur(ctx2) {
496
+ var _a;
497
+ (_a = ctx2.onBlur) == null ? void 0 : _a.call(ctx2, {
498
+ value: ctx2.value,
499
+ valueAsNumber: ctx2.valueAsNumber
500
+ });
501
+ },
502
+ invokeOnInvalid(ctx2) {
503
+ var _a;
504
+ if (!ctx2.isOutOfRange)
505
+ return;
506
+ const reason = ctx2.valueAsNumber > ctx2.max ? "rangeOverflow" : "rangeUnderflow";
507
+ (_a = ctx2.onInvalid) == null ? void 0 : _a.call(ctx2, {
508
+ reason,
509
+ value: ctx2.formattedValue,
510
+ valueAsNumber: ctx2.valueAsNumber
511
+ });
512
+ },
513
+ syncInputValue(ctx2) {
514
+ const input = dom.getInputEl(ctx2);
515
+ if (!input || input.value == ctx2.value)
516
+ return;
517
+ const value = utils.parse(ctx2, input.value);
518
+ ctx2.value = utils.sanitize(ctx2, value);
519
+ },
520
+ setCursorPoint(ctx2, evt) {
521
+ ctx2.scrubberCursorPoint = evt.point;
522
+ },
523
+ clearCursorPoint(ctx2) {
524
+ ctx2.scrubberCursorPoint = null;
525
+ },
526
+ setVirtualCursorPosition(ctx2) {
527
+ const cursor = dom.getCursorEl(ctx2);
528
+ if (!cursor || !ctx2.scrubberCursorPoint)
529
+ return;
530
+ const { x, y } = ctx2.scrubberCursorPoint;
531
+ cursor.style.transform = `translate3d(${x}px, ${y}px, 0px)`;
532
+ },
533
+ dispatchChangeEvent(ctx2) {
534
+ dispatchInputValueEvent(dom.getInputEl(ctx2), ctx2.formattedValue);
535
+ }
536
+ }
537
+ }
538
+ );
539
+ }
540
+
541
+ export {
542
+ machine
543
+ };
@@ -0,0 +1,151 @@
1
+ // ../../utilities/dom/src/platform.ts
2
+ var isDom = () => typeof window !== "undefined";
3
+ function getPlatform() {
4
+ var _a;
5
+ const agent = navigator.userAgentData;
6
+ return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
7
+ }
8
+ var pt = (v) => isDom() && v.test(getPlatform());
9
+ var vn = (v) => isDom() && v.test(navigator.vendor);
10
+ var isSafari = () => isApple() && vn(/apple/i);
11
+ var isApple = () => pt(/mac|iphone|ipad|ipod/i);
12
+
13
+ // ../../utilities/dom/src/query.ts
14
+ function isDocument(el) {
15
+ return el.nodeType === Node.DOCUMENT_NODE;
16
+ }
17
+ function isWindow(value) {
18
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
19
+ }
20
+ function getDocument(el) {
21
+ var _a;
22
+ if (isWindow(el))
23
+ return el.document;
24
+ if (isDocument(el))
25
+ return el;
26
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
27
+ }
28
+ function getWindow(el) {
29
+ var _a;
30
+ return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
31
+ }
32
+ function defineDomHelpers(helpers) {
33
+ const dom = {
34
+ getRootNode: (ctx) => {
35
+ var _a, _b;
36
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
37
+ },
38
+ getDoc: (ctx) => getDocument(dom.getRootNode(ctx)),
39
+ getWin: (ctx) => {
40
+ var _a;
41
+ return (_a = dom.getDoc(ctx).defaultView) != null ? _a : window;
42
+ },
43
+ getActiveElement: (ctx) => dom.getDoc(ctx).activeElement,
44
+ getById: (ctx, id) => dom.getRootNode(ctx).getElementById(id)
45
+ };
46
+ return {
47
+ ...dom,
48
+ ...helpers
49
+ };
50
+ }
51
+
52
+ // ../../utilities/core/src/guard.ts
53
+ var isArray = (v) => Array.isArray(v);
54
+ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
55
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
56
+
57
+ // ../../utilities/dom/src/event.ts
58
+ function getNativeEvent(e) {
59
+ var _a;
60
+ return (_a = e.nativeEvent) != null ? _a : e;
61
+ }
62
+ var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
63
+ var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
64
+ var isLeftClick = (v) => v.button === 0;
65
+ var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
66
+
67
+ // ../../utilities/number/src/number.ts
68
+ function wrap(num, max) {
69
+ return (num % max + max) % max;
70
+ }
71
+ function roundToDevicePixel(num) {
72
+ if (typeof window === "undefined")
73
+ return Math.round(num);
74
+ const dp = window.devicePixelRatio;
75
+ return Math.floor(num * dp + 0.5) / dp;
76
+ }
77
+ function clamp(v, o) {
78
+ return Math.min(Math.max(valueOf(v), o.min), o.max);
79
+ }
80
+ function countDecimals(value) {
81
+ if (!Number.isFinite(value))
82
+ return 0;
83
+ let e = 1, p = 0;
84
+ while (Math.round(value * e) / e !== value) {
85
+ e *= 10;
86
+ p += 1;
87
+ }
88
+ return p;
89
+ }
90
+ var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
91
+ var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
92
+ function valueOf(v) {
93
+ if (typeof v === "number")
94
+ return v;
95
+ const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
96
+ return !Number.isNaN(num) ? num : 0;
97
+ }
98
+ function formatDecimal(v, o) {
99
+ return new Intl.NumberFormat("en-US", {
100
+ useGrouping: false,
101
+ style: "decimal",
102
+ minimumFractionDigits: o.minFractionDigits,
103
+ maximumFractionDigits: o.maxFractionDigits
104
+ }).format(valueOf(v));
105
+ }
106
+ function isAtMax(v, o) {
107
+ const val = valueOf(v);
108
+ return val >= o.max;
109
+ }
110
+ function isAtMin(v, o) {
111
+ const val = valueOf(v);
112
+ return val <= o.min;
113
+ }
114
+ function isWithinRange(v, o) {
115
+ const val = valueOf(v);
116
+ return val >= o.min && val <= o.max;
117
+ }
118
+ function decimalOperation(a, op, b) {
119
+ let result = op === "+" ? a + b : a - b;
120
+ if (a % 1 !== 0 || b % 1 !== 0) {
121
+ const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
122
+ a = Math.round(a * multiplier);
123
+ b = Math.round(b * multiplier);
124
+ result = op === "+" ? a + b : a - b;
125
+ result /= multiplier;
126
+ }
127
+ return result;
128
+ }
129
+
130
+ export {
131
+ isObject,
132
+ hasProp,
133
+ isSafari,
134
+ getWindow,
135
+ defineDomHelpers,
136
+ getNativeEvent,
137
+ supportsPointerEvent,
138
+ isTouchEvent,
139
+ isLeftClick,
140
+ isModifiedEvent,
141
+ wrap,
142
+ roundToDevicePixel,
143
+ clamp,
144
+ increment,
145
+ decrement,
146
+ valueOf,
147
+ formatDecimal,
148
+ isAtMax,
149
+ isAtMin,
150
+ isWithinRange
151
+ };
@@ -0,0 +1,17 @@
1
+ // src/number-input.anatomy.ts
2
+ import { createAnatomy } from "@zag-js/anatomy";
3
+ var anatomy = createAnatomy("numberInput").parts(
4
+ "root",
5
+ "label",
6
+ "input",
7
+ "control",
8
+ "incrementTrigger",
9
+ "decrementTrigger",
10
+ "scrubber"
11
+ );
12
+ var parts = anatomy.build();
13
+
14
+ export {
15
+ anatomy,
16
+ parts
17
+ };