@zag-js/number-input 0.2.5 → 0.2.7
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/chunk-2SIS62IB.mjs +129 -0
- package/dist/chunk-7E3ZO263.mjs +540 -0
- package/dist/chunk-DDNK5RLW.mjs +169 -0
- package/dist/chunk-GWZPUXGU.mjs +53 -0
- package/dist/chunk-TSELS3UE.mjs +246 -0
- package/dist/chunk-XHRILSH3.mjs +17 -0
- package/dist/index.d.ts +7 -1092
- package/dist/index.js +41 -25
- package/dist/index.mjs +12 -1049
- package/dist/number-input.anatomy.d.ts +6 -0
- package/dist/number-input.anatomy.js +42 -0
- package/dist/number-input.anatomy.mjs +8 -0
- package/dist/number-input.connect.d.ts +28 -0
- package/dist/number-input.connect.js +560 -0
- package/dist/number-input.connect.mjs +10 -0
- package/dist/number-input.dom.d.ts +51 -0
- package/dist/number-input.dom.js +226 -0
- package/dist/number-input.dom.mjs +7 -0
- package/dist/number-input.machine.d.ts +7 -0
- package/dist/number-input.machine.js +847 -0
- package/dist/number-input.machine.mjs +9 -0
- package/dist/number-input.types.d.ts +217 -0
- package/dist/number-input.types.js +18 -0
- package/dist/number-input.types.mjs +0 -0
- package/dist/number-input.utils.d.ts +17 -0
- package/dist/number-input.utils.js +116 -0
- package/dist/number-input.utils.mjs +7 -0
- package/package.json +23 -13
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineDomHelpers,
|
|
3
|
+
isSafari,
|
|
4
|
+
roundToDevicePixel,
|
|
5
|
+
supportsPointerEvent,
|
|
6
|
+
wrap
|
|
7
|
+
} from "./chunk-DDNK5RLW.mjs";
|
|
8
|
+
|
|
9
|
+
// ../../utilities/dom/src/constants.ts
|
|
10
|
+
var MAX_Z_INDEX = 2147483647;
|
|
11
|
+
|
|
12
|
+
// src/number-input.dom.ts
|
|
13
|
+
var dom = defineDomHelpers({
|
|
14
|
+
getRootId: (ctx) => {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `number-input:${ctx.id}`;
|
|
17
|
+
},
|
|
18
|
+
getInputId: (ctx) => {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.input) != null ? _b : `number-input:${ctx.id}:input`;
|
|
21
|
+
},
|
|
22
|
+
getIncrementTriggerId: (ctx) => {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.incrementTrigger) != null ? _b : `number-input:${ctx.id}:inc`;
|
|
25
|
+
},
|
|
26
|
+
getDecrementTriggerId: (ctx) => {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.decrementTrigger) != null ? _b : `number-input:${ctx.id}:dec`;
|
|
29
|
+
},
|
|
30
|
+
getScrubberId: (ctx) => {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.scrubber) != null ? _b : `number-input:${ctx.id}:scrubber`;
|
|
33
|
+
},
|
|
34
|
+
getCursorId: (ctx) => `number-input:${ctx.id}:cursor`,
|
|
35
|
+
getLabelId: (ctx) => {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `number-input:${ctx.id}:label`;
|
|
38
|
+
},
|
|
39
|
+
getInputEl: (ctx) => dom.getById(ctx, dom.getInputId(ctx)),
|
|
40
|
+
getIncrementTriggerEl: (ctx) => dom.getById(ctx, dom.getIncrementTriggerId(ctx)),
|
|
41
|
+
getDecrementTriggerEl: (ctx) => dom.getById(ctx, dom.getDecrementTriggerId(ctx)),
|
|
42
|
+
getScrubberEl: (ctx) => dom.getById(ctx, dom.getScrubberId(ctx)),
|
|
43
|
+
getCursorEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getCursorId(ctx)),
|
|
44
|
+
getPressedTriggerEl: (ctx, hint = ctx.hint) => {
|
|
45
|
+
let btnEl = null;
|
|
46
|
+
if (hint === "increment") {
|
|
47
|
+
btnEl = dom.getIncrementTriggerEl(ctx);
|
|
48
|
+
}
|
|
49
|
+
if (hint === "decrement") {
|
|
50
|
+
btnEl = dom.getDecrementTriggerEl(ctx);
|
|
51
|
+
}
|
|
52
|
+
return btnEl;
|
|
53
|
+
},
|
|
54
|
+
setupVirtualCursor(ctx) {
|
|
55
|
+
if (isSafari() || !supportsPointerEvent())
|
|
56
|
+
return;
|
|
57
|
+
dom.createVirtualCursor(ctx);
|
|
58
|
+
return () => {
|
|
59
|
+
var _a;
|
|
60
|
+
(_a = dom.getCursorEl(ctx)) == null ? void 0 : _a.remove();
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
preventTextSelection(ctx) {
|
|
64
|
+
const doc = dom.getDoc(ctx);
|
|
65
|
+
const html = doc.documentElement;
|
|
66
|
+
const body = doc.body;
|
|
67
|
+
body.style.pointerEvents = "none";
|
|
68
|
+
html.style.userSelect = "none";
|
|
69
|
+
html.style.cursor = "ew-resize";
|
|
70
|
+
return () => {
|
|
71
|
+
body.style.pointerEvents = "";
|
|
72
|
+
html.style.userSelect = "";
|
|
73
|
+
html.style.cursor = "";
|
|
74
|
+
if (!html.style.length) {
|
|
75
|
+
html.removeAttribute("style");
|
|
76
|
+
}
|
|
77
|
+
if (!body.style.length) {
|
|
78
|
+
body.removeAttribute("style");
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
getMousementValue(ctx, event) {
|
|
83
|
+
const x = roundToDevicePixel(event.movementX);
|
|
84
|
+
const y = roundToDevicePixel(event.movementY);
|
|
85
|
+
let hint = x > 0 ? "increment" : x < 0 ? "decrement" : null;
|
|
86
|
+
if (ctx.isRtl && hint === "increment")
|
|
87
|
+
hint = "decrement";
|
|
88
|
+
if (ctx.isRtl && hint === "decrement")
|
|
89
|
+
hint = "increment";
|
|
90
|
+
const point = {
|
|
91
|
+
x: ctx.scrubberCursorPoint.x + x,
|
|
92
|
+
y: ctx.scrubberCursorPoint.y + y
|
|
93
|
+
};
|
|
94
|
+
const win = dom.getWin(ctx);
|
|
95
|
+
const width = win.innerWidth;
|
|
96
|
+
const half = roundToDevicePixel(7.5);
|
|
97
|
+
point.x = wrap(point.x + half, width) - half;
|
|
98
|
+
return { hint, point };
|
|
99
|
+
},
|
|
100
|
+
createVirtualCursor(ctx) {
|
|
101
|
+
const doc = dom.getDoc(ctx);
|
|
102
|
+
const el = doc.createElement("div");
|
|
103
|
+
el.className = "scrubber--cursor";
|
|
104
|
+
el.id = dom.getCursorId(ctx);
|
|
105
|
+
Object.assign(el.style, {
|
|
106
|
+
width: "15px",
|
|
107
|
+
height: "15px",
|
|
108
|
+
position: "fixed",
|
|
109
|
+
pointerEvents: "none",
|
|
110
|
+
left: "0px",
|
|
111
|
+
top: "0px",
|
|
112
|
+
zIndex: MAX_Z_INDEX,
|
|
113
|
+
transform: ctx.scrubberCursorPoint ? `translate3d(${ctx.scrubberCursorPoint.x}px, ${ctx.scrubberCursorPoint.y}px, 0px)` : void 0,
|
|
114
|
+
willChange: "transform"
|
|
115
|
+
});
|
|
116
|
+
el.innerHTML = `
|
|
117
|
+
<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);">
|
|
118
|
+
<g transform="translate(2 3)">
|
|
119
|
+
<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>
|
|
120
|
+
<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>
|
|
121
|
+
</g>
|
|
122
|
+
</svg>`;
|
|
123
|
+
doc.body.appendChild(el);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
export {
|
|
128
|
+
dom
|
|
129
|
+
};
|
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
import {
|
|
2
|
+
dom
|
|
3
|
+
} from "./chunk-2SIS62IB.mjs";
|
|
4
|
+
import {
|
|
5
|
+
utils
|
|
6
|
+
} from "./chunk-GWZPUXGU.mjs";
|
|
7
|
+
import {
|
|
8
|
+
getWindow,
|
|
9
|
+
hasProp,
|
|
10
|
+
isAtMax,
|
|
11
|
+
isAtMin,
|
|
12
|
+
isObject,
|
|
13
|
+
isSafari,
|
|
14
|
+
isWithinRange,
|
|
15
|
+
supportsPointerEvent,
|
|
16
|
+
valueOf
|
|
17
|
+
} from "./chunk-DDNK5RLW.mjs";
|
|
18
|
+
|
|
19
|
+
// src/number-input.machine.ts
|
|
20
|
+
import { choose, createMachine, guards } from "@zag-js/core";
|
|
21
|
+
|
|
22
|
+
// ../../utilities/core/src/functions.ts
|
|
23
|
+
var runIfFn = (v, ...a) => {
|
|
24
|
+
const res = typeof v === "function" ? v(...a) : v;
|
|
25
|
+
return res != null ? res : void 0;
|
|
26
|
+
};
|
|
27
|
+
var callAll = (...fns) => (...a) => {
|
|
28
|
+
fns.forEach(function(fn) {
|
|
29
|
+
fn == null ? void 0 : fn(...a);
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// ../../utilities/core/src/object.ts
|
|
34
|
+
function compact(obj) {
|
|
35
|
+
if (obj === void 0)
|
|
36
|
+
return obj;
|
|
37
|
+
return Object.fromEntries(
|
|
38
|
+
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// ../../utilities/dom/src/listener.ts
|
|
43
|
+
var isRef = (v) => hasProp(v, "current");
|
|
44
|
+
function addDomEvent(target, eventName, handler, options) {
|
|
45
|
+
const node = isRef(target) ? target.current : runIfFn(target);
|
|
46
|
+
node == null ? void 0 : node.addEventListener(eventName, handler, options);
|
|
47
|
+
return () => {
|
|
48
|
+
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ../../utilities/dom/src/mutation-observer.ts
|
|
53
|
+
function observeAttributes(node, attributes, fn) {
|
|
54
|
+
if (!node)
|
|
55
|
+
return;
|
|
56
|
+
const attrs = Array.isArray(attributes) ? attributes : [attributes];
|
|
57
|
+
const win = node.ownerDocument.defaultView || window;
|
|
58
|
+
const obs = new win.MutationObserver((changes) => {
|
|
59
|
+
for (const change of changes) {
|
|
60
|
+
if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
|
|
61
|
+
fn(change);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
obs.observe(node, { attributes: true, attributeFilter: attrs });
|
|
66
|
+
return () => obs.disconnect();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ../../utilities/dom/src/next-tick.ts
|
|
70
|
+
function raf(fn) {
|
|
71
|
+
const id = globalThis.requestAnimationFrame(fn);
|
|
72
|
+
return function cleanup() {
|
|
73
|
+
globalThis.cancelAnimationFrame(id);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ../../utilities/dom/src/pointerlock.ts
|
|
78
|
+
function addPointerlockChangeListener(doc, fn) {
|
|
79
|
+
return addDomEvent(doc, "pointerlockchange", fn, false);
|
|
80
|
+
}
|
|
81
|
+
function addPointerlockErrorListener(doc, fn) {
|
|
82
|
+
doc.addEventListener("pointerlockerror", fn, false);
|
|
83
|
+
return function cleanup() {
|
|
84
|
+
doc.removeEventListener("pointerlockerror", fn, false);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function requestPointerLock(doc, handlers = {}) {
|
|
88
|
+
const { onPointerLock, onPointerUnlock } = handlers;
|
|
89
|
+
const body = doc.body;
|
|
90
|
+
const supported = "pointerLockElement" in doc || "mozPointerLockElement" in doc;
|
|
91
|
+
const locked = !!doc.pointerLockElement;
|
|
92
|
+
function onPointerChange() {
|
|
93
|
+
if (locked)
|
|
94
|
+
onPointerLock == null ? void 0 : onPointerLock();
|
|
95
|
+
else
|
|
96
|
+
onPointerUnlock == null ? void 0 : onPointerUnlock();
|
|
97
|
+
}
|
|
98
|
+
function onPointerError(event) {
|
|
99
|
+
if (locked)
|
|
100
|
+
onPointerUnlock == null ? void 0 : onPointerUnlock();
|
|
101
|
+
console.error("PointerLock error occured:", event);
|
|
102
|
+
exit();
|
|
103
|
+
}
|
|
104
|
+
function exit() {
|
|
105
|
+
doc.exitPointerLock();
|
|
106
|
+
}
|
|
107
|
+
if (!supported)
|
|
108
|
+
return;
|
|
109
|
+
body.requestPointerLock();
|
|
110
|
+
const cleanup = callAll(
|
|
111
|
+
addPointerlockChangeListener(doc, onPointerChange),
|
|
112
|
+
addPointerlockErrorListener(doc, onPointerError)
|
|
113
|
+
);
|
|
114
|
+
return function dispose() {
|
|
115
|
+
if (!supported)
|
|
116
|
+
return;
|
|
117
|
+
cleanup();
|
|
118
|
+
exit();
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// ../../utilities/form-utils/src/input-event.ts
|
|
123
|
+
function getDescriptor(el, options) {
|
|
124
|
+
var _a;
|
|
125
|
+
const { type, property = "value" } = options;
|
|
126
|
+
const proto = getWindow(el)[type].prototype;
|
|
127
|
+
return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
|
|
128
|
+
}
|
|
129
|
+
function dispatchInputValueEvent(el, value) {
|
|
130
|
+
var _a;
|
|
131
|
+
if (!el)
|
|
132
|
+
return;
|
|
133
|
+
const win = getWindow(el);
|
|
134
|
+
if (!(el instanceof win.HTMLInputElement))
|
|
135
|
+
return;
|
|
136
|
+
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
137
|
+
(_a = desc.set) == null ? void 0 : _a.call(el, value);
|
|
138
|
+
const event = new win.Event("input", { bubbles: true });
|
|
139
|
+
el.dispatchEvent(event);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/number-input.machine.ts
|
|
143
|
+
var { not, and } = guards;
|
|
144
|
+
function machine(userContext) {
|
|
145
|
+
const ctx = compact(userContext);
|
|
146
|
+
return createMachine(
|
|
147
|
+
{
|
|
148
|
+
id: "number-input",
|
|
149
|
+
initial: "unknown",
|
|
150
|
+
context: {
|
|
151
|
+
dir: "ltr",
|
|
152
|
+
focusInputOnChange: true,
|
|
153
|
+
clampValueOnBlur: true,
|
|
154
|
+
allowOverflow: false,
|
|
155
|
+
inputMode: "decimal",
|
|
156
|
+
pattern: "[0-9]*(.[0-9]+)?",
|
|
157
|
+
hint: null,
|
|
158
|
+
value: "",
|
|
159
|
+
step: 1,
|
|
160
|
+
min: Number.MIN_SAFE_INTEGER,
|
|
161
|
+
max: Number.MAX_SAFE_INTEGER,
|
|
162
|
+
scrubberCursorPoint: null,
|
|
163
|
+
invalid: false,
|
|
164
|
+
spinOnPress: true,
|
|
165
|
+
...ctx,
|
|
166
|
+
translations: {
|
|
167
|
+
incrementLabel: "increment value",
|
|
168
|
+
decrementLabel: "decrease value",
|
|
169
|
+
...ctx.translations
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
computed: {
|
|
173
|
+
isRtl: (ctx2) => ctx2.dir === "rtl",
|
|
174
|
+
valueAsNumber: (ctx2) => valueOf(ctx2.value),
|
|
175
|
+
isAtMin: (ctx2) => isAtMin(ctx2.value, ctx2),
|
|
176
|
+
isAtMax: (ctx2) => isAtMax(ctx2.value, ctx2),
|
|
177
|
+
isOutOfRange: (ctx2) => !isWithinRange(ctx2.value, ctx2),
|
|
178
|
+
isValueEmpty: (ctx2) => ctx2.value === "",
|
|
179
|
+
canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
|
|
180
|
+
canDecrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMin,
|
|
181
|
+
valueText: (ctx2) => {
|
|
182
|
+
var _a, _b;
|
|
183
|
+
return (_b = (_a = ctx2.translations).valueText) == null ? void 0 : _b.call(_a, ctx2.value);
|
|
184
|
+
},
|
|
185
|
+
formattedValue: (ctx2) => {
|
|
186
|
+
var _a, _b;
|
|
187
|
+
return (_b = (_a = ctx2.format) == null ? void 0 : _a.call(ctx2, ctx2.value).toString()) != null ? _b : ctx2.value;
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
watch: {
|
|
191
|
+
value: ["invokeOnChange", "dispatchChangeEvent"],
|
|
192
|
+
isOutOfRange: ["invokeOnInvalid"],
|
|
193
|
+
scrubberCursorPoint: ["setVirtualCursorPosition"]
|
|
194
|
+
},
|
|
195
|
+
on: {
|
|
196
|
+
SET_VALUE: [
|
|
197
|
+
{
|
|
198
|
+
guard: "clampOnBlur",
|
|
199
|
+
actions: ["setValue", "clampValue", "setHintToSet"]
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
actions: ["setValue", "setHintToSet"]
|
|
203
|
+
}
|
|
204
|
+
],
|
|
205
|
+
CLEAR_VALUE: {
|
|
206
|
+
actions: ["clearValue"]
|
|
207
|
+
},
|
|
208
|
+
INCREMENT: {
|
|
209
|
+
actions: ["increment"]
|
|
210
|
+
},
|
|
211
|
+
DECREMENT: {
|
|
212
|
+
actions: ["decrement"]
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
states: {
|
|
216
|
+
unknown: {
|
|
217
|
+
on: {
|
|
218
|
+
SETUP: {
|
|
219
|
+
target: "idle",
|
|
220
|
+
actions: "syncInputValue"
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
idle: {
|
|
225
|
+
exit: "invokeOnFocus",
|
|
226
|
+
on: {
|
|
227
|
+
PRESS_DOWN: {
|
|
228
|
+
target: "before:spin",
|
|
229
|
+
actions: ["focusInput", "setHint"]
|
|
230
|
+
},
|
|
231
|
+
PRESS_DOWN_SCRUBBER: {
|
|
232
|
+
target: "scrubbing",
|
|
233
|
+
actions: ["focusInput", "setHint", "setCursorPoint"]
|
|
234
|
+
},
|
|
235
|
+
FOCUS: "focused"
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
focused: {
|
|
239
|
+
tags: "focus",
|
|
240
|
+
entry: "focusInput",
|
|
241
|
+
activities: "attachWheelListener",
|
|
242
|
+
on: {
|
|
243
|
+
PRESS_DOWN: {
|
|
244
|
+
target: "before:spin",
|
|
245
|
+
actions: ["focusInput", "setHint"]
|
|
246
|
+
},
|
|
247
|
+
PRESS_DOWN_SCRUBBER: {
|
|
248
|
+
target: "scrubbing",
|
|
249
|
+
actions: ["focusInput", "setHint", "setCursorPoint"]
|
|
250
|
+
},
|
|
251
|
+
ARROW_UP: {
|
|
252
|
+
actions: "increment"
|
|
253
|
+
},
|
|
254
|
+
ARROW_DOWN: {
|
|
255
|
+
actions: "decrement"
|
|
256
|
+
},
|
|
257
|
+
HOME: {
|
|
258
|
+
actions: "setToMin"
|
|
259
|
+
},
|
|
260
|
+
END: {
|
|
261
|
+
actions: "setToMax"
|
|
262
|
+
},
|
|
263
|
+
CHANGE: {
|
|
264
|
+
actions: ["setValue", "setHint"]
|
|
265
|
+
},
|
|
266
|
+
BLUR: [
|
|
267
|
+
{
|
|
268
|
+
guard: "isInvalidExponential",
|
|
269
|
+
target: "idle",
|
|
270
|
+
actions: ["clearValue", "clearHint", "invokeOnBlur"]
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
guard: and("clampOnBlur", not("isInRange"), not("isEmptyValue")),
|
|
274
|
+
target: "idle",
|
|
275
|
+
actions: ["clampValue", "clearHint", "invokeOnBlur"]
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
target: "idle",
|
|
279
|
+
actions: ["roundValue", "invokeOnBlur"]
|
|
280
|
+
}
|
|
281
|
+
]
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
"before:spin": {
|
|
285
|
+
tags: "focus",
|
|
286
|
+
activities: "trackButtonDisabled",
|
|
287
|
+
entry: choose([
|
|
288
|
+
{ guard: "isIncrementHint", actions: "increment" },
|
|
289
|
+
{ guard: "isDecrementHint", actions: "decrement" }
|
|
290
|
+
]),
|
|
291
|
+
after: {
|
|
292
|
+
CHANGE_DELAY: {
|
|
293
|
+
target: "spinning",
|
|
294
|
+
guard: and("isInRange", "spinOnPress")
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
on: {
|
|
298
|
+
PRESS_UP: {
|
|
299
|
+
target: "focused",
|
|
300
|
+
actions: "clearHint"
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
spinning: {
|
|
305
|
+
tags: "focus",
|
|
306
|
+
activities: "trackButtonDisabled",
|
|
307
|
+
every: [
|
|
308
|
+
{
|
|
309
|
+
delay: "CHANGE_INTERVAL",
|
|
310
|
+
guard: and(not("isAtMin"), "isIncrementHint"),
|
|
311
|
+
actions: "increment"
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
delay: "CHANGE_INTERVAL",
|
|
315
|
+
guard: and(not("isAtMax"), "isDecrementHint"),
|
|
316
|
+
actions: "decrement"
|
|
317
|
+
}
|
|
318
|
+
],
|
|
319
|
+
on: {
|
|
320
|
+
PRESS_UP: {
|
|
321
|
+
target: "focused",
|
|
322
|
+
actions: "clearHint"
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
scrubbing: {
|
|
327
|
+
tags: "focus",
|
|
328
|
+
exit: "clearCursorPoint",
|
|
329
|
+
activities: ["activatePointerLock", "trackMousemove", "setupVirtualCursor", "preventTextSelection"],
|
|
330
|
+
on: {
|
|
331
|
+
POINTER_UP_SCRUBBER: "focused",
|
|
332
|
+
POINTER_MOVE_SCRUBBER: [
|
|
333
|
+
{
|
|
334
|
+
guard: "isIncrementHint",
|
|
335
|
+
actions: ["increment", "setCursorPoint"]
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
guard: "isDecrementHint",
|
|
339
|
+
actions: ["decrement", "setCursorPoint"]
|
|
340
|
+
}
|
|
341
|
+
]
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
delays: {
|
|
348
|
+
CHANGE_INTERVAL: 50,
|
|
349
|
+
CHANGE_DELAY: 300
|
|
350
|
+
},
|
|
351
|
+
guards: {
|
|
352
|
+
clampOnBlur: (ctx2) => !!ctx2.clampValueOnBlur,
|
|
353
|
+
isAtMin: (ctx2) => ctx2.isAtMin,
|
|
354
|
+
spinOnPress: (ctx2) => !!ctx2.spinOnPress,
|
|
355
|
+
isAtMax: (ctx2) => ctx2.isAtMax,
|
|
356
|
+
isInRange: (ctx2) => !ctx2.isOutOfRange,
|
|
357
|
+
isDecrementHint: (ctx2, evt) => {
|
|
358
|
+
var _a;
|
|
359
|
+
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "decrement";
|
|
360
|
+
},
|
|
361
|
+
isEmptyValue: (ctx2) => ctx2.isValueEmpty,
|
|
362
|
+
isIncrementHint: (ctx2, evt) => {
|
|
363
|
+
var _a;
|
|
364
|
+
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "increment";
|
|
365
|
+
},
|
|
366
|
+
isInvalidExponential: (ctx2) => ctx2.value.toString().startsWith("e")
|
|
367
|
+
},
|
|
368
|
+
activities: {
|
|
369
|
+
setupVirtualCursor(ctx2) {
|
|
370
|
+
return dom.setupVirtualCursor(ctx2);
|
|
371
|
+
},
|
|
372
|
+
preventTextSelection(ctx2) {
|
|
373
|
+
return dom.preventTextSelection(ctx2);
|
|
374
|
+
},
|
|
375
|
+
trackButtonDisabled(ctx2, _evt, { send }) {
|
|
376
|
+
const btn = dom.getPressedTriggerEl(ctx2, ctx2.hint);
|
|
377
|
+
return observeAttributes(btn, "disabled", () => send("PRESS_UP"));
|
|
378
|
+
},
|
|
379
|
+
attachWheelListener(ctx2, _evt, { send }) {
|
|
380
|
+
const input = dom.getInputEl(ctx2);
|
|
381
|
+
if (!input)
|
|
382
|
+
return;
|
|
383
|
+
function onWheel(event) {
|
|
384
|
+
const isInputFocused = dom.getDoc(ctx2).activeElement === input;
|
|
385
|
+
if (!ctx2.allowMouseWheel || !isInputFocused)
|
|
386
|
+
return;
|
|
387
|
+
event.preventDefault();
|
|
388
|
+
const dir = Math.sign(event.deltaY) * -1;
|
|
389
|
+
if (dir === 1) {
|
|
390
|
+
send("INCREMENT");
|
|
391
|
+
} else if (dir === -1) {
|
|
392
|
+
send("DECREMENT");
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return addDomEvent(input, "wheel", onWheel, { passive: false });
|
|
396
|
+
},
|
|
397
|
+
activatePointerLock(ctx2) {
|
|
398
|
+
if (isSafari() || !supportsPointerEvent())
|
|
399
|
+
return;
|
|
400
|
+
return requestPointerLock(dom.getDoc(ctx2));
|
|
401
|
+
},
|
|
402
|
+
trackMousemove(ctx2, _evt, { send }) {
|
|
403
|
+
const doc = dom.getDoc(ctx2);
|
|
404
|
+
function onMousemove(event) {
|
|
405
|
+
if (!ctx2.scrubberCursorPoint)
|
|
406
|
+
return;
|
|
407
|
+
const value = dom.getMousementValue(ctx2, event);
|
|
408
|
+
if (!value.hint)
|
|
409
|
+
return;
|
|
410
|
+
send({
|
|
411
|
+
type: "POINTER_MOVE_SCRUBBER",
|
|
412
|
+
hint: value.hint,
|
|
413
|
+
point: value.point
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
function onMouseup() {
|
|
417
|
+
send("POINTER_UP_SCRUBBER");
|
|
418
|
+
}
|
|
419
|
+
return callAll(
|
|
420
|
+
addDomEvent(doc, "mousemove", onMousemove, false),
|
|
421
|
+
addDomEvent(doc, "mouseup", onMouseup, false)
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
},
|
|
425
|
+
actions: {
|
|
426
|
+
focusInput(ctx2) {
|
|
427
|
+
if (!ctx2.focusInputOnChange)
|
|
428
|
+
return;
|
|
429
|
+
const input = dom.getInputEl(ctx2);
|
|
430
|
+
raf(() => input == null ? void 0 : input.focus());
|
|
431
|
+
},
|
|
432
|
+
increment(ctx2, evt) {
|
|
433
|
+
ctx2.value = utils.increment(ctx2, evt.step);
|
|
434
|
+
},
|
|
435
|
+
decrement(ctx2, evt) {
|
|
436
|
+
ctx2.value = utils.decrement(ctx2, evt.step);
|
|
437
|
+
},
|
|
438
|
+
clampValue(ctx2) {
|
|
439
|
+
ctx2.value = utils.clamp(ctx2);
|
|
440
|
+
},
|
|
441
|
+
roundValue(ctx2) {
|
|
442
|
+
if (ctx2.value !== "") {
|
|
443
|
+
ctx2.value = utils.round(ctx2);
|
|
444
|
+
}
|
|
445
|
+
},
|
|
446
|
+
setValue(ctx2, evt) {
|
|
447
|
+
var _a, _b;
|
|
448
|
+
const value = (_b = (_a = evt.target) == null ? void 0 : _a.value) != null ? _b : evt.value;
|
|
449
|
+
ctx2.value = utils.sanitize(ctx2, utils.parse(ctx2, value.toString()));
|
|
450
|
+
},
|
|
451
|
+
clearValue(ctx2) {
|
|
452
|
+
ctx2.value = "";
|
|
453
|
+
},
|
|
454
|
+
setToMax(ctx2) {
|
|
455
|
+
ctx2.value = ctx2.max.toString();
|
|
456
|
+
},
|
|
457
|
+
setToMin(ctx2) {
|
|
458
|
+
ctx2.value = ctx2.min.toString();
|
|
459
|
+
},
|
|
460
|
+
setHint(ctx2, evt) {
|
|
461
|
+
ctx2.hint = evt.hint;
|
|
462
|
+
},
|
|
463
|
+
clearHint(ctx2) {
|
|
464
|
+
ctx2.hint = null;
|
|
465
|
+
},
|
|
466
|
+
setHintToSet(ctx2) {
|
|
467
|
+
ctx2.hint = "set";
|
|
468
|
+
},
|
|
469
|
+
invokeOnChange(ctx2) {
|
|
470
|
+
var _a;
|
|
471
|
+
(_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, {
|
|
472
|
+
value: ctx2.value,
|
|
473
|
+
valueAsNumber: ctx2.valueAsNumber
|
|
474
|
+
});
|
|
475
|
+
},
|
|
476
|
+
invokeOnFocus(ctx2, evt) {
|
|
477
|
+
var _a;
|
|
478
|
+
let srcElement = null;
|
|
479
|
+
if (evt.type === "PRESS_DOWN") {
|
|
480
|
+
srcElement = dom.getPressedTriggerEl(ctx2, evt.hint);
|
|
481
|
+
} else if (evt.type === "FOCUS") {
|
|
482
|
+
srcElement = dom.getInputEl(ctx2);
|
|
483
|
+
} else if (evt.type === "PRESS_DOWN_SCRUBBER") {
|
|
484
|
+
srcElement = dom.getScrubberEl(ctx2);
|
|
485
|
+
}
|
|
486
|
+
(_a = ctx2.onFocus) == null ? void 0 : _a.call(ctx2, {
|
|
487
|
+
value: ctx2.value,
|
|
488
|
+
valueAsNumber: ctx2.valueAsNumber,
|
|
489
|
+
srcElement
|
|
490
|
+
});
|
|
491
|
+
},
|
|
492
|
+
invokeOnBlur(ctx2) {
|
|
493
|
+
var _a;
|
|
494
|
+
(_a = ctx2.onBlur) == null ? void 0 : _a.call(ctx2, {
|
|
495
|
+
value: ctx2.value,
|
|
496
|
+
valueAsNumber: ctx2.valueAsNumber
|
|
497
|
+
});
|
|
498
|
+
},
|
|
499
|
+
invokeOnInvalid(ctx2) {
|
|
500
|
+
var _a;
|
|
501
|
+
if (!ctx2.isOutOfRange)
|
|
502
|
+
return;
|
|
503
|
+
const reason = ctx2.valueAsNumber > ctx2.max ? "rangeOverflow" : "rangeUnderflow";
|
|
504
|
+
(_a = ctx2.onInvalid) == null ? void 0 : _a.call(ctx2, {
|
|
505
|
+
reason,
|
|
506
|
+
value: ctx2.formattedValue,
|
|
507
|
+
valueAsNumber: ctx2.valueAsNumber
|
|
508
|
+
});
|
|
509
|
+
},
|
|
510
|
+
syncInputValue(ctx2) {
|
|
511
|
+
const input = dom.getInputEl(ctx2);
|
|
512
|
+
if (!input || input.value == ctx2.value)
|
|
513
|
+
return;
|
|
514
|
+
const value = utils.parse(ctx2, input.value);
|
|
515
|
+
ctx2.value = utils.sanitize(ctx2, value);
|
|
516
|
+
},
|
|
517
|
+
setCursorPoint(ctx2, evt) {
|
|
518
|
+
ctx2.scrubberCursorPoint = evt.point;
|
|
519
|
+
},
|
|
520
|
+
clearCursorPoint(ctx2) {
|
|
521
|
+
ctx2.scrubberCursorPoint = null;
|
|
522
|
+
},
|
|
523
|
+
setVirtualCursorPosition(ctx2) {
|
|
524
|
+
const cursor = dom.getCursorEl(ctx2);
|
|
525
|
+
if (!cursor || !ctx2.scrubberCursorPoint)
|
|
526
|
+
return;
|
|
527
|
+
const { x, y } = ctx2.scrubberCursorPoint;
|
|
528
|
+
cursor.style.transform = `translate3d(${x}px, ${y}px, 0px)`;
|
|
529
|
+
},
|
|
530
|
+
dispatchChangeEvent(ctx2) {
|
|
531
|
+
dispatchInputValueEvent(dom.getInputEl(ctx2), ctx2.formattedValue);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
export {
|
|
539
|
+
machine
|
|
540
|
+
};
|