@zag-js/number-input 0.2.6 → 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,847 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/number-input.machine.ts
|
|
21
|
+
var number_input_machine_exports = {};
|
|
22
|
+
__export(number_input_machine_exports, {
|
|
23
|
+
machine: () => machine
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(number_input_machine_exports);
|
|
26
|
+
var import_core = require("@zag-js/core");
|
|
27
|
+
|
|
28
|
+
// ../../utilities/dom/src/constants.ts
|
|
29
|
+
var MAX_Z_INDEX = 2147483647;
|
|
30
|
+
|
|
31
|
+
// ../../utilities/core/src/functions.ts
|
|
32
|
+
var runIfFn = (v, ...a) => {
|
|
33
|
+
const res = typeof v === "function" ? v(...a) : v;
|
|
34
|
+
return res != null ? res : void 0;
|
|
35
|
+
};
|
|
36
|
+
var callAll = (...fns) => (...a) => {
|
|
37
|
+
fns.forEach(function(fn) {
|
|
38
|
+
fn == null ? void 0 : fn(...a);
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// ../../utilities/core/src/guard.ts
|
|
43
|
+
var isArray = (v) => Array.isArray(v);
|
|
44
|
+
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
45
|
+
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
46
|
+
|
|
47
|
+
// ../../utilities/core/src/object.ts
|
|
48
|
+
function compact(obj) {
|
|
49
|
+
if (obj === void 0)
|
|
50
|
+
return obj;
|
|
51
|
+
return Object.fromEntries(
|
|
52
|
+
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ../../utilities/dom/src/platform.ts
|
|
57
|
+
var isDom = () => typeof window !== "undefined";
|
|
58
|
+
function getPlatform() {
|
|
59
|
+
var _a;
|
|
60
|
+
const agent = navigator.userAgentData;
|
|
61
|
+
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
62
|
+
}
|
|
63
|
+
var pt = (v) => isDom() && v.test(getPlatform());
|
|
64
|
+
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
65
|
+
var isSafari = () => isApple() && vn(/apple/i);
|
|
66
|
+
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
67
|
+
|
|
68
|
+
// ../../utilities/dom/src/query.ts
|
|
69
|
+
function isDocument(el) {
|
|
70
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
71
|
+
}
|
|
72
|
+
function isWindow(value) {
|
|
73
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
74
|
+
}
|
|
75
|
+
function getDocument(el) {
|
|
76
|
+
var _a;
|
|
77
|
+
if (isWindow(el))
|
|
78
|
+
return el.document;
|
|
79
|
+
if (isDocument(el))
|
|
80
|
+
return el;
|
|
81
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
82
|
+
}
|
|
83
|
+
function getWindow(el) {
|
|
84
|
+
var _a;
|
|
85
|
+
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
86
|
+
}
|
|
87
|
+
function defineDomHelpers(helpers) {
|
|
88
|
+
const dom2 = {
|
|
89
|
+
getRootNode: (ctx) => {
|
|
90
|
+
var _a, _b;
|
|
91
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
92
|
+
},
|
|
93
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
94
|
+
getWin: (ctx) => {
|
|
95
|
+
var _a;
|
|
96
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
97
|
+
},
|
|
98
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
99
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
|
|
100
|
+
createEmitter: (ctx, target) => {
|
|
101
|
+
const win = dom2.getWin(ctx);
|
|
102
|
+
return function emit(evt, detail, options) {
|
|
103
|
+
const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
|
|
104
|
+
const eventName = `zag:${evt}`;
|
|
105
|
+
const init = { bubbles, cancelable, composed, detail };
|
|
106
|
+
const event = new win.CustomEvent(eventName, init);
|
|
107
|
+
target.dispatchEvent(event);
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
createListener: (target) => {
|
|
111
|
+
return function listen(evt, handler) {
|
|
112
|
+
const eventName = `zag:${evt}`;
|
|
113
|
+
const listener = (e) => handler(e);
|
|
114
|
+
target.addEventListener(eventName, listener);
|
|
115
|
+
return () => target.removeEventListener(eventName, listener);
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
return {
|
|
120
|
+
...dom2,
|
|
121
|
+
...helpers
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// ../../utilities/dom/src/event.ts
|
|
126
|
+
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
127
|
+
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
128
|
+
|
|
129
|
+
// ../../utilities/dom/src/listener.ts
|
|
130
|
+
var isRef = (v) => hasProp(v, "current");
|
|
131
|
+
function addDomEvent(target, eventName, handler, options) {
|
|
132
|
+
const node = isRef(target) ? target.current : runIfFn(target);
|
|
133
|
+
node == null ? void 0 : node.addEventListener(eventName, handler, options);
|
|
134
|
+
return () => {
|
|
135
|
+
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// ../../utilities/dom/src/mutation-observer.ts
|
|
140
|
+
function observeAttributes(node, attributes, fn) {
|
|
141
|
+
if (!node)
|
|
142
|
+
return;
|
|
143
|
+
const attrs = Array.isArray(attributes) ? attributes : [attributes];
|
|
144
|
+
const win = node.ownerDocument.defaultView || window;
|
|
145
|
+
const obs = new win.MutationObserver((changes) => {
|
|
146
|
+
for (const change of changes) {
|
|
147
|
+
if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
|
|
148
|
+
fn(change);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
obs.observe(node, { attributes: true, attributeFilter: attrs });
|
|
153
|
+
return () => obs.disconnect();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// ../../utilities/dom/src/next-tick.ts
|
|
157
|
+
function raf(fn) {
|
|
158
|
+
const id = globalThis.requestAnimationFrame(fn);
|
|
159
|
+
return function cleanup() {
|
|
160
|
+
globalThis.cancelAnimationFrame(id);
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// ../../utilities/dom/src/pointerlock.ts
|
|
165
|
+
function addPointerlockChangeListener(doc, fn) {
|
|
166
|
+
return addDomEvent(doc, "pointerlockchange", fn, false);
|
|
167
|
+
}
|
|
168
|
+
function addPointerlockErrorListener(doc, fn) {
|
|
169
|
+
doc.addEventListener("pointerlockerror", fn, false);
|
|
170
|
+
return function cleanup() {
|
|
171
|
+
doc.removeEventListener("pointerlockerror", fn, false);
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function requestPointerLock(doc, handlers = {}) {
|
|
175
|
+
const { onPointerLock, onPointerUnlock } = handlers;
|
|
176
|
+
const body = doc.body;
|
|
177
|
+
const supported = "pointerLockElement" in doc || "mozPointerLockElement" in doc;
|
|
178
|
+
const locked = !!doc.pointerLockElement;
|
|
179
|
+
function onPointerChange() {
|
|
180
|
+
if (locked)
|
|
181
|
+
onPointerLock == null ? void 0 : onPointerLock();
|
|
182
|
+
else
|
|
183
|
+
onPointerUnlock == null ? void 0 : onPointerUnlock();
|
|
184
|
+
}
|
|
185
|
+
function onPointerError(event) {
|
|
186
|
+
if (locked)
|
|
187
|
+
onPointerUnlock == null ? void 0 : onPointerUnlock();
|
|
188
|
+
console.error("PointerLock error occured:", event);
|
|
189
|
+
exit();
|
|
190
|
+
}
|
|
191
|
+
function exit() {
|
|
192
|
+
doc.exitPointerLock();
|
|
193
|
+
}
|
|
194
|
+
if (!supported)
|
|
195
|
+
return;
|
|
196
|
+
body.requestPointerLock();
|
|
197
|
+
const cleanup = callAll(
|
|
198
|
+
addPointerlockChangeListener(doc, onPointerChange),
|
|
199
|
+
addPointerlockErrorListener(doc, onPointerError)
|
|
200
|
+
);
|
|
201
|
+
return function dispose() {
|
|
202
|
+
if (!supported)
|
|
203
|
+
return;
|
|
204
|
+
cleanup();
|
|
205
|
+
exit();
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// ../../utilities/number/src/number.ts
|
|
210
|
+
function wrap(num, max) {
|
|
211
|
+
return (num % max + max) % max;
|
|
212
|
+
}
|
|
213
|
+
function roundToDevicePixel(num) {
|
|
214
|
+
if (typeof window === "undefined")
|
|
215
|
+
return Math.round(num);
|
|
216
|
+
const dp = window.devicePixelRatio;
|
|
217
|
+
return Math.floor(num * dp + 0.5) / dp;
|
|
218
|
+
}
|
|
219
|
+
function clamp(v, o) {
|
|
220
|
+
return Math.min(Math.max(valueOf(v), o.min), o.max);
|
|
221
|
+
}
|
|
222
|
+
function countDecimals(value) {
|
|
223
|
+
if (!Number.isFinite(value))
|
|
224
|
+
return 0;
|
|
225
|
+
let e = 1, p = 0;
|
|
226
|
+
while (Math.round(value * e) / e !== value) {
|
|
227
|
+
e *= 10;
|
|
228
|
+
p += 1;
|
|
229
|
+
}
|
|
230
|
+
return p;
|
|
231
|
+
}
|
|
232
|
+
var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
|
|
233
|
+
var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
|
|
234
|
+
function valueOf(v) {
|
|
235
|
+
if (typeof v === "number")
|
|
236
|
+
return v;
|
|
237
|
+
const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
|
|
238
|
+
return !Number.isNaN(num) ? num : 0;
|
|
239
|
+
}
|
|
240
|
+
function formatDecimal(v, o) {
|
|
241
|
+
return new Intl.NumberFormat("en-US", {
|
|
242
|
+
useGrouping: false,
|
|
243
|
+
style: "decimal",
|
|
244
|
+
minimumFractionDigits: o.minFractionDigits,
|
|
245
|
+
maximumFractionDigits: o.maxFractionDigits
|
|
246
|
+
}).format(valueOf(v));
|
|
247
|
+
}
|
|
248
|
+
function isAtMax(v, o) {
|
|
249
|
+
const val = valueOf(v);
|
|
250
|
+
return val >= o.max;
|
|
251
|
+
}
|
|
252
|
+
function isAtMin(v, o) {
|
|
253
|
+
const val = valueOf(v);
|
|
254
|
+
return val <= o.min;
|
|
255
|
+
}
|
|
256
|
+
function isWithinRange(v, o) {
|
|
257
|
+
const val = valueOf(v);
|
|
258
|
+
return val >= o.min && val <= o.max;
|
|
259
|
+
}
|
|
260
|
+
function decimalOperation(a, op, b) {
|
|
261
|
+
let result = op === "+" ? a + b : a - b;
|
|
262
|
+
if (a % 1 !== 0 || b % 1 !== 0) {
|
|
263
|
+
const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
|
|
264
|
+
a = Math.round(a * multiplier);
|
|
265
|
+
b = Math.round(b * multiplier);
|
|
266
|
+
result = op === "+" ? a + b : a - b;
|
|
267
|
+
result /= multiplier;
|
|
268
|
+
}
|
|
269
|
+
return result;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// ../../utilities/form-utils/src/input-event.ts
|
|
273
|
+
function getDescriptor(el, options) {
|
|
274
|
+
var _a;
|
|
275
|
+
const { type, property = "value" } = options;
|
|
276
|
+
const proto = getWindow(el)[type].prototype;
|
|
277
|
+
return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
|
|
278
|
+
}
|
|
279
|
+
function dispatchInputValueEvent(el, value) {
|
|
280
|
+
var _a;
|
|
281
|
+
if (!el)
|
|
282
|
+
return;
|
|
283
|
+
const win = getWindow(el);
|
|
284
|
+
if (!(el instanceof win.HTMLInputElement))
|
|
285
|
+
return;
|
|
286
|
+
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
287
|
+
(_a = desc.set) == null ? void 0 : _a.call(el, value);
|
|
288
|
+
const event = new win.Event("input", { bubbles: true });
|
|
289
|
+
el.dispatchEvent(event);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// src/number-input.dom.ts
|
|
293
|
+
var dom = defineDomHelpers({
|
|
294
|
+
getRootId: (ctx) => {
|
|
295
|
+
var _a, _b;
|
|
296
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `number-input:${ctx.id}`;
|
|
297
|
+
},
|
|
298
|
+
getInputId: (ctx) => {
|
|
299
|
+
var _a, _b;
|
|
300
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.input) != null ? _b : `number-input:${ctx.id}:input`;
|
|
301
|
+
},
|
|
302
|
+
getIncrementTriggerId: (ctx) => {
|
|
303
|
+
var _a, _b;
|
|
304
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.incrementTrigger) != null ? _b : `number-input:${ctx.id}:inc`;
|
|
305
|
+
},
|
|
306
|
+
getDecrementTriggerId: (ctx) => {
|
|
307
|
+
var _a, _b;
|
|
308
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.decrementTrigger) != null ? _b : `number-input:${ctx.id}:dec`;
|
|
309
|
+
},
|
|
310
|
+
getScrubberId: (ctx) => {
|
|
311
|
+
var _a, _b;
|
|
312
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.scrubber) != null ? _b : `number-input:${ctx.id}:scrubber`;
|
|
313
|
+
},
|
|
314
|
+
getCursorId: (ctx) => `number-input:${ctx.id}:cursor`,
|
|
315
|
+
getLabelId: (ctx) => {
|
|
316
|
+
var _a, _b;
|
|
317
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `number-input:${ctx.id}:label`;
|
|
318
|
+
},
|
|
319
|
+
getInputEl: (ctx) => dom.getById(ctx, dom.getInputId(ctx)),
|
|
320
|
+
getIncrementTriggerEl: (ctx) => dom.getById(ctx, dom.getIncrementTriggerId(ctx)),
|
|
321
|
+
getDecrementTriggerEl: (ctx) => dom.getById(ctx, dom.getDecrementTriggerId(ctx)),
|
|
322
|
+
getScrubberEl: (ctx) => dom.getById(ctx, dom.getScrubberId(ctx)),
|
|
323
|
+
getCursorEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getCursorId(ctx)),
|
|
324
|
+
getPressedTriggerEl: (ctx, hint = ctx.hint) => {
|
|
325
|
+
let btnEl = null;
|
|
326
|
+
if (hint === "increment") {
|
|
327
|
+
btnEl = dom.getIncrementTriggerEl(ctx);
|
|
328
|
+
}
|
|
329
|
+
if (hint === "decrement") {
|
|
330
|
+
btnEl = dom.getDecrementTriggerEl(ctx);
|
|
331
|
+
}
|
|
332
|
+
return btnEl;
|
|
333
|
+
},
|
|
334
|
+
setupVirtualCursor(ctx) {
|
|
335
|
+
if (isSafari() || !supportsPointerEvent())
|
|
336
|
+
return;
|
|
337
|
+
dom.createVirtualCursor(ctx);
|
|
338
|
+
return () => {
|
|
339
|
+
var _a;
|
|
340
|
+
(_a = dom.getCursorEl(ctx)) == null ? void 0 : _a.remove();
|
|
341
|
+
};
|
|
342
|
+
},
|
|
343
|
+
preventTextSelection(ctx) {
|
|
344
|
+
const doc = dom.getDoc(ctx);
|
|
345
|
+
const html = doc.documentElement;
|
|
346
|
+
const body = doc.body;
|
|
347
|
+
body.style.pointerEvents = "none";
|
|
348
|
+
html.style.userSelect = "none";
|
|
349
|
+
html.style.cursor = "ew-resize";
|
|
350
|
+
return () => {
|
|
351
|
+
body.style.pointerEvents = "";
|
|
352
|
+
html.style.userSelect = "";
|
|
353
|
+
html.style.cursor = "";
|
|
354
|
+
if (!html.style.length) {
|
|
355
|
+
html.removeAttribute("style");
|
|
356
|
+
}
|
|
357
|
+
if (!body.style.length) {
|
|
358
|
+
body.removeAttribute("style");
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
},
|
|
362
|
+
getMousementValue(ctx, event) {
|
|
363
|
+
const x = roundToDevicePixel(event.movementX);
|
|
364
|
+
const y = roundToDevicePixel(event.movementY);
|
|
365
|
+
let hint = x > 0 ? "increment" : x < 0 ? "decrement" : null;
|
|
366
|
+
if (ctx.isRtl && hint === "increment")
|
|
367
|
+
hint = "decrement";
|
|
368
|
+
if (ctx.isRtl && hint === "decrement")
|
|
369
|
+
hint = "increment";
|
|
370
|
+
const point = {
|
|
371
|
+
x: ctx.scrubberCursorPoint.x + x,
|
|
372
|
+
y: ctx.scrubberCursorPoint.y + y
|
|
373
|
+
};
|
|
374
|
+
const win = dom.getWin(ctx);
|
|
375
|
+
const width = win.innerWidth;
|
|
376
|
+
const half = roundToDevicePixel(7.5);
|
|
377
|
+
point.x = wrap(point.x + half, width) - half;
|
|
378
|
+
return { hint, point };
|
|
379
|
+
},
|
|
380
|
+
createVirtualCursor(ctx) {
|
|
381
|
+
const doc = dom.getDoc(ctx);
|
|
382
|
+
const el = doc.createElement("div");
|
|
383
|
+
el.className = "scrubber--cursor";
|
|
384
|
+
el.id = dom.getCursorId(ctx);
|
|
385
|
+
Object.assign(el.style, {
|
|
386
|
+
width: "15px",
|
|
387
|
+
height: "15px",
|
|
388
|
+
position: "fixed",
|
|
389
|
+
pointerEvents: "none",
|
|
390
|
+
left: "0px",
|
|
391
|
+
top: "0px",
|
|
392
|
+
zIndex: MAX_Z_INDEX,
|
|
393
|
+
transform: ctx.scrubberCursorPoint ? `translate3d(${ctx.scrubberCursorPoint.x}px, ${ctx.scrubberCursorPoint.y}px, 0px)` : void 0,
|
|
394
|
+
willChange: "transform"
|
|
395
|
+
});
|
|
396
|
+
el.innerHTML = `
|
|
397
|
+
<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);">
|
|
398
|
+
<g transform="translate(2 3)">
|
|
399
|
+
<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>
|
|
400
|
+
<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>
|
|
401
|
+
</g>
|
|
402
|
+
</svg>`;
|
|
403
|
+
doc.body.appendChild(el);
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
// src/number-input.utils.ts
|
|
408
|
+
var utils = {
|
|
409
|
+
isValidNumericEvent: (ctx, event) => {
|
|
410
|
+
var _a, _b;
|
|
411
|
+
if (event.key == null)
|
|
412
|
+
return true;
|
|
413
|
+
const isModifier = isModifiedEvent(event);
|
|
414
|
+
const isSingleKey = event.key.length === 1;
|
|
415
|
+
if (isModifier || !isSingleKey)
|
|
416
|
+
return true;
|
|
417
|
+
return (_b = (_a = ctx.validateCharacter) == null ? void 0 : _a.call(ctx, event.key)) != null ? _b : utils.isFloatingPoint(event.key);
|
|
418
|
+
},
|
|
419
|
+
isFloatingPoint: (v) => /^[0-9+\-.]$/.test(v),
|
|
420
|
+
sanitize: (ctx, value) => {
|
|
421
|
+
var _a;
|
|
422
|
+
return value.split("").filter((_a = ctx.validateCharacter) != null ? _a : utils.isFloatingPoint).join("");
|
|
423
|
+
},
|
|
424
|
+
increment: (ctx, step) => {
|
|
425
|
+
const value = increment(ctx.value, step != null ? step : ctx.step);
|
|
426
|
+
return formatDecimal(clamp(value, ctx), ctx);
|
|
427
|
+
},
|
|
428
|
+
decrement: (ctx, step) => {
|
|
429
|
+
const value = decrement(ctx.value, step != null ? step : ctx.step);
|
|
430
|
+
return formatDecimal(clamp(value, ctx), ctx);
|
|
431
|
+
},
|
|
432
|
+
clamp: (ctx) => {
|
|
433
|
+
return formatDecimal(clamp(ctx.value, ctx), ctx);
|
|
434
|
+
},
|
|
435
|
+
parse: (ctx, value) => {
|
|
436
|
+
var _a, _b;
|
|
437
|
+
return (_b = (_a = ctx.parse) == null ? void 0 : _a.call(ctx, value)) != null ? _b : value;
|
|
438
|
+
},
|
|
439
|
+
format: (ctx, value) => {
|
|
440
|
+
var _a, _b;
|
|
441
|
+
const _val = value.toString();
|
|
442
|
+
return (_b = (_a = ctx.format) == null ? void 0 : _a.call(ctx, _val)) != null ? _b : _val;
|
|
443
|
+
},
|
|
444
|
+
round: (ctx) => {
|
|
445
|
+
return formatDecimal(ctx.value, ctx);
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
// src/number-input.machine.ts
|
|
450
|
+
var { not, and } = import_core.guards;
|
|
451
|
+
function machine(userContext) {
|
|
452
|
+
const ctx = compact(userContext);
|
|
453
|
+
return (0, import_core.createMachine)(
|
|
454
|
+
{
|
|
455
|
+
id: "number-input",
|
|
456
|
+
initial: "unknown",
|
|
457
|
+
context: {
|
|
458
|
+
dir: "ltr",
|
|
459
|
+
focusInputOnChange: true,
|
|
460
|
+
clampValueOnBlur: true,
|
|
461
|
+
allowOverflow: false,
|
|
462
|
+
inputMode: "decimal",
|
|
463
|
+
pattern: "[0-9]*(.[0-9]+)?",
|
|
464
|
+
hint: null,
|
|
465
|
+
value: "",
|
|
466
|
+
step: 1,
|
|
467
|
+
min: Number.MIN_SAFE_INTEGER,
|
|
468
|
+
max: Number.MAX_SAFE_INTEGER,
|
|
469
|
+
scrubberCursorPoint: null,
|
|
470
|
+
invalid: false,
|
|
471
|
+
spinOnPress: true,
|
|
472
|
+
...ctx,
|
|
473
|
+
translations: {
|
|
474
|
+
incrementLabel: "increment value",
|
|
475
|
+
decrementLabel: "decrease value",
|
|
476
|
+
...ctx.translations
|
|
477
|
+
}
|
|
478
|
+
},
|
|
479
|
+
computed: {
|
|
480
|
+
isRtl: (ctx2) => ctx2.dir === "rtl",
|
|
481
|
+
valueAsNumber: (ctx2) => valueOf(ctx2.value),
|
|
482
|
+
isAtMin: (ctx2) => isAtMin(ctx2.value, ctx2),
|
|
483
|
+
isAtMax: (ctx2) => isAtMax(ctx2.value, ctx2),
|
|
484
|
+
isOutOfRange: (ctx2) => !isWithinRange(ctx2.value, ctx2),
|
|
485
|
+
isValueEmpty: (ctx2) => ctx2.value === "",
|
|
486
|
+
canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
|
|
487
|
+
canDecrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMin,
|
|
488
|
+
valueText: (ctx2) => {
|
|
489
|
+
var _a, _b;
|
|
490
|
+
return (_b = (_a = ctx2.translations).valueText) == null ? void 0 : _b.call(_a, ctx2.value);
|
|
491
|
+
},
|
|
492
|
+
formattedValue: (ctx2) => {
|
|
493
|
+
var _a, _b;
|
|
494
|
+
return (_b = (_a = ctx2.format) == null ? void 0 : _a.call(ctx2, ctx2.value).toString()) != null ? _b : ctx2.value;
|
|
495
|
+
}
|
|
496
|
+
},
|
|
497
|
+
watch: {
|
|
498
|
+
value: ["invokeOnChange", "dispatchChangeEvent"],
|
|
499
|
+
isOutOfRange: ["invokeOnInvalid"],
|
|
500
|
+
scrubberCursorPoint: ["setVirtualCursorPosition"]
|
|
501
|
+
},
|
|
502
|
+
on: {
|
|
503
|
+
SET_VALUE: [
|
|
504
|
+
{
|
|
505
|
+
guard: "clampOnBlur",
|
|
506
|
+
actions: ["setValue", "clampValue", "setHintToSet"]
|
|
507
|
+
},
|
|
508
|
+
{
|
|
509
|
+
actions: ["setValue", "setHintToSet"]
|
|
510
|
+
}
|
|
511
|
+
],
|
|
512
|
+
CLEAR_VALUE: {
|
|
513
|
+
actions: ["clearValue"]
|
|
514
|
+
},
|
|
515
|
+
INCREMENT: {
|
|
516
|
+
actions: ["increment"]
|
|
517
|
+
},
|
|
518
|
+
DECREMENT: {
|
|
519
|
+
actions: ["decrement"]
|
|
520
|
+
}
|
|
521
|
+
},
|
|
522
|
+
states: {
|
|
523
|
+
unknown: {
|
|
524
|
+
on: {
|
|
525
|
+
SETUP: {
|
|
526
|
+
target: "idle",
|
|
527
|
+
actions: "syncInputValue"
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
},
|
|
531
|
+
idle: {
|
|
532
|
+
exit: "invokeOnFocus",
|
|
533
|
+
on: {
|
|
534
|
+
PRESS_DOWN: {
|
|
535
|
+
target: "before:spin",
|
|
536
|
+
actions: ["focusInput", "setHint"]
|
|
537
|
+
},
|
|
538
|
+
PRESS_DOWN_SCRUBBER: {
|
|
539
|
+
target: "scrubbing",
|
|
540
|
+
actions: ["focusInput", "setHint", "setCursorPoint"]
|
|
541
|
+
},
|
|
542
|
+
FOCUS: "focused"
|
|
543
|
+
}
|
|
544
|
+
},
|
|
545
|
+
focused: {
|
|
546
|
+
tags: "focus",
|
|
547
|
+
entry: "focusInput",
|
|
548
|
+
activities: "attachWheelListener",
|
|
549
|
+
on: {
|
|
550
|
+
PRESS_DOWN: {
|
|
551
|
+
target: "before:spin",
|
|
552
|
+
actions: ["focusInput", "setHint"]
|
|
553
|
+
},
|
|
554
|
+
PRESS_DOWN_SCRUBBER: {
|
|
555
|
+
target: "scrubbing",
|
|
556
|
+
actions: ["focusInput", "setHint", "setCursorPoint"]
|
|
557
|
+
},
|
|
558
|
+
ARROW_UP: {
|
|
559
|
+
actions: "increment"
|
|
560
|
+
},
|
|
561
|
+
ARROW_DOWN: {
|
|
562
|
+
actions: "decrement"
|
|
563
|
+
},
|
|
564
|
+
HOME: {
|
|
565
|
+
actions: "setToMin"
|
|
566
|
+
},
|
|
567
|
+
END: {
|
|
568
|
+
actions: "setToMax"
|
|
569
|
+
},
|
|
570
|
+
CHANGE: {
|
|
571
|
+
actions: ["setValue", "setHint"]
|
|
572
|
+
},
|
|
573
|
+
BLUR: [
|
|
574
|
+
{
|
|
575
|
+
guard: "isInvalidExponential",
|
|
576
|
+
target: "idle",
|
|
577
|
+
actions: ["clearValue", "clearHint", "invokeOnBlur"]
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
guard: and("clampOnBlur", not("isInRange"), not("isEmptyValue")),
|
|
581
|
+
target: "idle",
|
|
582
|
+
actions: ["clampValue", "clearHint", "invokeOnBlur"]
|
|
583
|
+
},
|
|
584
|
+
{
|
|
585
|
+
target: "idle",
|
|
586
|
+
actions: ["roundValue", "invokeOnBlur"]
|
|
587
|
+
}
|
|
588
|
+
]
|
|
589
|
+
}
|
|
590
|
+
},
|
|
591
|
+
"before:spin": {
|
|
592
|
+
tags: "focus",
|
|
593
|
+
activities: "trackButtonDisabled",
|
|
594
|
+
entry: (0, import_core.choose)([
|
|
595
|
+
{ guard: "isIncrementHint", actions: "increment" },
|
|
596
|
+
{ guard: "isDecrementHint", actions: "decrement" }
|
|
597
|
+
]),
|
|
598
|
+
after: {
|
|
599
|
+
CHANGE_DELAY: {
|
|
600
|
+
target: "spinning",
|
|
601
|
+
guard: and("isInRange", "spinOnPress")
|
|
602
|
+
}
|
|
603
|
+
},
|
|
604
|
+
on: {
|
|
605
|
+
PRESS_UP: {
|
|
606
|
+
target: "focused",
|
|
607
|
+
actions: "clearHint"
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
},
|
|
611
|
+
spinning: {
|
|
612
|
+
tags: "focus",
|
|
613
|
+
activities: "trackButtonDisabled",
|
|
614
|
+
every: [
|
|
615
|
+
{
|
|
616
|
+
delay: "CHANGE_INTERVAL",
|
|
617
|
+
guard: and(not("isAtMin"), "isIncrementHint"),
|
|
618
|
+
actions: "increment"
|
|
619
|
+
},
|
|
620
|
+
{
|
|
621
|
+
delay: "CHANGE_INTERVAL",
|
|
622
|
+
guard: and(not("isAtMax"), "isDecrementHint"),
|
|
623
|
+
actions: "decrement"
|
|
624
|
+
}
|
|
625
|
+
],
|
|
626
|
+
on: {
|
|
627
|
+
PRESS_UP: {
|
|
628
|
+
target: "focused",
|
|
629
|
+
actions: "clearHint"
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
},
|
|
633
|
+
scrubbing: {
|
|
634
|
+
tags: "focus",
|
|
635
|
+
exit: "clearCursorPoint",
|
|
636
|
+
activities: ["activatePointerLock", "trackMousemove", "setupVirtualCursor", "preventTextSelection"],
|
|
637
|
+
on: {
|
|
638
|
+
POINTER_UP_SCRUBBER: "focused",
|
|
639
|
+
POINTER_MOVE_SCRUBBER: [
|
|
640
|
+
{
|
|
641
|
+
guard: "isIncrementHint",
|
|
642
|
+
actions: ["increment", "setCursorPoint"]
|
|
643
|
+
},
|
|
644
|
+
{
|
|
645
|
+
guard: "isDecrementHint",
|
|
646
|
+
actions: ["decrement", "setCursorPoint"]
|
|
647
|
+
}
|
|
648
|
+
]
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
},
|
|
653
|
+
{
|
|
654
|
+
delays: {
|
|
655
|
+
CHANGE_INTERVAL: 50,
|
|
656
|
+
CHANGE_DELAY: 300
|
|
657
|
+
},
|
|
658
|
+
guards: {
|
|
659
|
+
clampOnBlur: (ctx2) => !!ctx2.clampValueOnBlur,
|
|
660
|
+
isAtMin: (ctx2) => ctx2.isAtMin,
|
|
661
|
+
spinOnPress: (ctx2) => !!ctx2.spinOnPress,
|
|
662
|
+
isAtMax: (ctx2) => ctx2.isAtMax,
|
|
663
|
+
isInRange: (ctx2) => !ctx2.isOutOfRange,
|
|
664
|
+
isDecrementHint: (ctx2, evt) => {
|
|
665
|
+
var _a;
|
|
666
|
+
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "decrement";
|
|
667
|
+
},
|
|
668
|
+
isEmptyValue: (ctx2) => ctx2.isValueEmpty,
|
|
669
|
+
isIncrementHint: (ctx2, evt) => {
|
|
670
|
+
var _a;
|
|
671
|
+
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "increment";
|
|
672
|
+
},
|
|
673
|
+
isInvalidExponential: (ctx2) => ctx2.value.toString().startsWith("e")
|
|
674
|
+
},
|
|
675
|
+
activities: {
|
|
676
|
+
setupVirtualCursor(ctx2) {
|
|
677
|
+
return dom.setupVirtualCursor(ctx2);
|
|
678
|
+
},
|
|
679
|
+
preventTextSelection(ctx2) {
|
|
680
|
+
return dom.preventTextSelection(ctx2);
|
|
681
|
+
},
|
|
682
|
+
trackButtonDisabled(ctx2, _evt, { send }) {
|
|
683
|
+
const btn = dom.getPressedTriggerEl(ctx2, ctx2.hint);
|
|
684
|
+
return observeAttributes(btn, "disabled", () => send("PRESS_UP"));
|
|
685
|
+
},
|
|
686
|
+
attachWheelListener(ctx2, _evt, { send }) {
|
|
687
|
+
const input = dom.getInputEl(ctx2);
|
|
688
|
+
if (!input)
|
|
689
|
+
return;
|
|
690
|
+
function onWheel(event) {
|
|
691
|
+
const isInputFocused = dom.getDoc(ctx2).activeElement === input;
|
|
692
|
+
if (!ctx2.allowMouseWheel || !isInputFocused)
|
|
693
|
+
return;
|
|
694
|
+
event.preventDefault();
|
|
695
|
+
const dir = Math.sign(event.deltaY) * -1;
|
|
696
|
+
if (dir === 1) {
|
|
697
|
+
send("INCREMENT");
|
|
698
|
+
} else if (dir === -1) {
|
|
699
|
+
send("DECREMENT");
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
return addDomEvent(input, "wheel", onWheel, { passive: false });
|
|
703
|
+
},
|
|
704
|
+
activatePointerLock(ctx2) {
|
|
705
|
+
if (isSafari() || !supportsPointerEvent())
|
|
706
|
+
return;
|
|
707
|
+
return requestPointerLock(dom.getDoc(ctx2));
|
|
708
|
+
},
|
|
709
|
+
trackMousemove(ctx2, _evt, { send }) {
|
|
710
|
+
const doc = dom.getDoc(ctx2);
|
|
711
|
+
function onMousemove(event) {
|
|
712
|
+
if (!ctx2.scrubberCursorPoint)
|
|
713
|
+
return;
|
|
714
|
+
const value = dom.getMousementValue(ctx2, event);
|
|
715
|
+
if (!value.hint)
|
|
716
|
+
return;
|
|
717
|
+
send({
|
|
718
|
+
type: "POINTER_MOVE_SCRUBBER",
|
|
719
|
+
hint: value.hint,
|
|
720
|
+
point: value.point
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
function onMouseup() {
|
|
724
|
+
send("POINTER_UP_SCRUBBER");
|
|
725
|
+
}
|
|
726
|
+
return callAll(
|
|
727
|
+
addDomEvent(doc, "mousemove", onMousemove, false),
|
|
728
|
+
addDomEvent(doc, "mouseup", onMouseup, false)
|
|
729
|
+
);
|
|
730
|
+
}
|
|
731
|
+
},
|
|
732
|
+
actions: {
|
|
733
|
+
focusInput(ctx2) {
|
|
734
|
+
if (!ctx2.focusInputOnChange)
|
|
735
|
+
return;
|
|
736
|
+
const input = dom.getInputEl(ctx2);
|
|
737
|
+
raf(() => input == null ? void 0 : input.focus());
|
|
738
|
+
},
|
|
739
|
+
increment(ctx2, evt) {
|
|
740
|
+
ctx2.value = utils.increment(ctx2, evt.step);
|
|
741
|
+
},
|
|
742
|
+
decrement(ctx2, evt) {
|
|
743
|
+
ctx2.value = utils.decrement(ctx2, evt.step);
|
|
744
|
+
},
|
|
745
|
+
clampValue(ctx2) {
|
|
746
|
+
ctx2.value = utils.clamp(ctx2);
|
|
747
|
+
},
|
|
748
|
+
roundValue(ctx2) {
|
|
749
|
+
if (ctx2.value !== "") {
|
|
750
|
+
ctx2.value = utils.round(ctx2);
|
|
751
|
+
}
|
|
752
|
+
},
|
|
753
|
+
setValue(ctx2, evt) {
|
|
754
|
+
var _a, _b;
|
|
755
|
+
const value = (_b = (_a = evt.target) == null ? void 0 : _a.value) != null ? _b : evt.value;
|
|
756
|
+
ctx2.value = utils.sanitize(ctx2, utils.parse(ctx2, value.toString()));
|
|
757
|
+
},
|
|
758
|
+
clearValue(ctx2) {
|
|
759
|
+
ctx2.value = "";
|
|
760
|
+
},
|
|
761
|
+
setToMax(ctx2) {
|
|
762
|
+
ctx2.value = ctx2.max.toString();
|
|
763
|
+
},
|
|
764
|
+
setToMin(ctx2) {
|
|
765
|
+
ctx2.value = ctx2.min.toString();
|
|
766
|
+
},
|
|
767
|
+
setHint(ctx2, evt) {
|
|
768
|
+
ctx2.hint = evt.hint;
|
|
769
|
+
},
|
|
770
|
+
clearHint(ctx2) {
|
|
771
|
+
ctx2.hint = null;
|
|
772
|
+
},
|
|
773
|
+
setHintToSet(ctx2) {
|
|
774
|
+
ctx2.hint = "set";
|
|
775
|
+
},
|
|
776
|
+
invokeOnChange(ctx2) {
|
|
777
|
+
var _a;
|
|
778
|
+
(_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, {
|
|
779
|
+
value: ctx2.value,
|
|
780
|
+
valueAsNumber: ctx2.valueAsNumber
|
|
781
|
+
});
|
|
782
|
+
},
|
|
783
|
+
invokeOnFocus(ctx2, evt) {
|
|
784
|
+
var _a;
|
|
785
|
+
let srcElement = null;
|
|
786
|
+
if (evt.type === "PRESS_DOWN") {
|
|
787
|
+
srcElement = dom.getPressedTriggerEl(ctx2, evt.hint);
|
|
788
|
+
} else if (evt.type === "FOCUS") {
|
|
789
|
+
srcElement = dom.getInputEl(ctx2);
|
|
790
|
+
} else if (evt.type === "PRESS_DOWN_SCRUBBER") {
|
|
791
|
+
srcElement = dom.getScrubberEl(ctx2);
|
|
792
|
+
}
|
|
793
|
+
(_a = ctx2.onFocus) == null ? void 0 : _a.call(ctx2, {
|
|
794
|
+
value: ctx2.value,
|
|
795
|
+
valueAsNumber: ctx2.valueAsNumber,
|
|
796
|
+
srcElement
|
|
797
|
+
});
|
|
798
|
+
},
|
|
799
|
+
invokeOnBlur(ctx2) {
|
|
800
|
+
var _a;
|
|
801
|
+
(_a = ctx2.onBlur) == null ? void 0 : _a.call(ctx2, {
|
|
802
|
+
value: ctx2.value,
|
|
803
|
+
valueAsNumber: ctx2.valueAsNumber
|
|
804
|
+
});
|
|
805
|
+
},
|
|
806
|
+
invokeOnInvalid(ctx2) {
|
|
807
|
+
var _a;
|
|
808
|
+
if (!ctx2.isOutOfRange)
|
|
809
|
+
return;
|
|
810
|
+
const reason = ctx2.valueAsNumber > ctx2.max ? "rangeOverflow" : "rangeUnderflow";
|
|
811
|
+
(_a = ctx2.onInvalid) == null ? void 0 : _a.call(ctx2, {
|
|
812
|
+
reason,
|
|
813
|
+
value: ctx2.formattedValue,
|
|
814
|
+
valueAsNumber: ctx2.valueAsNumber
|
|
815
|
+
});
|
|
816
|
+
},
|
|
817
|
+
syncInputValue(ctx2) {
|
|
818
|
+
const input = dom.getInputEl(ctx2);
|
|
819
|
+
if (!input || input.value == ctx2.value)
|
|
820
|
+
return;
|
|
821
|
+
const value = utils.parse(ctx2, input.value);
|
|
822
|
+
ctx2.value = utils.sanitize(ctx2, value);
|
|
823
|
+
},
|
|
824
|
+
setCursorPoint(ctx2, evt) {
|
|
825
|
+
ctx2.scrubberCursorPoint = evt.point;
|
|
826
|
+
},
|
|
827
|
+
clearCursorPoint(ctx2) {
|
|
828
|
+
ctx2.scrubberCursorPoint = null;
|
|
829
|
+
},
|
|
830
|
+
setVirtualCursorPosition(ctx2) {
|
|
831
|
+
const cursor = dom.getCursorEl(ctx2);
|
|
832
|
+
if (!cursor || !ctx2.scrubberCursorPoint)
|
|
833
|
+
return;
|
|
834
|
+
const { x, y } = ctx2.scrubberCursorPoint;
|
|
835
|
+
cursor.style.transform = `translate3d(${x}px, ${y}px, 0px)`;
|
|
836
|
+
},
|
|
837
|
+
dispatchChangeEvent(ctx2) {
|
|
838
|
+
dispatchInputValueEvent(dom.getInputEl(ctx2), ctx2.formattedValue);
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
);
|
|
843
|
+
}
|
|
844
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
845
|
+
0 && (module.exports = {
|
|
846
|
+
machine
|
|
847
|
+
});
|