@zag-js/number-input 1.34.1 → 1.35.0

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 (37) hide show
  1. package/dist/cursor.d.mts +12 -0
  2. package/dist/cursor.d.ts +12 -0
  3. package/dist/cursor.js +111 -0
  4. package/dist/cursor.mjs +84 -0
  5. package/dist/index.d.mts +9 -314
  6. package/dist/index.d.ts +9 -314
  7. package/dist/index.js +37 -931
  8. package/dist/index.mjs +9 -926
  9. package/dist/number-input.anatomy.d.mts +6 -0
  10. package/dist/number-input.anatomy.d.ts +6 -0
  11. package/dist/number-input.anatomy.js +43 -0
  12. package/dist/number-input.anatomy.mjs +17 -0
  13. package/dist/number-input.connect.d.mts +8 -0
  14. package/dist/number-input.connect.d.ts +8 -0
  15. package/dist/number-input.connect.js +308 -0
  16. package/dist/number-input.connect.mjs +284 -0
  17. package/dist/number-input.dom.d.mts +34 -0
  18. package/dist/number-input.dom.d.ts +34 -0
  19. package/dist/number-input.dom.js +150 -0
  20. package/dist/number-input.dom.mjs +109 -0
  21. package/dist/number-input.machine.d.mts +8 -0
  22. package/dist/number-input.machine.d.ts +8 -0
  23. package/dist/number-input.machine.js +460 -0
  24. package/dist/number-input.machine.mjs +441 -0
  25. package/dist/number-input.props.d.mts +9 -0
  26. package/dist/number-input.props.d.ts +9 -0
  27. package/dist/number-input.props.js +65 -0
  28. package/dist/number-input.props.mjs +39 -0
  29. package/dist/number-input.types.d.mts +303 -0
  30. package/dist/number-input.types.d.ts +303 -0
  31. package/dist/number-input.types.js +18 -0
  32. package/dist/number-input.types.mjs +0 -0
  33. package/dist/number-input.utils.d.mts +13 -0
  34. package/dist/number-input.utils.d.ts +13 -0
  35. package/dist/number-input.utils.js +63 -0
  36. package/dist/number-input.utils.mjs +34 -0
  37. package/package.json +17 -7
@@ -0,0 +1,6 @@
1
+ import * as _zag_js_anatomy from '@zag-js/anatomy';
2
+
3
+ declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "label" | "input" | "control" | "valueText" | "incrementTrigger" | "decrementTrigger" | "scrubber">;
4
+ declare const parts: Record<"root" | "label" | "input" | "control" | "valueText" | "incrementTrigger" | "decrementTrigger" | "scrubber", _zag_js_anatomy.AnatomyPart>;
5
+
6
+ export { anatomy, parts };
@@ -0,0 +1,6 @@
1
+ import * as _zag_js_anatomy from '@zag-js/anatomy';
2
+
3
+ declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "label" | "input" | "control" | "valueText" | "incrementTrigger" | "decrementTrigger" | "scrubber">;
4
+ declare const parts: Record<"root" | "label" | "input" | "control" | "valueText" | "incrementTrigger" | "decrementTrigger" | "scrubber", _zag_js_anatomy.AnatomyPart>;
5
+
6
+ export { anatomy, parts };
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/number-input.anatomy.ts
21
+ var number_input_anatomy_exports = {};
22
+ __export(number_input_anatomy_exports, {
23
+ anatomy: () => anatomy,
24
+ parts: () => parts
25
+ });
26
+ module.exports = __toCommonJS(number_input_anatomy_exports);
27
+ var import_anatomy = require("@zag-js/anatomy");
28
+ var anatomy = (0, import_anatomy.createAnatomy)("numberInput").parts(
29
+ "root",
30
+ "label",
31
+ "input",
32
+ "control",
33
+ "valueText",
34
+ "incrementTrigger",
35
+ "decrementTrigger",
36
+ "scrubber"
37
+ );
38
+ var parts = anatomy.build();
39
+ // Annotate the CommonJS export names for ESM import in node:
40
+ 0 && (module.exports = {
41
+ anatomy,
42
+ parts
43
+ });
@@ -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
+ "valueText",
9
+ "incrementTrigger",
10
+ "decrementTrigger",
11
+ "scrubber"
12
+ );
13
+ var parts = anatomy.build();
14
+ export {
15
+ anatomy,
16
+ parts
17
+ };
@@ -0,0 +1,8 @@
1
+ import { PropTypes, NormalizeProps } from '@zag-js/types';
2
+ import { NumberInputService, NumberInputApi } from './number-input.types.mjs';
3
+ import '@internationalized/number';
4
+ import '@zag-js/core';
5
+
6
+ declare function connect<T extends PropTypes>(service: NumberInputService, normalize: NormalizeProps<T>): NumberInputApi<T>;
7
+
8
+ export { connect };
@@ -0,0 +1,8 @@
1
+ import { PropTypes, NormalizeProps } from '@zag-js/types';
2
+ import { NumberInputService, NumberInputApi } from './number-input.types.js';
3
+ import '@internationalized/number';
4
+ import '@zag-js/core';
5
+
6
+ declare function connect<T extends PropTypes>(service: NumberInputService, normalize: NormalizeProps<T>): NumberInputApi<T>;
7
+
8
+ export { connect };
@@ -0,0 +1,308 @@
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
34
+ });
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.cjs");
39
+ var import_number_input = require("./number-input.anatomy.cjs");
40
+ var dom = __toESM(require("./number-input.dom.cjs"));
41
+ function connect(service, normalize) {
42
+ const { state, send, prop, scope, computed } = service;
43
+ const focused = state.hasTag("focus");
44
+ const disabled = computed("isDisabled");
45
+ const readOnly = !!prop("readOnly");
46
+ const required = !!prop("required");
47
+ const scrubbing = state.matches("scrubbing");
48
+ const empty = computed("isValueEmpty");
49
+ const invalid = prop("invalid") !== void 0 ? !!prop("invalid") : computed("isOutOfRange");
50
+ const isIncrementDisabled = disabled || !computed("canIncrement") || readOnly;
51
+ const isDecrementDisabled = disabled || !computed("canDecrement") || readOnly;
52
+ const translations = prop("translations");
53
+ return {
54
+ focused,
55
+ invalid,
56
+ empty,
57
+ value: computed("formattedValue"),
58
+ valueAsNumber: computed("valueAsNumber"),
59
+ setValue(value) {
60
+ send({ type: "VALUE.SET", value });
61
+ },
62
+ clearValue() {
63
+ send({ type: "VALUE.CLEAR" });
64
+ },
65
+ increment() {
66
+ send({ type: "VALUE.INCREMENT" });
67
+ },
68
+ decrement() {
69
+ send({ type: "VALUE.DECREMENT" });
70
+ },
71
+ setToMax() {
72
+ send({ type: "VALUE.SET", value: prop("max") });
73
+ },
74
+ setToMin() {
75
+ send({ type: "VALUE.SET", value: prop("min") });
76
+ },
77
+ focus() {
78
+ dom.getInputEl(scope)?.focus();
79
+ },
80
+ getRootProps() {
81
+ return normalize.element({
82
+ id: dom.getRootId(scope),
83
+ ...import_number_input.parts.root.attrs,
84
+ dir: prop("dir"),
85
+ "data-disabled": (0, import_dom_query.dataAttr)(disabled),
86
+ "data-focus": (0, import_dom_query.dataAttr)(focused),
87
+ "data-invalid": (0, import_dom_query.dataAttr)(invalid),
88
+ "data-scrubbing": (0, import_dom_query.dataAttr)(scrubbing)
89
+ });
90
+ },
91
+ getLabelProps() {
92
+ return normalize.label({
93
+ ...import_number_input.parts.label.attrs,
94
+ dir: prop("dir"),
95
+ "data-disabled": (0, import_dom_query.dataAttr)(disabled),
96
+ "data-focus": (0, import_dom_query.dataAttr)(focused),
97
+ "data-invalid": (0, import_dom_query.dataAttr)(invalid),
98
+ "data-required": (0, import_dom_query.dataAttr)(required),
99
+ "data-scrubbing": (0, import_dom_query.dataAttr)(scrubbing),
100
+ id: dom.getLabelId(scope),
101
+ htmlFor: dom.getInputId(scope),
102
+ onClick() {
103
+ (0, import_dom_query.raf)(() => {
104
+ (0, import_dom_query.setCaretToEnd)(dom.getInputEl(scope));
105
+ });
106
+ }
107
+ });
108
+ },
109
+ getControlProps() {
110
+ return normalize.element({
111
+ ...import_number_input.parts.control.attrs,
112
+ dir: prop("dir"),
113
+ role: "group",
114
+ "aria-disabled": disabled,
115
+ "data-focus": (0, import_dom_query.dataAttr)(focused),
116
+ "data-disabled": (0, import_dom_query.dataAttr)(disabled),
117
+ "data-invalid": (0, import_dom_query.dataAttr)(invalid),
118
+ "data-scrubbing": (0, import_dom_query.dataAttr)(scrubbing),
119
+ "aria-invalid": (0, import_dom_query.ariaAttr)(invalid)
120
+ });
121
+ },
122
+ getValueTextProps() {
123
+ return normalize.element({
124
+ ...import_number_input.parts.valueText.attrs,
125
+ dir: prop("dir"),
126
+ "data-disabled": (0, import_dom_query.dataAttr)(disabled),
127
+ "data-invalid": (0, import_dom_query.dataAttr)(invalid),
128
+ "data-focus": (0, import_dom_query.dataAttr)(focused),
129
+ "data-scrubbing": (0, import_dom_query.dataAttr)(scrubbing)
130
+ });
131
+ },
132
+ getInputProps() {
133
+ return normalize.input({
134
+ ...import_number_input.parts.input.attrs,
135
+ dir: prop("dir"),
136
+ name: prop("name"),
137
+ form: prop("form"),
138
+ id: dom.getInputId(scope),
139
+ role: "spinbutton",
140
+ defaultValue: computed("formattedValue"),
141
+ pattern: prop("formatOptions") ? void 0 : prop("pattern"),
142
+ inputMode: prop("inputMode"),
143
+ "aria-invalid": (0, import_dom_query.ariaAttr)(invalid),
144
+ "data-invalid": (0, import_dom_query.dataAttr)(invalid),
145
+ disabled,
146
+ "data-disabled": (0, import_dom_query.dataAttr)(disabled),
147
+ readOnly,
148
+ required: prop("required"),
149
+ autoComplete: "off",
150
+ autoCorrect: "off",
151
+ spellCheck: "false",
152
+ type: "text",
153
+ "aria-roledescription": "numberfield",
154
+ "aria-valuemin": prop("min"),
155
+ "aria-valuemax": prop("max"),
156
+ "aria-valuenow": Number.isNaN(computed("valueAsNumber")) ? void 0 : computed("valueAsNumber"),
157
+ "aria-valuetext": computed("valueText"),
158
+ "data-scrubbing": (0, import_dom_query.dataAttr)(scrubbing),
159
+ onFocus() {
160
+ send({ type: "INPUT.FOCUS" });
161
+ },
162
+ onBlur() {
163
+ send({ type: "INPUT.BLUR" });
164
+ },
165
+ onInput(event) {
166
+ const selection = (0, import_cursor.recordCursor)(event.currentTarget, scope);
167
+ send({ type: "INPUT.CHANGE", target: event.currentTarget, hint: "set", selection });
168
+ },
169
+ onBeforeInput(event) {
170
+ try {
171
+ const { selectionStart, selectionEnd, value } = event.currentTarget;
172
+ const nextValue = value.slice(0, selectionStart) + (event.data ?? "") + value.slice(selectionEnd);
173
+ const isValid = computed("parser").isValidPartialNumber(nextValue);
174
+ if (!isValid) {
175
+ event.preventDefault();
176
+ }
177
+ } catch {
178
+ }
179
+ },
180
+ onKeyDown(event) {
181
+ if (event.defaultPrevented) return;
182
+ if (readOnly) return;
183
+ if ((0, import_dom_query.isComposingEvent)(event)) return;
184
+ const step = (0, import_dom_query.getEventStep)(event) * prop("step");
185
+ const keyMap = {
186
+ ArrowUp() {
187
+ send({ type: "INPUT.ARROW_UP", step });
188
+ event.preventDefault();
189
+ },
190
+ ArrowDown() {
191
+ send({ type: "INPUT.ARROW_DOWN", step });
192
+ event.preventDefault();
193
+ },
194
+ Home() {
195
+ if ((0, import_dom_query.isModifierKey)(event)) return;
196
+ send({ type: "INPUT.HOME" });
197
+ event.preventDefault();
198
+ },
199
+ End() {
200
+ if ((0, import_dom_query.isModifierKey)(event)) return;
201
+ send({ type: "INPUT.END" });
202
+ event.preventDefault();
203
+ },
204
+ Enter(event2) {
205
+ const selection = (0, import_cursor.recordCursor)(event2.currentTarget, scope);
206
+ send({ type: "INPUT.ENTER", selection });
207
+ }
208
+ };
209
+ const exec = keyMap[event.key];
210
+ exec?.(event);
211
+ }
212
+ });
213
+ },
214
+ getDecrementTriggerProps() {
215
+ return normalize.button({
216
+ ...import_number_input.parts.decrementTrigger.attrs,
217
+ dir: prop("dir"),
218
+ id: dom.getDecrementTriggerId(scope),
219
+ disabled: isDecrementDisabled,
220
+ "data-disabled": (0, import_dom_query.dataAttr)(isDecrementDisabled),
221
+ "aria-label": translations.decrementLabel,
222
+ type: "button",
223
+ tabIndex: -1,
224
+ "aria-controls": dom.getInputId(scope),
225
+ "data-scrubbing": (0, import_dom_query.dataAttr)(scrubbing),
226
+ onPointerDown(event) {
227
+ if (isDecrementDisabled) return;
228
+ if (!(0, import_dom_query.isLeftClick)(event)) return;
229
+ send({ type: "TRIGGER.PRESS_DOWN", hint: "decrement", pointerType: event.pointerType });
230
+ if (event.pointerType === "mouse") {
231
+ event.preventDefault();
232
+ }
233
+ if (event.pointerType === "touch") {
234
+ event.currentTarget?.focus({ preventScroll: true });
235
+ }
236
+ },
237
+ onPointerUp(event) {
238
+ send({ type: "TRIGGER.PRESS_UP", hint: "decrement", pointerType: event.pointerType });
239
+ },
240
+ onPointerLeave() {
241
+ if (isDecrementDisabled) return;
242
+ send({ type: "TRIGGER.PRESS_UP", hint: "decrement" });
243
+ }
244
+ });
245
+ },
246
+ getIncrementTriggerProps() {
247
+ return normalize.button({
248
+ ...import_number_input.parts.incrementTrigger.attrs,
249
+ dir: prop("dir"),
250
+ id: dom.getIncrementTriggerId(scope),
251
+ disabled: isIncrementDisabled,
252
+ "data-disabled": (0, import_dom_query.dataAttr)(isIncrementDisabled),
253
+ "aria-label": translations.incrementLabel,
254
+ type: "button",
255
+ tabIndex: -1,
256
+ "aria-controls": dom.getInputId(scope),
257
+ "data-scrubbing": (0, import_dom_query.dataAttr)(scrubbing),
258
+ onPointerDown(event) {
259
+ if (isIncrementDisabled || !(0, import_dom_query.isLeftClick)(event)) return;
260
+ send({ type: "TRIGGER.PRESS_DOWN", hint: "increment", pointerType: event.pointerType });
261
+ if (event.pointerType === "mouse") {
262
+ event.preventDefault();
263
+ }
264
+ if (event.pointerType === "touch") {
265
+ event.currentTarget?.focus({ preventScroll: true });
266
+ }
267
+ },
268
+ onPointerUp(event) {
269
+ send({ type: "TRIGGER.PRESS_UP", hint: "increment", pointerType: event.pointerType });
270
+ },
271
+ onPointerLeave(event) {
272
+ send({ type: "TRIGGER.PRESS_UP", hint: "increment", pointerType: event.pointerType });
273
+ }
274
+ });
275
+ },
276
+ getScrubberProps() {
277
+ return normalize.element({
278
+ ...import_number_input.parts.scrubber.attrs,
279
+ dir: prop("dir"),
280
+ "data-disabled": (0, import_dom_query.dataAttr)(disabled),
281
+ id: dom.getScrubberId(scope),
282
+ role: "presentation",
283
+ "data-scrubbing": (0, import_dom_query.dataAttr)(scrubbing),
284
+ onMouseDown(event) {
285
+ if (disabled) return;
286
+ if (!(0, import_dom_query.isLeftClick)(event)) return;
287
+ const point = (0, import_dom_query.getEventPoint)(event);
288
+ const win = (0, import_dom_query.getWindow)(event.currentTarget);
289
+ const dpr = win.devicePixelRatio;
290
+ point.x = point.x - (0, import_utils.roundToDpr)(7.5, dpr);
291
+ point.y = point.y - (0, import_utils.roundToDpr)(7.5, dpr);
292
+ send({ type: "SCRUBBER.PRESS_DOWN", point });
293
+ event.preventDefault();
294
+ (0, import_dom_query.raf)(() => {
295
+ (0, import_dom_query.setCaretToEnd)(dom.getInputEl(scope));
296
+ });
297
+ },
298
+ style: {
299
+ cursor: disabled ? void 0 : "ew-resize"
300
+ }
301
+ });
302
+ }
303
+ };
304
+ }
305
+ // Annotate the CommonJS export names for ESM import in node:
306
+ 0 && (module.exports = {
307
+ connect
308
+ });
@@ -0,0 +1,284 @@
1
+ // src/number-input.connect.ts
2
+ import {
3
+ ariaAttr,
4
+ dataAttr,
5
+ getEventPoint,
6
+ getEventStep,
7
+ getWindow,
8
+ isComposingEvent,
9
+ isLeftClick,
10
+ isModifierKey,
11
+ raf,
12
+ setCaretToEnd
13
+ } from "@zag-js/dom-query";
14
+ import { roundToDpr } from "@zag-js/utils";
15
+ import { recordCursor } from "./cursor.mjs";
16
+ import { parts } from "./number-input.anatomy.mjs";
17
+ import * as dom from "./number-input.dom.mjs";
18
+ function connect(service, normalize) {
19
+ const { state, send, prop, scope, computed } = service;
20
+ const focused = state.hasTag("focus");
21
+ const disabled = computed("isDisabled");
22
+ const readOnly = !!prop("readOnly");
23
+ const required = !!prop("required");
24
+ const scrubbing = state.matches("scrubbing");
25
+ const empty = computed("isValueEmpty");
26
+ const invalid = prop("invalid") !== void 0 ? !!prop("invalid") : computed("isOutOfRange");
27
+ const isIncrementDisabled = disabled || !computed("canIncrement") || readOnly;
28
+ const isDecrementDisabled = disabled || !computed("canDecrement") || readOnly;
29
+ const translations = prop("translations");
30
+ return {
31
+ focused,
32
+ invalid,
33
+ empty,
34
+ value: computed("formattedValue"),
35
+ valueAsNumber: computed("valueAsNumber"),
36
+ setValue(value) {
37
+ send({ type: "VALUE.SET", value });
38
+ },
39
+ clearValue() {
40
+ send({ type: "VALUE.CLEAR" });
41
+ },
42
+ increment() {
43
+ send({ type: "VALUE.INCREMENT" });
44
+ },
45
+ decrement() {
46
+ send({ type: "VALUE.DECREMENT" });
47
+ },
48
+ setToMax() {
49
+ send({ type: "VALUE.SET", value: prop("max") });
50
+ },
51
+ setToMin() {
52
+ send({ type: "VALUE.SET", value: prop("min") });
53
+ },
54
+ focus() {
55
+ dom.getInputEl(scope)?.focus();
56
+ },
57
+ getRootProps() {
58
+ return normalize.element({
59
+ id: dom.getRootId(scope),
60
+ ...parts.root.attrs,
61
+ dir: prop("dir"),
62
+ "data-disabled": dataAttr(disabled),
63
+ "data-focus": dataAttr(focused),
64
+ "data-invalid": dataAttr(invalid),
65
+ "data-scrubbing": dataAttr(scrubbing)
66
+ });
67
+ },
68
+ getLabelProps() {
69
+ return normalize.label({
70
+ ...parts.label.attrs,
71
+ dir: prop("dir"),
72
+ "data-disabled": dataAttr(disabled),
73
+ "data-focus": dataAttr(focused),
74
+ "data-invalid": dataAttr(invalid),
75
+ "data-required": dataAttr(required),
76
+ "data-scrubbing": dataAttr(scrubbing),
77
+ id: dom.getLabelId(scope),
78
+ htmlFor: dom.getInputId(scope),
79
+ onClick() {
80
+ raf(() => {
81
+ setCaretToEnd(dom.getInputEl(scope));
82
+ });
83
+ }
84
+ });
85
+ },
86
+ getControlProps() {
87
+ return normalize.element({
88
+ ...parts.control.attrs,
89
+ dir: prop("dir"),
90
+ role: "group",
91
+ "aria-disabled": disabled,
92
+ "data-focus": dataAttr(focused),
93
+ "data-disabled": dataAttr(disabled),
94
+ "data-invalid": dataAttr(invalid),
95
+ "data-scrubbing": dataAttr(scrubbing),
96
+ "aria-invalid": ariaAttr(invalid)
97
+ });
98
+ },
99
+ getValueTextProps() {
100
+ return normalize.element({
101
+ ...parts.valueText.attrs,
102
+ dir: prop("dir"),
103
+ "data-disabled": dataAttr(disabled),
104
+ "data-invalid": dataAttr(invalid),
105
+ "data-focus": dataAttr(focused),
106
+ "data-scrubbing": dataAttr(scrubbing)
107
+ });
108
+ },
109
+ getInputProps() {
110
+ return normalize.input({
111
+ ...parts.input.attrs,
112
+ dir: prop("dir"),
113
+ name: prop("name"),
114
+ form: prop("form"),
115
+ id: dom.getInputId(scope),
116
+ role: "spinbutton",
117
+ defaultValue: computed("formattedValue"),
118
+ pattern: prop("formatOptions") ? void 0 : prop("pattern"),
119
+ inputMode: prop("inputMode"),
120
+ "aria-invalid": ariaAttr(invalid),
121
+ "data-invalid": dataAttr(invalid),
122
+ disabled,
123
+ "data-disabled": dataAttr(disabled),
124
+ readOnly,
125
+ required: prop("required"),
126
+ autoComplete: "off",
127
+ autoCorrect: "off",
128
+ spellCheck: "false",
129
+ type: "text",
130
+ "aria-roledescription": "numberfield",
131
+ "aria-valuemin": prop("min"),
132
+ "aria-valuemax": prop("max"),
133
+ "aria-valuenow": Number.isNaN(computed("valueAsNumber")) ? void 0 : computed("valueAsNumber"),
134
+ "aria-valuetext": computed("valueText"),
135
+ "data-scrubbing": dataAttr(scrubbing),
136
+ onFocus() {
137
+ send({ type: "INPUT.FOCUS" });
138
+ },
139
+ onBlur() {
140
+ send({ type: "INPUT.BLUR" });
141
+ },
142
+ onInput(event) {
143
+ const selection = recordCursor(event.currentTarget, scope);
144
+ send({ type: "INPUT.CHANGE", target: event.currentTarget, hint: "set", selection });
145
+ },
146
+ onBeforeInput(event) {
147
+ try {
148
+ const { selectionStart, selectionEnd, value } = event.currentTarget;
149
+ const nextValue = value.slice(0, selectionStart) + (event.data ?? "") + value.slice(selectionEnd);
150
+ const isValid = computed("parser").isValidPartialNumber(nextValue);
151
+ if (!isValid) {
152
+ event.preventDefault();
153
+ }
154
+ } catch {
155
+ }
156
+ },
157
+ onKeyDown(event) {
158
+ if (event.defaultPrevented) return;
159
+ if (readOnly) return;
160
+ if (isComposingEvent(event)) return;
161
+ const step = getEventStep(event) * prop("step");
162
+ const keyMap = {
163
+ ArrowUp() {
164
+ send({ type: "INPUT.ARROW_UP", step });
165
+ event.preventDefault();
166
+ },
167
+ ArrowDown() {
168
+ send({ type: "INPUT.ARROW_DOWN", step });
169
+ event.preventDefault();
170
+ },
171
+ Home() {
172
+ if (isModifierKey(event)) return;
173
+ send({ type: "INPUT.HOME" });
174
+ event.preventDefault();
175
+ },
176
+ End() {
177
+ if (isModifierKey(event)) return;
178
+ send({ type: "INPUT.END" });
179
+ event.preventDefault();
180
+ },
181
+ Enter(event2) {
182
+ const selection = recordCursor(event2.currentTarget, scope);
183
+ send({ type: "INPUT.ENTER", selection });
184
+ }
185
+ };
186
+ const exec = keyMap[event.key];
187
+ exec?.(event);
188
+ }
189
+ });
190
+ },
191
+ getDecrementTriggerProps() {
192
+ return normalize.button({
193
+ ...parts.decrementTrigger.attrs,
194
+ dir: prop("dir"),
195
+ id: dom.getDecrementTriggerId(scope),
196
+ disabled: isDecrementDisabled,
197
+ "data-disabled": dataAttr(isDecrementDisabled),
198
+ "aria-label": translations.decrementLabel,
199
+ type: "button",
200
+ tabIndex: -1,
201
+ "aria-controls": dom.getInputId(scope),
202
+ "data-scrubbing": dataAttr(scrubbing),
203
+ onPointerDown(event) {
204
+ if (isDecrementDisabled) return;
205
+ if (!isLeftClick(event)) return;
206
+ send({ type: "TRIGGER.PRESS_DOWN", hint: "decrement", pointerType: event.pointerType });
207
+ if (event.pointerType === "mouse") {
208
+ event.preventDefault();
209
+ }
210
+ if (event.pointerType === "touch") {
211
+ event.currentTarget?.focus({ preventScroll: true });
212
+ }
213
+ },
214
+ onPointerUp(event) {
215
+ send({ type: "TRIGGER.PRESS_UP", hint: "decrement", pointerType: event.pointerType });
216
+ },
217
+ onPointerLeave() {
218
+ if (isDecrementDisabled) return;
219
+ send({ type: "TRIGGER.PRESS_UP", hint: "decrement" });
220
+ }
221
+ });
222
+ },
223
+ getIncrementTriggerProps() {
224
+ return normalize.button({
225
+ ...parts.incrementTrigger.attrs,
226
+ dir: prop("dir"),
227
+ id: dom.getIncrementTriggerId(scope),
228
+ disabled: isIncrementDisabled,
229
+ "data-disabled": dataAttr(isIncrementDisabled),
230
+ "aria-label": translations.incrementLabel,
231
+ type: "button",
232
+ tabIndex: -1,
233
+ "aria-controls": dom.getInputId(scope),
234
+ "data-scrubbing": dataAttr(scrubbing),
235
+ onPointerDown(event) {
236
+ if (isIncrementDisabled || !isLeftClick(event)) return;
237
+ send({ type: "TRIGGER.PRESS_DOWN", hint: "increment", pointerType: event.pointerType });
238
+ if (event.pointerType === "mouse") {
239
+ event.preventDefault();
240
+ }
241
+ if (event.pointerType === "touch") {
242
+ event.currentTarget?.focus({ preventScroll: true });
243
+ }
244
+ },
245
+ onPointerUp(event) {
246
+ send({ type: "TRIGGER.PRESS_UP", hint: "increment", pointerType: event.pointerType });
247
+ },
248
+ onPointerLeave(event) {
249
+ send({ type: "TRIGGER.PRESS_UP", hint: "increment", pointerType: event.pointerType });
250
+ }
251
+ });
252
+ },
253
+ getScrubberProps() {
254
+ return normalize.element({
255
+ ...parts.scrubber.attrs,
256
+ dir: prop("dir"),
257
+ "data-disabled": dataAttr(disabled),
258
+ id: dom.getScrubberId(scope),
259
+ role: "presentation",
260
+ "data-scrubbing": dataAttr(scrubbing),
261
+ onMouseDown(event) {
262
+ if (disabled) return;
263
+ if (!isLeftClick(event)) return;
264
+ const point = getEventPoint(event);
265
+ const win = getWindow(event.currentTarget);
266
+ const dpr = win.devicePixelRatio;
267
+ point.x = point.x - roundToDpr(7.5, dpr);
268
+ point.y = point.y - roundToDpr(7.5, dpr);
269
+ send({ type: "SCRUBBER.PRESS_DOWN", point });
270
+ event.preventDefault();
271
+ raf(() => {
272
+ setCaretToEnd(dom.getInputEl(scope));
273
+ });
274
+ },
275
+ style: {
276
+ cursor: disabled ? void 0 : "ew-resize"
277
+ }
278
+ });
279
+ }
280
+ };
281
+ }
282
+ export {
283
+ connect
284
+ };