@zag-js/number-input 0.50.0 → 0.51.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.
- package/dist/index.js +2 -859
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -830
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -1,865 +1,8 @@
|
|
|
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/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
anatomy: () => anatomy,
|
|
24
|
-
connect: () => connect,
|
|
25
|
-
machine: () => machine
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(src_exports);
|
|
28
|
-
|
|
29
|
-
// src/number-input.anatomy.ts
|
|
30
|
-
var import_anatomy = require("@zag-js/anatomy");
|
|
31
|
-
var anatomy = (0, import_anatomy.createAnatomy)("numberInput").parts(
|
|
32
|
-
"root",
|
|
33
|
-
"label",
|
|
34
|
-
"input",
|
|
35
|
-
"control",
|
|
36
|
-
"incrementTrigger",
|
|
37
|
-
"decrementTrigger",
|
|
38
|
-
"scrubber"
|
|
39
|
-
);
|
|
40
|
-
var parts = anatomy.build();
|
|
41
|
-
|
|
42
|
-
// src/number-input.connect.ts
|
|
43
|
-
var import_dom_event = require("@zag-js/dom-event");
|
|
44
|
-
var import_dom_query2 = require("@zag-js/dom-query");
|
|
45
|
-
var import_number_utils2 = require("@zag-js/number-utils");
|
|
46
|
-
|
|
47
|
-
// src/number-input.dom.ts
|
|
48
|
-
var import_dom_query = require("@zag-js/dom-query");
|
|
49
|
-
var import_number_utils = require("@zag-js/number-utils");
|
|
50
|
-
var dom = (0, import_dom_query.createScope)({
|
|
51
|
-
getRootId: (ctx) => ctx.ids?.root ?? `number-input:${ctx.id}`,
|
|
52
|
-
getInputId: (ctx) => ctx.ids?.input ?? `number-input:${ctx.id}:input`,
|
|
53
|
-
getIncrementTriggerId: (ctx) => ctx.ids?.incrementTrigger ?? `number-input:${ctx.id}:inc`,
|
|
54
|
-
getDecrementTriggerId: (ctx) => ctx.ids?.decrementTrigger ?? `number-input:${ctx.id}:dec`,
|
|
55
|
-
getScrubberId: (ctx) => ctx.ids?.scrubber ?? `number-input:${ctx.id}:scrubber`,
|
|
56
|
-
getCursorId: (ctx) => `number-input:${ctx.id}:cursor`,
|
|
57
|
-
getLabelId: (ctx) => ctx.ids?.label ?? `number-input:${ctx.id}:label`,
|
|
58
|
-
getInputEl: (ctx) => dom.getById(ctx, dom.getInputId(ctx)),
|
|
59
|
-
getIncrementTriggerEl: (ctx) => dom.getById(ctx, dom.getIncrementTriggerId(ctx)),
|
|
60
|
-
getDecrementTriggerEl: (ctx) => dom.getById(ctx, dom.getDecrementTriggerId(ctx)),
|
|
61
|
-
getScrubberEl: (ctx) => dom.getById(ctx, dom.getScrubberId(ctx)),
|
|
62
|
-
getCursorEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getCursorId(ctx)),
|
|
63
|
-
getPressedTriggerEl: (ctx, hint = ctx.hint) => {
|
|
64
|
-
let btnEl = null;
|
|
65
|
-
if (hint === "increment") {
|
|
66
|
-
btnEl = dom.getIncrementTriggerEl(ctx);
|
|
67
|
-
}
|
|
68
|
-
if (hint === "decrement") {
|
|
69
|
-
btnEl = dom.getDecrementTriggerEl(ctx);
|
|
70
|
-
}
|
|
71
|
-
return btnEl;
|
|
72
|
-
},
|
|
73
|
-
setupVirtualCursor(ctx) {
|
|
74
|
-
if ((0, import_dom_query.isSafari)())
|
|
75
|
-
return;
|
|
76
|
-
dom.createVirtualCursor(ctx);
|
|
77
|
-
return () => {
|
|
78
|
-
dom.getCursorEl(ctx)?.remove();
|
|
79
|
-
};
|
|
80
|
-
},
|
|
81
|
-
preventTextSelection(ctx) {
|
|
82
|
-
const doc = dom.getDoc(ctx);
|
|
83
|
-
const html = doc.documentElement;
|
|
84
|
-
const body = doc.body;
|
|
85
|
-
body.style.pointerEvents = "none";
|
|
86
|
-
html.style.userSelect = "none";
|
|
87
|
-
html.style.cursor = "ew-resize";
|
|
88
|
-
return () => {
|
|
89
|
-
body.style.pointerEvents = "";
|
|
90
|
-
html.style.userSelect = "";
|
|
91
|
-
html.style.cursor = "";
|
|
92
|
-
if (!html.style.length) {
|
|
93
|
-
html.removeAttribute("style");
|
|
94
|
-
}
|
|
95
|
-
if (!body.style.length) {
|
|
96
|
-
body.removeAttribute("style");
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
},
|
|
100
|
-
getMousementValue(ctx, event) {
|
|
101
|
-
const x = (0, import_number_utils.roundToDevicePixel)(event.movementX);
|
|
102
|
-
const y = (0, import_number_utils.roundToDevicePixel)(event.movementY);
|
|
103
|
-
let hint = x > 0 ? "increment" : x < 0 ? "decrement" : null;
|
|
104
|
-
if (ctx.isRtl && hint === "increment")
|
|
105
|
-
hint = "decrement";
|
|
106
|
-
if (ctx.isRtl && hint === "decrement")
|
|
107
|
-
hint = "increment";
|
|
108
|
-
const point = {
|
|
109
|
-
x: ctx.scrubberCursorPoint.x + x,
|
|
110
|
-
y: ctx.scrubberCursorPoint.y + y
|
|
111
|
-
};
|
|
112
|
-
const win = dom.getWin(ctx);
|
|
113
|
-
const width = win.innerWidth;
|
|
114
|
-
const half = (0, import_number_utils.roundToDevicePixel)(7.5);
|
|
115
|
-
point.x = (0, import_number_utils.wrap)(point.x + half, width) - half;
|
|
116
|
-
return { hint, point };
|
|
117
|
-
},
|
|
118
|
-
createVirtualCursor(ctx) {
|
|
119
|
-
const doc = dom.getDoc(ctx);
|
|
120
|
-
const el = doc.createElement("div");
|
|
121
|
-
el.className = "scrubber--cursor";
|
|
122
|
-
el.id = dom.getCursorId(ctx);
|
|
123
|
-
Object.assign(el.style, {
|
|
124
|
-
width: "15px",
|
|
125
|
-
height: "15px",
|
|
126
|
-
position: "fixed",
|
|
127
|
-
pointerEvents: "none",
|
|
128
|
-
left: "0px",
|
|
129
|
-
top: "0px",
|
|
130
|
-
zIndex: import_dom_query.MAX_Z_INDEX,
|
|
131
|
-
transform: ctx.scrubberCursorPoint ? `translate3d(${ctx.scrubberCursorPoint.x}px, ${ctx.scrubberCursorPoint.y}px, 0px)` : void 0,
|
|
132
|
-
willChange: "transform"
|
|
133
|
-
});
|
|
134
|
-
el.innerHTML = `
|
|
1
|
+
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var src_exports={};__export(src_exports,{anatomy:()=>anatomy,connect:()=>connect,machine:()=>machine});module.exports=__toCommonJS(src_exports);var import_anatomy=require("@zag-js/anatomy");var anatomy=(0,import_anatomy.createAnatomy)("numberInput").parts("root","label","input","control","incrementTrigger","decrementTrigger","scrubber");var parts=anatomy.build();var import_dom_event=require("@zag-js/dom-event");var import_dom_query2=require("@zag-js/dom-query");var import_number_utils2=require("@zag-js/number-utils");var import_dom_query=require("@zag-js/dom-query");var import_number_utils=require("@zag-js/number-utils");var dom=(0,import_dom_query.createScope)({getRootId:ctx=>ctx.ids?.root??`number-input:${ctx.id}`,getInputId:ctx=>ctx.ids?.input??`number-input:${ctx.id}:input`,getIncrementTriggerId:ctx=>ctx.ids?.incrementTrigger??`number-input:${ctx.id}:inc`,getDecrementTriggerId:ctx=>ctx.ids?.decrementTrigger??`number-input:${ctx.id}:dec`,getScrubberId:ctx=>ctx.ids?.scrubber??`number-input:${ctx.id}:scrubber`,getCursorId:ctx=>`number-input:${ctx.id}:cursor`,getLabelId:ctx=>ctx.ids?.label??`number-input:${ctx.id}:label`,getInputEl:ctx=>dom.getById(ctx,dom.getInputId(ctx)),getIncrementTriggerEl:ctx=>dom.getById(ctx,dom.getIncrementTriggerId(ctx)),getDecrementTriggerEl:ctx=>dom.getById(ctx,dom.getDecrementTriggerId(ctx)),getScrubberEl:ctx=>dom.getById(ctx,dom.getScrubberId(ctx)),getCursorEl:ctx=>dom.getDoc(ctx).getElementById(dom.getCursorId(ctx)),getPressedTriggerEl:(ctx,hint=ctx.hint)=>{let btnEl=null;if(hint==="increment"){btnEl=dom.getIncrementTriggerEl(ctx)}if(hint==="decrement"){btnEl=dom.getDecrementTriggerEl(ctx)}return btnEl},setupVirtualCursor(ctx){if((0,import_dom_query.isSafari)())return;dom.createVirtualCursor(ctx);return()=>{dom.getCursorEl(ctx)?.remove()}},preventTextSelection(ctx){const doc=dom.getDoc(ctx);const html=doc.documentElement;const body=doc.body;body.style.pointerEvents="none";html.style.userSelect="none";html.style.cursor="ew-resize";return()=>{body.style.pointerEvents="";html.style.userSelect="";html.style.cursor="";if(!html.style.length){html.removeAttribute("style")}if(!body.style.length){body.removeAttribute("style")}}},getMousementValue(ctx,event){const x=(0,import_number_utils.roundToDevicePixel)(event.movementX);const y=(0,import_number_utils.roundToDevicePixel)(event.movementY);let hint=x>0?"increment":x<0?"decrement":null;if(ctx.isRtl&&hint==="increment")hint="decrement";if(ctx.isRtl&&hint==="decrement")hint="increment";const point={x:ctx.scrubberCursorPoint.x+x,y:ctx.scrubberCursorPoint.y+y};const win=dom.getWin(ctx);const width=win.innerWidth;const half=(0,import_number_utils.roundToDevicePixel)(7.5);point.x=(0,import_number_utils.wrap)(point.x+half,width)-half;return{hint,point}},createVirtualCursor(ctx){const doc=dom.getDoc(ctx);const el=doc.createElement("div");el.className="scrubber--cursor";el.id=dom.getCursorId(ctx);Object.assign(el.style,{width:"15px",height:"15px",position:"fixed",pointerEvents:"none",left:"0px",top:"0px",zIndex:import_dom_query.MAX_Z_INDEX,transform:ctx.scrubberCursorPoint?`translate3d(${ctx.scrubberCursorPoint.x}px, ${ctx.scrubberCursorPoint.y}px, 0px)`:void 0,willChange:"transform"});el.innerHTML=`
|
|
135
2
|
<svg width="46" height="15" style="left: -15.5px; position: absolute; top: 0; filter: drop-shadow(rgba(0, 0, 0, 0.4) 0px 1px 1.1px);">
|
|
136
3
|
<g transform="translate(2 3)">
|
|
137
4
|
<path fill-rule="evenodd" d="M 15 4.5L 15 2L 11.5 5.5L 15 9L 15 6.5L 31 6.5L 31 9L 34.5 5.5L 31 2L 31 4.5Z" style="stroke-width: 2px; stroke: white;"></path>
|
|
138
5
|
<path fill-rule="evenodd" d="M 15 4.5L 15 2L 11.5 5.5L 15 9L 15 6.5L 31 6.5L 31 9L 34.5 5.5L 31 2L 31 4.5Z"></path>
|
|
139
6
|
</g>
|
|
140
|
-
</svg>`;
|
|
141
|
-
doc.body.appendChild(el);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
// src/number-input.connect.ts
|
|
146
|
-
function connect(state, send, normalize) {
|
|
147
|
-
const focused = state.hasTag("focus");
|
|
148
|
-
const disabled = state.context.isDisabled;
|
|
149
|
-
const readOnly = state.context.readOnly;
|
|
150
|
-
const empty = state.context.isValueEmpty;
|
|
151
|
-
const invalid = state.context.isOutOfRange || !!state.context.invalid;
|
|
152
|
-
const isIncrementDisabled = disabled || !state.context.canIncrement || readOnly;
|
|
153
|
-
const isDecrementDisabled = disabled || !state.context.canDecrement || readOnly;
|
|
154
|
-
const translations = state.context.translations;
|
|
155
|
-
return {
|
|
156
|
-
focused,
|
|
157
|
-
invalid,
|
|
158
|
-
empty,
|
|
159
|
-
value: state.context.formattedValue,
|
|
160
|
-
valueAsNumber: state.context.valueAsNumber,
|
|
161
|
-
setValue(value) {
|
|
162
|
-
send({ type: "VALUE.SET", value });
|
|
163
|
-
},
|
|
164
|
-
clearValue() {
|
|
165
|
-
send("VALUE.CLEAR");
|
|
166
|
-
},
|
|
167
|
-
increment() {
|
|
168
|
-
send("VALUE.INCREMENT");
|
|
169
|
-
},
|
|
170
|
-
decrement() {
|
|
171
|
-
send("VALUE.DECREMENT");
|
|
172
|
-
},
|
|
173
|
-
setToMax() {
|
|
174
|
-
send({ type: "VALUE.SET", value: state.context.max });
|
|
175
|
-
},
|
|
176
|
-
setToMin() {
|
|
177
|
-
send({ type: "VALUE.SET", value: state.context.min });
|
|
178
|
-
},
|
|
179
|
-
focus() {
|
|
180
|
-
dom.getInputEl(state.context)?.focus();
|
|
181
|
-
},
|
|
182
|
-
rootProps: normalize.element({
|
|
183
|
-
id: dom.getRootId(state.context),
|
|
184
|
-
...parts.root.attrs,
|
|
185
|
-
dir: state.context.dir,
|
|
186
|
-
"data-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
187
|
-
"data-focus": (0, import_dom_query2.dataAttr)(focused),
|
|
188
|
-
"data-invalid": (0, import_dom_query2.dataAttr)(invalid)
|
|
189
|
-
}),
|
|
190
|
-
labelProps: normalize.label({
|
|
191
|
-
...parts.label.attrs,
|
|
192
|
-
dir: state.context.dir,
|
|
193
|
-
"data-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
194
|
-
"data-focus": (0, import_dom_query2.dataAttr)(focused),
|
|
195
|
-
"data-invalid": (0, import_dom_query2.dataAttr)(invalid),
|
|
196
|
-
id: dom.getLabelId(state.context),
|
|
197
|
-
htmlFor: dom.getInputId(state.context)
|
|
198
|
-
}),
|
|
199
|
-
controlProps: normalize.element({
|
|
200
|
-
...parts.control.attrs,
|
|
201
|
-
dir: state.context.dir,
|
|
202
|
-
role: "group",
|
|
203
|
-
"aria-disabled": disabled,
|
|
204
|
-
"data-focus": (0, import_dom_query2.dataAttr)(focused),
|
|
205
|
-
"data-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
206
|
-
"data-invalid": (0, import_dom_query2.dataAttr)(invalid),
|
|
207
|
-
"aria-invalid": (0, import_dom_query2.ariaAttr)(state.context.invalid)
|
|
208
|
-
}),
|
|
209
|
-
inputProps: normalize.input({
|
|
210
|
-
...parts.input.attrs,
|
|
211
|
-
dir: state.context.dir,
|
|
212
|
-
name: state.context.name,
|
|
213
|
-
form: state.context.form,
|
|
214
|
-
id: dom.getInputId(state.context),
|
|
215
|
-
role: "spinbutton",
|
|
216
|
-
defaultValue: state.context.formattedValue,
|
|
217
|
-
pattern: state.context.pattern,
|
|
218
|
-
inputMode: state.context.inputMode,
|
|
219
|
-
"aria-invalid": (0, import_dom_query2.ariaAttr)(invalid),
|
|
220
|
-
"data-invalid": (0, import_dom_query2.dataAttr)(invalid),
|
|
221
|
-
disabled,
|
|
222
|
-
"data-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
223
|
-
readOnly: !!state.context.readOnly,
|
|
224
|
-
autoComplete: "off",
|
|
225
|
-
autoCorrect: "off",
|
|
226
|
-
spellCheck: "false",
|
|
227
|
-
type: "text",
|
|
228
|
-
"aria-roledescription": "numberfield",
|
|
229
|
-
"aria-valuemin": state.context.min,
|
|
230
|
-
"aria-valuemax": state.context.max,
|
|
231
|
-
"aria-valuenow": Number.isNaN(state.context.valueAsNumber) ? void 0 : state.context.valueAsNumber,
|
|
232
|
-
"aria-valuetext": state.context.valueText,
|
|
233
|
-
onFocus() {
|
|
234
|
-
send("INPUT.FOCUS");
|
|
235
|
-
},
|
|
236
|
-
onBlur() {
|
|
237
|
-
send({ type: "INPUT.COMMIT", src: "blur" });
|
|
238
|
-
},
|
|
239
|
-
onChange(event) {
|
|
240
|
-
send({ type: "INPUT.CHANGE", target: event.currentTarget, hint: "set" });
|
|
241
|
-
},
|
|
242
|
-
onBeforeInput(event) {
|
|
243
|
-
try {
|
|
244
|
-
const { selectionStart, selectionEnd, value } = event.currentTarget;
|
|
245
|
-
const nextValue = value.slice(0, selectionStart) + (event.data ?? "") + value.slice(selectionEnd);
|
|
246
|
-
const isValid = state.context.parser.isValidPartialNumber(nextValue);
|
|
247
|
-
if (!isValid) {
|
|
248
|
-
event.preventDefault();
|
|
249
|
-
}
|
|
250
|
-
} catch {
|
|
251
|
-
}
|
|
252
|
-
},
|
|
253
|
-
onKeyDown(event) {
|
|
254
|
-
if (event.defaultPrevented)
|
|
255
|
-
return;
|
|
256
|
-
if (readOnly)
|
|
257
|
-
return;
|
|
258
|
-
const evt = (0, import_dom_event.getNativeEvent)(event);
|
|
259
|
-
if (evt.isComposing)
|
|
260
|
-
return;
|
|
261
|
-
const step = (0, import_dom_event.getEventStep)(event) * state.context.step;
|
|
262
|
-
const keyMap = {
|
|
263
|
-
ArrowUp() {
|
|
264
|
-
send({ type: "INPUT.ARROW_UP", step });
|
|
265
|
-
event.preventDefault();
|
|
266
|
-
},
|
|
267
|
-
ArrowDown() {
|
|
268
|
-
send({ type: "INPUT.ARROW_DOWN", step });
|
|
269
|
-
event.preventDefault();
|
|
270
|
-
},
|
|
271
|
-
Home() {
|
|
272
|
-
send("INPUT.HOME");
|
|
273
|
-
event.preventDefault();
|
|
274
|
-
},
|
|
275
|
-
End() {
|
|
276
|
-
send("INPUT.END");
|
|
277
|
-
event.preventDefault();
|
|
278
|
-
},
|
|
279
|
-
Enter() {
|
|
280
|
-
send({ type: "INPUT.COMMIT", src: "enter" });
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
const exec = keyMap[event.key];
|
|
284
|
-
exec?.(event);
|
|
285
|
-
}
|
|
286
|
-
}),
|
|
287
|
-
decrementTriggerProps: normalize.button({
|
|
288
|
-
...parts.decrementTrigger.attrs,
|
|
289
|
-
dir: state.context.dir,
|
|
290
|
-
id: dom.getDecrementTriggerId(state.context),
|
|
291
|
-
disabled: isDecrementDisabled,
|
|
292
|
-
"data-disabled": (0, import_dom_query2.dataAttr)(isDecrementDisabled),
|
|
293
|
-
"aria-label": translations.decrementLabel,
|
|
294
|
-
type: "button",
|
|
295
|
-
tabIndex: -1,
|
|
296
|
-
"aria-controls": dom.getInputId(state.context),
|
|
297
|
-
onPointerDown(event) {
|
|
298
|
-
if (isDecrementDisabled || !(0, import_dom_event.isLeftClick)(event))
|
|
299
|
-
return;
|
|
300
|
-
send({ type: "TRIGGER.PRESS_DOWN", hint: "decrement", pointerType: event.pointerType });
|
|
301
|
-
if (event.pointerType === "mouse") {
|
|
302
|
-
event.preventDefault();
|
|
303
|
-
}
|
|
304
|
-
if (event.pointerType === "touch") {
|
|
305
|
-
event.currentTarget?.focus({ preventScroll: true });
|
|
306
|
-
}
|
|
307
|
-
},
|
|
308
|
-
onPointerUp(event) {
|
|
309
|
-
send({ type: "TRIGGER.PRESS_UP", hint: "decrement", pointerType: event.pointerType });
|
|
310
|
-
},
|
|
311
|
-
onPointerLeave() {
|
|
312
|
-
if (isDecrementDisabled)
|
|
313
|
-
return;
|
|
314
|
-
send({ type: "TRIGGER.PRESS_UP", hint: "decrement" });
|
|
315
|
-
}
|
|
316
|
-
}),
|
|
317
|
-
incrementTriggerProps: normalize.button({
|
|
318
|
-
...parts.incrementTrigger.attrs,
|
|
319
|
-
dir: state.context.dir,
|
|
320
|
-
id: dom.getIncrementTriggerId(state.context),
|
|
321
|
-
disabled: isIncrementDisabled,
|
|
322
|
-
"data-disabled": (0, import_dom_query2.dataAttr)(isIncrementDisabled),
|
|
323
|
-
"aria-label": translations.incrementLabel,
|
|
324
|
-
type: "button",
|
|
325
|
-
tabIndex: -1,
|
|
326
|
-
"aria-controls": dom.getInputId(state.context),
|
|
327
|
-
onPointerDown(event) {
|
|
328
|
-
if (isIncrementDisabled || !(0, import_dom_event.isLeftClick)(event))
|
|
329
|
-
return;
|
|
330
|
-
send({ type: "TRIGGER.PRESS_DOWN", hint: "increment", pointerType: event.pointerType });
|
|
331
|
-
if (event.pointerType === "mouse") {
|
|
332
|
-
event.preventDefault();
|
|
333
|
-
}
|
|
334
|
-
if (event.pointerType === "touch") {
|
|
335
|
-
event.currentTarget?.focus({ preventScroll: true });
|
|
336
|
-
}
|
|
337
|
-
},
|
|
338
|
-
onPointerUp(event) {
|
|
339
|
-
send({ type: "TRIGGER.PRESS_UP", hint: "increment", pointerType: event.pointerType });
|
|
340
|
-
},
|
|
341
|
-
onPointerLeave(event) {
|
|
342
|
-
send({ type: "TRIGGER.PRESS_UP", hint: "increment", pointerType: event.pointerType });
|
|
343
|
-
}
|
|
344
|
-
}),
|
|
345
|
-
scrubberProps: normalize.element({
|
|
346
|
-
...parts.scrubber.attrs,
|
|
347
|
-
dir: state.context.dir,
|
|
348
|
-
"data-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
349
|
-
id: dom.getScrubberId(state.context),
|
|
350
|
-
role: "presentation",
|
|
351
|
-
onMouseDown(event) {
|
|
352
|
-
if (disabled)
|
|
353
|
-
return;
|
|
354
|
-
const evt = (0, import_dom_event.getNativeEvent)(event);
|
|
355
|
-
const point = (0, import_dom_event.getEventPoint)(evt);
|
|
356
|
-
point.x = point.x - (0, import_number_utils2.roundToDevicePixel)(7.5);
|
|
357
|
-
point.y = point.y - (0, import_number_utils2.roundToDevicePixel)(7.5);
|
|
358
|
-
send({ type: "SCRUBBER.PRESS_DOWN", point });
|
|
359
|
-
event.preventDefault();
|
|
360
|
-
},
|
|
361
|
-
style: {
|
|
362
|
-
cursor: disabled ? void 0 : "ew-resize"
|
|
363
|
-
}
|
|
364
|
-
})
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// src/number-input.machine.ts
|
|
369
|
-
var import_core2 = require("@zag-js/core");
|
|
370
|
-
var import_dom_event2 = require("@zag-js/dom-event");
|
|
371
|
-
var import_dom_query3 = require("@zag-js/dom-query");
|
|
372
|
-
var import_form_utils = require("@zag-js/form-utils");
|
|
373
|
-
var import_number_utils3 = require("@zag-js/number-utils");
|
|
374
|
-
var import_utils = require("@zag-js/utils");
|
|
375
|
-
|
|
376
|
-
// src/cursor.ts
|
|
377
|
-
function recordCursor(inputEl) {
|
|
378
|
-
if (inputEl.ownerDocument.activeElement !== inputEl)
|
|
379
|
-
return;
|
|
380
|
-
try {
|
|
381
|
-
const { selectionStart: start, selectionEnd: end, value } = inputEl;
|
|
382
|
-
const beforeTxt = value.substring(0, start);
|
|
383
|
-
const afterTxt = value.substring(end);
|
|
384
|
-
return {
|
|
385
|
-
start,
|
|
386
|
-
end,
|
|
387
|
-
value,
|
|
388
|
-
beforeTxt,
|
|
389
|
-
afterTxt
|
|
390
|
-
};
|
|
391
|
-
} catch {
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
function restoreCursor(inputEl, selection) {
|
|
395
|
-
if (inputEl.ownerDocument.activeElement !== inputEl)
|
|
396
|
-
return;
|
|
397
|
-
if (!selection) {
|
|
398
|
-
inputEl.setSelectionRange(inputEl.value.length, inputEl.value.length);
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
401
|
-
try {
|
|
402
|
-
const { value } = inputEl;
|
|
403
|
-
const { beforeTxt = "", afterTxt = "", start } = selection;
|
|
404
|
-
let startPos = value.length;
|
|
405
|
-
if (value.endsWith(afterTxt)) {
|
|
406
|
-
startPos = value.length - afterTxt.length;
|
|
407
|
-
} else if (value.startsWith(beforeTxt)) {
|
|
408
|
-
startPos = beforeTxt.length;
|
|
409
|
-
} else if (start != null) {
|
|
410
|
-
const beforeLastChar = beforeTxt[start - 1];
|
|
411
|
-
const newIndex = value.indexOf(beforeLastChar, start - 1);
|
|
412
|
-
if (newIndex !== -1) {
|
|
413
|
-
startPos = newIndex + 1;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
inputEl.setSelectionRange(startPos, startPos);
|
|
417
|
-
} catch {
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
// src/number-input.utils.ts
|
|
422
|
-
var import_number = require("@internationalized/number");
|
|
423
|
-
var import_core = require("@zag-js/core");
|
|
424
|
-
var createFormatter = (locale, options = {}) => {
|
|
425
|
-
return (0, import_core.ref)(new Intl.NumberFormat(locale, options));
|
|
426
|
-
};
|
|
427
|
-
var createParser = (locale, options = {}) => {
|
|
428
|
-
return (0, import_core.ref)(new import_number.NumberParser(locale, options));
|
|
429
|
-
};
|
|
430
|
-
var parseValue = (ctx, value) => {
|
|
431
|
-
if (!ctx.formatOptions)
|
|
432
|
-
return parseFloat(value);
|
|
433
|
-
return ctx.parser.parse(String(value));
|
|
434
|
-
};
|
|
435
|
-
var formatValue = (ctx, value) => {
|
|
436
|
-
if (Number.isNaN(value))
|
|
437
|
-
return "";
|
|
438
|
-
if (!ctx.formatOptions)
|
|
439
|
-
return value.toString();
|
|
440
|
-
return ctx.formatter.format(value);
|
|
441
|
-
};
|
|
442
|
-
|
|
443
|
-
// src/number-input.machine.ts
|
|
444
|
-
var { not, and } = import_core2.guards;
|
|
445
|
-
function machine(userContext) {
|
|
446
|
-
const ctx = (0, import_utils.compact)(userContext);
|
|
447
|
-
return (0, import_core2.createMachine)(
|
|
448
|
-
{
|
|
449
|
-
id: "number-input",
|
|
450
|
-
initial: "idle",
|
|
451
|
-
context: {
|
|
452
|
-
dir: "ltr",
|
|
453
|
-
locale: "en-US",
|
|
454
|
-
focusInputOnChange: true,
|
|
455
|
-
clampValueOnBlur: true,
|
|
456
|
-
allowOverflow: false,
|
|
457
|
-
inputMode: "decimal",
|
|
458
|
-
pattern: "[0-9]*(.[0-9]+)?",
|
|
459
|
-
value: "",
|
|
460
|
-
step: 1,
|
|
461
|
-
min: Number.MIN_SAFE_INTEGER,
|
|
462
|
-
max: Number.MAX_SAFE_INTEGER,
|
|
463
|
-
invalid: false,
|
|
464
|
-
spinOnPress: true,
|
|
465
|
-
...ctx,
|
|
466
|
-
hint: null,
|
|
467
|
-
scrubberCursorPoint: null,
|
|
468
|
-
fieldsetDisabled: false,
|
|
469
|
-
formatter: createFormatter(ctx.locale || "en-US", ctx.formatOptions),
|
|
470
|
-
parser: createParser(ctx.locale || "en-US", ctx.formatOptions),
|
|
471
|
-
translations: {
|
|
472
|
-
incrementLabel: "increment value",
|
|
473
|
-
decrementLabel: "decrease value",
|
|
474
|
-
...ctx.translations
|
|
475
|
-
}
|
|
476
|
-
},
|
|
477
|
-
computed: {
|
|
478
|
-
isRtl: (ctx2) => ctx2.dir === "rtl",
|
|
479
|
-
valueAsNumber: (ctx2) => parseValue(ctx2, ctx2.value),
|
|
480
|
-
formattedValue: (ctx2) => formatValue(ctx2, ctx2.valueAsNumber),
|
|
481
|
-
isAtMin: (ctx2) => (0, import_number_utils3.isAtMin)(ctx2.valueAsNumber, ctx2),
|
|
482
|
-
isAtMax: (ctx2) => (0, import_number_utils3.isAtMax)(ctx2.valueAsNumber, ctx2),
|
|
483
|
-
isOutOfRange: (ctx2) => !(0, import_number_utils3.isWithinRange)(ctx2.valueAsNumber, ctx2),
|
|
484
|
-
isValueEmpty: (ctx2) => ctx2.value === "",
|
|
485
|
-
isDisabled: (ctx2) => !!ctx2.disabled || ctx2.fieldsetDisabled,
|
|
486
|
-
canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
|
|
487
|
-
canDecrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMin,
|
|
488
|
-
valueText: (ctx2) => ctx2.translations.valueText?.(ctx2.value)
|
|
489
|
-
},
|
|
490
|
-
watch: {
|
|
491
|
-
formatOptions: ["setFormatterAndParser", "syncInputElement"],
|
|
492
|
-
locale: ["setFormatterAndParser", "syncInputElement"],
|
|
493
|
-
value: ["syncInputElement"],
|
|
494
|
-
isOutOfRange: ["invokeOnInvalid"],
|
|
495
|
-
scrubberCursorPoint: ["setVirtualCursorPosition"]
|
|
496
|
-
},
|
|
497
|
-
activities: ["trackFormControl"],
|
|
498
|
-
on: {
|
|
499
|
-
"VALUE.SET": {
|
|
500
|
-
actions: ["setRawValue", "setHintToSet"]
|
|
501
|
-
},
|
|
502
|
-
"VALUE.CLEAR": {
|
|
503
|
-
actions: ["clearValue"]
|
|
504
|
-
},
|
|
505
|
-
"VALUE.INCREMENT": {
|
|
506
|
-
actions: ["increment"]
|
|
507
|
-
},
|
|
508
|
-
"VALUE.DECREMENT": {
|
|
509
|
-
actions: ["decrement"]
|
|
510
|
-
}
|
|
511
|
-
},
|
|
512
|
-
states: {
|
|
513
|
-
idle: {
|
|
514
|
-
on: {
|
|
515
|
-
"TRIGGER.PRESS_DOWN": [
|
|
516
|
-
{ guard: "isTouchPointer", target: "before:spin", actions: ["setHint"] },
|
|
517
|
-
{
|
|
518
|
-
target: "before:spin",
|
|
519
|
-
actions: ["focusInput", "invokeOnFocus", "setHint"]
|
|
520
|
-
}
|
|
521
|
-
],
|
|
522
|
-
"SCRUBBER.PRESS_DOWN": {
|
|
523
|
-
target: "scrubbing",
|
|
524
|
-
actions: ["focusInput", "invokeOnFocus", "setHint", "setCursorPoint"]
|
|
525
|
-
},
|
|
526
|
-
"INPUT.FOCUS": {
|
|
527
|
-
target: "focused",
|
|
528
|
-
actions: ["focusInput", "invokeOnFocus"]
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
},
|
|
532
|
-
focused: {
|
|
533
|
-
tags: "focus",
|
|
534
|
-
activities: "attachWheelListener",
|
|
535
|
-
on: {
|
|
536
|
-
"TRIGGER.PRESS_DOWN": [
|
|
537
|
-
{ guard: "isTouchPointer", target: "before:spin", actions: ["setHint"] },
|
|
538
|
-
{ target: "before:spin", actions: ["focusInput", "setHint"] }
|
|
539
|
-
],
|
|
540
|
-
"SCRUBBER.PRESS_DOWN": {
|
|
541
|
-
target: "scrubbing",
|
|
542
|
-
actions: ["focusInput", "setHint", "setCursorPoint"]
|
|
543
|
-
},
|
|
544
|
-
"INPUT.ARROW_UP": {
|
|
545
|
-
actions: "increment"
|
|
546
|
-
},
|
|
547
|
-
"INPUT.ARROW_DOWN": {
|
|
548
|
-
actions: "decrement"
|
|
549
|
-
},
|
|
550
|
-
"INPUT.HOME": {
|
|
551
|
-
actions: "decrementToMin"
|
|
552
|
-
},
|
|
553
|
-
"INPUT.END": {
|
|
554
|
-
actions: "incrementToMax"
|
|
555
|
-
},
|
|
556
|
-
"INPUT.CHANGE": {
|
|
557
|
-
actions: ["setValue", "setHint"]
|
|
558
|
-
},
|
|
559
|
-
"INPUT.COMMIT": [
|
|
560
|
-
{
|
|
561
|
-
guard: and("clampValueOnBlur", not("isInRange")),
|
|
562
|
-
target: "idle",
|
|
563
|
-
actions: ["setClampedValue", "clearHint", "invokeOnBlur"]
|
|
564
|
-
},
|
|
565
|
-
{
|
|
566
|
-
target: "idle",
|
|
567
|
-
actions: ["setFormattedValue", "clearHint", "invokeOnBlur"]
|
|
568
|
-
}
|
|
569
|
-
]
|
|
570
|
-
}
|
|
571
|
-
},
|
|
572
|
-
"before:spin": {
|
|
573
|
-
tags: "focus",
|
|
574
|
-
activities: "trackButtonDisabled",
|
|
575
|
-
entry: (0, import_core2.choose)([
|
|
576
|
-
{ guard: "isIncrementHint", actions: "increment" },
|
|
577
|
-
{ guard: "isDecrementHint", actions: "decrement" }
|
|
578
|
-
]),
|
|
579
|
-
after: {
|
|
580
|
-
CHANGE_DELAY: {
|
|
581
|
-
target: "spinning",
|
|
582
|
-
guard: and("isInRange", "spinOnPress")
|
|
583
|
-
}
|
|
584
|
-
},
|
|
585
|
-
on: {
|
|
586
|
-
"TRIGGER.PRESS_UP": [
|
|
587
|
-
{ guard: "isTouchPointer", target: "focused", actions: "clearHint" },
|
|
588
|
-
{ target: "focused", actions: ["focusInput", "clearHint"] }
|
|
589
|
-
]
|
|
590
|
-
}
|
|
591
|
-
},
|
|
592
|
-
spinning: {
|
|
593
|
-
tags: "focus",
|
|
594
|
-
activities: "trackButtonDisabled",
|
|
595
|
-
every: [
|
|
596
|
-
{
|
|
597
|
-
delay: "CHANGE_INTERVAL",
|
|
598
|
-
guard: and(not("isAtMin"), "isIncrementHint"),
|
|
599
|
-
actions: "increment"
|
|
600
|
-
},
|
|
601
|
-
{
|
|
602
|
-
delay: "CHANGE_INTERVAL",
|
|
603
|
-
guard: and(not("isAtMax"), "isDecrementHint"),
|
|
604
|
-
actions: "decrement"
|
|
605
|
-
}
|
|
606
|
-
],
|
|
607
|
-
on: {
|
|
608
|
-
"TRIGGER.PRESS_UP": {
|
|
609
|
-
target: "focused",
|
|
610
|
-
actions: ["focusInput", "clearHint"]
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
},
|
|
614
|
-
scrubbing: {
|
|
615
|
-
tags: "focus",
|
|
616
|
-
activities: ["activatePointerLock", "trackMousemove", "setupVirtualCursor", "preventTextSelection"],
|
|
617
|
-
on: {
|
|
618
|
-
"SCRUBBER.POINTER_UP": {
|
|
619
|
-
target: "focused",
|
|
620
|
-
actions: ["focusInput", "clearCursorPoint"]
|
|
621
|
-
},
|
|
622
|
-
"SCRUBBER.POINTER_MOVE": [
|
|
623
|
-
{
|
|
624
|
-
guard: "isIncrementHint",
|
|
625
|
-
actions: ["increment", "setCursorPoint"]
|
|
626
|
-
},
|
|
627
|
-
{
|
|
628
|
-
guard: "isDecrementHint",
|
|
629
|
-
actions: ["decrement", "setCursorPoint"]
|
|
630
|
-
}
|
|
631
|
-
]
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
},
|
|
636
|
-
{
|
|
637
|
-
delays: {
|
|
638
|
-
CHANGE_INTERVAL: 50,
|
|
639
|
-
CHANGE_DELAY: 300
|
|
640
|
-
},
|
|
641
|
-
guards: {
|
|
642
|
-
clampValueOnBlur: (ctx2) => ctx2.clampValueOnBlur,
|
|
643
|
-
isAtMin: (ctx2) => ctx2.isAtMin,
|
|
644
|
-
spinOnPress: (ctx2) => !!ctx2.spinOnPress,
|
|
645
|
-
isAtMax: (ctx2) => ctx2.isAtMax,
|
|
646
|
-
isInRange: (ctx2) => !ctx2.isOutOfRange,
|
|
647
|
-
isDecrementHint: (ctx2, evt) => (evt.hint ?? ctx2.hint) === "decrement",
|
|
648
|
-
isIncrementHint: (ctx2, evt) => (evt.hint ?? ctx2.hint) === "increment",
|
|
649
|
-
isTouchPointer: (_ctx, evt) => evt.pointerType === "touch"
|
|
650
|
-
},
|
|
651
|
-
activities: {
|
|
652
|
-
trackFormControl(ctx2, _evt, { initialContext }) {
|
|
653
|
-
const inputEl = dom.getInputEl(ctx2);
|
|
654
|
-
return (0, import_form_utils.trackFormControl)(inputEl, {
|
|
655
|
-
onFieldsetDisabledChange(disabled) {
|
|
656
|
-
ctx2.fieldsetDisabled = disabled;
|
|
657
|
-
},
|
|
658
|
-
onFormReset() {
|
|
659
|
-
set.value(ctx2, initialContext.value);
|
|
660
|
-
}
|
|
661
|
-
});
|
|
662
|
-
},
|
|
663
|
-
setupVirtualCursor(ctx2) {
|
|
664
|
-
return dom.setupVirtualCursor(ctx2);
|
|
665
|
-
},
|
|
666
|
-
preventTextSelection(ctx2) {
|
|
667
|
-
return dom.preventTextSelection(ctx2);
|
|
668
|
-
},
|
|
669
|
-
trackButtonDisabled(ctx2, _evt, { send }) {
|
|
670
|
-
const btn = dom.getPressedTriggerEl(ctx2, ctx2.hint);
|
|
671
|
-
return (0, import_dom_query3.observeAttributes)(btn, {
|
|
672
|
-
attributes: ["disabled"],
|
|
673
|
-
callback() {
|
|
674
|
-
send({ type: "TRIGGER.PRESS_UP", src: "attr" });
|
|
675
|
-
}
|
|
676
|
-
});
|
|
677
|
-
},
|
|
678
|
-
attachWheelListener(ctx2, _evt, { send }) {
|
|
679
|
-
const inputEl = dom.getInputEl(ctx2);
|
|
680
|
-
if (!inputEl || !dom.isActiveElement(ctx2, inputEl) || !ctx2.allowMouseWheel)
|
|
681
|
-
return;
|
|
682
|
-
function onWheel(event) {
|
|
683
|
-
event.preventDefault();
|
|
684
|
-
const dir = Math.sign(event.deltaY) * -1;
|
|
685
|
-
if (dir === 1) {
|
|
686
|
-
send("VALUE.INCREMENT");
|
|
687
|
-
} else if (dir === -1) {
|
|
688
|
-
send("VALUE.DECREMENT");
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
return (0, import_dom_event2.addDomEvent)(inputEl, "wheel", onWheel, { passive: false });
|
|
692
|
-
},
|
|
693
|
-
activatePointerLock(ctx2) {
|
|
694
|
-
if ((0, import_dom_query3.isSafari)())
|
|
695
|
-
return;
|
|
696
|
-
return (0, import_dom_event2.requestPointerLock)(dom.getDoc(ctx2));
|
|
697
|
-
},
|
|
698
|
-
trackMousemove(ctx2, _evt, { send }) {
|
|
699
|
-
const doc = dom.getDoc(ctx2);
|
|
700
|
-
function onMousemove(event) {
|
|
701
|
-
if (!ctx2.scrubberCursorPoint)
|
|
702
|
-
return;
|
|
703
|
-
const value = dom.getMousementValue(ctx2, event);
|
|
704
|
-
if (!value.hint)
|
|
705
|
-
return;
|
|
706
|
-
send({
|
|
707
|
-
type: "SCRUBBER.POINTER_MOVE",
|
|
708
|
-
hint: value.hint,
|
|
709
|
-
point: value.point
|
|
710
|
-
});
|
|
711
|
-
}
|
|
712
|
-
function onMouseup() {
|
|
713
|
-
send("SCRUBBER.POINTER_UP");
|
|
714
|
-
}
|
|
715
|
-
return (0, import_utils.callAll)(
|
|
716
|
-
(0, import_dom_event2.addDomEvent)(doc, "mousemove", onMousemove, false),
|
|
717
|
-
(0, import_dom_event2.addDomEvent)(doc, "mouseup", onMouseup, false)
|
|
718
|
-
);
|
|
719
|
-
}
|
|
720
|
-
},
|
|
721
|
-
actions: {
|
|
722
|
-
focusInput(ctx2) {
|
|
723
|
-
if (!ctx2.focusInputOnChange)
|
|
724
|
-
return;
|
|
725
|
-
const inputEl = dom.getInputEl(ctx2);
|
|
726
|
-
if (dom.isActiveElement(ctx2, inputEl))
|
|
727
|
-
return;
|
|
728
|
-
(0, import_dom_query3.raf)(() => inputEl?.focus({ preventScroll: true }));
|
|
729
|
-
},
|
|
730
|
-
increment(ctx2, evt) {
|
|
731
|
-
const nextValue = (0, import_number_utils3.increment)(ctx2.valueAsNumber, evt.step ?? ctx2.step);
|
|
732
|
-
const value = formatValue(ctx2, (0, import_number_utils3.clamp)(nextValue, ctx2));
|
|
733
|
-
set.value(ctx2, value);
|
|
734
|
-
},
|
|
735
|
-
decrement(ctx2, evt) {
|
|
736
|
-
const nextValue = (0, import_number_utils3.decrement)(ctx2.valueAsNumber, evt.step ?? ctx2.step);
|
|
737
|
-
const value = formatValue(ctx2, (0, import_number_utils3.clamp)(nextValue, ctx2));
|
|
738
|
-
set.value(ctx2, value);
|
|
739
|
-
},
|
|
740
|
-
setClampedValue(ctx2) {
|
|
741
|
-
const nextValue = (0, import_number_utils3.clamp)(ctx2.valueAsNumber, ctx2);
|
|
742
|
-
set.value(ctx2, formatValue(ctx2, nextValue));
|
|
743
|
-
},
|
|
744
|
-
setRawValue(ctx2, evt) {
|
|
745
|
-
const parsedValue = parseValue(ctx2, evt.value);
|
|
746
|
-
const value = formatValue(ctx2, (0, import_number_utils3.clamp)(parsedValue, ctx2));
|
|
747
|
-
set.value(ctx2, value);
|
|
748
|
-
},
|
|
749
|
-
setValue(ctx2, evt) {
|
|
750
|
-
const value = evt.target?.value ?? evt.value;
|
|
751
|
-
set.value(ctx2, value);
|
|
752
|
-
},
|
|
753
|
-
clearValue(ctx2) {
|
|
754
|
-
set.value(ctx2, "");
|
|
755
|
-
},
|
|
756
|
-
incrementToMax(ctx2) {
|
|
757
|
-
const value = formatValue(ctx2, ctx2.max);
|
|
758
|
-
set.value(ctx2, value);
|
|
759
|
-
},
|
|
760
|
-
decrementToMin(ctx2) {
|
|
761
|
-
const value = formatValue(ctx2, ctx2.min);
|
|
762
|
-
set.value(ctx2, value);
|
|
763
|
-
},
|
|
764
|
-
setHint(ctx2, evt) {
|
|
765
|
-
ctx2.hint = evt.hint;
|
|
766
|
-
},
|
|
767
|
-
clearHint(ctx2) {
|
|
768
|
-
ctx2.hint = null;
|
|
769
|
-
},
|
|
770
|
-
setHintToSet(ctx2) {
|
|
771
|
-
ctx2.hint = "set";
|
|
772
|
-
},
|
|
773
|
-
invokeOnFocus(ctx2) {
|
|
774
|
-
ctx2.onFocusChange?.({
|
|
775
|
-
focused: true,
|
|
776
|
-
value: ctx2.formattedValue,
|
|
777
|
-
valueAsNumber: ctx2.valueAsNumber
|
|
778
|
-
});
|
|
779
|
-
},
|
|
780
|
-
invokeOnBlur(ctx2) {
|
|
781
|
-
ctx2.onFocusChange?.({
|
|
782
|
-
focused: false,
|
|
783
|
-
value: ctx2.formattedValue,
|
|
784
|
-
valueAsNumber: ctx2.valueAsNumber
|
|
785
|
-
});
|
|
786
|
-
},
|
|
787
|
-
invokeOnInvalid(ctx2) {
|
|
788
|
-
if (!ctx2.isOutOfRange)
|
|
789
|
-
return;
|
|
790
|
-
const reason = ctx2.valueAsNumber > ctx2.max ? "rangeOverflow" : "rangeUnderflow";
|
|
791
|
-
ctx2.onValueInvalid?.({
|
|
792
|
-
reason,
|
|
793
|
-
value: ctx2.formattedValue,
|
|
794
|
-
valueAsNumber: ctx2.valueAsNumber
|
|
795
|
-
});
|
|
796
|
-
},
|
|
797
|
-
syncInputElement(ctx2, evt) {
|
|
798
|
-
const value = evt.type.endsWith("CHANGE") ? ctx2.value : ctx2.formattedValue;
|
|
799
|
-
sync.input(ctx2, value);
|
|
800
|
-
},
|
|
801
|
-
setFormattedValue(ctx2) {
|
|
802
|
-
set.value(ctx2, ctx2.formattedValue);
|
|
803
|
-
},
|
|
804
|
-
setCursorPoint(ctx2, evt) {
|
|
805
|
-
ctx2.scrubberCursorPoint = evt.point;
|
|
806
|
-
},
|
|
807
|
-
clearCursorPoint(ctx2) {
|
|
808
|
-
ctx2.scrubberCursorPoint = null;
|
|
809
|
-
},
|
|
810
|
-
setVirtualCursorPosition(ctx2) {
|
|
811
|
-
const cursorEl = dom.getCursorEl(ctx2);
|
|
812
|
-
if (!cursorEl || !ctx2.scrubberCursorPoint)
|
|
813
|
-
return;
|
|
814
|
-
const { x, y } = ctx2.scrubberCursorPoint;
|
|
815
|
-
cursorEl.style.transform = `translate3d(${x}px, ${y}px, 0px)`;
|
|
816
|
-
},
|
|
817
|
-
setFormatterAndParser(ctx2) {
|
|
818
|
-
if (!ctx2.locale)
|
|
819
|
-
return;
|
|
820
|
-
ctx2.formatter = createFormatter(ctx2.locale, ctx2.formatOptions);
|
|
821
|
-
ctx2.parser = createParser(ctx2.locale, ctx2.formatOptions);
|
|
822
|
-
}
|
|
823
|
-
},
|
|
824
|
-
compareFns: {
|
|
825
|
-
formatOptions: (a, b) => (0, import_utils.isEqual)(a, b),
|
|
826
|
-
scrubberCursorPoint: (a, b) => (0, import_utils.isEqual)(a, b)
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
);
|
|
830
|
-
}
|
|
831
|
-
var sync = {
|
|
832
|
-
input(ctx, value) {
|
|
833
|
-
const inputEl = dom.getInputEl(ctx);
|
|
834
|
-
if (!inputEl)
|
|
835
|
-
return;
|
|
836
|
-
const sel = recordCursor(inputEl);
|
|
837
|
-
(0, import_dom_query3.raf)(() => {
|
|
838
|
-
dom.setValue(inputEl, value);
|
|
839
|
-
restoreCursor(inputEl, sel);
|
|
840
|
-
});
|
|
841
|
-
}
|
|
842
|
-
};
|
|
843
|
-
var invoke = {
|
|
844
|
-
onChange: (ctx) => {
|
|
845
|
-
ctx.onValueChange?.({
|
|
846
|
-
value: ctx.value,
|
|
847
|
-
valueAsNumber: ctx.valueAsNumber
|
|
848
|
-
});
|
|
849
|
-
}
|
|
850
|
-
};
|
|
851
|
-
var set = {
|
|
852
|
-
value: (ctx, value) => {
|
|
853
|
-
if ((0, import_utils.isEqual)(ctx.value, value))
|
|
854
|
-
return;
|
|
855
|
-
ctx.value = value;
|
|
856
|
-
invoke.onChange(ctx);
|
|
857
|
-
}
|
|
858
|
-
};
|
|
859
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
860
|
-
0 && (module.exports = {
|
|
861
|
-
anatomy,
|
|
862
|
-
connect,
|
|
863
|
-
machine
|
|
864
|
-
});
|
|
7
|
+
</svg>`;doc.body.appendChild(el)}});function connect(state,send,normalize){const focused=state.hasTag("focus");const disabled=state.context.isDisabled;const readOnly=state.context.readOnly;const empty=state.context.isValueEmpty;const invalid=state.context.isOutOfRange||!!state.context.invalid;const isIncrementDisabled=disabled||!state.context.canIncrement||readOnly;const isDecrementDisabled=disabled||!state.context.canDecrement||readOnly;const translations=state.context.translations;return{focused,invalid,empty,value:state.context.formattedValue,valueAsNumber:state.context.valueAsNumber,setValue(value){send({type:"VALUE.SET",value})},clearValue(){send("VALUE.CLEAR")},increment(){send("VALUE.INCREMENT")},decrement(){send("VALUE.DECREMENT")},setToMax(){send({type:"VALUE.SET",value:state.context.max})},setToMin(){send({type:"VALUE.SET",value:state.context.min})},focus(){dom.getInputEl(state.context)?.focus()},rootProps:normalize.element({id:dom.getRootId(state.context),...parts.root.attrs,dir:state.context.dir,"data-disabled":(0,import_dom_query2.dataAttr)(disabled),"data-focus":(0,import_dom_query2.dataAttr)(focused),"data-invalid":(0,import_dom_query2.dataAttr)(invalid)}),labelProps:normalize.label({...parts.label.attrs,dir:state.context.dir,"data-disabled":(0,import_dom_query2.dataAttr)(disabled),"data-focus":(0,import_dom_query2.dataAttr)(focused),"data-invalid":(0,import_dom_query2.dataAttr)(invalid),id:dom.getLabelId(state.context),htmlFor:dom.getInputId(state.context)}),controlProps:normalize.element({...parts.control.attrs,dir:state.context.dir,role:"group","aria-disabled":disabled,"data-focus":(0,import_dom_query2.dataAttr)(focused),"data-disabled":(0,import_dom_query2.dataAttr)(disabled),"data-invalid":(0,import_dom_query2.dataAttr)(invalid),"aria-invalid":(0,import_dom_query2.ariaAttr)(state.context.invalid)}),inputProps:normalize.input({...parts.input.attrs,dir:state.context.dir,name:state.context.name,form:state.context.form,id:dom.getInputId(state.context),role:"spinbutton",defaultValue:state.context.formattedValue,pattern:state.context.pattern,inputMode:state.context.inputMode,"aria-invalid":(0,import_dom_query2.ariaAttr)(invalid),"data-invalid":(0,import_dom_query2.dataAttr)(invalid),disabled,"data-disabled":(0,import_dom_query2.dataAttr)(disabled),readOnly:!!state.context.readOnly,autoComplete:"off",autoCorrect:"off",spellCheck:"false",type:"text","aria-roledescription":"numberfield","aria-valuemin":state.context.min,"aria-valuemax":state.context.max,"aria-valuenow":Number.isNaN(state.context.valueAsNumber)?void 0:state.context.valueAsNumber,"aria-valuetext":state.context.valueText,onFocus(){send("INPUT.FOCUS")},onBlur(){send({type:"INPUT.COMMIT",src:"blur"})},onChange(event){send({type:"INPUT.CHANGE",target:event.currentTarget,hint:"set"})},onBeforeInput(event){try{const{selectionStart,selectionEnd,value}=event.currentTarget;const nextValue=value.slice(0,selectionStart)+(event.data??"")+value.slice(selectionEnd);const isValid=state.context.parser.isValidPartialNumber(nextValue);if(!isValid){event.preventDefault()}}catch{}},onKeyDown(event){if(event.defaultPrevented)return;if(readOnly)return;const evt=(0,import_dom_event.getNativeEvent)(event);if(evt.isComposing)return;const step=(0,import_dom_event.getEventStep)(event)*state.context.step;const keyMap={ArrowUp(){send({type:"INPUT.ARROW_UP",step});event.preventDefault()},ArrowDown(){send({type:"INPUT.ARROW_DOWN",step});event.preventDefault()},Home(){send("INPUT.HOME");event.preventDefault()},End(){send("INPUT.END");event.preventDefault()},Enter(){send({type:"INPUT.COMMIT",src:"enter"})}};const exec=keyMap[event.key];exec?.(event)}}),decrementTriggerProps:normalize.button({...parts.decrementTrigger.attrs,dir:state.context.dir,id:dom.getDecrementTriggerId(state.context),disabled:isDecrementDisabled,"data-disabled":(0,import_dom_query2.dataAttr)(isDecrementDisabled),"aria-label":translations.decrementLabel,type:"button",tabIndex:-1,"aria-controls":dom.getInputId(state.context),onPointerDown(event){if(isDecrementDisabled||!(0,import_dom_event.isLeftClick)(event))return;send({type:"TRIGGER.PRESS_DOWN",hint:"decrement",pointerType:event.pointerType});if(event.pointerType==="mouse"){event.preventDefault()}if(event.pointerType==="touch"){event.currentTarget?.focus({preventScroll:true})}},onPointerUp(event){send({type:"TRIGGER.PRESS_UP",hint:"decrement",pointerType:event.pointerType})},onPointerLeave(){if(isDecrementDisabled)return;send({type:"TRIGGER.PRESS_UP",hint:"decrement"})}}),incrementTriggerProps:normalize.button({...parts.incrementTrigger.attrs,dir:state.context.dir,id:dom.getIncrementTriggerId(state.context),disabled:isIncrementDisabled,"data-disabled":(0,import_dom_query2.dataAttr)(isIncrementDisabled),"aria-label":translations.incrementLabel,type:"button",tabIndex:-1,"aria-controls":dom.getInputId(state.context),onPointerDown(event){if(isIncrementDisabled||!(0,import_dom_event.isLeftClick)(event))return;send({type:"TRIGGER.PRESS_DOWN",hint:"increment",pointerType:event.pointerType});if(event.pointerType==="mouse"){event.preventDefault()}if(event.pointerType==="touch"){event.currentTarget?.focus({preventScroll:true})}},onPointerUp(event){send({type:"TRIGGER.PRESS_UP",hint:"increment",pointerType:event.pointerType})},onPointerLeave(event){send({type:"TRIGGER.PRESS_UP",hint:"increment",pointerType:event.pointerType})}}),scrubberProps:normalize.element({...parts.scrubber.attrs,dir:state.context.dir,"data-disabled":(0,import_dom_query2.dataAttr)(disabled),id:dom.getScrubberId(state.context),role:"presentation",onMouseDown(event){if(disabled)return;const evt=(0,import_dom_event.getNativeEvent)(event);const point=(0,import_dom_event.getEventPoint)(evt);point.x=point.x-(0,import_number_utils2.roundToDevicePixel)(7.5);point.y=point.y-(0,import_number_utils2.roundToDevicePixel)(7.5);send({type:"SCRUBBER.PRESS_DOWN",point});event.preventDefault()},style:{cursor:disabled?void 0:"ew-resize"}})}}var import_core2=require("@zag-js/core");var import_dom_event2=require("@zag-js/dom-event");var import_dom_query3=require("@zag-js/dom-query");var import_form_utils=require("@zag-js/form-utils");var import_number_utils3=require("@zag-js/number-utils");var import_utils=require("@zag-js/utils");function recordCursor(inputEl){if(inputEl.ownerDocument.activeElement!==inputEl)return;try{const{selectionStart:start,selectionEnd:end,value}=inputEl;const beforeTxt=value.substring(0,start);const afterTxt=value.substring(end);return{start,end,value,beforeTxt,afterTxt}}catch{}}function restoreCursor(inputEl,selection){if(inputEl.ownerDocument.activeElement!==inputEl)return;if(!selection){inputEl.setSelectionRange(inputEl.value.length,inputEl.value.length);return}try{const{value}=inputEl;const{beforeTxt="",afterTxt="",start}=selection;let startPos=value.length;if(value.endsWith(afterTxt)){startPos=value.length-afterTxt.length}else if(value.startsWith(beforeTxt)){startPos=beforeTxt.length}else if(start!=null){const beforeLastChar=beforeTxt[start-1];const newIndex=value.indexOf(beforeLastChar,start-1);if(newIndex!==-1){startPos=newIndex+1}}inputEl.setSelectionRange(startPos,startPos)}catch{}}var import_number=require("@internationalized/number");var import_core=require("@zag-js/core");var createFormatter=(locale,options={})=>{return(0,import_core.ref)(new Intl.NumberFormat(locale,options))};var createParser=(locale,options={})=>{return(0,import_core.ref)(new import_number.NumberParser(locale,options))};var parseValue=(ctx,value)=>{if(!ctx.formatOptions)return parseFloat(value);return ctx.parser.parse(String(value))};var formatValue=(ctx,value)=>{if(Number.isNaN(value))return"";if(!ctx.formatOptions)return value.toString();return ctx.formatter.format(value)};var{not,and}=import_core2.guards;function machine(userContext){const ctx=(0,import_utils.compact)(userContext);return(0,import_core2.createMachine)({id:"number-input",initial:"idle",context:{dir:"ltr",locale:"en-US",focusInputOnChange:true,clampValueOnBlur:true,allowOverflow:false,inputMode:"decimal",pattern:"[0-9]*(.[0-9]+)?",value:"",step:1,min:Number.MIN_SAFE_INTEGER,max:Number.MAX_SAFE_INTEGER,invalid:false,spinOnPress:true,...ctx,hint:null,scrubberCursorPoint:null,fieldsetDisabled:false,formatter:createFormatter(ctx.locale||"en-US",ctx.formatOptions),parser:createParser(ctx.locale||"en-US",ctx.formatOptions),translations:{incrementLabel:"increment value",decrementLabel:"decrease value",...ctx.translations}},computed:{isRtl:ctx2=>ctx2.dir==="rtl",valueAsNumber:ctx2=>parseValue(ctx2,ctx2.value),formattedValue:ctx2=>formatValue(ctx2,ctx2.valueAsNumber),isAtMin:ctx2=>(0,import_number_utils3.isAtMin)(ctx2.valueAsNumber,ctx2),isAtMax:ctx2=>(0,import_number_utils3.isAtMax)(ctx2.valueAsNumber,ctx2),isOutOfRange:ctx2=>!(0,import_number_utils3.isWithinRange)(ctx2.valueAsNumber,ctx2),isValueEmpty:ctx2=>ctx2.value==="",isDisabled:ctx2=>!!ctx2.disabled||ctx2.fieldsetDisabled,canIncrement:ctx2=>ctx2.allowOverflow||!ctx2.isAtMax,canDecrement:ctx2=>ctx2.allowOverflow||!ctx2.isAtMin,valueText:ctx2=>ctx2.translations.valueText?.(ctx2.value)},watch:{formatOptions:["setFormatterAndParser","syncInputElement"],locale:["setFormatterAndParser","syncInputElement"],value:["syncInputElement"],isOutOfRange:["invokeOnInvalid"],scrubberCursorPoint:["setVirtualCursorPosition"]},activities:["trackFormControl"],on:{"VALUE.SET":{actions:["setRawValue","setHintToSet"]},"VALUE.CLEAR":{actions:["clearValue"]},"VALUE.INCREMENT":{actions:["increment"]},"VALUE.DECREMENT":{actions:["decrement"]}},states:{idle:{on:{"TRIGGER.PRESS_DOWN":[{guard:"isTouchPointer",target:"before:spin",actions:["setHint"]},{target:"before:spin",actions:["focusInput","invokeOnFocus","setHint"]}],"SCRUBBER.PRESS_DOWN":{target:"scrubbing",actions:["focusInput","invokeOnFocus","setHint","setCursorPoint"]},"INPUT.FOCUS":{target:"focused",actions:["focusInput","invokeOnFocus"]}}},focused:{tags:"focus",activities:"attachWheelListener",on:{"TRIGGER.PRESS_DOWN":[{guard:"isTouchPointer",target:"before:spin",actions:["setHint"]},{target:"before:spin",actions:["focusInput","setHint"]}],"SCRUBBER.PRESS_DOWN":{target:"scrubbing",actions:["focusInput","setHint","setCursorPoint"]},"INPUT.ARROW_UP":{actions:"increment"},"INPUT.ARROW_DOWN":{actions:"decrement"},"INPUT.HOME":{actions:"decrementToMin"},"INPUT.END":{actions:"incrementToMax"},"INPUT.CHANGE":{actions:["setValue","setHint"]},"INPUT.COMMIT":[{guard:and("clampValueOnBlur",not("isInRange")),target:"idle",actions:["setClampedValue","clearHint","invokeOnBlur"]},{target:"idle",actions:["setFormattedValue","clearHint","invokeOnBlur"]}]}},"before:spin":{tags:"focus",activities:"trackButtonDisabled",entry:(0,import_core2.choose)([{guard:"isIncrementHint",actions:"increment"},{guard:"isDecrementHint",actions:"decrement"}]),after:{CHANGE_DELAY:{target:"spinning",guard:and("isInRange","spinOnPress")}},on:{"TRIGGER.PRESS_UP":[{guard:"isTouchPointer",target:"focused",actions:"clearHint"},{target:"focused",actions:["focusInput","clearHint"]}]}},spinning:{tags:"focus",activities:"trackButtonDisabled",every:[{delay:"CHANGE_INTERVAL",guard:and(not("isAtMin"),"isIncrementHint"),actions:"increment"},{delay:"CHANGE_INTERVAL",guard:and(not("isAtMax"),"isDecrementHint"),actions:"decrement"}],on:{"TRIGGER.PRESS_UP":{target:"focused",actions:["focusInput","clearHint"]}}},scrubbing:{tags:"focus",activities:["activatePointerLock","trackMousemove","setupVirtualCursor","preventTextSelection"],on:{"SCRUBBER.POINTER_UP":{target:"focused",actions:["focusInput","clearCursorPoint"]},"SCRUBBER.POINTER_MOVE":[{guard:"isIncrementHint",actions:["increment","setCursorPoint"]},{guard:"isDecrementHint",actions:["decrement","setCursorPoint"]}]}}}},{delays:{CHANGE_INTERVAL:50,CHANGE_DELAY:300},guards:{clampValueOnBlur:ctx2=>ctx2.clampValueOnBlur,isAtMin:ctx2=>ctx2.isAtMin,spinOnPress:ctx2=>!!ctx2.spinOnPress,isAtMax:ctx2=>ctx2.isAtMax,isInRange:ctx2=>!ctx2.isOutOfRange,isDecrementHint:(ctx2,evt)=>(evt.hint??ctx2.hint)==="decrement",isIncrementHint:(ctx2,evt)=>(evt.hint??ctx2.hint)==="increment",isTouchPointer:(_ctx,evt)=>evt.pointerType==="touch"},activities:{trackFormControl(ctx2,_evt,{initialContext}){const inputEl=dom.getInputEl(ctx2);return(0,import_form_utils.trackFormControl)(inputEl,{onFieldsetDisabledChange(disabled){ctx2.fieldsetDisabled=disabled},onFormReset(){set.value(ctx2,initialContext.value)}})},setupVirtualCursor(ctx2){return dom.setupVirtualCursor(ctx2)},preventTextSelection(ctx2){return dom.preventTextSelection(ctx2)},trackButtonDisabled(ctx2,_evt,{send}){const btn=dom.getPressedTriggerEl(ctx2,ctx2.hint);return(0,import_dom_query3.observeAttributes)(btn,{attributes:["disabled"],callback(){send({type:"TRIGGER.PRESS_UP",src:"attr"})}})},attachWheelListener(ctx2,_evt,{send}){const inputEl=dom.getInputEl(ctx2);if(!inputEl||!dom.isActiveElement(ctx2,inputEl)||!ctx2.allowMouseWheel)return;function onWheel(event){event.preventDefault();const dir=Math.sign(event.deltaY)*-1;if(dir===1){send("VALUE.INCREMENT")}else if(dir===-1){send("VALUE.DECREMENT")}}return(0,import_dom_event2.addDomEvent)(inputEl,"wheel",onWheel,{passive:false})},activatePointerLock(ctx2){if((0,import_dom_query3.isSafari)())return;return(0,import_dom_event2.requestPointerLock)(dom.getDoc(ctx2))},trackMousemove(ctx2,_evt,{send}){const doc=dom.getDoc(ctx2);function onMousemove(event){if(!ctx2.scrubberCursorPoint)return;const value=dom.getMousementValue(ctx2,event);if(!value.hint)return;send({type:"SCRUBBER.POINTER_MOVE",hint:value.hint,point:value.point})}function onMouseup(){send("SCRUBBER.POINTER_UP")}return(0,import_utils.callAll)((0,import_dom_event2.addDomEvent)(doc,"mousemove",onMousemove,false),(0,import_dom_event2.addDomEvent)(doc,"mouseup",onMouseup,false))}},actions:{focusInput(ctx2){if(!ctx2.focusInputOnChange)return;const inputEl=dom.getInputEl(ctx2);if(dom.isActiveElement(ctx2,inputEl))return;(0,import_dom_query3.raf)(()=>inputEl?.focus({preventScroll:true}))},increment(ctx2,evt){const nextValue=(0,import_number_utils3.increment)(ctx2.valueAsNumber,evt.step??ctx2.step);const value=formatValue(ctx2,(0,import_number_utils3.clamp)(nextValue,ctx2));set.value(ctx2,value)},decrement(ctx2,evt){const nextValue=(0,import_number_utils3.decrement)(ctx2.valueAsNumber,evt.step??ctx2.step);const value=formatValue(ctx2,(0,import_number_utils3.clamp)(nextValue,ctx2));set.value(ctx2,value)},setClampedValue(ctx2){const nextValue=(0,import_number_utils3.clamp)(ctx2.valueAsNumber,ctx2);set.value(ctx2,formatValue(ctx2,nextValue))},setRawValue(ctx2,evt){const parsedValue=parseValue(ctx2,evt.value);const value=formatValue(ctx2,(0,import_number_utils3.clamp)(parsedValue,ctx2));set.value(ctx2,value)},setValue(ctx2,evt){const value=evt.target?.value??evt.value;set.value(ctx2,value)},clearValue(ctx2){set.value(ctx2,"")},incrementToMax(ctx2){const value=formatValue(ctx2,ctx2.max);set.value(ctx2,value)},decrementToMin(ctx2){const value=formatValue(ctx2,ctx2.min);set.value(ctx2,value)},setHint(ctx2,evt){ctx2.hint=evt.hint},clearHint(ctx2){ctx2.hint=null},setHintToSet(ctx2){ctx2.hint="set"},invokeOnFocus(ctx2){ctx2.onFocusChange?.({focused:true,value:ctx2.formattedValue,valueAsNumber:ctx2.valueAsNumber})},invokeOnBlur(ctx2){ctx2.onFocusChange?.({focused:false,value:ctx2.formattedValue,valueAsNumber:ctx2.valueAsNumber})},invokeOnInvalid(ctx2){if(!ctx2.isOutOfRange)return;const reason=ctx2.valueAsNumber>ctx2.max?"rangeOverflow":"rangeUnderflow";ctx2.onValueInvalid?.({reason,value:ctx2.formattedValue,valueAsNumber:ctx2.valueAsNumber})},syncInputElement(ctx2,evt){const value=evt.type.endsWith("CHANGE")?ctx2.value:ctx2.formattedValue;sync.input(ctx2,value)},setFormattedValue(ctx2){set.value(ctx2,ctx2.formattedValue)},setCursorPoint(ctx2,evt){ctx2.scrubberCursorPoint=evt.point},clearCursorPoint(ctx2){ctx2.scrubberCursorPoint=null},setVirtualCursorPosition(ctx2){const cursorEl=dom.getCursorEl(ctx2);if(!cursorEl||!ctx2.scrubberCursorPoint)return;const{x,y}=ctx2.scrubberCursorPoint;cursorEl.style.transform=`translate3d(${x}px, ${y}px, 0px)`},setFormatterAndParser(ctx2){if(!ctx2.locale)return;ctx2.formatter=createFormatter(ctx2.locale,ctx2.formatOptions);ctx2.parser=createParser(ctx2.locale,ctx2.formatOptions)}},compareFns:{formatOptions:(a,b)=>(0,import_utils.isEqual)(a,b),scrubberCursorPoint:(a,b)=>(0,import_utils.isEqual)(a,b)}})}var sync={input(ctx,value){const inputEl=dom.getInputEl(ctx);if(!inputEl)return;const sel=recordCursor(inputEl);(0,import_dom_query3.raf)(()=>{dom.setValue(inputEl,value);restoreCursor(inputEl,sel)})}};var invoke={onChange:ctx=>{ctx.onValueChange?.({value:ctx.value,valueAsNumber:ctx.valueAsNumber})}};var set={value:(ctx,value)=>{if((0,import_utils.isEqual)(ctx.value,value))return;ctx.value=value;invoke.onChange(ctx)}};0&&(module.exports={anatomy,connect,machine});
|
|
865
8
|
//# sourceMappingURL=index.js.map
|