@zag-js/number-input 0.2.11 → 0.2.13
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-4A67X5BX.mjs → chunk-3O7PA63J.mjs} +13 -138
- package/dist/{chunk-6CS5P7OC.mjs → chunk-AXXDGYUW.mjs} +2 -8
- package/dist/{chunk-4ASBTBA5.mjs → chunk-DYFCS7PF.mjs} +46 -43
- package/dist/{chunk-GQN3V2LU.mjs → chunk-QYY4CWRS.mjs} +4 -13
- package/dist/index.js +105 -326
- package/dist/index.mjs +4 -5
- package/dist/number-input.connect.d.ts +39 -0
- package/dist/number-input.connect.js +81 -175
- package/dist/number-input.connect.mjs +3 -4
- package/dist/number-input.dom.d.ts +9 -6
- package/dist/number-input.dom.js +9 -65
- package/dist/number-input.dom.mjs +1 -2
- package/dist/number-input.machine.js +41 -266
- package/dist/number-input.machine.mjs +3 -4
- package/dist/number-input.utils.js +9 -54
- package/dist/number-input.utils.mjs +1 -2
- package/package.json +10 -8
- package/dist/chunk-EPCXXTFL.mjs +0 -141
|
@@ -24,247 +24,17 @@ __export(number_input_machine_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(number_input_machine_exports);
|
|
26
26
|
var import_core = require("@zag-js/core");
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
var
|
|
33
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
34
|
-
return res ?? void 0;
|
|
35
|
-
};
|
|
36
|
-
var callAll = (...fns) => (...a) => {
|
|
37
|
-
fns.forEach(function(fn) {
|
|
38
|
-
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
|
-
const agent = navigator.userAgentData;
|
|
60
|
-
return agent?.platform ?? navigator.platform;
|
|
61
|
-
}
|
|
62
|
-
var pt = (v) => isDom() && v.test(getPlatform());
|
|
63
|
-
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
64
|
-
var isSafari = () => isApple() && vn(/apple/i);
|
|
65
|
-
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
66
|
-
|
|
67
|
-
// ../../utilities/dom/src/query.ts
|
|
68
|
-
function isDocument(el) {
|
|
69
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
70
|
-
}
|
|
71
|
-
function isWindow(value) {
|
|
72
|
-
return value?.toString() === "[object Window]";
|
|
73
|
-
}
|
|
74
|
-
function getDocument(el) {
|
|
75
|
-
if (isWindow(el))
|
|
76
|
-
return el.document;
|
|
77
|
-
if (isDocument(el))
|
|
78
|
-
return el;
|
|
79
|
-
return el?.ownerDocument ?? document;
|
|
80
|
-
}
|
|
81
|
-
function getWindow(el) {
|
|
82
|
-
return el?.ownerDocument.defaultView ?? window;
|
|
83
|
-
}
|
|
84
|
-
function defineDomHelpers(helpers) {
|
|
85
|
-
const dom2 = {
|
|
86
|
-
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
87
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
88
|
-
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
89
|
-
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
90
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
91
|
-
};
|
|
92
|
-
return {
|
|
93
|
-
...dom2,
|
|
94
|
-
...helpers
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// ../../utilities/dom/src/event.ts
|
|
99
|
-
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
100
|
-
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
101
|
-
|
|
102
|
-
// ../../utilities/dom/src/listener.ts
|
|
103
|
-
var isRef = (v) => hasProp(v, "current");
|
|
104
|
-
function addDomEvent(target, eventName, handler, options) {
|
|
105
|
-
const node = isRef(target) ? target.current : runIfFn(target);
|
|
106
|
-
node?.addEventListener(eventName, handler, options);
|
|
107
|
-
return () => {
|
|
108
|
-
node?.removeEventListener(eventName, handler, options);
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// ../../utilities/dom/src/mutation-observer.ts
|
|
113
|
-
function observeAttributes(node, attributes, fn) {
|
|
114
|
-
if (!node)
|
|
115
|
-
return;
|
|
116
|
-
const attrs = Array.isArray(attributes) ? attributes : [attributes];
|
|
117
|
-
const win = node.ownerDocument.defaultView || window;
|
|
118
|
-
const obs = new win.MutationObserver((changes) => {
|
|
119
|
-
for (const change of changes) {
|
|
120
|
-
if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
|
|
121
|
-
fn(change);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
obs.observe(node, { attributes: true, attributeFilter: attrs });
|
|
126
|
-
return () => obs.disconnect();
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// ../../utilities/dom/src/next-tick.ts
|
|
130
|
-
function raf(fn) {
|
|
131
|
-
const id = globalThis.requestAnimationFrame(fn);
|
|
132
|
-
return function cleanup() {
|
|
133
|
-
globalThis.cancelAnimationFrame(id);
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// ../../utilities/dom/src/pointerlock.ts
|
|
138
|
-
function addPointerlockChangeListener(doc, fn) {
|
|
139
|
-
return addDomEvent(doc, "pointerlockchange", fn, false);
|
|
140
|
-
}
|
|
141
|
-
function addPointerlockErrorListener(doc, fn) {
|
|
142
|
-
doc.addEventListener("pointerlockerror", fn, false);
|
|
143
|
-
return function cleanup() {
|
|
144
|
-
doc.removeEventListener("pointerlockerror", fn, false);
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
function requestPointerLock(doc, handlers = {}) {
|
|
148
|
-
const { onPointerLock, onPointerUnlock } = handlers;
|
|
149
|
-
const body = doc.body;
|
|
150
|
-
const supported = "pointerLockElement" in doc || "mozPointerLockElement" in doc;
|
|
151
|
-
const locked = !!doc.pointerLockElement;
|
|
152
|
-
function onPointerChange() {
|
|
153
|
-
if (locked)
|
|
154
|
-
onPointerLock?.();
|
|
155
|
-
else
|
|
156
|
-
onPointerUnlock?.();
|
|
157
|
-
}
|
|
158
|
-
function onPointerError(event) {
|
|
159
|
-
if (locked)
|
|
160
|
-
onPointerUnlock?.();
|
|
161
|
-
console.error("PointerLock error occured:", event);
|
|
162
|
-
exit();
|
|
163
|
-
}
|
|
164
|
-
function exit() {
|
|
165
|
-
doc.exitPointerLock();
|
|
166
|
-
}
|
|
167
|
-
if (!supported)
|
|
168
|
-
return;
|
|
169
|
-
try {
|
|
170
|
-
body.requestPointerLock();
|
|
171
|
-
} catch {
|
|
172
|
-
}
|
|
173
|
-
const cleanup = callAll(
|
|
174
|
-
addPointerlockChangeListener(doc, onPointerChange),
|
|
175
|
-
addPointerlockErrorListener(doc, onPointerError)
|
|
176
|
-
);
|
|
177
|
-
return function dispose() {
|
|
178
|
-
if (!supported)
|
|
179
|
-
return;
|
|
180
|
-
cleanup();
|
|
181
|
-
exit();
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// ../../utilities/number/src/number.ts
|
|
186
|
-
function wrap(num, max) {
|
|
187
|
-
return (num % max + max) % max;
|
|
188
|
-
}
|
|
189
|
-
function roundToDevicePixel(num) {
|
|
190
|
-
if (typeof window === "undefined")
|
|
191
|
-
return Math.round(num);
|
|
192
|
-
const dp = window.devicePixelRatio;
|
|
193
|
-
return Math.floor(num * dp + 0.5) / dp;
|
|
194
|
-
}
|
|
195
|
-
function clamp(v, o) {
|
|
196
|
-
return Math.min(Math.max(valueOf(v), o.min), o.max);
|
|
197
|
-
}
|
|
198
|
-
function countDecimals(value) {
|
|
199
|
-
if (!Number.isFinite(value))
|
|
200
|
-
return 0;
|
|
201
|
-
let e = 1, p = 0;
|
|
202
|
-
while (Math.round(value * e) / e !== value) {
|
|
203
|
-
e *= 10;
|
|
204
|
-
p += 1;
|
|
205
|
-
}
|
|
206
|
-
return p;
|
|
207
|
-
}
|
|
208
|
-
var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
|
|
209
|
-
var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
|
|
210
|
-
function valueOf(v) {
|
|
211
|
-
if (typeof v === "number")
|
|
212
|
-
return v;
|
|
213
|
-
const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
|
|
214
|
-
return !Number.isNaN(num) ? num : 0;
|
|
215
|
-
}
|
|
216
|
-
function formatDecimal(v, o) {
|
|
217
|
-
return new Intl.NumberFormat("en-US", {
|
|
218
|
-
useGrouping: false,
|
|
219
|
-
style: "decimal",
|
|
220
|
-
minimumFractionDigits: o.minFractionDigits,
|
|
221
|
-
maximumFractionDigits: o.maxFractionDigits
|
|
222
|
-
}).format(valueOf(v));
|
|
223
|
-
}
|
|
224
|
-
function isAtMax(v, o) {
|
|
225
|
-
const val = valueOf(v);
|
|
226
|
-
return val >= o.max;
|
|
227
|
-
}
|
|
228
|
-
function isAtMin(v, o) {
|
|
229
|
-
const val = valueOf(v);
|
|
230
|
-
return val <= o.min;
|
|
231
|
-
}
|
|
232
|
-
function isWithinRange(v, o) {
|
|
233
|
-
const val = valueOf(v);
|
|
234
|
-
return val >= o.min && val <= o.max;
|
|
235
|
-
}
|
|
236
|
-
function decimalOperation(a, op, b) {
|
|
237
|
-
let result = op === "+" ? a + b : a - b;
|
|
238
|
-
if (a % 1 !== 0 || b % 1 !== 0) {
|
|
239
|
-
const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
|
|
240
|
-
a = Math.round(a * multiplier);
|
|
241
|
-
b = Math.round(b * multiplier);
|
|
242
|
-
result = op === "+" ? a + b : a - b;
|
|
243
|
-
result /= multiplier;
|
|
244
|
-
}
|
|
245
|
-
return result;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// ../../utilities/form-utils/src/input-event.ts
|
|
249
|
-
function getDescriptor(el, options) {
|
|
250
|
-
const { type, property = "value" } = options;
|
|
251
|
-
const proto = getWindow(el)[type].prototype;
|
|
252
|
-
return Object.getOwnPropertyDescriptor(proto, property) ?? {};
|
|
253
|
-
}
|
|
254
|
-
function dispatchInputValueEvent(el, value) {
|
|
255
|
-
if (!el)
|
|
256
|
-
return;
|
|
257
|
-
const win = getWindow(el);
|
|
258
|
-
if (!(el instanceof win.HTMLInputElement))
|
|
259
|
-
return;
|
|
260
|
-
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
261
|
-
desc.set?.call(el, value);
|
|
262
|
-
const event = new win.Event("input", { bubbles: true });
|
|
263
|
-
el.dispatchEvent(event);
|
|
264
|
-
}
|
|
27
|
+
var import_dom_event2 = require("@zag-js/dom-event");
|
|
28
|
+
var import_dom_query2 = require("@zag-js/dom-query");
|
|
29
|
+
var import_form_utils = require("@zag-js/form-utils");
|
|
30
|
+
var import_mutation_observer = require("@zag-js/mutation-observer");
|
|
31
|
+
var import_number_utils3 = require("@zag-js/number-utils");
|
|
32
|
+
var import_utils = require("@zag-js/utils");
|
|
265
33
|
|
|
266
34
|
// src/number-input.dom.ts
|
|
267
|
-
var
|
|
35
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
36
|
+
var import_number_utils = require("@zag-js/number-utils");
|
|
37
|
+
var dom = (0, import_dom_query.createScope)({
|
|
268
38
|
getRootId: (ctx) => ctx.ids?.root ?? `number-input:${ctx.id}`,
|
|
269
39
|
getInputId: (ctx) => ctx.ids?.input ?? `number-input:${ctx.id}:input`,
|
|
270
40
|
getIncrementTriggerId: (ctx) => ctx.ids?.incrementTrigger ?? `number-input:${ctx.id}:inc`,
|
|
@@ -288,7 +58,7 @@ var dom = defineDomHelpers({
|
|
|
288
58
|
return btnEl;
|
|
289
59
|
},
|
|
290
60
|
setupVirtualCursor(ctx) {
|
|
291
|
-
if (isSafari
|
|
61
|
+
if ((0, import_dom_query.isSafari)())
|
|
292
62
|
return;
|
|
293
63
|
dom.createVirtualCursor(ctx);
|
|
294
64
|
return () => {
|
|
@@ -315,8 +85,8 @@ var dom = defineDomHelpers({
|
|
|
315
85
|
};
|
|
316
86
|
},
|
|
317
87
|
getMousementValue(ctx, event) {
|
|
318
|
-
const x = roundToDevicePixel(event.movementX);
|
|
319
|
-
const y = roundToDevicePixel(event.movementY);
|
|
88
|
+
const x = (0, import_number_utils.roundToDevicePixel)(event.movementX);
|
|
89
|
+
const y = (0, import_number_utils.roundToDevicePixel)(event.movementY);
|
|
320
90
|
let hint = x > 0 ? "increment" : x < 0 ? "decrement" : null;
|
|
321
91
|
if (ctx.isRtl && hint === "increment")
|
|
322
92
|
hint = "decrement";
|
|
@@ -328,8 +98,8 @@ var dom = defineDomHelpers({
|
|
|
328
98
|
};
|
|
329
99
|
const win = dom.getWin(ctx);
|
|
330
100
|
const width = win.innerWidth;
|
|
331
|
-
const half = roundToDevicePixel(7.5);
|
|
332
|
-
point.x = wrap(point.x + half, width) - half;
|
|
101
|
+
const half = (0, import_number_utils.roundToDevicePixel)(7.5);
|
|
102
|
+
point.x = (0, import_number_utils.wrap)(point.x + half, width) - half;
|
|
333
103
|
return { hint, point };
|
|
334
104
|
},
|
|
335
105
|
createVirtualCursor(ctx) {
|
|
@@ -344,7 +114,7 @@ var dom = defineDomHelpers({
|
|
|
344
114
|
pointerEvents: "none",
|
|
345
115
|
left: "0px",
|
|
346
116
|
top: "0px",
|
|
347
|
-
zIndex: MAX_Z_INDEX,
|
|
117
|
+
zIndex: import_dom_query.MAX_Z_INDEX,
|
|
348
118
|
transform: ctx.scrubberCursorPoint ? `translate3d(${ctx.scrubberCursorPoint.x}px, ${ctx.scrubberCursorPoint.y}px, 0px)` : void 0,
|
|
349
119
|
willChange: "transform"
|
|
350
120
|
});
|
|
@@ -360,11 +130,13 @@ var dom = defineDomHelpers({
|
|
|
360
130
|
});
|
|
361
131
|
|
|
362
132
|
// src/number-input.utils.ts
|
|
133
|
+
var import_dom_event = require("@zag-js/dom-event");
|
|
134
|
+
var import_number_utils2 = require("@zag-js/number-utils");
|
|
363
135
|
var utils = {
|
|
364
136
|
isValidNumericEvent: (ctx, event) => {
|
|
365
137
|
if (event.key == null)
|
|
366
138
|
return true;
|
|
367
|
-
const isModifier = isModifiedEvent(event);
|
|
139
|
+
const isModifier = (0, import_dom_event.isModifiedEvent)(event);
|
|
368
140
|
const isSingleKey = event.key.length === 1;
|
|
369
141
|
if (isModifier || !isSingleKey)
|
|
370
142
|
return true;
|
|
@@ -375,15 +147,15 @@ var utils = {
|
|
|
375
147
|
return value.split("").filter(ctx.validateCharacter ?? utils.isFloatingPoint).join("");
|
|
376
148
|
},
|
|
377
149
|
increment: (ctx, step) => {
|
|
378
|
-
const value = increment(ctx.value, step ?? ctx.step);
|
|
379
|
-
return formatDecimal(clamp(value, ctx), ctx);
|
|
150
|
+
const value = (0, import_number_utils2.increment)(ctx.value, step ?? ctx.step);
|
|
151
|
+
return (0, import_number_utils2.formatDecimal)((0, import_number_utils2.clamp)(value, ctx), ctx);
|
|
380
152
|
},
|
|
381
153
|
decrement: (ctx, step) => {
|
|
382
|
-
const value = decrement(ctx.value, step ?? ctx.step);
|
|
383
|
-
return formatDecimal(clamp(value, ctx), ctx);
|
|
154
|
+
const value = (0, import_number_utils2.decrement)(ctx.value, step ?? ctx.step);
|
|
155
|
+
return (0, import_number_utils2.formatDecimal)((0, import_number_utils2.clamp)(value, ctx), ctx);
|
|
384
156
|
},
|
|
385
157
|
clamp: (ctx) => {
|
|
386
|
-
return formatDecimal(clamp(ctx.value, ctx), ctx);
|
|
158
|
+
return (0, import_number_utils2.formatDecimal)((0, import_number_utils2.clamp)(ctx.value, ctx), ctx);
|
|
387
159
|
},
|
|
388
160
|
parse: (ctx, value) => {
|
|
389
161
|
return ctx.parse?.(value) ?? value;
|
|
@@ -393,14 +165,14 @@ var utils = {
|
|
|
393
165
|
return ctx.format?.(_val) ?? _val;
|
|
394
166
|
},
|
|
395
167
|
round: (ctx) => {
|
|
396
|
-
return formatDecimal(ctx.value, ctx);
|
|
168
|
+
return (0, import_number_utils2.formatDecimal)(ctx.value, ctx);
|
|
397
169
|
}
|
|
398
170
|
};
|
|
399
171
|
|
|
400
172
|
// src/number-input.machine.ts
|
|
401
173
|
var { not, and } = import_core.guards;
|
|
402
174
|
function machine(userContext) {
|
|
403
|
-
const ctx = compact(userContext);
|
|
175
|
+
const ctx = (0, import_utils.compact)(userContext);
|
|
404
176
|
return (0, import_core.createMachine)(
|
|
405
177
|
{
|
|
406
178
|
id: "number-input",
|
|
@@ -429,10 +201,10 @@ function machine(userContext) {
|
|
|
429
201
|
},
|
|
430
202
|
computed: {
|
|
431
203
|
isRtl: (ctx2) => ctx2.dir === "rtl",
|
|
432
|
-
valueAsNumber: (ctx2) => valueOf(ctx2.value),
|
|
433
|
-
isAtMin: (ctx2) => isAtMin(ctx2.value, ctx2),
|
|
434
|
-
isAtMax: (ctx2) => isAtMax(ctx2.value, ctx2),
|
|
435
|
-
isOutOfRange: (ctx2) => !isWithinRange(ctx2.value, ctx2),
|
|
204
|
+
valueAsNumber: (ctx2) => (0, import_number_utils3.valueOf)(ctx2.value),
|
|
205
|
+
isAtMin: (ctx2) => (0, import_number_utils3.isAtMin)(ctx2.value, ctx2),
|
|
206
|
+
isAtMax: (ctx2) => (0, import_number_utils3.isAtMax)(ctx2.value, ctx2),
|
|
207
|
+
isOutOfRange: (ctx2) => !(0, import_number_utils3.isWithinRange)(ctx2.value, ctx2),
|
|
436
208
|
isValueEmpty: (ctx2) => ctx2.value === "",
|
|
437
209
|
canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
|
|
438
210
|
canDecrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMin,
|
|
@@ -613,7 +385,9 @@ function machine(userContext) {
|
|
|
613
385
|
},
|
|
614
386
|
trackButtonDisabled(ctx2, _evt, { send }) {
|
|
615
387
|
const btn = dom.getPressedTriggerEl(ctx2, ctx2.hint);
|
|
616
|
-
return observeAttributes(btn, "disabled", () =>
|
|
388
|
+
return (0, import_mutation_observer.observeAttributes)(btn, ["disabled"], () => {
|
|
389
|
+
send("PRESS_UP");
|
|
390
|
+
});
|
|
617
391
|
},
|
|
618
392
|
attachWheelListener(ctx2, _evt, { send }) {
|
|
619
393
|
const input = dom.getInputEl(ctx2);
|
|
@@ -631,12 +405,12 @@ function machine(userContext) {
|
|
|
631
405
|
send("DECREMENT");
|
|
632
406
|
}
|
|
633
407
|
}
|
|
634
|
-
return addDomEvent(input, "wheel", onWheel, { passive: false });
|
|
408
|
+
return (0, import_dom_event2.addDomEvent)(input, "wheel", onWheel, { passive: false });
|
|
635
409
|
},
|
|
636
410
|
activatePointerLock(ctx2) {
|
|
637
|
-
if (isSafari
|
|
411
|
+
if ((0, import_dom_query2.isSafari)())
|
|
638
412
|
return;
|
|
639
|
-
return requestPointerLock(dom.getDoc(ctx2));
|
|
413
|
+
return (0, import_dom_event2.requestPointerLock)(dom.getDoc(ctx2));
|
|
640
414
|
},
|
|
641
415
|
trackMousemove(ctx2, _evt, { send }) {
|
|
642
416
|
const doc = dom.getDoc(ctx2);
|
|
@@ -655,9 +429,9 @@ function machine(userContext) {
|
|
|
655
429
|
function onMouseup() {
|
|
656
430
|
send("POINTER_UP_SCRUBBER");
|
|
657
431
|
}
|
|
658
|
-
return callAll(
|
|
659
|
-
addDomEvent(doc, "mousemove", onMousemove, false),
|
|
660
|
-
addDomEvent(doc, "mouseup", onMouseup, false)
|
|
432
|
+
return (0, import_utils.callAll)(
|
|
433
|
+
(0, import_dom_event2.addDomEvent)(doc, "mousemove", onMousemove, false),
|
|
434
|
+
(0, import_dom_event2.addDomEvent)(doc, "mouseup", onMouseup, false)
|
|
661
435
|
);
|
|
662
436
|
}
|
|
663
437
|
},
|
|
@@ -666,7 +440,7 @@ function machine(userContext) {
|
|
|
666
440
|
if (!ctx2.focusInputOnChange)
|
|
667
441
|
return;
|
|
668
442
|
const input = dom.getInputEl(ctx2);
|
|
669
|
-
raf(() => input?.focus());
|
|
443
|
+
(0, import_dom_query2.raf)(() => input?.focus());
|
|
670
444
|
},
|
|
671
445
|
increment(ctx2, evt) {
|
|
672
446
|
ctx2.value = utils.increment(ctx2, evt.step);
|
|
@@ -741,6 +515,7 @@ function machine(userContext) {
|
|
|
741
515
|
valueAsNumber: ctx2.valueAsNumber
|
|
742
516
|
});
|
|
743
517
|
},
|
|
518
|
+
// sync input value, in event it was set from form libraries via `ref`, `bind:this`, etc.
|
|
744
519
|
syncInputValue(ctx2) {
|
|
745
520
|
const input = dom.getInputEl(ctx2);
|
|
746
521
|
if (!input || input.value == ctx2.value)
|
|
@@ -762,7 +537,7 @@ function machine(userContext) {
|
|
|
762
537
|
cursor.style.transform = `translate3d(${x}px, ${y}px, 0px)`;
|
|
763
538
|
},
|
|
764
539
|
dispatchChangeEvent(ctx2) {
|
|
765
|
-
dispatchInputValueEvent(dom.getInputEl(ctx2), ctx2.formattedValue);
|
|
540
|
+
(0, import_form_utils.dispatchInputValueEvent)(dom.getInputEl(ctx2), ctx2.formattedValue);
|
|
766
541
|
}
|
|
767
542
|
}
|
|
768
543
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
machine
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-EPCXXTFL.mjs";
|
|
3
|
+
} from "./chunk-3O7PA63J.mjs";
|
|
4
|
+
import "./chunk-QYY4CWRS.mjs";
|
|
5
|
+
import "./chunk-AXXDGYUW.mjs";
|
|
7
6
|
export {
|
|
8
7
|
machine
|
|
9
8
|
};
|
|
@@ -23,58 +23,13 @@ __export(number_input_utils_exports, {
|
|
|
23
23
|
utils: () => utils
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(number_input_utils_exports);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
29
|
-
|
|
30
|
-
// ../../utilities/number/src/number.ts
|
|
31
|
-
function clamp(v, o) {
|
|
32
|
-
return Math.min(Math.max(valueOf(v), o.min), o.max);
|
|
33
|
-
}
|
|
34
|
-
function countDecimals(value) {
|
|
35
|
-
if (!Number.isFinite(value))
|
|
36
|
-
return 0;
|
|
37
|
-
let e = 1, p = 0;
|
|
38
|
-
while (Math.round(value * e) / e !== value) {
|
|
39
|
-
e *= 10;
|
|
40
|
-
p += 1;
|
|
41
|
-
}
|
|
42
|
-
return p;
|
|
43
|
-
}
|
|
44
|
-
var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
|
|
45
|
-
var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
|
|
46
|
-
function valueOf(v) {
|
|
47
|
-
if (typeof v === "number")
|
|
48
|
-
return v;
|
|
49
|
-
const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
|
|
50
|
-
return !Number.isNaN(num) ? num : 0;
|
|
51
|
-
}
|
|
52
|
-
function formatDecimal(v, o) {
|
|
53
|
-
return new Intl.NumberFormat("en-US", {
|
|
54
|
-
useGrouping: false,
|
|
55
|
-
style: "decimal",
|
|
56
|
-
minimumFractionDigits: o.minFractionDigits,
|
|
57
|
-
maximumFractionDigits: o.maxFractionDigits
|
|
58
|
-
}).format(valueOf(v));
|
|
59
|
-
}
|
|
60
|
-
function decimalOperation(a, op, b) {
|
|
61
|
-
let result = op === "+" ? a + b : a - b;
|
|
62
|
-
if (a % 1 !== 0 || b % 1 !== 0) {
|
|
63
|
-
const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
|
|
64
|
-
a = Math.round(a * multiplier);
|
|
65
|
-
b = Math.round(b * multiplier);
|
|
66
|
-
result = op === "+" ? a + b : a - b;
|
|
67
|
-
result /= multiplier;
|
|
68
|
-
}
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// src/number-input.utils.ts
|
|
26
|
+
var import_dom_event = require("@zag-js/dom-event");
|
|
27
|
+
var import_number_utils = require("@zag-js/number-utils");
|
|
73
28
|
var utils = {
|
|
74
29
|
isValidNumericEvent: (ctx, event) => {
|
|
75
30
|
if (event.key == null)
|
|
76
31
|
return true;
|
|
77
|
-
const isModifier = isModifiedEvent(event);
|
|
32
|
+
const isModifier = (0, import_dom_event.isModifiedEvent)(event);
|
|
78
33
|
const isSingleKey = event.key.length === 1;
|
|
79
34
|
if (isModifier || !isSingleKey)
|
|
80
35
|
return true;
|
|
@@ -85,15 +40,15 @@ var utils = {
|
|
|
85
40
|
return value.split("").filter(ctx.validateCharacter ?? utils.isFloatingPoint).join("");
|
|
86
41
|
},
|
|
87
42
|
increment: (ctx, step) => {
|
|
88
|
-
const value = increment(ctx.value, step ?? ctx.step);
|
|
89
|
-
return formatDecimal(clamp(value, ctx), ctx);
|
|
43
|
+
const value = (0, import_number_utils.increment)(ctx.value, step ?? ctx.step);
|
|
44
|
+
return (0, import_number_utils.formatDecimal)((0, import_number_utils.clamp)(value, ctx), ctx);
|
|
90
45
|
},
|
|
91
46
|
decrement: (ctx, step) => {
|
|
92
|
-
const value = decrement(ctx.value, step ?? ctx.step);
|
|
93
|
-
return formatDecimal(clamp(value, ctx), ctx);
|
|
47
|
+
const value = (0, import_number_utils.decrement)(ctx.value, step ?? ctx.step);
|
|
48
|
+
return (0, import_number_utils.formatDecimal)((0, import_number_utils.clamp)(value, ctx), ctx);
|
|
94
49
|
},
|
|
95
50
|
clamp: (ctx) => {
|
|
96
|
-
return formatDecimal(clamp(ctx.value, ctx), ctx);
|
|
51
|
+
return (0, import_number_utils.formatDecimal)((0, import_number_utils.clamp)(ctx.value, ctx), ctx);
|
|
97
52
|
},
|
|
98
53
|
parse: (ctx, value) => {
|
|
99
54
|
return ctx.parse?.(value) ?? value;
|
|
@@ -103,7 +58,7 @@ var utils = {
|
|
|
103
58
|
return ctx.format?.(_val) ?? _val;
|
|
104
59
|
},
|
|
105
60
|
round: (ctx) => {
|
|
106
|
-
return formatDecimal(ctx.value, ctx);
|
|
61
|
+
return (0, import_number_utils.formatDecimal)(ctx.value, ctx);
|
|
107
62
|
}
|
|
108
63
|
};
|
|
109
64
|
// Annotate the CommonJS export names for ESM import in node:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/number-input",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.13",
|
|
4
4
|
"description": "Core logic for the number-input widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -27,15 +27,17 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@zag-js/anatomy": "0.1.4",
|
|
30
|
-
"@zag-js/core": "0.2.
|
|
31
|
-
"@zag-js/
|
|
30
|
+
"@zag-js/core": "0.2.10",
|
|
31
|
+
"@zag-js/dom-query": "0.1.3",
|
|
32
|
+
"@zag-js/dom-event": "0.0.1",
|
|
33
|
+
"@zag-js/form-utils": "0.2.5",
|
|
34
|
+
"@zag-js/mutation-observer": "0.0.1",
|
|
35
|
+
"@zag-js/utils": "0.3.3",
|
|
36
|
+
"@zag-js/types": "0.3.4",
|
|
37
|
+
"@zag-js/number-utils": "0.2.3"
|
|
32
38
|
},
|
|
33
39
|
"devDependencies": {
|
|
34
|
-
"clean-package": "2.2.0"
|
|
35
|
-
"@zag-js/dom-utils": "0.2.4",
|
|
36
|
-
"@zag-js/form-utils": "0.2.4",
|
|
37
|
-
"@zag-js/number-utils": "0.2.3",
|
|
38
|
-
"@zag-js/utils": "0.3.3"
|
|
40
|
+
"clean-package": "2.2.0"
|
|
39
41
|
},
|
|
40
42
|
"clean-package": "../../../clean-package.config.json",
|
|
41
43
|
"main": "dist/index.js",
|