@zag-js/number-input 0.1.12 → 0.1.15
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/LICENSE +21 -0
- package/dist/index.d.ts +239 -3
- package/dist/index.js +477 -439
- package/dist/index.mjs +474 -444
- package/package.json +14 -12
- package/dist/number-input.connect.d.ts +0 -23
- package/dist/number-input.dom.d.ts +0 -39
- package/dist/number-input.machine.d.ts +0 -2
- package/dist/number-input.types.d.ts +0 -212
- package/dist/number-input.utils.d.ts +0 -13
package/dist/index.mjs
CHANGED
|
@@ -1,40 +1,4 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
|
|
21
1
|
// ../../utilities/dom/dist/index.mjs
|
|
22
|
-
var __defProp2 = Object.defineProperty;
|
|
23
|
-
var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
|
|
24
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
25
|
-
var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
|
|
26
|
-
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
27
|
-
var __spreadValues2 = (a, b) => {
|
|
28
|
-
for (var prop in b || (b = {}))
|
|
29
|
-
if (__hasOwnProp2.call(b, prop))
|
|
30
|
-
__defNormalProp2(a, prop, b[prop]);
|
|
31
|
-
if (__getOwnPropSymbols2)
|
|
32
|
-
for (var prop of __getOwnPropSymbols2(b)) {
|
|
33
|
-
if (__propIsEnum2.call(b, prop))
|
|
34
|
-
__defNormalProp2(a, prop, b[prop]);
|
|
35
|
-
}
|
|
36
|
-
return a;
|
|
37
|
-
};
|
|
38
2
|
var dataAttr = (guard) => {
|
|
39
3
|
return guard ? "" : void 0;
|
|
40
4
|
};
|
|
@@ -44,7 +8,7 @@ var ariaAttr = (guard) => {
|
|
|
44
8
|
var MAX_Z_INDEX = 2147483647;
|
|
45
9
|
var runIfFn = (v, ...a) => {
|
|
46
10
|
const res = typeof v === "function" ? v(...a) : v;
|
|
47
|
-
return res
|
|
11
|
+
return res ?? void 0;
|
|
48
12
|
};
|
|
49
13
|
var callAll = (...fns) => (...a) => {
|
|
50
14
|
fns.forEach(function(fn) {
|
|
@@ -56,17 +20,13 @@ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
|
56
20
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
57
21
|
var isDom = () => typeof window !== "undefined";
|
|
58
22
|
function getPlatform() {
|
|
59
|
-
var _a;
|
|
60
23
|
const agent = navigator.userAgentData;
|
|
61
|
-
return (
|
|
24
|
+
return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
|
|
62
25
|
}
|
|
63
26
|
var pt = (v) => isDom() && v.test(getPlatform());
|
|
64
27
|
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
65
|
-
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
66
|
-
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
67
28
|
var isSafari = () => isApple() && vn(/apple/i);
|
|
68
29
|
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
69
|
-
var isIos = () => isApple() && !isMac();
|
|
70
30
|
function isDocument(el) {
|
|
71
31
|
return el.nodeType === Node.DOCUMENT_NODE;
|
|
72
32
|
}
|
|
@@ -74,52 +34,35 @@ function isWindow(value) {
|
|
|
74
34
|
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
75
35
|
}
|
|
76
36
|
function getDocument(el) {
|
|
77
|
-
var _a;
|
|
78
37
|
if (isWindow(el))
|
|
79
38
|
return el.document;
|
|
80
39
|
if (isDocument(el))
|
|
81
40
|
return el;
|
|
82
|
-
return (
|
|
41
|
+
return (el == null ? void 0 : el.ownerDocument) ?? document;
|
|
83
42
|
}
|
|
84
43
|
function defineDomHelpers(helpers) {
|
|
85
44
|
const dom2 = {
|
|
86
45
|
getRootNode: (ctx) => {
|
|
87
|
-
var _a, _b;
|
|
88
|
-
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
89
|
-
},
|
|
90
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
91
|
-
getWin: (ctx) => {
|
|
92
46
|
var _a;
|
|
93
|
-
return (_a =
|
|
47
|
+
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
|
|
94
48
|
},
|
|
49
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
50
|
+
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
95
51
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
96
52
|
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
97
53
|
};
|
|
98
|
-
return
|
|
54
|
+
return {
|
|
55
|
+
...dom2,
|
|
56
|
+
...helpers
|
|
57
|
+
};
|
|
99
58
|
}
|
|
100
59
|
function getNativeEvent(e) {
|
|
101
|
-
|
|
102
|
-
return (_a = e.nativeEvent) != null ? _a : e;
|
|
60
|
+
return e.nativeEvent ?? e;
|
|
103
61
|
}
|
|
104
62
|
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
105
63
|
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
106
64
|
var isLeftClick = (v) => v.button === 0;
|
|
107
65
|
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
108
|
-
function observeAttributes(node, attributes, fn) {
|
|
109
|
-
if (!node)
|
|
110
|
-
return;
|
|
111
|
-
const attrs = Array.isArray(attributes) ? attributes : [attributes];
|
|
112
|
-
const win = node.ownerDocument.defaultView || window;
|
|
113
|
-
const obs = new win.MutationObserver((changes) => {
|
|
114
|
-
for (const change of changes) {
|
|
115
|
-
if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
|
|
116
|
-
fn(change);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
obs.observe(node, { attributes: true, attributeFilter: attrs });
|
|
121
|
-
return () => obs.disconnect();
|
|
122
|
-
}
|
|
123
66
|
var fallback = {
|
|
124
67
|
pageX: 0,
|
|
125
68
|
pageY: 0,
|
|
@@ -127,8 +70,7 @@ var fallback = {
|
|
|
127
70
|
clientY: 0
|
|
128
71
|
};
|
|
129
72
|
function getEventPoint(event, type = "page") {
|
|
130
|
-
|
|
131
|
-
const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event;
|
|
73
|
+
const point = isTouchEvent(event) ? event.touches[0] ?? event.changedTouches[0] ?? fallback : event;
|
|
132
74
|
return { x: point[`${type}X`], y: point[`${type}Y`] };
|
|
133
75
|
}
|
|
134
76
|
var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
|
|
@@ -150,6 +92,21 @@ function addDomEvent(target, eventName, handler, options) {
|
|
|
150
92
|
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
151
93
|
};
|
|
152
94
|
}
|
|
95
|
+
function observeAttributes(node, attributes, fn) {
|
|
96
|
+
if (!node)
|
|
97
|
+
return;
|
|
98
|
+
const attrs = Array.isArray(attributes) ? attributes : [attributes];
|
|
99
|
+
const win = node.ownerDocument.defaultView || window;
|
|
100
|
+
const obs = new win.MutationObserver((changes) => {
|
|
101
|
+
for (const change of changes) {
|
|
102
|
+
if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
|
|
103
|
+
fn(change);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
obs.observe(node, { attributes: true, attributeFilter: attrs });
|
|
108
|
+
return () => obs.disconnect();
|
|
109
|
+
}
|
|
153
110
|
function raf(fn) {
|
|
154
111
|
const id = globalThis.requestAnimationFrame(fn);
|
|
155
112
|
return function cleanup() {
|
|
@@ -188,7 +145,10 @@ function requestPointerLock(doc, handlers = {}) {
|
|
|
188
145
|
if (!supported)
|
|
189
146
|
return;
|
|
190
147
|
body.requestPointerLock();
|
|
191
|
-
const cleanup = callAll(
|
|
148
|
+
const cleanup = callAll(
|
|
149
|
+
addPointerlockChangeListener(doc, onPointerChange),
|
|
150
|
+
addPointerlockErrorListener(doc, onPointerError)
|
|
151
|
+
);
|
|
192
152
|
return function dispose() {
|
|
193
153
|
if (!supported)
|
|
194
154
|
return;
|
|
@@ -198,7 +158,6 @@ function requestPointerLock(doc, handlers = {}) {
|
|
|
198
158
|
}
|
|
199
159
|
|
|
200
160
|
// ../../utilities/number/dist/index.mjs
|
|
201
|
-
var __pow = Math.pow;
|
|
202
161
|
function wrap(num, max) {
|
|
203
162
|
return (num % max + max) % max;
|
|
204
163
|
}
|
|
@@ -252,7 +211,7 @@ function isWithinRange(v, o) {
|
|
|
252
211
|
function decimalOperation(a, op, b) {
|
|
253
212
|
let result = op === "+" ? a + b : a - b;
|
|
254
213
|
if (a % 1 !== 0 || b % 1 !== 0) {
|
|
255
|
-
const multiplier =
|
|
214
|
+
const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
|
|
256
215
|
a = Math.round(a * multiplier);
|
|
257
216
|
b = Math.round(b * multiplier);
|
|
258
217
|
result = op === "+" ? a + b : a - b;
|
|
@@ -265,35 +224,73 @@ var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigit
|
|
|
265
224
|
// src/number-input.dom.ts
|
|
266
225
|
var dom = defineDomHelpers({
|
|
267
226
|
getRootId: (ctx) => {
|
|
268
|
-
var _a
|
|
269
|
-
return (
|
|
227
|
+
var _a;
|
|
228
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.root) ?? `number-input:${ctx.id}`;
|
|
270
229
|
},
|
|
271
230
|
getInputId: (ctx) => {
|
|
272
|
-
var _a
|
|
273
|
-
return (
|
|
231
|
+
var _a;
|
|
232
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.input) ?? `number-input:${ctx.id}:input`;
|
|
274
233
|
},
|
|
275
234
|
getIncButtonId: (ctx) => {
|
|
276
|
-
var _a
|
|
277
|
-
return (
|
|
235
|
+
var _a;
|
|
236
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.incBtn) ?? `number-input:${ctx.id}:inc-btn`;
|
|
278
237
|
},
|
|
279
238
|
getDecButtonId: (ctx) => {
|
|
280
|
-
var _a
|
|
281
|
-
return (
|
|
239
|
+
var _a;
|
|
240
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.decBtn) ?? `number-input:${ctx.id}:dec-btn`;
|
|
282
241
|
},
|
|
283
242
|
getScrubberId: (ctx) => {
|
|
284
|
-
var _a
|
|
285
|
-
return (
|
|
243
|
+
var _a;
|
|
244
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.scrubber) ?? `number-input:${ctx.id}:scrubber`;
|
|
286
245
|
},
|
|
287
246
|
getCursorId: (ctx) => `number-input:${ctx.id}:cursor`,
|
|
288
247
|
getLabelId: (ctx) => {
|
|
289
|
-
var _a
|
|
290
|
-
return (
|
|
248
|
+
var _a;
|
|
249
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.label) ?? `number-input:${ctx.id}:label`;
|
|
291
250
|
},
|
|
292
251
|
getInputEl: (ctx) => dom.getById(ctx, dom.getInputId(ctx)),
|
|
293
252
|
getIncButtonEl: (ctx) => dom.getById(ctx, dom.getIncButtonId(ctx)),
|
|
294
253
|
getDecButtonEl: (ctx) => dom.getById(ctx, dom.getDecButtonId(ctx)),
|
|
295
254
|
getScrubberEl: (ctx) => dom.getById(ctx, dom.getScrubberId(ctx)),
|
|
296
255
|
getCursorEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getCursorId(ctx)),
|
|
256
|
+
getActiveButton: (ctx, hint = ctx.hint) => {
|
|
257
|
+
let btnEl = null;
|
|
258
|
+
if (hint === "increment") {
|
|
259
|
+
btnEl = dom.getIncButtonEl(ctx);
|
|
260
|
+
}
|
|
261
|
+
if (hint === "decrement") {
|
|
262
|
+
btnEl = dom.getDecButtonEl(ctx);
|
|
263
|
+
}
|
|
264
|
+
return btnEl;
|
|
265
|
+
},
|
|
266
|
+
setupVirtualCursor(ctx) {
|
|
267
|
+
if (isSafari() || !supportsPointerEvent())
|
|
268
|
+
return;
|
|
269
|
+
dom.createVirtualCursor(ctx);
|
|
270
|
+
return () => {
|
|
271
|
+
var _a;
|
|
272
|
+
(_a = dom.getCursorEl(ctx)) == null ? void 0 : _a.remove();
|
|
273
|
+
};
|
|
274
|
+
},
|
|
275
|
+
preventTextSelection(ctx) {
|
|
276
|
+
const doc = dom.getDoc(ctx);
|
|
277
|
+
const html = doc.documentElement;
|
|
278
|
+
const body = doc.body;
|
|
279
|
+
body.style.pointerEvents = "none";
|
|
280
|
+
html.style.userSelect = "none";
|
|
281
|
+
html.style.cursor = "ew-resize";
|
|
282
|
+
return () => {
|
|
283
|
+
body.style.pointerEvents = "";
|
|
284
|
+
html.style.userSelect = "";
|
|
285
|
+
html.style.cursor = "";
|
|
286
|
+
if (!html.style.length) {
|
|
287
|
+
html.removeAttribute("style");
|
|
288
|
+
}
|
|
289
|
+
if (!body.style.length) {
|
|
290
|
+
body.removeAttribute("style");
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
},
|
|
297
294
|
getMousementValue(ctx, event) {
|
|
298
295
|
const x = roundToDevicePixel(event.movementX);
|
|
299
296
|
const y = roundToDevicePixel(event.movementY);
|
|
@@ -342,39 +339,38 @@ var dom = defineDomHelpers({
|
|
|
342
339
|
// src/number-input.utils.ts
|
|
343
340
|
var utils = {
|
|
344
341
|
isValidNumericEvent: (ctx, event) => {
|
|
345
|
-
var _a
|
|
342
|
+
var _a;
|
|
346
343
|
if (event.key == null)
|
|
347
344
|
return true;
|
|
348
345
|
const isModifier = isModifiedEvent(event);
|
|
349
346
|
const isSingleKey = event.key.length === 1;
|
|
350
347
|
if (isModifier || !isSingleKey)
|
|
351
348
|
return true;
|
|
352
|
-
return (
|
|
349
|
+
return ((_a = ctx.validateCharacter) == null ? void 0 : _a.call(ctx, event.key)) ?? utils.isFloatingPoint(event.key);
|
|
353
350
|
},
|
|
354
351
|
isFloatingPoint: (v) => /^[Ee0-9+\-.]$/.test(v),
|
|
355
352
|
sanitize: (ctx, value) => {
|
|
356
|
-
|
|
357
|
-
return value.split("").filter((_a = ctx.validateCharacter) != null ? _a : utils.isFloatingPoint).join("");
|
|
353
|
+
return value.split("").filter(ctx.validateCharacter ?? utils.isFloatingPoint).join("");
|
|
358
354
|
},
|
|
359
355
|
increment: (ctx, step) => {
|
|
360
|
-
const value = increment(ctx.value, step
|
|
356
|
+
const value = increment(ctx.value, step ?? ctx.step);
|
|
361
357
|
return formatDecimal(clamp(value, ctx), ctx);
|
|
362
358
|
},
|
|
363
359
|
decrement: (ctx, step) => {
|
|
364
|
-
const value = decrement(ctx.value, step
|
|
360
|
+
const value = decrement(ctx.value, step ?? ctx.step);
|
|
365
361
|
return formatDecimal(clamp(value, ctx), ctx);
|
|
366
362
|
},
|
|
367
363
|
clamp: (ctx) => {
|
|
368
364
|
return formatDecimal(clamp(ctx.value, ctx), ctx);
|
|
369
365
|
},
|
|
370
366
|
parse: (ctx, value) => {
|
|
371
|
-
var _a
|
|
372
|
-
return (
|
|
367
|
+
var _a;
|
|
368
|
+
return ((_a = ctx.parse) == null ? void 0 : _a.call(ctx, value)) ?? value;
|
|
373
369
|
},
|
|
374
370
|
format: (ctx, value) => {
|
|
375
|
-
var _a
|
|
371
|
+
var _a;
|
|
376
372
|
const _val = value.toString();
|
|
377
|
-
return (
|
|
373
|
+
return ((_a = ctx.format) == null ? void 0 : _a.call(ctx, _val)) ?? _val;
|
|
378
374
|
},
|
|
379
375
|
round: (ctx) => {
|
|
380
376
|
return formatDecimal(ctx.value, ctx);
|
|
@@ -418,6 +414,10 @@ function connect(state, send, normalize) {
|
|
|
418
414
|
var _a;
|
|
419
415
|
(_a = dom.getInputEl(state.context)) == null ? void 0 : _a.focus();
|
|
420
416
|
},
|
|
417
|
+
blur() {
|
|
418
|
+
var _a;
|
|
419
|
+
(_a = dom.getInputEl(state.context)) == null ? void 0 : _a.blur();
|
|
420
|
+
},
|
|
421
421
|
rootProps: normalize.element({
|
|
422
422
|
id: dom.getRootId(state.context),
|
|
423
423
|
"data-part": "root",
|
|
@@ -443,7 +443,7 @@ function connect(state, send, normalize) {
|
|
|
443
443
|
name: state.context.name,
|
|
444
444
|
id: dom.getInputId(state.context),
|
|
445
445
|
role: "spinbutton",
|
|
446
|
-
|
|
446
|
+
defaultValue: state.context.formattedValue,
|
|
447
447
|
pattern: state.context.pattern,
|
|
448
448
|
inputMode: state.context.inputMode,
|
|
449
449
|
"aria-invalid": isInvalid || void 0,
|
|
@@ -455,7 +455,7 @@ function connect(state, send, normalize) {
|
|
|
455
455
|
autoCorrect: "off",
|
|
456
456
|
spellCheck: "false",
|
|
457
457
|
type: "text",
|
|
458
|
-
"aria-roledescription":
|
|
458
|
+
"aria-roledescription": "numberfield",
|
|
459
459
|
"aria-valuemin": state.context.min,
|
|
460
460
|
"aria-valuemax": state.context.max,
|
|
461
461
|
"aria-valuenow": isNaN(state.context.valueAsNumber) ? void 0 : state.context.valueAsNumber,
|
|
@@ -581,386 +581,416 @@ var callAll2 = (...fns) => (...a) => {
|
|
|
581
581
|
});
|
|
582
582
|
};
|
|
583
583
|
|
|
584
|
+
// ../../utilities/form-utils/dist/index.mjs
|
|
585
|
+
function getWindow(el) {
|
|
586
|
+
return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
|
|
587
|
+
}
|
|
588
|
+
function getDescriptor(el, options) {
|
|
589
|
+
const { type, property } = options;
|
|
590
|
+
const proto = getWindow(el)[type].prototype;
|
|
591
|
+
return Object.getOwnPropertyDescriptor(proto, property) ?? {};
|
|
592
|
+
}
|
|
593
|
+
function dispatchInputValueEvent(el, value) {
|
|
594
|
+
var _a;
|
|
595
|
+
if (!el)
|
|
596
|
+
return;
|
|
597
|
+
const win = getWindow(el);
|
|
598
|
+
if (!(el instanceof win.HTMLInputElement))
|
|
599
|
+
return;
|
|
600
|
+
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
601
|
+
(_a = desc.set) == null ? void 0 : _a.call(el, value);
|
|
602
|
+
const event = new win.Event("input", { bubbles: true });
|
|
603
|
+
el.dispatchEvent(event);
|
|
604
|
+
}
|
|
605
|
+
|
|
584
606
|
// src/number-input.machine.ts
|
|
585
607
|
var { not, and } = guards;
|
|
586
608
|
function machine(ctx) {
|
|
587
|
-
return createMachine(
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
valueAsNumber: (ctx2) => valueOf(ctx2.value),
|
|
613
|
-
isAtMin: (ctx2) => isAtMin(ctx2.value, ctx2),
|
|
614
|
-
isAtMax: (ctx2) => isAtMax(ctx2.value, ctx2),
|
|
615
|
-
isOutOfRange: (ctx2) => !isWithinRange(ctx2.value, ctx2),
|
|
616
|
-
isValueEmpty: (ctx2) => ctx2.value === "",
|
|
617
|
-
canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
|
|
618
|
-
canDecrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMin,
|
|
619
|
-
valueText: (ctx2) => {
|
|
620
|
-
var _a, _b;
|
|
621
|
-
return (_b = (_a = ctx2.messages).valueText) == null ? void 0 : _b.call(_a, ctx2.value);
|
|
622
|
-
},
|
|
623
|
-
formattedValue: (ctx2) => {
|
|
624
|
-
var _a, _b;
|
|
625
|
-
return (_b = (_a = ctx2.format) == null ? void 0 : _a.call(ctx2, ctx2.value).toString()) != null ? _b : ctx2.value;
|
|
626
|
-
}
|
|
627
|
-
},
|
|
628
|
-
watch: {
|
|
629
|
-
value: ["invokeOnChange"],
|
|
630
|
-
isOutOfRange: ["invokeOnInvalid"]
|
|
631
|
-
},
|
|
632
|
-
on: {
|
|
633
|
-
SET_VALUE: {
|
|
634
|
-
actions: ["setValue", "setHintToSet"]
|
|
635
|
-
},
|
|
636
|
-
CLEAR_VALUE: {
|
|
637
|
-
actions: ["clearValue"]
|
|
638
|
-
},
|
|
639
|
-
INCREMENT: {
|
|
640
|
-
actions: ["increment"]
|
|
609
|
+
return createMachine(
|
|
610
|
+
{
|
|
611
|
+
id: "number-input",
|
|
612
|
+
initial: "unknown",
|
|
613
|
+
context: {
|
|
614
|
+
dir: "ltr",
|
|
615
|
+
focusInputOnChange: true,
|
|
616
|
+
clampValueOnBlur: true,
|
|
617
|
+
allowOverflow: false,
|
|
618
|
+
inputMode: "decimal",
|
|
619
|
+
pattern: "[0-9]*(.[0-9]+)?",
|
|
620
|
+
hint: null,
|
|
621
|
+
value: "",
|
|
622
|
+
step: 1,
|
|
623
|
+
min: Number.MIN_SAFE_INTEGER,
|
|
624
|
+
max: Number.MAX_SAFE_INTEGER,
|
|
625
|
+
scrubberCursorPoint: null,
|
|
626
|
+
invalid: false,
|
|
627
|
+
spinOnPress: true,
|
|
628
|
+
...ctx,
|
|
629
|
+
messages: {
|
|
630
|
+
incrementLabel: "increment value",
|
|
631
|
+
decrementLabel: "decrease value",
|
|
632
|
+
...ctx.messages
|
|
633
|
+
}
|
|
641
634
|
},
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
635
|
+
computed: {
|
|
636
|
+
isRtl: (ctx2) => ctx2.dir === "rtl",
|
|
637
|
+
valueAsNumber: (ctx2) => valueOf(ctx2.value),
|
|
638
|
+
isAtMin: (ctx2) => isAtMin(ctx2.value, ctx2),
|
|
639
|
+
isAtMax: (ctx2) => isAtMax(ctx2.value, ctx2),
|
|
640
|
+
isOutOfRange: (ctx2) => !isWithinRange(ctx2.value, ctx2),
|
|
641
|
+
isValueEmpty: (ctx2) => ctx2.value === "",
|
|
642
|
+
canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
|
|
643
|
+
canDecrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMin,
|
|
644
|
+
valueText: (ctx2) => {
|
|
645
|
+
var _a, _b;
|
|
646
|
+
return (_b = (_a = ctx2.messages).valueText) == null ? void 0 : _b.call(_a, ctx2.value);
|
|
647
|
+
},
|
|
648
|
+
formattedValue: (ctx2) => {
|
|
649
|
+
var _a;
|
|
650
|
+
return ((_a = ctx2.format) == null ? void 0 : _a.call(ctx2, ctx2.value).toString()) ?? ctx2.value;
|
|
653
651
|
}
|
|
654
652
|
},
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
653
|
+
watch: {
|
|
654
|
+
value: ["invokeOnChange", "dispatchChangeEvent"],
|
|
655
|
+
isOutOfRange: ["invokeOnInvalid"],
|
|
656
|
+
scrubberCursorPoint: ["setVirtualCursorPosition"]
|
|
657
|
+
},
|
|
658
|
+
on: {
|
|
659
|
+
SET_VALUE: [
|
|
660
|
+
{
|
|
661
|
+
guard: "clampOnBlur",
|
|
662
|
+
actions: ["setValue", "clampValue", "setHintToSet"]
|
|
664
663
|
},
|
|
665
|
-
|
|
664
|
+
{
|
|
665
|
+
actions: ["setValue", "setHintToSet"]
|
|
666
|
+
}
|
|
667
|
+
],
|
|
668
|
+
CLEAR_VALUE: {
|
|
669
|
+
actions: ["clearValue"]
|
|
670
|
+
},
|
|
671
|
+
INCREMENT: {
|
|
672
|
+
actions: ["increment"]
|
|
673
|
+
},
|
|
674
|
+
DECREMENT: {
|
|
675
|
+
actions: ["decrement"]
|
|
666
676
|
}
|
|
667
677
|
},
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
on: {
|
|
673
|
-
PRESS_DOWN: {
|
|
674
|
-
target: "before:spin",
|
|
675
|
-
actions: ["focusInput", "setHint"]
|
|
676
|
-
},
|
|
677
|
-
PRESS_DOWN_SCRUBBER: {
|
|
678
|
-
target: "scrubbing",
|
|
679
|
-
actions: ["focusInput", "setHint", "setCursorPoint"]
|
|
680
|
-
},
|
|
681
|
-
ARROW_UP: {
|
|
682
|
-
actions: "increment"
|
|
683
|
-
},
|
|
684
|
-
ARROW_DOWN: {
|
|
685
|
-
actions: "decrement"
|
|
686
|
-
},
|
|
687
|
-
HOME: {
|
|
688
|
-
actions: "setToMin"
|
|
689
|
-
},
|
|
690
|
-
END: {
|
|
691
|
-
actions: "setToMax"
|
|
692
|
-
},
|
|
693
|
-
CHANGE: {
|
|
694
|
-
actions: ["setValue", "setHint"]
|
|
695
|
-
},
|
|
696
|
-
BLUR: [
|
|
697
|
-
{
|
|
698
|
-
guard: "isInvalidExponential",
|
|
678
|
+
states: {
|
|
679
|
+
unknown: {
|
|
680
|
+
on: {
|
|
681
|
+
SETUP: {
|
|
699
682
|
target: "idle",
|
|
700
|
-
actions:
|
|
683
|
+
actions: "syncInputValue"
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
},
|
|
687
|
+
idle: {
|
|
688
|
+
exit: "invokeOnFocus",
|
|
689
|
+
on: {
|
|
690
|
+
PRESS_DOWN: {
|
|
691
|
+
target: "before:spin",
|
|
692
|
+
actions: ["focusInput", "setHint"]
|
|
701
693
|
},
|
|
702
|
-
{
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
actions: ["clampValue", "clearHint"]
|
|
694
|
+
PRESS_DOWN_SCRUBBER: {
|
|
695
|
+
target: "scrubbing",
|
|
696
|
+
actions: ["focusInput", "setHint", "setCursorPoint"]
|
|
706
697
|
},
|
|
707
|
-
|
|
708
|
-
target: "idle",
|
|
709
|
-
actions: "roundValue"
|
|
710
|
-
}
|
|
711
|
-
]
|
|
712
|
-
}
|
|
713
|
-
},
|
|
714
|
-
"before:spin": {
|
|
715
|
-
tags: ["focus"],
|
|
716
|
-
activities: "trackButtonDisabled",
|
|
717
|
-
entry: choose([
|
|
718
|
-
{ guard: "isIncrementHint", actions: "increment" },
|
|
719
|
-
{ guard: "isDecrementHint", actions: "decrement" }
|
|
720
|
-
]),
|
|
721
|
-
after: {
|
|
722
|
-
CHANGE_DELAY: {
|
|
723
|
-
target: "spinning",
|
|
724
|
-
guard: "isInRange"
|
|
698
|
+
FOCUS: "focused"
|
|
725
699
|
}
|
|
726
700
|
},
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
701
|
+
focused: {
|
|
702
|
+
tags: "focus",
|
|
703
|
+
entry: "focusInput",
|
|
704
|
+
activities: "attachWheelListener",
|
|
705
|
+
on: {
|
|
706
|
+
PRESS_DOWN: {
|
|
707
|
+
target: "before:spin",
|
|
708
|
+
actions: ["focusInput", "setHint"]
|
|
709
|
+
},
|
|
710
|
+
PRESS_DOWN_SCRUBBER: {
|
|
711
|
+
target: "scrubbing",
|
|
712
|
+
actions: ["focusInput", "setHint", "setCursorPoint"]
|
|
713
|
+
},
|
|
714
|
+
ARROW_UP: {
|
|
715
|
+
actions: "increment"
|
|
716
|
+
},
|
|
717
|
+
ARROW_DOWN: {
|
|
718
|
+
actions: "decrement"
|
|
719
|
+
},
|
|
720
|
+
HOME: {
|
|
721
|
+
actions: "setToMin"
|
|
722
|
+
},
|
|
723
|
+
END: {
|
|
724
|
+
actions: "setToMax"
|
|
725
|
+
},
|
|
726
|
+
CHANGE: {
|
|
727
|
+
actions: ["setValue", "setHint"]
|
|
728
|
+
},
|
|
729
|
+
BLUR: [
|
|
730
|
+
{
|
|
731
|
+
guard: "isInvalidExponential",
|
|
732
|
+
target: "idle",
|
|
733
|
+
actions: ["clearValue", "clearHint", "invokeOnBlur"]
|
|
734
|
+
},
|
|
735
|
+
{
|
|
736
|
+
guard: and("clampOnBlur", not("isInRange"), not("isEmptyValue")),
|
|
737
|
+
target: "idle",
|
|
738
|
+
actions: ["clampValue", "clearHint", "invokeOnBlur"]
|
|
739
|
+
},
|
|
740
|
+
{
|
|
741
|
+
target: "idle",
|
|
742
|
+
actions: ["roundValue", "invokeOnBlur"]
|
|
743
|
+
}
|
|
744
|
+
]
|
|
731
745
|
}
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
746
|
+
},
|
|
747
|
+
"before:spin": {
|
|
748
|
+
tags: "focus",
|
|
749
|
+
activities: "trackButtonDisabled",
|
|
750
|
+
entry: choose([
|
|
751
|
+
{ guard: "isIncrementHint", actions: "increment" },
|
|
752
|
+
{ guard: "isDecrementHint", actions: "decrement" }
|
|
753
|
+
]),
|
|
754
|
+
after: {
|
|
755
|
+
CHANGE_DELAY: {
|
|
756
|
+
target: "spinning",
|
|
757
|
+
guard: and("isInRange", "spinOnPress")
|
|
758
|
+
}
|
|
742
759
|
},
|
|
743
|
-
{
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
],
|
|
749
|
-
on: {
|
|
750
|
-
PRESS_UP: {
|
|
751
|
-
target: "focused",
|
|
752
|
-
actions: "clearHint"
|
|
760
|
+
on: {
|
|
761
|
+
PRESS_UP: {
|
|
762
|
+
target: "focused",
|
|
763
|
+
actions: "clearHint"
|
|
764
|
+
}
|
|
753
765
|
}
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
exit: ["removeCustomCursor", "restoreTextSelection"],
|
|
760
|
-
activities: ["activatePointerLock", "trackMousemove"],
|
|
761
|
-
on: {
|
|
762
|
-
POINTER_UP_SCRUBBER: {
|
|
763
|
-
target: "focused",
|
|
764
|
-
actions: "clearCursorPoint"
|
|
765
|
-
},
|
|
766
|
-
POINTER_MOVE_SCRUBBER: [
|
|
766
|
+
},
|
|
767
|
+
spinning: {
|
|
768
|
+
tags: "focus",
|
|
769
|
+
activities: "trackButtonDisabled",
|
|
770
|
+
every: [
|
|
767
771
|
{
|
|
768
|
-
|
|
769
|
-
|
|
772
|
+
delay: "CHANGE_INTERVAL",
|
|
773
|
+
guard: and(not("isAtMin"), "isIncrementHint"),
|
|
774
|
+
actions: "increment"
|
|
770
775
|
},
|
|
771
776
|
{
|
|
772
|
-
|
|
773
|
-
|
|
777
|
+
delay: "CHANGE_INTERVAL",
|
|
778
|
+
guard: and(not("isAtMax"), "isDecrementHint"),
|
|
779
|
+
actions: "decrement"
|
|
780
|
+
}
|
|
781
|
+
],
|
|
782
|
+
on: {
|
|
783
|
+
PRESS_UP: {
|
|
784
|
+
target: "focused",
|
|
785
|
+
actions: "clearHint"
|
|
774
786
|
}
|
|
775
|
-
|
|
787
|
+
}
|
|
788
|
+
},
|
|
789
|
+
scrubbing: {
|
|
790
|
+
tags: "focus",
|
|
791
|
+
exit: "clearCursorPoint",
|
|
792
|
+
activities: ["activatePointerLock", "trackMousemove", "setupVirtualCursor", "preventTextSelection"],
|
|
793
|
+
on: {
|
|
794
|
+
POINTER_UP_SCRUBBER: "focused",
|
|
795
|
+
POINTER_MOVE_SCRUBBER: [
|
|
796
|
+
{
|
|
797
|
+
guard: "isIncrementHint",
|
|
798
|
+
actions: ["increment", "setCursorPoint"]
|
|
799
|
+
},
|
|
800
|
+
{
|
|
801
|
+
guard: "isDecrementHint",
|
|
802
|
+
actions: ["decrement", "setCursorPoint"]
|
|
803
|
+
}
|
|
804
|
+
]
|
|
805
|
+
}
|
|
776
806
|
}
|
|
777
807
|
}
|
|
778
|
-
}
|
|
779
|
-
}, {
|
|
780
|
-
delays: {
|
|
781
|
-
CHANGE_INTERVAL: 50,
|
|
782
|
-
CHANGE_DELAY: 300
|
|
783
|
-
},
|
|
784
|
-
guards: {
|
|
785
|
-
clampOnBlur: (ctx2) => !!ctx2.clampValueOnBlur,
|
|
786
|
-
isAtMin: (ctx2) => ctx2.isAtMin,
|
|
787
|
-
isAtMax: (ctx2) => ctx2.isAtMax,
|
|
788
|
-
isInRange: (ctx2) => !ctx2.isOutOfRange,
|
|
789
|
-
isDecrementHint: (ctx2, evt) => {
|
|
790
|
-
var _a;
|
|
791
|
-
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "decrement";
|
|
792
|
-
},
|
|
793
|
-
isEmptyValue: (ctx2) => ctx2.isValueEmpty,
|
|
794
|
-
isIncrementHint: (ctx2, evt) => {
|
|
795
|
-
var _a;
|
|
796
|
-
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "increment";
|
|
797
|
-
},
|
|
798
|
-
isInvalidExponential: (ctx2) => ctx2.value.toString().startsWith("e")
|
|
799
808
|
},
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
809
|
+
{
|
|
810
|
+
delays: {
|
|
811
|
+
CHANGE_INTERVAL: 50,
|
|
812
|
+
CHANGE_DELAY: 300
|
|
813
|
+
},
|
|
814
|
+
guards: {
|
|
815
|
+
clampOnBlur: (ctx2) => !!ctx2.clampValueOnBlur,
|
|
816
|
+
isAtMin: (ctx2) => ctx2.isAtMin,
|
|
817
|
+
spinOnPress: (ctx2) => !!ctx2.spinOnPress,
|
|
818
|
+
isAtMax: (ctx2) => ctx2.isAtMax,
|
|
819
|
+
isInRange: (ctx2) => !ctx2.isOutOfRange,
|
|
820
|
+
isDecrementHint: (ctx2, evt) => (evt.hint ?? ctx2.hint) === "decrement",
|
|
821
|
+
isEmptyValue: (ctx2) => ctx2.isValueEmpty,
|
|
822
|
+
isIncrementHint: (ctx2, evt) => (evt.hint ?? ctx2.hint) === "increment",
|
|
823
|
+
isInvalidExponential: (ctx2) => ctx2.value.toString().startsWith("e")
|
|
824
|
+
},
|
|
825
|
+
activities: {
|
|
826
|
+
setupVirtualCursor(ctx2) {
|
|
827
|
+
return dom.setupVirtualCursor(ctx2);
|
|
828
|
+
},
|
|
829
|
+
preventTextSelection(ctx2) {
|
|
830
|
+
return dom.preventTextSelection(ctx2);
|
|
831
|
+
},
|
|
832
|
+
trackButtonDisabled(ctx2, _evt, { send }) {
|
|
833
|
+
const btn = dom.getActiveButton(ctx2, ctx2.hint);
|
|
834
|
+
return observeAttributes(btn, "disabled", () => send("PRESS_UP"));
|
|
835
|
+
},
|
|
836
|
+
attachWheelListener(ctx2, _evt, { send }) {
|
|
837
|
+
const input = dom.getInputEl(ctx2);
|
|
838
|
+
if (!input)
|
|
820
839
|
return;
|
|
821
|
-
event
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
840
|
+
function onWheel(event) {
|
|
841
|
+
const isInputFocused = dom.getDoc(ctx2).activeElement === input;
|
|
842
|
+
if (!ctx2.allowMouseWheel || !isInputFocused)
|
|
843
|
+
return;
|
|
844
|
+
event.preventDefault();
|
|
845
|
+
const dir = Math.sign(event.deltaY) * -1;
|
|
846
|
+
if (dir === 1) {
|
|
847
|
+
send("INCREMENT");
|
|
848
|
+
} else if (dir === -1) {
|
|
849
|
+
send("DECREMENT");
|
|
850
|
+
}
|
|
827
851
|
}
|
|
852
|
+
return addDomEvent(input, "wheel", onWheel, { passive: false });
|
|
853
|
+
},
|
|
854
|
+
activatePointerLock(ctx2) {
|
|
855
|
+
if (isSafari() || !supportsPointerEvent())
|
|
856
|
+
return;
|
|
857
|
+
return requestPointerLock(dom.getDoc(ctx2));
|
|
858
|
+
},
|
|
859
|
+
trackMousemove(ctx2, _evt, { send }) {
|
|
860
|
+
const doc = dom.getDoc(ctx2);
|
|
861
|
+
function onMousemove(event) {
|
|
862
|
+
if (!ctx2.scrubberCursorPoint)
|
|
863
|
+
return;
|
|
864
|
+
const value = dom.getMousementValue(ctx2, event);
|
|
865
|
+
if (!value.hint)
|
|
866
|
+
return;
|
|
867
|
+
send({
|
|
868
|
+
type: "POINTER_MOVE_SCRUBBER",
|
|
869
|
+
hint: value.hint,
|
|
870
|
+
point: value.point
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
function onMouseup() {
|
|
874
|
+
send("POINTER_UP_SCRUBBER");
|
|
875
|
+
}
|
|
876
|
+
return callAll2(
|
|
877
|
+
addDomEvent(doc, "mousemove", onMousemove, false),
|
|
878
|
+
addDomEvent(doc, "mouseup", onMouseup, false)
|
|
879
|
+
);
|
|
828
880
|
}
|
|
829
|
-
return addDomEvent(input, "wheel", onWheel, { passive: false });
|
|
830
881
|
},
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
return requestPointerLock(dom.getDoc(ctx2));
|
|
835
|
-
},
|
|
836
|
-
trackMousemove(ctx2, _evt, { send }) {
|
|
837
|
-
const doc = dom.getDoc(ctx2);
|
|
838
|
-
function onMousemove(event) {
|
|
839
|
-
if (!ctx2.scrubberCursorPoint)
|
|
882
|
+
actions: {
|
|
883
|
+
focusInput(ctx2) {
|
|
884
|
+
if (!ctx2.focusInputOnChange)
|
|
840
885
|
return;
|
|
841
|
-
const
|
|
842
|
-
|
|
886
|
+
const input = dom.getInputEl(ctx2);
|
|
887
|
+
raf(() => input == null ? void 0 : input.focus());
|
|
888
|
+
},
|
|
889
|
+
increment(ctx2, evt) {
|
|
890
|
+
ctx2.value = utils.increment(ctx2, evt.step);
|
|
891
|
+
},
|
|
892
|
+
decrement(ctx2, evt) {
|
|
893
|
+
ctx2.value = utils.decrement(ctx2, evt.step);
|
|
894
|
+
},
|
|
895
|
+
clampValue(ctx2) {
|
|
896
|
+
ctx2.value = utils.clamp(ctx2);
|
|
897
|
+
},
|
|
898
|
+
roundValue(ctx2) {
|
|
899
|
+
if (ctx2.value !== "") {
|
|
900
|
+
ctx2.value = utils.round(ctx2);
|
|
901
|
+
}
|
|
902
|
+
},
|
|
903
|
+
setValue(ctx2, evt) {
|
|
904
|
+
var _a;
|
|
905
|
+
const value = ((_a = evt.target) == null ? void 0 : _a.value) ?? evt.value;
|
|
906
|
+
ctx2.value = utils.sanitize(ctx2, utils.parse(ctx2, value.toString()));
|
|
907
|
+
},
|
|
908
|
+
clearValue(ctx2) {
|
|
909
|
+
ctx2.value = "";
|
|
910
|
+
},
|
|
911
|
+
setToMax(ctx2) {
|
|
912
|
+
ctx2.value = ctx2.max.toString();
|
|
913
|
+
},
|
|
914
|
+
setToMin(ctx2) {
|
|
915
|
+
ctx2.value = ctx2.min.toString();
|
|
916
|
+
},
|
|
917
|
+
setHint(ctx2, evt) {
|
|
918
|
+
ctx2.hint = evt.hint;
|
|
919
|
+
},
|
|
920
|
+
clearHint(ctx2) {
|
|
921
|
+
ctx2.hint = null;
|
|
922
|
+
},
|
|
923
|
+
setHintToSet(ctx2) {
|
|
924
|
+
ctx2.hint = "set";
|
|
925
|
+
},
|
|
926
|
+
invokeOnChange(ctx2) {
|
|
927
|
+
var _a;
|
|
928
|
+
(_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, {
|
|
929
|
+
value: ctx2.value,
|
|
930
|
+
valueAsNumber: ctx2.valueAsNumber
|
|
931
|
+
});
|
|
932
|
+
},
|
|
933
|
+
invokeOnFocus(ctx2, evt) {
|
|
934
|
+
var _a;
|
|
935
|
+
let srcElement = null;
|
|
936
|
+
if (evt.type === "PRESS_DOWN") {
|
|
937
|
+
srcElement = dom.getActiveButton(ctx2, evt.hint);
|
|
938
|
+
} else if (evt.type === "FOCUS") {
|
|
939
|
+
srcElement = dom.getInputEl(ctx2);
|
|
940
|
+
} else if (evt.type === "PRESS_DOWN_SCRUBBER") {
|
|
941
|
+
srcElement = dom.getScrubberEl(ctx2);
|
|
942
|
+
}
|
|
943
|
+
(_a = ctx2.onFocus) == null ? void 0 : _a.call(ctx2, {
|
|
944
|
+
value: ctx2.value,
|
|
945
|
+
valueAsNumber: ctx2.valueAsNumber,
|
|
946
|
+
srcElement
|
|
947
|
+
});
|
|
948
|
+
},
|
|
949
|
+
invokeOnBlur(ctx2) {
|
|
950
|
+
var _a;
|
|
951
|
+
(_a = ctx2.onBlur) == null ? void 0 : _a.call(ctx2, {
|
|
952
|
+
value: ctx2.value,
|
|
953
|
+
valueAsNumber: ctx2.valueAsNumber
|
|
954
|
+
});
|
|
955
|
+
},
|
|
956
|
+
invokeOnInvalid(ctx2) {
|
|
957
|
+
var _a;
|
|
958
|
+
if (!ctx2.isOutOfRange)
|
|
843
959
|
return;
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
960
|
+
const reason = ctx2.valueAsNumber > ctx2.max ? "rangeOverflow" : "rangeUnderflow";
|
|
961
|
+
(_a = ctx2.onInvalid) == null ? void 0 : _a.call(ctx2, {
|
|
962
|
+
reason,
|
|
963
|
+
value: ctx2.formattedValue,
|
|
964
|
+
valueAsNumber: ctx2.valueAsNumber
|
|
848
965
|
});
|
|
966
|
+
},
|
|
967
|
+
syncInputValue(ctx2) {
|
|
968
|
+
const input = dom.getInputEl(ctx2);
|
|
969
|
+
if (!input || input.value == ctx2.value)
|
|
970
|
+
return;
|
|
971
|
+
const value = utils.parse(ctx2, input.value);
|
|
972
|
+
ctx2.value = utils.sanitize(ctx2, value);
|
|
973
|
+
},
|
|
974
|
+
setCursorPoint(ctx2, evt) {
|
|
975
|
+
ctx2.scrubberCursorPoint = evt.point;
|
|
976
|
+
},
|
|
977
|
+
clearCursorPoint(ctx2) {
|
|
978
|
+
ctx2.scrubberCursorPoint = null;
|
|
979
|
+
},
|
|
980
|
+
setVirtualCursorPosition(ctx2) {
|
|
981
|
+
const cursor = dom.getCursorEl(ctx2);
|
|
982
|
+
if (!cursor || !ctx2.scrubberCursorPoint)
|
|
983
|
+
return;
|
|
984
|
+
const { x, y } = ctx2.scrubberCursorPoint;
|
|
985
|
+
cursor.style.transform = `translate3d(${x}px, ${y}px, 0px)`;
|
|
986
|
+
},
|
|
987
|
+
dispatchChangeEvent(ctx2) {
|
|
988
|
+
dispatchInputValueEvent(dom.getInputEl(ctx2), ctx2.formattedValue);
|
|
849
989
|
}
|
|
850
|
-
function onMouseup() {
|
|
851
|
-
send("POINTER_UP_SCRUBBER");
|
|
852
|
-
}
|
|
853
|
-
return callAll2(addDomEvent(doc, "mousemove", onMousemove, false), addDomEvent(doc, "mouseup", onMouseup, false));
|
|
854
|
-
}
|
|
855
|
-
},
|
|
856
|
-
actions: {
|
|
857
|
-
focusInput(ctx2) {
|
|
858
|
-
if (!ctx2.focusInputOnChange)
|
|
859
|
-
return;
|
|
860
|
-
const input = dom.getInputEl(ctx2);
|
|
861
|
-
raf(() => input == null ? void 0 : input.focus());
|
|
862
|
-
},
|
|
863
|
-
increment(ctx2, evt) {
|
|
864
|
-
ctx2.value = utils.increment(ctx2, evt.step);
|
|
865
|
-
},
|
|
866
|
-
decrement(ctx2, evt) {
|
|
867
|
-
ctx2.value = utils.decrement(ctx2, evt.step);
|
|
868
|
-
},
|
|
869
|
-
clampValue(ctx2) {
|
|
870
|
-
ctx2.value = utils.clamp(ctx2);
|
|
871
|
-
},
|
|
872
|
-
roundValue(ctx2) {
|
|
873
|
-
if (ctx2.value !== "") {
|
|
874
|
-
ctx2.value = utils.round(ctx2);
|
|
875
|
-
}
|
|
876
|
-
},
|
|
877
|
-
setValue(ctx2, evt) {
|
|
878
|
-
var _a, _b;
|
|
879
|
-
const value = (_b = (_a = evt.target) == null ? void 0 : _a.value) != null ? _b : evt.value;
|
|
880
|
-
ctx2.value = utils.sanitize(ctx2, utils.parse(ctx2, value.toString()));
|
|
881
|
-
},
|
|
882
|
-
clearValue(ctx2) {
|
|
883
|
-
ctx2.value = "";
|
|
884
|
-
},
|
|
885
|
-
setToMax(ctx2) {
|
|
886
|
-
ctx2.value = ctx2.max.toString();
|
|
887
|
-
},
|
|
888
|
-
setToMin(ctx2) {
|
|
889
|
-
ctx2.value = ctx2.min.toString();
|
|
890
|
-
},
|
|
891
|
-
setHint(ctx2, evt) {
|
|
892
|
-
ctx2.hint = evt.hint;
|
|
893
|
-
},
|
|
894
|
-
clearHint(ctx2) {
|
|
895
|
-
ctx2.hint = null;
|
|
896
|
-
},
|
|
897
|
-
setHintToSet(ctx2) {
|
|
898
|
-
ctx2.hint = "set";
|
|
899
|
-
},
|
|
900
|
-
invokeOnChange(ctx2) {
|
|
901
|
-
var _a;
|
|
902
|
-
(_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, {
|
|
903
|
-
value: ctx2.value,
|
|
904
|
-
valueAsNumber: ctx2.valueAsNumber
|
|
905
|
-
});
|
|
906
|
-
},
|
|
907
|
-
invokeOnInvalid(ctx2) {
|
|
908
|
-
var _a;
|
|
909
|
-
if (!ctx2.isOutOfRange)
|
|
910
|
-
return;
|
|
911
|
-
const reason = ctx2.valueAsNumber > ctx2.max ? "rangeOverflow" : "rangeUnderflow";
|
|
912
|
-
(_a = ctx2.onInvalid) == null ? void 0 : _a.call(ctx2, {
|
|
913
|
-
reason,
|
|
914
|
-
value: ctx2.formattedValue,
|
|
915
|
-
valueAsNumber: ctx2.valueAsNumber
|
|
916
|
-
});
|
|
917
|
-
},
|
|
918
|
-
syncInputValue(ctx2) {
|
|
919
|
-
const input = dom.getInputEl(ctx2);
|
|
920
|
-
if (!input || input.value == ctx2.value)
|
|
921
|
-
return;
|
|
922
|
-
const value = utils.parse(ctx2, input.value);
|
|
923
|
-
ctx2.value = utils.sanitize(ctx2, value);
|
|
924
990
|
},
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
clearCursorPoint(ctx2) {
|
|
929
|
-
ctx2.scrubberCursorPoint = null;
|
|
930
|
-
},
|
|
931
|
-
updateCursor(ctx2) {
|
|
932
|
-
const cursor = dom.getCursorEl(ctx2);
|
|
933
|
-
if (!cursor || !ctx2.scrubberCursorPoint)
|
|
934
|
-
return;
|
|
935
|
-
const { x, y } = ctx2.scrubberCursorPoint;
|
|
936
|
-
cursor.style.transform = `translate3d(${x}px, ${y}px, 0px)`;
|
|
937
|
-
},
|
|
938
|
-
addCustomCursor(ctx2) {
|
|
939
|
-
if (isSafari() || !supportsPointerEvent())
|
|
940
|
-
return;
|
|
941
|
-
dom.createVirtualCursor(ctx2);
|
|
942
|
-
},
|
|
943
|
-
removeCustomCursor(ctx2) {
|
|
944
|
-
var _a;
|
|
945
|
-
if (isSafari() || !supportsPointerEvent())
|
|
946
|
-
return;
|
|
947
|
-
(_a = dom.getCursorEl(ctx2)) == null ? void 0 : _a.remove();
|
|
948
|
-
},
|
|
949
|
-
disableTextSelection(ctx2) {
|
|
950
|
-
const doc = dom.getDoc(ctx2);
|
|
951
|
-
doc.body.style.pointerEvents = "none";
|
|
952
|
-
doc.documentElement.style.userSelect = "none";
|
|
953
|
-
doc.documentElement.style.cursor = "ew-resize";
|
|
954
|
-
},
|
|
955
|
-
restoreTextSelection(ctx2) {
|
|
956
|
-
const doc = dom.getDoc(ctx2);
|
|
957
|
-
doc.body.style.pointerEvents = "";
|
|
958
|
-
doc.documentElement.style.userSelect = "";
|
|
959
|
-
doc.documentElement.style.cursor = "";
|
|
960
|
-
}
|
|
961
|
-
},
|
|
962
|
-
hookSync: true
|
|
963
|
-
});
|
|
991
|
+
hookSync: true
|
|
992
|
+
}
|
|
993
|
+
);
|
|
964
994
|
}
|
|
965
995
|
export {
|
|
966
996
|
connect,
|