@zag-js/number-input 0.1.6 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +56 -37
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +56 -37
- package/dist/index.mjs.map +3 -3
- package/dist/number-input.types.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -54,6 +54,13 @@ function raf(fn) {
|
|
|
54
54
|
globalThis.cancelAnimationFrame(id);
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
+
var isDom = () => typeof window !== "undefined";
|
|
58
|
+
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
59
|
+
var isTouchDevice = isDom() && !!navigator.maxTouchPoints;
|
|
60
|
+
var runIfFn = (v, ...a) => {
|
|
61
|
+
const res = typeof v === "function" ? v(...a) : v;
|
|
62
|
+
return res != null ? res : void 0;
|
|
63
|
+
};
|
|
57
64
|
var noop = () => {
|
|
58
65
|
};
|
|
59
66
|
var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
|
|
@@ -67,7 +74,7 @@ function getListenerCache() {
|
|
|
67
74
|
globalThis.__listenerCache__ = globalThis.__listenerCache__ || /* @__PURE__ */ new Map();
|
|
68
75
|
return globalThis.__listenerCache__;
|
|
69
76
|
}
|
|
70
|
-
function
|
|
77
|
+
function addGlobalEventListener(node, type, handler, options) {
|
|
71
78
|
var _a;
|
|
72
79
|
if (!node)
|
|
73
80
|
return noop;
|
|
@@ -119,28 +126,15 @@ function globalEventBus(node, type, handler, options) {
|
|
|
119
126
|
}
|
|
120
127
|
};
|
|
121
128
|
}
|
|
122
|
-
var
|
|
123
|
-
var isRef = (v) => t(v) === "Object" && "current" in v;
|
|
124
|
-
var runIfFn = (fn) => t(fn) === "Function" ? fn() : fn;
|
|
129
|
+
var isRef = (v) => hasProp(v, "current");
|
|
125
130
|
function addDomEvent(target, event, listener, options) {
|
|
126
131
|
const node = isRef(target) ? target.current : runIfFn(target);
|
|
127
|
-
return
|
|
132
|
+
return addGlobalEventListener(node, event, listener, options);
|
|
128
133
|
}
|
|
129
134
|
var MAX_Z_INDEX = 2147483647;
|
|
130
|
-
function getNativeEvent(
|
|
135
|
+
function getNativeEvent(e) {
|
|
131
136
|
var _a;
|
|
132
|
-
return (_a =
|
|
133
|
-
}
|
|
134
|
-
var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
|
|
135
|
-
var ARROW_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
|
|
136
|
-
function getEventStep(event) {
|
|
137
|
-
if (event.ctrlKey || event.metaKey) {
|
|
138
|
-
return 0.1;
|
|
139
|
-
} else {
|
|
140
|
-
const isPageKey = PAGE_KEYS.has(event.key);
|
|
141
|
-
const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.has(event.key);
|
|
142
|
-
return isSkipKey ? 10 : 1;
|
|
143
|
-
}
|
|
137
|
+
return (_a = e.nativeEvent) != null ? _a : e;
|
|
144
138
|
}
|
|
145
139
|
function observeAttributes(node, attributes, fn) {
|
|
146
140
|
if (!node)
|
|
@@ -157,6 +151,17 @@ function observeAttributes(node, attributes, fn) {
|
|
|
157
151
|
obs.observe(node, { attributes: true, attributeFilter: attrs });
|
|
158
152
|
return () => obs.disconnect();
|
|
159
153
|
}
|
|
154
|
+
var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
|
|
155
|
+
var ARROW_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
|
|
156
|
+
function getEventStep(event) {
|
|
157
|
+
if (event.ctrlKey || event.metaKey) {
|
|
158
|
+
return 0.1;
|
|
159
|
+
} else {
|
|
160
|
+
const isPageKey = PAGE_KEYS.has(event.key);
|
|
161
|
+
const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.has(event.key);
|
|
162
|
+
return isSkipKey ? 10 : 1;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
160
165
|
function itemById(v, id) {
|
|
161
166
|
return v.find((node) => node.id === id);
|
|
162
167
|
}
|
|
@@ -316,33 +321,46 @@ function decimalOperation(a, op, b) {
|
|
|
316
321
|
var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
|
|
317
322
|
|
|
318
323
|
// ../../utilities/rect/dist/index.mjs
|
|
324
|
+
var isDom2 = () => typeof window !== "undefined";
|
|
319
325
|
var isArray = (v) => Array.isArray(v);
|
|
320
326
|
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
321
|
-
var
|
|
327
|
+
var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
328
|
+
var isTouchDevice2 = isDom2() && !!navigator.maxTouchPoints;
|
|
329
|
+
var isTouchEvent = (v) => isObject(v) && hasProp2(v, "touches");
|
|
322
330
|
var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
|
|
323
|
-
function getEventPoint(e,
|
|
331
|
+
function getEventPoint(e, t = "page") {
|
|
324
332
|
const p = isTouchEvent(e) ? e.touches[0] || e.changedTouches[0] || fallback : e;
|
|
325
|
-
return { x: p[`${
|
|
333
|
+
return { x: p[`${t}X`], y: p[`${t}Y`] };
|
|
326
334
|
}
|
|
327
335
|
|
|
328
336
|
// ../../types/dist/index.mjs
|
|
329
337
|
function createNormalizer(fn) {
|
|
330
|
-
return {
|
|
338
|
+
return new Proxy({}, {
|
|
339
|
+
get() {
|
|
340
|
+
return fn;
|
|
341
|
+
}
|
|
342
|
+
});
|
|
331
343
|
}
|
|
332
344
|
var normalizeProp = createNormalizer((v) => v);
|
|
333
345
|
|
|
334
346
|
// ../../utilities/core/dist/index.mjs
|
|
335
|
-
var
|
|
336
|
-
|
|
337
|
-
var
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
var
|
|
342
|
-
var
|
|
343
|
-
var
|
|
344
|
-
var
|
|
347
|
+
var isDom3 = () => typeof window !== "undefined";
|
|
348
|
+
function getPlatform() {
|
|
349
|
+
var _a;
|
|
350
|
+
const agent = navigator.userAgentData;
|
|
351
|
+
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
352
|
+
}
|
|
353
|
+
var pt = (v) => isDom3() && v.test(getPlatform());
|
|
354
|
+
var vn = (v) => isDom3() && v.test(navigator.vendor);
|
|
355
|
+
var isTouchDevice3 = isDom3() && !!navigator.maxTouchPoints;
|
|
356
|
+
var isMac = () => pt(/^Mac/) && !isTouchDevice3;
|
|
357
|
+
var isSafari = () => isApple() && vn(/apple/i);
|
|
358
|
+
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
359
|
+
var isIos = () => isApple() && !isMac();
|
|
360
|
+
var supportsPointerEvent = () => isDom3() && window.onpointerdown === null;
|
|
361
|
+
var isLeftClick = (v) => v.button === 0;
|
|
345
362
|
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
363
|
+
var pipe2 = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
|
|
346
364
|
|
|
347
365
|
// src/number-input.dom.ts
|
|
348
366
|
var dom = {
|
|
@@ -606,7 +624,7 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
606
624
|
onPointerDown(event) {
|
|
607
625
|
if (isDecrementDisabled)
|
|
608
626
|
return;
|
|
609
|
-
send({ type: "PRESS_DOWN", hint: "decrement" });
|
|
627
|
+
send(isLeftClick(event) ? { type: "PRESS_DOWN", hint: "decrement" } : { type: "FOCUS" });
|
|
610
628
|
event.preventDefault();
|
|
611
629
|
},
|
|
612
630
|
onPointerUp() {
|
|
@@ -629,10 +647,10 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
629
647
|
tabIndex: -1,
|
|
630
648
|
"aria-controls": dom.getInputId(state.context),
|
|
631
649
|
onPointerDown(event) {
|
|
632
|
-
event.preventDefault();
|
|
633
650
|
if (isIncrementDisabled)
|
|
634
651
|
return;
|
|
635
|
-
send({ type: "PRESS_DOWN", hint: "increment" });
|
|
652
|
+
send(isLeftClick(event) ? { type: "PRESS_DOWN", hint: "increment" } : { type: "FOCUS" });
|
|
653
|
+
event.preventDefault();
|
|
636
654
|
},
|
|
637
655
|
onPointerUp() {
|
|
638
656
|
send({ type: "PRESS_UP", hint: "increment" });
|
|
@@ -750,6 +768,7 @@ function machine(ctx = {}) {
|
|
|
750
768
|
},
|
|
751
769
|
focused: {
|
|
752
770
|
tags: ["focus"],
|
|
771
|
+
entry: "focusInput",
|
|
753
772
|
activities: "attachWheelListener",
|
|
754
773
|
on: {
|
|
755
774
|
PRESS_DOWN: {
|
|
@@ -788,7 +807,7 @@ function machine(ctx = {}) {
|
|
|
788
807
|
},
|
|
789
808
|
{
|
|
790
809
|
target: "idle",
|
|
791
|
-
actions:
|
|
810
|
+
actions: "roundValue"
|
|
792
811
|
}
|
|
793
812
|
]
|
|
794
813
|
}
|
|
@@ -843,7 +862,7 @@ function machine(ctx = {}) {
|
|
|
843
862
|
on: {
|
|
844
863
|
POINTER_UP_SCRUBBER: {
|
|
845
864
|
target: "focused",
|
|
846
|
-
actions:
|
|
865
|
+
actions: "clearCursorPoint"
|
|
847
866
|
},
|
|
848
867
|
POINTER_MOVE_SCRUBBER: [
|
|
849
868
|
{
|