@zag-js/number-input 2.0.0-next.3 → 2.0.0-next.4

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.
Files changed (41) hide show
  1. package/dist/index.d.mts +6 -9
  2. package/dist/index.d.ts +6 -9
  3. package/dist/index.js +12 -38
  4. package/dist/index.mjs +2 -7
  5. package/dist/number-input.anatomy.d.mts +2 -6
  6. package/dist/number-input.anatomy.d.ts +2 -6
  7. package/dist/number-input.anatomy.js +8 -43
  8. package/dist/number-input.anatomy.mjs +4 -17
  9. package/dist/number-input.connect.d.mts +3 -8
  10. package/dist/number-input.connect.d.ts +3 -8
  11. package/dist/number-input.connect.js +483 -377
  12. package/dist/number-input.connect.mjs +478 -353
  13. package/dist/number-input.dom.d.mts +33 -33
  14. package/dist/number-input.dom.d.ts +33 -33
  15. package/dist/number-input.dom.js +99 -142
  16. package/dist/number-input.dom.mjs +78 -103
  17. package/dist/number-input.machine.d.mts +2 -8
  18. package/dist/number-input.machine.d.ts +2 -8
  19. package/dist/number-input.machine.js +600 -528
  20. package/dist/number-input.machine.mjs +596 -512
  21. package/dist/number-input.props.d.mts +3 -9
  22. package/dist/number-input.props.d.ts +3 -9
  23. package/dist/number-input.props.js +43 -69
  24. package/dist/number-input.props.mjs +39 -43
  25. package/dist/number-input.translations.d.mts +3 -8
  26. package/dist/number-input.translations.d.ts +3 -8
  27. package/dist/number-input.translations.js +9 -31
  28. package/dist/number-input.translations.mjs +5 -6
  29. package/dist/number-input.types.d.mts +418 -408
  30. package/dist/number-input.types.d.ts +418 -408
  31. package/dist/number-input.types.js +4 -18
  32. package/dist/number-input.types.mjs +1 -0
  33. package/dist/number-input.utils.d.mts +16 -12
  34. package/dist/number-input.utils.d.ts +16 -12
  35. package/dist/number-input.utils.js +51 -57
  36. package/dist/number-input.utils.mjs +39 -27
  37. package/package.json +8 -8
  38. package/dist/cursor.d.mts +0 -12
  39. package/dist/cursor.d.ts +0 -12
  40. package/dist/cursor.js +0 -111
  41. package/dist/cursor.mjs +0 -84
@@ -1,530 +1,602 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/number-input.machine.ts
31
- var number_input_machine_exports = {};
32
- __export(number_input_machine_exports, {
33
- machine: () => machine
34
- });
35
- module.exports = __toCommonJS(number_input_machine_exports);
36
- var import_core = require("@zag-js/core");
37
- var import_dom_query = require("@zag-js/dom-query");
38
- var import_utils = require("@zag-js/utils");
39
- var import_cursor = require("./cursor.js");
40
- var dom = __toESM(require("./number-input.dom.js"));
41
- var import_number_input = require("./number-input.translations.js");
42
- var import_number_input2 = require("./number-input.utils.js");
43
- var { choose, guards, createMachine } = (0, import_core.setup)();
44
- var { not, and } = guards;
45
- var machine = createMachine({
46
- props({ props }) {
47
- const step = (0, import_number_input2.getDefaultStep)(props.step, props.formatOptions);
48
- return {
49
- dir: "ltr",
50
- locale: "en-US",
51
- focusInputOnChange: true,
52
- clampValueOnBlur: !props.allowOverflow,
53
- allowOverflow: false,
54
- inputMode: "decimal",
55
- pattern: "-?[0-9]*(.[0-9]+)?",
56
- defaultValue: "",
57
- step,
58
- min: Number.MIN_SAFE_INTEGER,
59
- max: Number.MAX_SAFE_INTEGER,
60
- spinOnPress: true,
61
- scrubberPixelSensitivity: 2,
62
- scrubberDirection: "horizontal",
63
- snapOnStep: false,
64
- ...props,
65
- largeStep: props.largeStep ?? 10 * step,
66
- smallStep: props.smallStep ?? step / 10
67
- };
68
- },
69
- initialState() {
70
- return "idle";
71
- },
72
- context({ prop, bindable, getComputed, getEvent }) {
73
- return {
74
- value: bindable(() => ({
75
- defaultValue: prop("defaultValue"),
76
- value: prop("value"),
77
- onChange(value) {
78
- const computed = getComputed();
79
- const valueAsNumber = (0, import_number_input2.parseValue)(value, { computed, prop });
80
- prop("onValueChange")?.({ value, valueAsNumber, reason: getEvent().src });
81
- }
82
- })),
83
- hint: bindable(() => ({ defaultValue: null })),
84
- scrubberCursorPoint: bindable(() => ({
85
- defaultValue: null,
86
- hash(value) {
87
- return value ? `x:${value.x}, y:${value.y}` : "";
88
- }
89
- })),
90
- fieldsetDisabled: bindable(() => ({ defaultValue: false })),
91
- cumulativeDelta: bindable(() => ({ defaultValue: 0 })),
92
- isPointerLockSupported: bindable(() => ({ defaultValue: false })),
93
- visualScale: bindable(() => ({ defaultValue: 1 }))
94
- };
95
- },
96
- computed: {
97
- isRtl: ({ prop }) => prop("dir") === "rtl",
98
- valueAsNumber: ({ context, computed, prop }) => (0, import_number_input2.parseValue)(context.get("value"), { computed, prop }),
99
- formattedValue: ({ computed, prop }) => (0, import_number_input2.formatValue)(computed("valueAsNumber"), { computed, prop }),
100
- isAtMin: ({ computed, prop }) => (0, import_utils.isValueAtMin)(computed("valueAsNumber"), prop("min")),
101
- isAtMax: ({ computed, prop }) => (0, import_utils.isValueAtMax)(computed("valueAsNumber"), prop("max")),
102
- isOutOfRange: ({ computed, prop }) => !(0, import_utils.isValueWithinRange)(computed("valueAsNumber"), prop("min"), prop("max")),
103
- isValueEmpty: ({ context }) => context.get("value") === "",
104
- isDisabled: ({ prop, context }) => !!prop("disabled") || context.get("fieldsetDisabled"),
105
- canIncrement: ({ prop, computed }) => prop("allowOverflow") || !computed("isAtMax"),
106
- canDecrement: ({ prop, computed }) => prop("allowOverflow") || !computed("isAtMin"),
107
- // Only useful when the display differs from `aria-valuenow`, as with currency or percent.
108
- valueText: ({ prop, context, computed }) => {
109
- const translations = (0, import_utils.mergeWithDefault)(import_number_input.defaultTranslations, prop("translations"));
110
- const custom = translations.valueText?.(context.get("value"));
111
- if (custom) return custom;
112
- if (computed("isValueEmpty")) return void 0;
113
- const formatted = computed("formattedValue");
114
- return formatted === String(computed("valueAsNumber")) ? void 0 : formatted;
115
- },
116
- formatter: (0, import_core.memo)(
117
- ({ prop }) => [prop("locale"), prop("formatOptions")],
118
- ([locale, formatOptions]) => (0, import_number_input2.createFormatter)(locale, formatOptions)
119
- ),
120
- parser: (0, import_core.memo)(
121
- ({ prop }) => [prop("locale"), prop("formatOptions")],
122
- ([locale, formatOptions]) => (0, import_number_input2.createParser)(locale, formatOptions)
123
- )
124
- },
125
- watch({ track, action, context, computed, prop }) {
126
- track([() => context.get("value"), () => prop("locale"), () => JSON.stringify(prop("formatOptions"))], () => {
127
- action(["syncInputElement"]);
128
- });
129
- track([() => computed("isOutOfRange")], () => {
130
- if (!computed("isOutOfRange")) return;
131
- action(["invokeOnInvalid"]);
132
- });
133
- track([() => context.hash("scrubberCursorPoint")], () => {
134
- action(["setVirtualCursorPosition"]);
135
- });
136
- },
137
- effects: ["trackFormControl", "detectPointerLock"],
138
- on: {
139
- "INPUT.FOCUS": {
140
- actions: ["invokeOnFocus"]
141
- },
142
- "VALUE.SET": {
143
- actions: ["setRawValue", "invokeOnValueCommit"]
144
- },
145
- "VALUE.CLEAR": {
146
- actions: ["clearValue", "invokeOnValueCommit"]
147
- },
148
- "VALUE.INCREMENT": {
149
- actions: ["increment", "invokeOnValueCommit"]
150
- },
151
- "VALUE.DECREMENT": {
152
- actions: ["decrement", "invokeOnValueCommit"]
153
- }
154
- },
155
- states: {
156
- idle: {
157
- on: {
158
- "TRIGGER.PRESS_DOWN": [
159
- { guard: "isTouchPointer", target: "pressed", actions: ["setHint"] },
160
- {
161
- target: "pressed",
162
- actions: ["focusInput", "setHint"]
163
- }
164
- ],
165
- "SCRUBBER.PRESS_DOWN": {
166
- target: "scrubbing",
167
- actions: ["focusInput", "setHint", "setCursorPoint"]
168
- },
169
- "INPUT.FOCUS": {
170
- target: "focused",
171
- actions: ["focusInput", "invokeOnFocus"]
172
- }
173
- }
174
- },
175
- focused: {
176
- tags: ["focus"],
177
- effects: ["attachWheelListener"],
178
- on: {
179
- "TRIGGER.PRESS_DOWN": [
180
- { guard: "isTouchPointer", target: "pressed", actions: ["setHint"] },
181
- { target: "pressed", actions: ["focusInput", "setHint"] }
182
- ],
183
- "SCRUBBER.PRESS_DOWN": {
184
- target: "scrubbing",
185
- actions: ["focusInput", "setHint", "setCursorPoint"]
186
- },
187
- "INPUT.ARROW_UP": {
188
- actions: ["increment", "invokeOnValueCommit"]
189
- },
190
- "INPUT.ARROW_DOWN": {
191
- actions: ["decrement", "invokeOnValueCommit"]
192
- },
193
- "INPUT.HOME": {
194
- actions: ["decrementToMin", "invokeOnValueCommit"]
195
- },
196
- "INPUT.END": {
197
- actions: ["incrementToMax", "invokeOnValueCommit"]
198
- },
199
- "INPUT.CHANGE": {
200
- actions: ["setValue", "setHint"]
201
- },
202
- "INPUT.BLUR": [
203
- {
204
- guard: and("clampValueOnBlur", not("isValueEmpty"), not("isInRange")),
205
- target: "idle",
206
- actions: ["setClampedValue", "clearHint", "invokeOnBlur", "invokeOnValueCommit"]
207
- },
208
- {
209
- guard: not("isInRange"),
210
- target: "idle",
211
- actions: ["setFormattedValue", "clearHint", "invokeOnBlur", "invokeOnValueCommit"]
212
- },
213
- {
214
- target: "idle",
215
- actions: ["setFormattedValue", "clearHint", "invokeOnBlur", "invokeOnValueCommit"]
216
- }
217
- ],
218
- // No target, so the input stays focused. It must not report a blur.
219
- "INPUT.ENTER": {
220
- actions: ["setFormattedValue", "clearHint", "invokeOnValueCommit"]
221
- }
222
- }
223
- },
224
- pressed: {
225
- tags: ["focus"],
226
- initial: "waiting",
227
- effects: ["trackButtonDisabled", "preventContextMenu"],
228
- on: {
229
- "TRIGGER.PRESS_UP": [
230
- { guard: "isTouchPointer", target: "focused", actions: ["clearHint", "invokeOnValueCommit"] },
231
- { target: "focused", actions: ["focusInput", "clearHint", "invokeOnValueCommit"] }
232
- ]
233
- },
234
- states: {
235
- waiting: {
236
- effects: ["waitForChangeDelay"],
237
- entry: choose([
238
- { guard: "isIncrementHint", actions: ["increment"] },
239
- { guard: "isDecrementHint", actions: ["decrement"] }
240
- ]),
241
- on: {
242
- CHANGE_DELAY: {
243
- target: "repeating",
244
- guard: and("isInRange", "spinOnPress")
245
- }
246
- }
247
- },
248
- repeating: {
249
- effects: ["spinValue"],
250
- on: {
251
- SPIN: [
252
- {
253
- guard: "isIncrementHint",
254
- actions: ["increment"]
255
- },
256
- {
257
- guard: "isDecrementHint",
258
- actions: ["decrement"]
259
- }
260
- ]
261
- }
262
- }
263
- }
264
- },
265
- scrubbing: {
266
- tags: ["focus"],
267
- effects: ["activatePointerLock", "trackMousemove", "preventTextSelection", "trackVisualViewport"],
268
- entry: ["clearCumulativeDelta"],
269
- on: {
270
- "SCRUBBER.STEP": [
271
- {
272
- guard: "isIncrementHint",
273
- actions: ["increment"]
274
- },
275
- {
276
- guard: "isDecrementHint",
277
- actions: ["decrement"]
278
- }
279
- ],
280
- "SCRUBBER.POINTER_UP": {
281
- target: "focused",
282
- actions: ["focusInput", "clearCursorPoint", "clearCumulativeDelta", "invokeOnValueCommit"]
283
- },
284
- "SCRUBBER.POINTER_MOVE": {
285
- actions: ["accumulateDelta", "setCursorPoint"]
286
- }
287
- }
288
- }
289
- },
290
- implementations: {
291
- guards: {
292
- clampValueOnBlur: ({ prop }) => prop("clampValueOnBlur"),
293
- spinOnPress: ({ prop }) => !!prop("spinOnPress"),
294
- isInRange: ({ computed }) => !computed("isOutOfRange"),
295
- isValueEmpty: ({ computed }) => computed("isValueEmpty"),
296
- isDecrementHint: ({ context, event }) => (event.hint ?? context.get("hint")) === "decrement",
297
- isIncrementHint: ({ context, event }) => (event.hint ?? context.get("hint")) === "increment",
298
- isTouchPointer: ({ event }) => event.pointerType === "touch"
299
- },
300
- effects: {
301
- waitForChangeDelay({ send }) {
302
- const id = setTimeout(() => {
303
- send({ type: "CHANGE_DELAY" });
304
- }, 300);
305
- return () => clearTimeout(id);
306
- },
307
- preventContextMenu({ scope }) {
308
- return (0, import_dom_query.addDomEvent)(scope.getWin(), "contextmenu", (event) => event.preventDefault());
309
- },
310
- spinValue({ send, context }) {
311
- const id = setInterval(() => {
312
- const src = context.get("hint") === "increment" ? "increment-press" : "decrement-press";
313
- send({ type: "SPIN", src });
314
- }, 50);
315
- return () => clearInterval(id);
316
- },
317
- detectPointerLock({ context }) {
318
- context.set("isPointerLockSupported", !(0, import_dom_query.isSafari)());
319
- },
320
- trackFormControl({ context, scope }) {
321
- const inputEl = dom.getInputEl(scope);
322
- return (0, import_dom_query.trackFormControl)(inputEl, {
323
- onFieldsetDisabledChange(disabled) {
324
- context.set("fieldsetDisabled", disabled);
325
- },
326
- onFormReset() {
327
- context.set("value", context.initial("value"));
328
- }
329
- });
330
- },
331
- preventTextSelection({ scope, prop }) {
332
- return dom.preventTextSelection(scope, prop("scrubberDirection"));
333
- },
334
- trackButtonDisabled({ context, scope, send }) {
335
- const hint = context.get("hint");
336
- const btn = dom.getPressedTriggerEl(scope, hint);
337
- return (0, import_dom_query.observeAttributes)(btn, {
338
- attributes: ["disabled"],
339
- callback() {
340
- const src = hint === "increment" ? "increment-press" : "decrement-press";
341
- send({ type: "TRIGGER.PRESS_UP", src });
342
- }
343
- });
344
- },
345
- attachWheelListener({ scope, send, prop }) {
346
- const inputEl = dom.getInputEl(scope);
347
- if (!inputEl || !scope.isActiveElement(inputEl) || !prop("allowMouseWheel")) return;
348
- function onWheel(event) {
349
- event.preventDefault();
350
- const dir = Math.sign(event.deltaY) * -1;
351
- if (dir === 1) {
352
- send({ type: "VALUE.INCREMENT", src: "wheel" });
353
- } else if (dir === -1) {
354
- send({ type: "VALUE.DECREMENT", src: "wheel" });
355
- }
356
- }
357
- return (0, import_dom_query.addDomEvent)(inputEl, "wheel", onWheel, { passive: false });
358
- },
359
- trackVisualViewport({ scope, context }) {
360
- const vV = scope.getWin().visualViewport;
361
- if (!vV) return;
362
- function onResize() {
363
- context.set("visualScale", vV.scale);
364
- }
365
- onResize();
366
- return (0, import_dom_query.addDomEvent)(vV, "resize", onResize);
367
- },
368
- activatePointerLock({ scope }) {
369
- if ((0, import_dom_query.isSafari)()) return;
370
- const cleanup = (0, import_dom_query.requestPointerLock)(scope.getDoc());
371
- return () => {
372
- if ((0, import_dom_query.isFirefox)()) {
373
- setTimeout(() => cleanup?.(), 20);
374
- } else {
375
- cleanup?.();
376
- }
377
- };
378
- },
379
- trackMousemove({ scope, send, context, computed, prop }) {
380
- const doc = scope.getDoc();
381
- function onMousemove(event) {
382
- const point = context.get("scrubberCursorPoint");
383
- const isRtl = computed("isRtl");
384
- const direction = prop("scrubberDirection");
385
- const teleportDistance = prop("scrubberTeleportDistance");
386
- const value = dom.getMousemoveValue(scope, { point, isRtl, event, direction, teleportDistance });
387
- send({
388
- type: "SCRUBBER.POINTER_MOVE",
389
- hint: value.hint,
390
- point: value.point,
391
- delta: value.delta
392
- });
393
- }
394
- function onMouseup() {
395
- send({ type: "SCRUBBER.POINTER_UP", src: "scrub" });
396
- }
397
- return (0, import_utils.callAll)((0, import_dom_query.addDomEvent)(doc, "mousemove", onMousemove, false), (0, import_dom_query.addDomEvent)(doc, "mouseup", onMouseup, false));
398
- }
399
- },
400
- actions: {
401
- focusInput({ scope, prop }) {
402
- if (!prop("focusInputOnChange")) return;
403
- const inputEl = dom.getInputEl(scope);
404
- if (scope.isActiveElement(inputEl)) return;
405
- (0, import_dom_query.raf)(() => inputEl?.focus({ preventScroll: true }));
406
- },
407
- increment({ context, event, prop, computed }) {
408
- let nextValue = (0, import_utils.incrementValue)(computed("valueAsNumber"), event.step ?? prop("step"));
409
- if (!prop("allowOverflow")) nextValue = (0, import_utils.clampValue)(nextValue, prop("min"), prop("max"));
410
- if (prop("snapOnStep"))
411
- nextValue = (0, import_utils.snapValueToStep)(nextValue, prop("min"), prop("max"), event.step ?? prop("step"));
412
- context.set("value", (0, import_number_input2.formatValue)(nextValue, { computed, prop }));
413
- },
414
- decrement({ context, event, prop, computed }) {
415
- let nextValue = (0, import_utils.decrementValue)(computed("valueAsNumber"), event.step ?? prop("step"));
416
- if (!prop("allowOverflow")) nextValue = (0, import_utils.clampValue)(nextValue, prop("min"), prop("max"));
417
- if (prop("snapOnStep"))
418
- nextValue = (0, import_utils.snapValueToStep)(nextValue, prop("min"), prop("max"), event.step ?? prop("step"));
419
- context.set("value", (0, import_number_input2.formatValue)(nextValue, { computed, prop }));
420
- },
421
- setClampedValue({ context, prop, computed }) {
422
- const nextValue = (0, import_utils.clampValue)(computed("valueAsNumber"), prop("min"), prop("max"));
423
- context.set("value", (0, import_number_input2.formatValue)(nextValue, { computed, prop }));
424
- },
425
- setRawValue({ context, event, prop, computed }) {
426
- let nextValue = typeof event.value === "number" ? event.value : (0, import_number_input2.parseValue)(event.value, { computed, prop });
427
- if (!prop("allowOverflow")) nextValue = (0, import_utils.clampValue)(nextValue, prop("min"), prop("max"));
428
- context.set("value", (0, import_number_input2.formatValue)(nextValue, { computed, prop }));
429
- },
430
- setValue({ context, event }) {
431
- const value = event.target?.value ?? event.value;
432
- context.set("value", value);
433
- },
434
- clearValue({ context }) {
435
- context.set("value", "");
436
- },
437
- incrementToMax({ context, prop, computed }) {
438
- const value = (0, import_number_input2.formatValue)(prop("max"), { computed, prop });
439
- context.set("value", value);
440
- },
441
- decrementToMin({ context, prop, computed }) {
442
- const value = (0, import_number_input2.formatValue)(prop("min"), { computed, prop });
443
- context.set("value", value);
444
- },
445
- setHint({ context, event }) {
446
- context.set("hint", event.hint);
447
- },
448
- clearHint({ context }) {
449
- context.set("hint", null);
450
- },
451
- invokeOnFocus({ computed, prop }) {
452
- prop("onFocusChange")?.({
453
- focused: true,
454
- value: computed("formattedValue"),
455
- valueAsNumber: computed("valueAsNumber")
456
- });
457
- },
458
- invokeOnBlur({ computed, prop }) {
459
- prop("onFocusChange")?.({
460
- focused: false,
461
- value: computed("formattedValue"),
462
- valueAsNumber: computed("valueAsNumber")
463
- });
464
- },
465
- invokeOnInvalid({ computed, prop }) {
466
- const reason = computed("valueAsNumber") > prop("max") ? "rangeOverflow" : "rangeUnderflow";
467
- prop("onValueInvalid")?.({
468
- reason,
469
- value: computed("formattedValue"),
470
- valueAsNumber: computed("valueAsNumber")
471
- });
472
- },
473
- invokeOnValueCommit({ computed, prop, event }) {
474
- prop("onValueCommit")?.({
475
- value: computed("formattedValue"),
476
- valueAsNumber: computed("valueAsNumber"),
477
- reason: event.src
478
- });
479
- },
480
- syncInputElement({ context, event, computed, scope }) {
481
- const value = event.type.endsWith("CHANGE") ? context.get("value") : computed("formattedValue");
482
- const inputEl = dom.getInputEl(scope);
483
- const sel = event.selection ?? (0, import_cursor.recordCursor)(inputEl, scope);
484
- (0, import_dom_query.raf)(() => {
485
- (0, import_dom_query.setElementValue)(inputEl, value);
486
- (0, import_cursor.restoreCursor)(inputEl, sel, scope);
487
- });
488
- },
489
- setFormattedValue({ context, computed, action }) {
490
- context.set("value", computed("formattedValue"));
491
- action(["syncInputElement"]);
492
- },
493
- setCursorPoint({ context, event }) {
494
- context.set("scrubberCursorPoint", event.point);
495
- },
496
- clearCursorPoint({ context }) {
497
- context.set("scrubberCursorPoint", null);
498
- },
499
- setVirtualCursorPosition({ context, scope }) {
500
- const scrubberEl = dom.getScrubberEl(scope);
501
- const point = context.get("scrubberCursorPoint");
502
- if (!scrubberEl || !point) return;
503
- scrubberEl.style.setProperty("--scrubber-x", `${point.x}px`);
504
- scrubberEl.style.setProperty("--scrubber-y", `${point.y}px`);
505
- },
506
- accumulateDelta({ context, event, prop, send }) {
507
- const delta = event.delta ?? 0;
508
- const newDelta = context.get("cumulativeDelta") + delta;
509
- const sensitivity = prop("scrubberPixelSensitivity");
510
- if (Math.abs(newDelta) >= sensitivity) {
511
- const step = prop("step");
512
- const hint = event.hint;
513
- if (hint === "increment" || hint === "decrement") {
514
- send({ type: "SCRUBBER.STEP", step, hint, src: "scrub" });
515
- }
516
- context.set("cumulativeDelta", newDelta % sensitivity);
517
- } else {
518
- context.set("cumulativeDelta", newDelta);
519
- }
520
- },
521
- clearCumulativeDelta({ context }) {
522
- context.set("cumulativeDelta", 0);
523
- }
524
- }
525
- }
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
526
4
  });
527
- // Annotate the CommonJS export names for ESM import in node:
528
- 0 && (module.exports = {
529
- machine
5
+ const require_number_input_dom = require("./number-input.dom.js");
6
+ const require_number_input_utils = require("./number-input.utils.js");
7
+ let _zag_js_dom_query = require("@zag-js/dom-query");
8
+ let _zag_js_utils = require("@zag-js/utils");
9
+ let _zag_js_core = require("@zag-js/core");
10
+ // src/number-input.machine.ts
11
+ const { choose, guards, createMachine } = (0, _zag_js_core.setup)();
12
+ const { not, and } = guards;
13
+ const machine = createMachine({
14
+ props({ props }) {
15
+ const step = require_number_input_utils.getDefaultStep(props.step, props.formatOptions);
16
+ return {
17
+ dir: "ltr",
18
+ locale: "en-US",
19
+ focusInputOnChange: true,
20
+ allowOutOfRange: false,
21
+ pattern: "-?[0-9]*(.[0-9]+)?",
22
+ defaultValue: null,
23
+ step,
24
+ spinOnPress: true,
25
+ scrubberPixelSensitivity: 2,
26
+ scrubberDirection: "horizontal",
27
+ snapOnStep: false,
28
+ ...props,
29
+ largeStep: props.largeStep ?? 10 * step,
30
+ smallStep: props.smallStep ?? step / 10
31
+ };
32
+ },
33
+ initialState() {
34
+ return "idle";
35
+ },
36
+ refs({ prop }) {
37
+ return {
38
+ syncFrame: _zag_js_dom_query.AnimationFrame.create(),
39
+ pressDirection: 1,
40
+ focusFrame: _zag_js_dom_query.AnimationFrame.create(),
41
+ committedValue: prop("value") ?? prop("defaultValue") ?? null
42
+ };
43
+ },
44
+ exit: ["cancelFrames"],
45
+ context({ prop, bindable, getComputed, getEvent }) {
46
+ return {
47
+ value: bindable(() => ({
48
+ defaultValue: prop("defaultValue"),
49
+ value: prop("value"),
50
+ onChange(value) {
51
+ const formattedValue = require_number_input_utils.formatValue(value, {
52
+ computed: getComputed(),
53
+ prop
54
+ });
55
+ prop("onValueChange")?.({
56
+ value,
57
+ formattedValue,
58
+ reason: getEvent().src
59
+ });
60
+ }
61
+ })),
62
+ inputValue: bindable(() => ({ defaultValue: require_number_input_utils.formatNumber(prop("value") ?? prop("defaultValue"), require_number_input_utils.createFormatter(prop("locale"), prop("formatOptions")), prop("formatOptions")) })),
63
+ scrubberCursorPoint: bindable(() => ({
64
+ defaultValue: null,
65
+ hash(value) {
66
+ return value ? `x:${value.x}, y:${value.y}` : "";
67
+ }
68
+ })),
69
+ fieldsetDisabled: bindable(() => ({ defaultValue: false })),
70
+ cumulativeDelta: bindable(() => ({ defaultValue: 0 })),
71
+ platform: bindable(() => ({ defaultValue: {
72
+ iPhone: false,
73
+ ios: false,
74
+ supportsPointerLock: false
75
+ } })),
76
+ visualScale: bindable(() => ({ defaultValue: 1 }))
77
+ };
78
+ },
79
+ computed: {
80
+ isRtl: ({ prop }) => prop("dir") === "rtl",
81
+ min: ({ prop }) => prop("min") ?? -1e400,
82
+ max: ({ prop }) => prop("max") ?? 1e400,
83
+ formattedValue: ({ context, computed, prop }) => require_number_input_utils.formatValue(context.get("value"), {
84
+ computed,
85
+ prop
86
+ }),
87
+ isAtMin: ({ context, computed }) => {
88
+ const value = context.get("value");
89
+ return value != null && value <= computed("min");
90
+ },
91
+ isAtMax: ({ context, computed }) => {
92
+ const value = context.get("value");
93
+ return value != null && value >= computed("max");
94
+ },
95
+ isOutOfRange: ({ context, prop }) => {
96
+ const value = context.get("value");
97
+ return value != null && !(0, _zag_js_utils.isValueWithinRange)(value, prop("min"), prop("max"));
98
+ },
99
+ isValueEmpty: ({ context }) => context.get("value") == null,
100
+ isDisabled: ({ prop, context }) => !!prop("disabled") || context.get("fieldsetDisabled"),
101
+ canIncrement: ({ computed }) => !computed("isAtMax"),
102
+ canDecrement: ({ computed }) => !computed("isAtMin"),
103
+ formatter: (0, _zag_js_core.memo)(({ prop }) => [prop("locale"), prop("formatOptions")], ([locale, formatOptions]) => require_number_input_utils.createFormatter(locale, formatOptions)),
104
+ parser: (0, _zag_js_core.memo)(({ prop }) => [prop("locale"), prop("formatOptions")], ([locale, formatOptions]) => require_number_input_utils.createParser(locale, formatOptions))
105
+ },
106
+ watch({ track, action, context, computed, prop }) {
107
+ track([
108
+ () => context.get("value"),
109
+ () => prop("locale"),
110
+ () => JSON.stringify(prop("formatOptions"))
111
+ ], () => {
112
+ action(["syncInputValue", "syncHiddenInput"]);
113
+ });
114
+ track([() => context.get("inputValue")], () => {
115
+ action(["syncInputValue", "syncInputElement"]);
116
+ });
117
+ track([() => computed("isOutOfRange")], () => {
118
+ if (!computed("isOutOfRange")) return;
119
+ action(["invokeOnInvalid"]);
120
+ });
121
+ track([() => context.hash("scrubberCursorPoint")], () => {
122
+ action(["setVirtualCursorPosition"]);
123
+ });
124
+ },
125
+ effects: ["trackFormControl", "detectPlatform"],
126
+ on: {
127
+ "INPUT.FOCUS": { actions: ["invokeOnFocus"] },
128
+ "VALUE.SET": { actions: ["setRawValue", "invokeOnValueCommit"] },
129
+ "VALUE.CLEAR": { actions: ["clearValue", "invokeOnValueCommit"] },
130
+ "VALUE.INCREMENT": { actions: ["increment", "invokeOnValueCommit"] },
131
+ "VALUE.DECREMENT": { actions: ["decrement", "invokeOnValueCommit"] }
132
+ },
133
+ states: {
134
+ idle: { on: {
135
+ "TRIGGER.PRESS_DOWN": [{
136
+ guard: "isTouchPointer",
137
+ target: "pressed",
138
+ actions: ["setPressDirection"]
139
+ }, {
140
+ target: "pressed",
141
+ actions: ["focusInput", "setPressDirection"]
142
+ }],
143
+ "SCRUBBER.PRESS_DOWN": {
144
+ target: "scrubbing",
145
+ actions: ["focusInput", "setCursorPoint"]
146
+ },
147
+ "INPUT.FOCUS": {
148
+ target: "focused",
149
+ actions: ["focusInput", "invokeOnFocus"]
150
+ }
151
+ } },
152
+ focused: {
153
+ tags: ["focus"],
154
+ effects: ["attachWheelListener"],
155
+ on: {
156
+ "TRIGGER.PRESS_DOWN": [{
157
+ guard: "isTouchPointer",
158
+ target: "pressed",
159
+ actions: ["setPressDirection"]
160
+ }, {
161
+ target: "pressed",
162
+ actions: ["focusInput", "setPressDirection"]
163
+ }],
164
+ "SCRUBBER.PRESS_DOWN": {
165
+ target: "scrubbing",
166
+ actions: ["focusInput", "setCursorPoint"]
167
+ },
168
+ "INPUT.ARROW_UP": { actions: ["increment", "invokeOnValueCommit"] },
169
+ "INPUT.ARROW_DOWN": { actions: ["decrement", "invokeOnValueCommit"] },
170
+ "INPUT.HOME": { actions: ["decrementToMin", "invokeOnValueCommit"] },
171
+ "INPUT.END": { actions: ["incrementToMax", "invokeOnValueCommit"] },
172
+ "INPUT.CHANGE": { actions: ["setInputValue"] },
173
+ "INPUT.BLUR": [{
174
+ guard: and(not("allowOutOfRange"), not("isInRange")),
175
+ target: "idle",
176
+ actions: [
177
+ "setClampedValue",
178
+ "invokeOnBlur",
179
+ "invokeOnValueCommit"
180
+ ]
181
+ }, {
182
+ target: "idle",
183
+ actions: [
184
+ "setFormattedValue",
185
+ "invokeOnBlur",
186
+ "invokeOnValueCommit"
187
+ ]
188
+ }],
189
+ "INPUT.ENTER": [{
190
+ guard: and(not("allowOutOfRange"), not("isInRange")),
191
+ actions: ["setClampedValue", "invokeOnValueCommit"]
192
+ }, { actions: ["setFormattedValue", "invokeOnValueCommit"] }]
193
+ }
194
+ },
195
+ pressed: {
196
+ tags: ["focus"],
197
+ initial: "waiting",
198
+ effects: ["trackButtonDisabled", "preventContextMenu"],
199
+ on: { "TRIGGER.PRESS_UP": [{
200
+ guard: "isTouchPointer",
201
+ target: "focused",
202
+ actions: ["invokeOnValueCommit"]
203
+ }, {
204
+ target: "focused",
205
+ actions: ["focusInput", "invokeOnValueCommit"]
206
+ }] },
207
+ states: {
208
+ waiting: {
209
+ effects: ["waitForChangeDelay"],
210
+ entry: choose([{
211
+ guard: not("isTouchPointer"),
212
+ actions: ["step"]
213
+ }]),
214
+ on: {
215
+ "TRIGGER.PRESS_UP": [
216
+ {
217
+ guard: and("isTouchPointer", "isTouchTap"),
218
+ target: "focused",
219
+ actions: ["step", "invokeOnValueCommit"]
220
+ },
221
+ {
222
+ guard: "isTouchPointer",
223
+ target: "focused"
224
+ },
225
+ {
226
+ target: "focused",
227
+ actions: ["focusInput", "invokeOnValueCommit"]
228
+ }
229
+ ],
230
+ CHANGE_DELAY: {
231
+ target: "repeating",
232
+ guard: and("isInRange", "spinOnPress")
233
+ }
234
+ }
235
+ },
236
+ repeating: {
237
+ effects: ["spinValue"],
238
+ on: { SPIN: { actions: ["step"] } }
239
+ }
240
+ }
241
+ },
242
+ scrubbing: {
243
+ tags: ["focus"],
244
+ effects: [
245
+ "activatePointerLock",
246
+ "trackMousemove",
247
+ "preventTextSelection",
248
+ "trackVisualViewport"
249
+ ],
250
+ entry: ["clearCumulativeDelta"],
251
+ on: {
252
+ "SCRUBBER.STEP": { actions: ["step"] },
253
+ "SCRUBBER.POINTER_UP": {
254
+ target: "focused",
255
+ actions: [
256
+ "focusInput",
257
+ "clearCursorPoint",
258
+ "clearCumulativeDelta",
259
+ "invokeOnValueCommit"
260
+ ]
261
+ },
262
+ "SCRUBBER.POINTER_MOVE": { actions: ["setCursorPoint", "accumulateDelta"] }
263
+ }
264
+ }
265
+ },
266
+ implementations: {
267
+ guards: {
268
+ allowOutOfRange: ({ prop }) => !!prop("allowOutOfRange"),
269
+ spinOnPress: ({ prop }) => !!prop("spinOnPress"),
270
+ isInRange: ({ computed }) => !computed("isOutOfRange"),
271
+ isTouchPointer: ({ event }) => event.pointerType === "touch",
272
+ isTouchTap: ({ event }) => !event.cancelled
273
+ },
274
+ effects: {
275
+ waitForChangeDelay({ send }) {
276
+ const id = setTimeout(() => {
277
+ send({ type: "CHANGE_DELAY" });
278
+ }, 400);
279
+ return () => clearTimeout(id);
280
+ },
281
+ preventContextMenu({ scope }) {
282
+ return (0, _zag_js_dom_query.addDomEvent)(scope.getWin(), "contextmenu", (event) => event.preventDefault());
283
+ },
284
+ spinValue({ send, refs }) {
285
+ const id = setInterval(() => {
286
+ send({
287
+ type: "SPIN",
288
+ src: getPressSource(refs.get("pressDirection"))
289
+ });
290
+ }, 60);
291
+ return () => clearInterval(id);
292
+ },
293
+ detectPlatform({ context }) {
294
+ context.set("platform", {
295
+ iPhone: (0, _zag_js_dom_query.isIPhone)(),
296
+ ios: (0, _zag_js_dom_query.isIos)(),
297
+ supportsPointerLock: !(0, _zag_js_dom_query.isSafari)()
298
+ });
299
+ },
300
+ trackFormControl({ context, scope }) {
301
+ const inputEl = require_number_input_dom.getHiddenInputEl(scope) ?? require_number_input_dom.getInputEl(scope);
302
+ return (0, _zag_js_dom_query.trackFormControl)(inputEl, {
303
+ onFieldsetDisabledChange(disabled) {
304
+ context.set("fieldsetDisabled", disabled);
305
+ },
306
+ onFormReset() {
307
+ context.set("value", context.initial("value") ?? null);
308
+ }
309
+ });
310
+ },
311
+ preventTextSelection({ scope, prop }) {
312
+ return require_number_input_dom.preventTextSelection(scope, prop("scrubberDirection"));
313
+ },
314
+ trackButtonDisabled({ refs, scope, send }) {
315
+ const direction = refs.get("pressDirection");
316
+ const btn = require_number_input_dom.getTriggerEl(scope, direction);
317
+ return (0, _zag_js_dom_query.observeAttributes)(btn, {
318
+ attributes: ["disabled"],
319
+ callback() {
320
+ send({
321
+ type: "TRIGGER.PRESS_UP",
322
+ src: getPressSource(direction)
323
+ });
324
+ }
325
+ });
326
+ },
327
+ attachWheelListener({ scope, send, prop }) {
328
+ const inputEl = require_number_input_dom.getInputEl(scope);
329
+ if (!inputEl || !scope.isActiveElement(inputEl) || !prop("allowMouseWheel")) return;
330
+ function onWheel(event) {
331
+ if (prop("readOnly")) return;
332
+ if (event.ctrlKey) return;
333
+ const isHorizontal = Math.abs(event.deltaX) > Math.abs(event.deltaY);
334
+ const delta = event.shiftKey && isHorizontal ? event.deltaX : event.deltaY;
335
+ if (delta === 0 || isHorizontal && !event.shiftKey) return;
336
+ event.preventDefault();
337
+ const step = event.altKey ? prop("smallStep") : event.shiftKey ? prop("largeStep") : prop("step");
338
+ send({
339
+ type: delta < 0 ? "VALUE.INCREMENT" : "VALUE.DECREMENT",
340
+ step,
341
+ src: "wheel"
342
+ });
343
+ }
344
+ return (0, _zag_js_dom_query.addDomEvent)(inputEl, "wheel", onWheel, { passive: false });
345
+ },
346
+ trackVisualViewport({ scope, context }) {
347
+ const vV = scope.getWin().visualViewport;
348
+ if (!vV) return;
349
+ function onResize() {
350
+ context.set("visualScale", vV.scale);
351
+ }
352
+ onResize();
353
+ return (0, _zag_js_dom_query.addDomEvent)(vV, "resize", onResize);
354
+ },
355
+ activatePointerLock({ scope }) {
356
+ if ((0, _zag_js_dom_query.isSafari)()) return;
357
+ const cleanup = (0, _zag_js_dom_query.requestPointerLock)(scope.getDoc());
358
+ return () => {
359
+ if ((0, _zag_js_dom_query.isFirefox)()) setTimeout(() => cleanup?.(), 20);
360
+ else cleanup?.();
361
+ };
362
+ },
363
+ trackMousemove({ scope, send, context, computed, prop }) {
364
+ const doc = scope.getDoc();
365
+ function onMousemove(event) {
366
+ const point = context.get("scrubberCursorPoint");
367
+ const isRtl = computed("isRtl");
368
+ const axis = prop("scrubberDirection");
369
+ const teleportDistance = prop("scrubberTeleportDistance");
370
+ const value = require_number_input_dom.getMousemoveValue(scope, {
371
+ point,
372
+ isRtl,
373
+ event,
374
+ axis,
375
+ teleportDistance
376
+ });
377
+ send({
378
+ type: "SCRUBBER.POINTER_MOVE",
379
+ direction: value.direction,
380
+ point: value.point,
381
+ delta: value.delta
382
+ });
383
+ }
384
+ function onMouseup() {
385
+ send({
386
+ type: "SCRUBBER.POINTER_UP",
387
+ src: "scrub"
388
+ });
389
+ }
390
+ return (0, _zag_js_utils.callAll)((0, _zag_js_dom_query.addDomEvent)(doc, "mousemove", onMousemove, false), (0, _zag_js_dom_query.addDomEvent)(doc, "mouseup", onMouseup, false));
391
+ }
392
+ },
393
+ actions: {
394
+ focusInput({ scope, prop, refs }) {
395
+ if (!prop("focusInputOnChange")) return;
396
+ const inputEl = require_number_input_dom.getInputEl(scope);
397
+ if (scope.isActiveElement(inputEl)) return;
398
+ refs.get("focusFrame").request(() => inputEl?.focus({ preventScroll: true }));
399
+ },
400
+ cancelFrames({ refs }) {
401
+ refs.get("syncFrame").cancel();
402
+ refs.get("focusFrame").cancel();
403
+ },
404
+ increment({ event, prop, computed, context }) {
405
+ const value = context.get("value");
406
+ const step = event.step ?? prop("step");
407
+ const next = value == null ? 0 : (0, _zag_js_utils.incrementValue)(value, step);
408
+ setNumber({
409
+ context,
410
+ prop,
411
+ computed
412
+ }, getStepValue(next, step, 1, {
413
+ prop,
414
+ computed
415
+ }));
416
+ },
417
+ decrement({ event, prop, computed, context }) {
418
+ const value = context.get("value");
419
+ const step = event.step ?? prop("step");
420
+ const next = value == null ? 0 : (0, _zag_js_utils.decrementValue)(value, step);
421
+ setNumber({
422
+ context,
423
+ prop,
424
+ computed
425
+ }, getStepValue(next, step, -1, {
426
+ prop,
427
+ computed
428
+ }));
429
+ },
430
+ setClampedValue({ context, prop, computed }) {
431
+ const value = context.get("value");
432
+ setNumber({
433
+ context,
434
+ prop,
435
+ computed
436
+ }, value == null ? null : (0, _zag_js_utils.clampValue)(value, computed("min"), computed("max")));
437
+ },
438
+ setRawValue({ context, event, prop, computed }) {
439
+ let value = event.value;
440
+ if (!prop("allowOutOfRange")) value = (0, _zag_js_utils.clampValue)(value, computed("min"), computed("max"));
441
+ setNumber({
442
+ context,
443
+ prop,
444
+ computed
445
+ }, value);
446
+ },
447
+ setInputValue({ context, event, computed, prop }) {
448
+ const text = event.value;
449
+ context.set("inputValue", text);
450
+ if (text.trim() === "") {
451
+ context.set("value", null);
452
+ return;
453
+ }
454
+ const value = require_number_input_utils.parseValue(text, {
455
+ computed,
456
+ prop
457
+ });
458
+ if (!Number.isNaN(value)) context.set("value", normalizeZero(value));
459
+ },
460
+ clearValue({ context }) {
461
+ context.set("value", null);
462
+ context.set("inputValue", "");
463
+ },
464
+ incrementToMax({ context, prop, computed }) {
465
+ setNumber({
466
+ context,
467
+ prop,
468
+ computed
469
+ }, computed("max"));
470
+ },
471
+ decrementToMin({ context, prop, computed }) {
472
+ setNumber({
473
+ context,
474
+ prop,
475
+ computed
476
+ }, computed("min"));
477
+ },
478
+ setPressDirection({ refs, event }) {
479
+ refs.set("pressDirection", event.direction);
480
+ },
481
+ step({ event, refs, action }) {
482
+ action([(event.direction ?? refs.get("pressDirection")) > 0 ? "increment" : "decrement"]);
483
+ },
484
+ invokeOnFocus({ context, computed, prop }) {
485
+ prop("onFocusChange")?.({
486
+ focused: true,
487
+ value: context.get("value"),
488
+ formattedValue: computed("formattedValue")
489
+ });
490
+ },
491
+ invokeOnBlur({ context, computed, prop }) {
492
+ prop("onFocusChange")?.({
493
+ focused: false,
494
+ value: context.get("value"),
495
+ formattedValue: computed("formattedValue")
496
+ });
497
+ },
498
+ invokeOnInvalid({ context, computed, prop }) {
499
+ const value = context.get("value");
500
+ if (value == null) return;
501
+ prop("onValueInvalid")?.({
502
+ reason: value > computed("max") ? "rangeOverflow" : "rangeUnderflow",
503
+ value,
504
+ formattedValue: computed("formattedValue")
505
+ });
506
+ },
507
+ invokeOnValueCommit({ context, computed, prop, event, refs }) {
508
+ const reason = event.src;
509
+ queueMicrotask(() => {
510
+ const value = context.get("value");
511
+ if (value === refs.get("committedValue")) return;
512
+ refs.set("committedValue", value);
513
+ prop("onValueCommit")?.({
514
+ value,
515
+ formattedValue: computed("formattedValue"),
516
+ reason
517
+ });
518
+ });
519
+ },
520
+ syncInputValue({ context, computed, prop, state }) {
521
+ const text = context.get("inputValue");
522
+ const formatted = computed("formattedValue");
523
+ if (text === formatted) return;
524
+ if (state.hasTag("focus") && representsValue(text, context.get("value"), {
525
+ computed,
526
+ prop
527
+ })) return;
528
+ context.set("inputValue", formatted);
529
+ },
530
+ syncInputElement({ context, event, scope, refs }) {
531
+ const value = context.get("inputValue");
532
+ const inputEl = require_number_input_dom.getInputEl(scope);
533
+ const sel = event.selection ?? (0, _zag_js_dom_query.recordCursor)(inputEl);
534
+ refs.get("syncFrame").request(() => {
535
+ const unchanged = inputEl?.value === value;
536
+ (0, _zag_js_dom_query.setElementValue)(inputEl, value);
537
+ if (!unchanged) (0, _zag_js_dom_query.restoreCursor)(inputEl, sel);
538
+ });
539
+ },
540
+ syncHiddenInput({ scope, context }) {
541
+ const value = context.get("value");
542
+ require_number_input_dom.dispatchHiddenInputValue(scope, value == null ? "" : String(value));
543
+ },
544
+ setFormattedValue({ context, computed }) {
545
+ context.set("inputValue", computed("formattedValue"));
546
+ },
547
+ setCursorPoint({ context, event }) {
548
+ context.set("scrubberCursorPoint", event.point);
549
+ },
550
+ clearCursorPoint({ context }) {
551
+ context.set("scrubberCursorPoint", null);
552
+ },
553
+ setVirtualCursorPosition({ context, scope }) {
554
+ const scrubberEl = require_number_input_dom.getScrubberEl(scope);
555
+ const point = context.get("scrubberCursorPoint");
556
+ if (!scrubberEl || !point) return;
557
+ scrubberEl.style.setProperty("--scrubber-x", `${point.x}px`);
558
+ scrubberEl.style.setProperty("--scrubber-y", `${point.y}px`);
559
+ },
560
+ accumulateDelta({ context, event, prop, send }) {
561
+ const delta = event.delta ?? 0;
562
+ const newDelta = context.get("cumulativeDelta") + delta;
563
+ const pixels = prop("scrubberPixelSensitivity");
564
+ const sensitivity = pixels > 0 ? pixels : 1;
565
+ if (Math.abs(newDelta) >= sensitivity) {
566
+ const step = prop("step");
567
+ if (event.direction) send({
568
+ type: "SCRUBBER.STEP",
569
+ step,
570
+ direction: event.direction,
571
+ src: "scrub"
572
+ });
573
+ context.set("cumulativeDelta", newDelta % sensitivity);
574
+ } else context.set("cumulativeDelta", newDelta);
575
+ },
576
+ clearCumulativeDelta({ context }) {
577
+ context.set("cumulativeDelta", 0);
578
+ }
579
+ }
580
+ }
530
581
  });
582
+ const getPressSource = (direction) => direction > 0 ? "increment-trigger" : "decrement-trigger";
583
+ /** Sets the number and shows it formatted */
584
+ function setNumber({ context, prop, computed }, value) {
585
+ value = value == null ? null : normalizeZero(value);
586
+ context.set("value", value);
587
+ context.set("inputValue", require_number_input_utils.formatValue(value, {
588
+ computed,
589
+ prop
590
+ }));
591
+ }
592
+ function getStepValue(value, step, direction, { prop, computed }) {
593
+ if (prop("snapOnStep")) value = require_number_input_utils.snapToStep(value, prop("min") ?? 0, step, direction);
594
+ return (0, _zag_js_utils.clampValue)(value, computed("min"), computed("max"));
595
+ }
596
+ function representsValue(text, value, params) {
597
+ if (text.trim() === "") return value == null;
598
+ const parsed = require_number_input_utils.parseValue(text, params);
599
+ return Number.isNaN(parsed) || parsed === value;
600
+ }
601
+ const normalizeZero = (value) => value === 0 ? 0 : value;
602
+ exports.machine = machine;