@zag-js/number-input 2.0.0-next.2 → 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,380 +1,486 @@
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.connect.ts
31
- var number_input_connect_exports = {};
32
- __export(number_input_connect_exports, {
33
- connect: () => connect
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
34
4
  });
35
- module.exports = __toCommonJS(number_input_connect_exports);
36
- var import_dom_query = require("@zag-js/dom-query");
37
- var import_utils = require("@zag-js/utils");
38
- var import_cursor = require("./cursor.js");
39
- var import_number_input = require("./number-input.anatomy.js");
40
- var dom = __toESM(require("./number-input.dom.js"));
41
- var import_number_input2 = require("./number-input.translations.js");
5
+ const require_number_input_anatomy = require("./number-input.anatomy.js");
6
+ const require_number_input_dom = require("./number-input.dom.js");
7
+ const require_number_input_translations = require("./number-input.translations.js");
8
+ const require_number_input_utils = require("./number-input.utils.js");
9
+ let _zag_js_dom_query = require("@zag-js/dom-query");
10
+ let _zag_js_utils = require("@zag-js/utils");
11
+ // src/number-input.connect.ts
42
12
  function connect(service, normalize) {
43
- const { state, send, prop, scope, computed, context } = service;
44
- const focused = state.hasTag("focus");
45
- const disabled = computed("isDisabled");
46
- const readOnly = !!prop("readOnly");
47
- const required = !!prop("required");
48
- const scrubbing = state.matches("scrubbing");
49
- const empty = computed("isValueEmpty");
50
- const invalid = prop("invalid") !== void 0 ? !!prop("invalid") : computed("isOutOfRange");
51
- const isIncrementDisabled = disabled || !computed("canIncrement") || readOnly;
52
- const isDecrementDisabled = disabled || !computed("canDecrement") || readOnly;
53
- const translations = (0, import_utils.mergeWithDefault)(import_number_input2.defaultTranslations, prop("translations"));
54
- function getRootState() {
55
- return { disabled, focused, invalid, scrubbing };
56
- }
57
- function getInputState() {
58
- return { disabled, invalid, readOnly, scrubbing };
59
- }
60
- function getIncrementTriggerState() {
61
- return { disabled: isIncrementDisabled };
62
- }
63
- function getDecrementTriggerState() {
64
- return { disabled: isDecrementDisabled };
65
- }
66
- return {
67
- focused,
68
- scrubbing,
69
- invalid,
70
- empty,
71
- value: computed("formattedValue"),
72
- valueAsNumber: computed("valueAsNumber"),
73
- setValue(value) {
74
- send({ type: "VALUE.SET", value, src: "script" });
75
- },
76
- clearValue() {
77
- send({ type: "VALUE.CLEAR", src: "script" });
78
- },
79
- increment() {
80
- send({ type: "VALUE.INCREMENT", src: "script" });
81
- },
82
- decrement() {
83
- send({ type: "VALUE.DECREMENT", src: "script" });
84
- },
85
- setToMax() {
86
- send({ type: "VALUE.SET", value: prop("max"), src: "script" });
87
- },
88
- setToMin() {
89
- send({ type: "VALUE.SET", value: prop("min"), src: "script" });
90
- },
91
- focus() {
92
- dom.getInputEl(scope)?.focus();
93
- },
94
- getRootState,
95
- getRootProps() {
96
- const rootState = getRootState();
97
- return normalize.element({
98
- ...import_number_input.parts.root.attrs(scope.id),
99
- dir: prop("dir"),
100
- "data-disabled": (0, import_dom_query.dataAttr)(rootState.disabled),
101
- "data-focus": (0, import_dom_query.dataAttr)(rootState.focused),
102
- "data-invalid": (0, import_dom_query.dataAttr)(rootState.invalid),
103
- "data-scrubbing": (0, import_dom_query.dataAttr)(rootState.scrubbing)
104
- });
105
- },
106
- getLabelProps() {
107
- return normalize.label({
108
- ...import_number_input.parts.label.attrs(scope.id),
109
- dir: prop("dir"),
110
- "data-disabled": (0, import_dom_query.dataAttr)(disabled),
111
- "data-focus": (0, import_dom_query.dataAttr)(focused),
112
- "data-invalid": (0, import_dom_query.dataAttr)(invalid),
113
- "data-required": (0, import_dom_query.dataAttr)(required),
114
- "data-scrubbing": (0, import_dom_query.dataAttr)(scrubbing),
115
- id: dom.getLabelId(scope),
116
- htmlFor: dom.getInputId(scope),
117
- onClick() {
118
- (0, import_dom_query.raf)(() => {
119
- (0, import_dom_query.setCaretToEnd)(dom.getInputEl(scope));
120
- });
121
- }
122
- });
123
- },
124
- getControlProps() {
125
- return normalize.element({
126
- ...import_number_input.parts.control.attrs(scope.id),
127
- dir: prop("dir"),
128
- role: "group",
129
- "aria-disabled": disabled,
130
- "data-focus": (0, import_dom_query.dataAttr)(focused),
131
- "data-disabled": (0, import_dom_query.dataAttr)(disabled),
132
- "data-invalid": (0, import_dom_query.dataAttr)(invalid),
133
- "data-scrubbing": (0, import_dom_query.dataAttr)(scrubbing),
134
- "aria-invalid": (0, import_dom_query.ariaAttr)(invalid)
135
- });
136
- },
137
- getValueTextProps() {
138
- return normalize.element({
139
- ...import_number_input.parts.valueText.attrs(scope.id),
140
- dir: prop("dir"),
141
- "data-disabled": (0, import_dom_query.dataAttr)(disabled),
142
- "data-invalid": (0, import_dom_query.dataAttr)(invalid),
143
- "data-focus": (0, import_dom_query.dataAttr)(focused),
144
- "data-scrubbing": (0, import_dom_query.dataAttr)(scrubbing)
145
- });
146
- },
147
- getInputState,
148
- getInputProps() {
149
- const inputState = getInputState();
150
- return normalize.input({
151
- ...import_number_input.parts.input.attrs(scope.id),
152
- dir: prop("dir"),
153
- name: prop("name"),
154
- form: prop("form"),
155
- id: dom.getInputId(scope),
156
- role: "spinbutton",
157
- defaultValue: computed("formattedValue"),
158
- pattern: prop("formatOptions") ? void 0 : prop("pattern"),
159
- inputMode: prop("inputMode"),
160
- "aria-invalid": (0, import_dom_query.ariaAttr)(inputState.invalid),
161
- "data-invalid": (0, import_dom_query.dataAttr)(inputState.invalid),
162
- disabled: inputState.disabled,
163
- "data-disabled": (0, import_dom_query.dataAttr)(inputState.disabled),
164
- readOnly: inputState.readOnly,
165
- required: prop("required"),
166
- autoComplete: "off",
167
- autoCorrect: "off",
168
- spellCheck: "false",
169
- type: "text",
170
- "aria-roledescription": "numberfield",
171
- "aria-valuemin": prop("min"),
172
- "aria-valuemax": prop("max"),
173
- "aria-valuenow": Number.isNaN(computed("valueAsNumber")) ? void 0 : computed("valueAsNumber"),
174
- "aria-valuetext": computed("valueText"),
175
- "data-scrubbing": (0, import_dom_query.dataAttr)(inputState.scrubbing),
176
- onFocus() {
177
- send({ type: "INPUT.FOCUS" });
178
- },
179
- onBlur() {
180
- send({ type: "INPUT.BLUR", src: "input-blur" });
181
- },
182
- onInput(event) {
183
- const selection = (0, import_cursor.recordCursor)(event.currentTarget, scope);
184
- send({ type: "INPUT.CHANGE", target: event.currentTarget, hint: "set", selection, src: "input-change" });
185
- },
186
- onBeforeInput(event) {
187
- try {
188
- const { selectionStart, selectionEnd, value } = event.currentTarget;
189
- const nextValue = value.slice(0, selectionStart) + (event.data ?? "") + value.slice(selectionEnd);
190
- const isValid = computed("parser").isValidPartialNumber(nextValue);
191
- if (!isValid) {
192
- event.preventDefault();
193
- }
194
- } catch {
195
- }
196
- },
197
- onKeyDown(event) {
198
- if (event.defaultPrevented) return;
199
- if (readOnly) return;
200
- if ((0, import_dom_query.isComposingEvent)(event)) return;
201
- const step = (0, import_dom_query.getEventStepValue)(event, {
202
- step: prop("step"),
203
- largeStep: prop("largeStep"),
204
- smallStep: prop("smallStep")
205
- });
206
- const keyMap = {
207
- ArrowUp() {
208
- send({ type: "INPUT.ARROW_UP", step, src: "keyboard" });
209
- event.preventDefault();
210
- event.stopPropagation();
211
- },
212
- ArrowDown() {
213
- send({ type: "INPUT.ARROW_DOWN", step, src: "keyboard" });
214
- event.preventDefault();
215
- event.stopPropagation();
216
- },
217
- PageUp() {
218
- send({ type: "INPUT.ARROW_UP", step, src: "keyboard" });
219
- event.preventDefault();
220
- event.stopPropagation();
221
- },
222
- PageDown() {
223
- send({ type: "INPUT.ARROW_DOWN", step, src: "keyboard" });
224
- event.preventDefault();
225
- event.stopPropagation();
226
- },
227
- Home() {
228
- if ((0, import_dom_query.isModifierKey)(event)) return;
229
- send({ type: "INPUT.HOME", src: "keyboard" });
230
- event.preventDefault();
231
- event.stopPropagation();
232
- },
233
- End() {
234
- if ((0, import_dom_query.isModifierKey)(event)) return;
235
- send({ type: "INPUT.END", src: "keyboard" });
236
- event.preventDefault();
237
- event.stopPropagation();
238
- },
239
- Enter(event2) {
240
- const selection = (0, import_cursor.recordCursor)(event2.currentTarget, scope);
241
- send({ type: "INPUT.ENTER", selection, src: "keyboard" });
242
- }
243
- };
244
- const exec = keyMap[event.key];
245
- exec?.(event);
246
- }
247
- });
248
- },
249
- getDecrementTriggerState,
250
- getDecrementTriggerProps() {
251
- const decrementTriggerState = getDecrementTriggerState();
252
- return normalize.button({
253
- ...import_number_input.parts.decrementTrigger.attrs(scope.id),
254
- dir: prop("dir"),
255
- disabled: decrementTriggerState.disabled,
256
- "data-disabled": (0, import_dom_query.dataAttr)(decrementTriggerState.disabled),
257
- "aria-label": translations.decrementLabel,
258
- type: "button",
259
- tabIndex: -1,
260
- "aria-controls": dom.getInputId(scope),
261
- "data-scrubbing": (0, import_dom_query.dataAttr)(scrubbing),
262
- onPointerDown(event) {
263
- if (decrementTriggerState.disabled) return;
264
- if (!(0, import_dom_query.isLeftClick)(event)) return;
265
- send({
266
- type: "TRIGGER.PRESS_DOWN",
267
- hint: "decrement",
268
- pointerType: event.pointerType,
269
- src: "decrement-press"
270
- });
271
- if (event.pointerType === "mouse") {
272
- event.preventDefault();
273
- }
274
- if (event.pointerType === "touch") {
275
- event.currentTarget?.focus({ preventScroll: true });
276
- }
277
- },
278
- onPointerUp(event) {
279
- send({ type: "TRIGGER.PRESS_UP", hint: "decrement", pointerType: event.pointerType, src: "decrement-press" });
280
- },
281
- onPointerLeave() {
282
- if (decrementTriggerState.disabled) return;
283
- send({ type: "TRIGGER.PRESS_UP", hint: "decrement", src: "decrement-press" });
284
- },
285
- onPointerCancel(event) {
286
- send({ type: "TRIGGER.PRESS_UP", hint: "decrement", pointerType: event.pointerType, src: "decrement-press" });
287
- }
288
- });
289
- },
290
- getIncrementTriggerState,
291
- getIncrementTriggerProps() {
292
- const incrementTriggerState = getIncrementTriggerState();
293
- return normalize.button({
294
- ...import_number_input.parts.incrementTrigger.attrs(scope.id),
295
- dir: prop("dir"),
296
- disabled: incrementTriggerState.disabled,
297
- "data-disabled": (0, import_dom_query.dataAttr)(incrementTriggerState.disabled),
298
- "aria-label": translations.incrementLabel,
299
- type: "button",
300
- tabIndex: -1,
301
- "aria-controls": dom.getInputId(scope),
302
- "data-scrubbing": (0, import_dom_query.dataAttr)(scrubbing),
303
- onPointerDown(event) {
304
- if (incrementTriggerState.disabled || !(0, import_dom_query.isLeftClick)(event)) return;
305
- send({
306
- type: "TRIGGER.PRESS_DOWN",
307
- hint: "increment",
308
- pointerType: event.pointerType,
309
- src: "increment-press"
310
- });
311
- if (event.pointerType === "mouse") {
312
- event.preventDefault();
313
- }
314
- if (event.pointerType === "touch") {
315
- event.currentTarget?.focus({ preventScroll: true });
316
- }
317
- },
318
- onPointerUp(event) {
319
- send({ type: "TRIGGER.PRESS_UP", hint: "increment", pointerType: event.pointerType, src: "increment-press" });
320
- },
321
- onPointerLeave(event) {
322
- send({ type: "TRIGGER.PRESS_UP", hint: "increment", pointerType: event.pointerType, src: "increment-press" });
323
- },
324
- onPointerCancel(event) {
325
- send({ type: "TRIGGER.PRESS_UP", hint: "increment", pointerType: event.pointerType, src: "increment-press" });
326
- }
327
- });
328
- },
329
- getScrubberProps() {
330
- const direction = prop("scrubberDirection");
331
- const point = context.get("scrubberCursorPoint");
332
- return normalize.element({
333
- ...import_number_input.parts.scrubber.attrs(scope.id),
334
- dir: prop("dir"),
335
- "data-disabled": (0, import_dom_query.dataAttr)(disabled),
336
- role: "presentation",
337
- "data-scrubbing": (0, import_dom_query.dataAttr)(scrubbing),
338
- onMouseDown(event) {
339
- if (disabled) return;
340
- if (!(0, import_dom_query.isLeftClick)(event)) return;
341
- const pt = (0, import_dom_query.getEventPoint)(event);
342
- const win = (0, import_dom_query.getWindow)(event.currentTarget);
343
- const dpr = win.devicePixelRatio;
344
- pt.x = pt.x - (0, import_utils.roundToDpr)(7.5, dpr);
345
- pt.y = pt.y - (0, import_utils.roundToDpr)(7.5, dpr);
346
- send({ type: "SCRUBBER.PRESS_DOWN", point: pt });
347
- event.preventDefault();
348
- (0, import_dom_query.raf)(() => {
349
- (0, import_dom_query.setCaretToEnd)(dom.getInputEl(scope));
350
- });
351
- },
352
- style: {
353
- cursor: disabled ? void 0 : direction === "vertical" ? "ns-resize" : "ew-resize",
354
- "--scrubber-x": point ? (0, import_utils.toPx)(point.x) : void 0,
355
- "--scrubber-y": point ? (0, import_utils.toPx)(point.y) : void 0,
356
- "--scrubber-scale": `${1 / context.get("visualScale")}`
357
- }
358
- });
359
- },
360
- getScrubberCursorProps() {
361
- return normalize.element({
362
- ...import_number_input.parts.scrubberCursor.attrs(scope.id),
363
- hidden: !scrubbing || !context.get("isPointerLockSupported"),
364
- style: {
365
- position: "fixed",
366
- pointerEvents: "none",
367
- left: "0px",
368
- top: "0px",
369
- zIndex: import_dom_query.MAX_Z_INDEX,
370
- transform: "translate3d(var(--scrubber-x, 0px), var(--scrubber-y, 0px), 0px) scale(var(--scrubber-scale, 1))",
371
- willChange: "transform"
372
- }
373
- });
374
- }
375
- };
13
+ const { state, send, prop, scope, computed, context } = service;
14
+ const focused = state.hasTag("focus");
15
+ const disabled = computed("isDisabled");
16
+ const readOnly = !!prop("readOnly");
17
+ const required = !!prop("required");
18
+ const scrubbing = state.matches("scrubbing");
19
+ const empty = computed("isValueEmpty");
20
+ const invalid = prop("invalid") !== void 0 ? !!prop("invalid") : computed("isOutOfRange");
21
+ const isIncrementDisabled = disabled || !computed("canIncrement") || readOnly;
22
+ const isDecrementDisabled = disabled || !computed("canDecrement") || readOnly;
23
+ const translations = (0, _zag_js_utils.mergeWithDefault)(require_number_input_translations.defaultTranslations, prop("translations"));
24
+ const min = prop("min");
25
+ const max = prop("max");
26
+ const allowsNegative = min == null || min < 0;
27
+ const inputMode = prop("inputMode") ?? (context.get("platform").iPhone && allowsNegative ? "text" : "decimal");
28
+ function getRootState() {
29
+ return {
30
+ disabled,
31
+ focused,
32
+ invalid,
33
+ scrubbing
34
+ };
35
+ }
36
+ function getInputState() {
37
+ return {
38
+ disabled,
39
+ invalid,
40
+ readOnly,
41
+ scrubbing
42
+ };
43
+ }
44
+ function getIncrementTriggerState() {
45
+ return { disabled: isIncrementDisabled };
46
+ }
47
+ function getDecrementTriggerState() {
48
+ return { disabled: isDecrementDisabled };
49
+ }
50
+ return {
51
+ focused,
52
+ scrubbing,
53
+ invalid,
54
+ empty,
55
+ value: context.get("value"),
56
+ formattedValue: computed("formattedValue"),
57
+ setValue(value) {
58
+ send({
59
+ type: "VALUE.SET",
60
+ value,
61
+ src: "script"
62
+ });
63
+ },
64
+ clearValue() {
65
+ send({
66
+ type: "VALUE.CLEAR",
67
+ src: "script"
68
+ });
69
+ },
70
+ increment() {
71
+ send({
72
+ type: "VALUE.INCREMENT",
73
+ src: "script"
74
+ });
75
+ },
76
+ decrement() {
77
+ send({
78
+ type: "VALUE.DECREMENT",
79
+ src: "script"
80
+ });
81
+ },
82
+ setToMax() {
83
+ if (max == null) return;
84
+ send({
85
+ type: "VALUE.SET",
86
+ value: max,
87
+ src: "script"
88
+ });
89
+ },
90
+ setToMin() {
91
+ if (min == null) return;
92
+ send({
93
+ type: "VALUE.SET",
94
+ value: min,
95
+ src: "script"
96
+ });
97
+ },
98
+ focus() {
99
+ require_number_input_dom.getInputEl(scope)?.focus();
100
+ },
101
+ getRootState,
102
+ getRootProps() {
103
+ const rootState = getRootState();
104
+ return normalize.element({
105
+ ...require_number_input_anatomy.parts.root.attrs(scope.id),
106
+ dir: prop("dir"),
107
+ "data-disabled": (0, _zag_js_dom_query.dataAttr)(rootState.disabled),
108
+ "data-focus": (0, _zag_js_dom_query.dataAttr)(rootState.focused),
109
+ "data-invalid": (0, _zag_js_dom_query.dataAttr)(rootState.invalid),
110
+ "data-scrubbing": (0, _zag_js_dom_query.dataAttr)(rootState.scrubbing)
111
+ });
112
+ },
113
+ getLabelProps() {
114
+ return normalize.label({
115
+ ...require_number_input_anatomy.parts.label.attrs(scope.id),
116
+ dir: prop("dir"),
117
+ "data-disabled": (0, _zag_js_dom_query.dataAttr)(disabled),
118
+ "data-focus": (0, _zag_js_dom_query.dataAttr)(focused),
119
+ "data-invalid": (0, _zag_js_dom_query.dataAttr)(invalid),
120
+ "data-required": (0, _zag_js_dom_query.dataAttr)(required),
121
+ "data-scrubbing": (0, _zag_js_dom_query.dataAttr)(scrubbing),
122
+ id: require_number_input_dom.getLabelId(scope),
123
+ htmlFor: require_number_input_dom.getInputId(scope),
124
+ onClick() {
125
+ (0, _zag_js_dom_query.raf)(() => {
126
+ (0, _zag_js_dom_query.setCaretToEnd)(require_number_input_dom.getInputEl(scope));
127
+ });
128
+ }
129
+ });
130
+ },
131
+ getControlProps() {
132
+ return normalize.element({
133
+ ...require_number_input_anatomy.parts.control.attrs(scope.id),
134
+ dir: prop("dir"),
135
+ role: "group",
136
+ "aria-disabled": disabled,
137
+ "data-focus": (0, _zag_js_dom_query.dataAttr)(focused),
138
+ "data-disabled": (0, _zag_js_dom_query.dataAttr)(disabled),
139
+ "data-invalid": (0, _zag_js_dom_query.dataAttr)(invalid),
140
+ "data-scrubbing": (0, _zag_js_dom_query.dataAttr)(scrubbing),
141
+ "aria-invalid": (0, _zag_js_dom_query.ariaAttr)(invalid)
142
+ });
143
+ },
144
+ getValueTextProps() {
145
+ return normalize.element({
146
+ ...require_number_input_anatomy.parts.valueText.attrs(scope.id),
147
+ dir: prop("dir"),
148
+ "data-disabled": (0, _zag_js_dom_query.dataAttr)(disabled),
149
+ "data-invalid": (0, _zag_js_dom_query.dataAttr)(invalid),
150
+ "data-focus": (0, _zag_js_dom_query.dataAttr)(focused),
151
+ "data-scrubbing": (0, _zag_js_dom_query.dataAttr)(scrubbing)
152
+ });
153
+ },
154
+ getInputState,
155
+ getInputProps() {
156
+ const inputState = getInputState();
157
+ return normalize.input({
158
+ ...require_number_input_anatomy.parts.input.attrs(scope.id),
159
+ dir: prop("dir"),
160
+ id: require_number_input_dom.getInputId(scope),
161
+ defaultValue: context.get("inputValue"),
162
+ pattern: prop("formatOptions") ? void 0 : prop("pattern"),
163
+ inputMode,
164
+ "aria-invalid": (0, _zag_js_dom_query.ariaAttr)(inputState.invalid),
165
+ "data-invalid": (0, _zag_js_dom_query.dataAttr)(inputState.invalid),
166
+ disabled: inputState.disabled,
167
+ "data-disabled": (0, _zag_js_dom_query.dataAttr)(inputState.disabled),
168
+ readOnly: inputState.readOnly,
169
+ required: prop("required"),
170
+ autoComplete: "off",
171
+ autoCorrect: "off",
172
+ spellCheck: "false",
173
+ type: "text",
174
+ "aria-roledescription": context.get("platform").ios ? void 0 : translations.roleDescription,
175
+ "data-scrubbing": (0, _zag_js_dom_query.dataAttr)(inputState.scrubbing),
176
+ onFocus() {
177
+ send({ type: "INPUT.FOCUS" });
178
+ },
179
+ onBlur() {
180
+ send({
181
+ type: "INPUT.BLUR",
182
+ src: "input-blur"
183
+ });
184
+ },
185
+ onInput(event) {
186
+ const selection = (0, _zag_js_dom_query.recordCursor)(event.currentTarget);
187
+ send({
188
+ type: "INPUT.CHANGE",
189
+ value: event.currentTarget.value,
190
+ selection,
191
+ src: "input-change"
192
+ });
193
+ },
194
+ onBeforeInput(event) {
195
+ try {
196
+ const { selectionStart, selectionEnd, value } = event.currentTarget;
197
+ const nextValue = value.slice(0, selectionStart) + (event.data ?? "") + value.slice(selectionEnd);
198
+ const allowOutOfRange = prop("allowOutOfRange");
199
+ if (!computed("parser").isValidPartialNumber(require_number_input_utils.normalizeNumberText(nextValue), allowOutOfRange ? void 0 : min, allowOutOfRange ? void 0 : max)) event.preventDefault();
200
+ } catch {}
201
+ },
202
+ onKeyDown(event) {
203
+ if (event.defaultPrevented) return;
204
+ if (readOnly) return;
205
+ if ((0, _zag_js_dom_query.isComposingEvent)(event)) return;
206
+ const step = (0, _zag_js_dom_query.getEventStepValue)(event, {
207
+ step: prop("step"),
208
+ largeStep: prop("largeStep"),
209
+ smallStep: prop("smallStep")
210
+ });
211
+ const exec = {
212
+ ArrowUp() {
213
+ send({
214
+ type: "INPUT.ARROW_UP",
215
+ step,
216
+ src: "keyboard"
217
+ });
218
+ event.preventDefault();
219
+ event.stopPropagation();
220
+ },
221
+ ArrowDown() {
222
+ send({
223
+ type: "INPUT.ARROW_DOWN",
224
+ step,
225
+ src: "keyboard"
226
+ });
227
+ event.preventDefault();
228
+ event.stopPropagation();
229
+ },
230
+ PageUp() {
231
+ send({
232
+ type: "INPUT.ARROW_UP",
233
+ step,
234
+ src: "keyboard"
235
+ });
236
+ event.preventDefault();
237
+ event.stopPropagation();
238
+ },
239
+ PageDown() {
240
+ send({
241
+ type: "INPUT.ARROW_DOWN",
242
+ step,
243
+ src: "keyboard"
244
+ });
245
+ event.preventDefault();
246
+ event.stopPropagation();
247
+ },
248
+ Home() {
249
+ if ((0, _zag_js_dom_query.isModifierKey)(event) || min == null) return;
250
+ send({
251
+ type: "INPUT.HOME",
252
+ src: "keyboard"
253
+ });
254
+ event.preventDefault();
255
+ event.stopPropagation();
256
+ },
257
+ End() {
258
+ if ((0, _zag_js_dom_query.isModifierKey)(event) || max == null) return;
259
+ send({
260
+ type: "INPUT.END",
261
+ src: "keyboard"
262
+ });
263
+ event.preventDefault();
264
+ event.stopPropagation();
265
+ },
266
+ Enter(event) {
267
+ const selection = (0, _zag_js_dom_query.recordCursor)(event.currentTarget);
268
+ send({
269
+ type: "INPUT.ENTER",
270
+ selection,
271
+ src: "keyboard"
272
+ });
273
+ }
274
+ }[event.key];
275
+ exec?.(event);
276
+ }
277
+ });
278
+ },
279
+ getHiddenInputProps() {
280
+ const value = context.get("value");
281
+ const handleChange = (e) => {
282
+ if ((0, _zag_js_dom_query.isInternalChangeEvent)((0, _zag_js_dom_query.getNativeEvent)(e)) || disabled || readOnly) return;
283
+ const next = e.currentTarget.valueAsNumber;
284
+ if (Number.isNaN(next)) send({
285
+ type: "VALUE.CLEAR",
286
+ src: "autofill"
287
+ });
288
+ else send({
289
+ type: "VALUE.SET",
290
+ value: next,
291
+ src: "autofill"
292
+ });
293
+ };
294
+ return normalize.input({
295
+ type: "number",
296
+ id: require_number_input_dom.getHiddenInputId(scope),
297
+ name: prop("name"),
298
+ form: prop("form"),
299
+ min,
300
+ max,
301
+ step: "any",
302
+ disabled,
303
+ readOnly,
304
+ required,
305
+ defaultValue: value == null ? "" : String(value),
306
+ "aria-hidden": true,
307
+ tabIndex: -1,
308
+ style: _zag_js_dom_query.visuallyHiddenStyle,
309
+ onChange: handleChange,
310
+ onInput: handleChange,
311
+ onFocus() {
312
+ require_number_input_dom.getInputEl(scope)?.focus({ preventScroll: true });
313
+ }
314
+ });
315
+ },
316
+ getDecrementTriggerState,
317
+ getDecrementTriggerProps() {
318
+ const decrementTriggerState = getDecrementTriggerState();
319
+ return normalize.button({
320
+ ...require_number_input_anatomy.parts.decrementTrigger.attrs(scope.id),
321
+ dir: prop("dir"),
322
+ disabled: decrementTriggerState.disabled,
323
+ "data-disabled": (0, _zag_js_dom_query.dataAttr)(decrementTriggerState.disabled),
324
+ "aria-label": translations.decrementLabel,
325
+ type: "button",
326
+ tabIndex: -1,
327
+ "aria-controls": require_number_input_dom.getInputId(scope),
328
+ "data-scrubbing": (0, _zag_js_dom_query.dataAttr)(scrubbing),
329
+ onClick(event) {
330
+ if (decrementTriggerState.disabled || event.detail !== 0) return;
331
+ send({
332
+ type: "VALUE.DECREMENT",
333
+ src: "decrement-trigger"
334
+ });
335
+ },
336
+ onPointerDown(event) {
337
+ if (decrementTriggerState.disabled) return;
338
+ if (!(0, _zag_js_dom_query.isLeftClick)(event)) return;
339
+ send({
340
+ type: "TRIGGER.PRESS_DOWN",
341
+ direction: -1,
342
+ pointerType: event.pointerType,
343
+ src: "decrement-trigger"
344
+ });
345
+ if (event.pointerType === "mouse") event.preventDefault();
346
+ if (event.pointerType === "touch") event.currentTarget?.focus({ preventScroll: true });
347
+ },
348
+ onPointerUp(event) {
349
+ send({
350
+ type: "TRIGGER.PRESS_UP",
351
+ direction: -1,
352
+ pointerType: event.pointerType,
353
+ src: "decrement-trigger"
354
+ });
355
+ },
356
+ onPointerLeave(event) {
357
+ if (decrementTriggerState.disabled) return;
358
+ send({
359
+ type: "TRIGGER.PRESS_UP",
360
+ direction: -1,
361
+ pointerType: event.pointerType,
362
+ cancelled: true,
363
+ src: "decrement-trigger"
364
+ });
365
+ },
366
+ onPointerCancel(event) {
367
+ send({
368
+ type: "TRIGGER.PRESS_UP",
369
+ direction: -1,
370
+ pointerType: event.pointerType,
371
+ cancelled: true,
372
+ src: "decrement-trigger"
373
+ });
374
+ }
375
+ });
376
+ },
377
+ getIncrementTriggerState,
378
+ getIncrementTriggerProps() {
379
+ const incrementTriggerState = getIncrementTriggerState();
380
+ return normalize.button({
381
+ ...require_number_input_anatomy.parts.incrementTrigger.attrs(scope.id),
382
+ dir: prop("dir"),
383
+ disabled: incrementTriggerState.disabled,
384
+ "data-disabled": (0, _zag_js_dom_query.dataAttr)(incrementTriggerState.disabled),
385
+ "aria-label": translations.incrementLabel,
386
+ type: "button",
387
+ tabIndex: -1,
388
+ "aria-controls": require_number_input_dom.getInputId(scope),
389
+ "data-scrubbing": (0, _zag_js_dom_query.dataAttr)(scrubbing),
390
+ onClick(event) {
391
+ if (incrementTriggerState.disabled || event.detail !== 0) return;
392
+ send({
393
+ type: "VALUE.INCREMENT",
394
+ src: "increment-trigger"
395
+ });
396
+ },
397
+ onPointerDown(event) {
398
+ if (incrementTriggerState.disabled || !(0, _zag_js_dom_query.isLeftClick)(event)) return;
399
+ send({
400
+ type: "TRIGGER.PRESS_DOWN",
401
+ direction: 1,
402
+ pointerType: event.pointerType,
403
+ src: "increment-trigger"
404
+ });
405
+ if (event.pointerType === "mouse") event.preventDefault();
406
+ if (event.pointerType === "touch") event.currentTarget?.focus({ preventScroll: true });
407
+ },
408
+ onPointerUp(event) {
409
+ send({
410
+ type: "TRIGGER.PRESS_UP",
411
+ direction: 1,
412
+ pointerType: event.pointerType,
413
+ src: "increment-trigger"
414
+ });
415
+ },
416
+ onPointerLeave(event) {
417
+ send({
418
+ type: "TRIGGER.PRESS_UP",
419
+ direction: 1,
420
+ pointerType: event.pointerType,
421
+ cancelled: true,
422
+ src: "increment-trigger"
423
+ });
424
+ },
425
+ onPointerCancel(event) {
426
+ send({
427
+ type: "TRIGGER.PRESS_UP",
428
+ direction: 1,
429
+ pointerType: event.pointerType,
430
+ cancelled: true,
431
+ src: "increment-trigger"
432
+ });
433
+ }
434
+ });
435
+ },
436
+ getScrubberProps() {
437
+ const direction = prop("scrubberDirection");
438
+ const point = context.get("scrubberCursorPoint");
439
+ return normalize.element({
440
+ ...require_number_input_anatomy.parts.scrubber.attrs(scope.id),
441
+ dir: prop("dir"),
442
+ "data-disabled": (0, _zag_js_dom_query.dataAttr)(disabled),
443
+ role: "presentation",
444
+ "data-scrubbing": (0, _zag_js_dom_query.dataAttr)(scrubbing),
445
+ onMouseDown(event) {
446
+ if (disabled || readOnly) return;
447
+ if (!(0, _zag_js_dom_query.isLeftClick)(event)) return;
448
+ const pt = (0, _zag_js_dom_query.getEventPoint)(event);
449
+ const dpr = (0, _zag_js_dom_query.getWindow)(event.currentTarget).devicePixelRatio;
450
+ pt.x = pt.x - (0, _zag_js_utils.roundToDpr)(7.5, dpr);
451
+ pt.y = pt.y - (0, _zag_js_utils.roundToDpr)(7.5, dpr);
452
+ send({
453
+ type: "SCRUBBER.PRESS_DOWN",
454
+ point: pt
455
+ });
456
+ event.preventDefault();
457
+ (0, _zag_js_dom_query.raf)(() => {
458
+ (0, _zag_js_dom_query.setCaretToEnd)(require_number_input_dom.getInputEl(scope));
459
+ });
460
+ },
461
+ style: {
462
+ cursor: disabled ? void 0 : direction === "vertical" ? "ns-resize" : "ew-resize",
463
+ "--scrubber-x": point ? (0, _zag_js_utils.toPx)(point.x) : void 0,
464
+ "--scrubber-y": point ? (0, _zag_js_utils.toPx)(point.y) : void 0,
465
+ "--scrubber-scale": `${1 / context.get("visualScale")}`
466
+ }
467
+ });
468
+ },
469
+ getScrubberCursorProps() {
470
+ return normalize.element({
471
+ ...require_number_input_anatomy.parts.scrubberCursor.attrs(scope.id),
472
+ hidden: !scrubbing || !context.get("platform").supportsPointerLock,
473
+ style: {
474
+ position: "fixed",
475
+ pointerEvents: "none",
476
+ left: "0px",
477
+ top: "0px",
478
+ zIndex: _zag_js_dom_query.MAX_Z_INDEX,
479
+ transform: "translate3d(var(--scrubber-x, 0px), var(--scrubber-y, 0px), 0px) scale(var(--scrubber-scale, 1))",
480
+ willChange: "transform"
481
+ }
482
+ });
483
+ }
484
+ };
376
485
  }
377
- // Annotate the CommonJS export names for ESM import in node:
378
- 0 && (module.exports = {
379
- connect
380
- });
486
+ exports.connect = connect;