@zag-js/number-input 0.2.6 → 0.2.8
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-2UDY2X4M.mjs +246 -0
- package/dist/chunk-EUVYGWZ6.mjs +129 -0
- package/dist/chunk-HP6F2HUY.mjs +53 -0
- package/dist/chunk-MIZ4MW4C.mjs +543 -0
- package/dist/chunk-VCZUWKJT.mjs +151 -0
- package/dist/chunk-XHRILSH3.mjs +17 -0
- package/dist/index.d.ts +7 -1092
- package/dist/index.js +46 -45
- 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 +542 -0
- package/dist/number-input.connect.mjs +10 -0
- package/dist/number-input.dom.d.ts +47 -0
- package/dist/number-input.dom.js +208 -0
- package/dist/number-input.dom.mjs +7 -0
- package/dist/number-input.machine.d.ts +7 -0
- package/dist/number-input.machine.js +832 -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,6 @@
|
|
|
1
|
+
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
2
|
+
|
|
3
|
+
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "label" | "input" | "control" | "incrementTrigger" | "decrementTrigger" | "scrubber">;
|
|
4
|
+
declare const parts: Record<"root" | "label" | "input" | "control" | "incrementTrigger" | "decrementTrigger" | "scrubber", _zag_js_anatomy.AnatomyPart>;
|
|
5
|
+
|
|
6
|
+
export { anatomy, parts };
|
|
@@ -0,0 +1,42 @@
|
|
|
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.anatomy.ts
|
|
21
|
+
var number_input_anatomy_exports = {};
|
|
22
|
+
__export(number_input_anatomy_exports, {
|
|
23
|
+
anatomy: () => anatomy,
|
|
24
|
+
parts: () => parts
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(number_input_anatomy_exports);
|
|
27
|
+
var import_anatomy = require("@zag-js/anatomy");
|
|
28
|
+
var anatomy = (0, import_anatomy.createAnatomy)("numberInput").parts(
|
|
29
|
+
"root",
|
|
30
|
+
"label",
|
|
31
|
+
"input",
|
|
32
|
+
"control",
|
|
33
|
+
"incrementTrigger",
|
|
34
|
+
"decrementTrigger",
|
|
35
|
+
"scrubber"
|
|
36
|
+
);
|
|
37
|
+
var parts = anatomy.build();
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
anatomy,
|
|
41
|
+
parts
|
|
42
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PropTypes, NormalizeProps } from '@zag-js/types';
|
|
2
|
+
import { State, Send } from './number-input.types.js';
|
|
3
|
+
import '@zag-js/core';
|
|
4
|
+
|
|
5
|
+
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
6
|
+
isFocused: boolean;
|
|
7
|
+
isInvalid: boolean;
|
|
8
|
+
isValueEmpty: boolean;
|
|
9
|
+
value: string;
|
|
10
|
+
valueAsNumber: number;
|
|
11
|
+
setValue(value: string | number): void;
|
|
12
|
+
clearValue(): void;
|
|
13
|
+
increment(): void;
|
|
14
|
+
decrement(): void;
|
|
15
|
+
setToMax(): void;
|
|
16
|
+
setToMin(): void;
|
|
17
|
+
focus(): void;
|
|
18
|
+
blur(): void;
|
|
19
|
+
rootProps: T["element"];
|
|
20
|
+
labelProps: T["label"];
|
|
21
|
+
controlProps: T["element"];
|
|
22
|
+
inputProps: T["input"];
|
|
23
|
+
decrementTriggerProps: T["button"];
|
|
24
|
+
incrementTriggerProps: T["button"];
|
|
25
|
+
scrubberProps: T["element"];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { connect };
|
|
@@ -0,0 +1,542 @@
|
|
|
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.connect.ts
|
|
21
|
+
var number_input_connect_exports = {};
|
|
22
|
+
__export(number_input_connect_exports, {
|
|
23
|
+
connect: () => connect
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(number_input_connect_exports);
|
|
26
|
+
|
|
27
|
+
// ../../utilities/dom/src/attrs.ts
|
|
28
|
+
var dataAttr = (guard) => {
|
|
29
|
+
return guard ? "" : void 0;
|
|
30
|
+
};
|
|
31
|
+
var ariaAttr = (guard) => {
|
|
32
|
+
return guard ? "true" : void 0;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// ../../utilities/dom/src/constants.ts
|
|
36
|
+
var MAX_Z_INDEX = 2147483647;
|
|
37
|
+
|
|
38
|
+
// ../../utilities/core/src/guard.ts
|
|
39
|
+
var isArray = (v) => Array.isArray(v);
|
|
40
|
+
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
41
|
+
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
42
|
+
|
|
43
|
+
// ../../utilities/dom/src/platform.ts
|
|
44
|
+
var isDom = () => typeof window !== "undefined";
|
|
45
|
+
function getPlatform() {
|
|
46
|
+
var _a;
|
|
47
|
+
const agent = navigator.userAgentData;
|
|
48
|
+
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
49
|
+
}
|
|
50
|
+
var pt = (v) => isDom() && v.test(getPlatform());
|
|
51
|
+
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
52
|
+
var isSafari = () => isApple() && vn(/apple/i);
|
|
53
|
+
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
54
|
+
|
|
55
|
+
// ../../utilities/dom/src/query.ts
|
|
56
|
+
function isDocument(el) {
|
|
57
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
58
|
+
}
|
|
59
|
+
function isWindow(value) {
|
|
60
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
61
|
+
}
|
|
62
|
+
function getDocument(el) {
|
|
63
|
+
var _a;
|
|
64
|
+
if (isWindow(el))
|
|
65
|
+
return el.document;
|
|
66
|
+
if (isDocument(el))
|
|
67
|
+
return el;
|
|
68
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
69
|
+
}
|
|
70
|
+
function defineDomHelpers(helpers) {
|
|
71
|
+
const dom2 = {
|
|
72
|
+
getRootNode: (ctx) => {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
75
|
+
},
|
|
76
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
77
|
+
getWin: (ctx) => {
|
|
78
|
+
var _a;
|
|
79
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
80
|
+
},
|
|
81
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
82
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
...dom2,
|
|
86
|
+
...helpers
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ../../utilities/dom/src/event.ts
|
|
91
|
+
function getNativeEvent(e) {
|
|
92
|
+
var _a;
|
|
93
|
+
return (_a = e.nativeEvent) != null ? _a : e;
|
|
94
|
+
}
|
|
95
|
+
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
96
|
+
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
97
|
+
var isLeftClick = (v) => v.button === 0;
|
|
98
|
+
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
99
|
+
|
|
100
|
+
// ../../utilities/dom/src/get-event-point.ts
|
|
101
|
+
var fallback = {
|
|
102
|
+
pageX: 0,
|
|
103
|
+
pageY: 0,
|
|
104
|
+
clientX: 0,
|
|
105
|
+
clientY: 0
|
|
106
|
+
};
|
|
107
|
+
function getEventPoint(event, type = "page") {
|
|
108
|
+
var _a, _b;
|
|
109
|
+
const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event;
|
|
110
|
+
return { x: point[`${type}X`], y: point[`${type}Y`] };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// ../../utilities/dom/src/keyboard-event.ts
|
|
114
|
+
var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
|
|
115
|
+
var ARROW_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
|
|
116
|
+
function getEventStep(event) {
|
|
117
|
+
if (event.ctrlKey || event.metaKey) {
|
|
118
|
+
return 0.1;
|
|
119
|
+
} else {
|
|
120
|
+
const isPageKey = PAGE_KEYS.has(event.key);
|
|
121
|
+
const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.has(event.key);
|
|
122
|
+
return isSkipKey ? 10 : 1;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// ../../utilities/number/src/number.ts
|
|
127
|
+
function wrap(num, max) {
|
|
128
|
+
return (num % max + max) % max;
|
|
129
|
+
}
|
|
130
|
+
function roundToDevicePixel(num) {
|
|
131
|
+
if (typeof window === "undefined")
|
|
132
|
+
return Math.round(num);
|
|
133
|
+
const dp = window.devicePixelRatio;
|
|
134
|
+
return Math.floor(num * dp + 0.5) / dp;
|
|
135
|
+
}
|
|
136
|
+
function clamp(v, o) {
|
|
137
|
+
return Math.min(Math.max(valueOf(v), o.min), o.max);
|
|
138
|
+
}
|
|
139
|
+
function countDecimals(value) {
|
|
140
|
+
if (!Number.isFinite(value))
|
|
141
|
+
return 0;
|
|
142
|
+
let e = 1, p = 0;
|
|
143
|
+
while (Math.round(value * e) / e !== value) {
|
|
144
|
+
e *= 10;
|
|
145
|
+
p += 1;
|
|
146
|
+
}
|
|
147
|
+
return p;
|
|
148
|
+
}
|
|
149
|
+
var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
|
|
150
|
+
var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
|
|
151
|
+
function valueOf(v) {
|
|
152
|
+
if (typeof v === "number")
|
|
153
|
+
return v;
|
|
154
|
+
const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
|
|
155
|
+
return !Number.isNaN(num) ? num : 0;
|
|
156
|
+
}
|
|
157
|
+
function formatDecimal(v, o) {
|
|
158
|
+
return new Intl.NumberFormat("en-US", {
|
|
159
|
+
useGrouping: false,
|
|
160
|
+
style: "decimal",
|
|
161
|
+
minimumFractionDigits: o.minFractionDigits,
|
|
162
|
+
maximumFractionDigits: o.maxFractionDigits
|
|
163
|
+
}).format(valueOf(v));
|
|
164
|
+
}
|
|
165
|
+
function decimalOperation(a, op, b) {
|
|
166
|
+
let result = op === "+" ? a + b : a - b;
|
|
167
|
+
if (a % 1 !== 0 || b % 1 !== 0) {
|
|
168
|
+
const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
|
|
169
|
+
a = Math.round(a * multiplier);
|
|
170
|
+
b = Math.round(b * multiplier);
|
|
171
|
+
result = op === "+" ? a + b : a - b;
|
|
172
|
+
result /= multiplier;
|
|
173
|
+
}
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// src/number-input.anatomy.ts
|
|
178
|
+
var import_anatomy = require("@zag-js/anatomy");
|
|
179
|
+
var anatomy = (0, import_anatomy.createAnatomy)("numberInput").parts(
|
|
180
|
+
"root",
|
|
181
|
+
"label",
|
|
182
|
+
"input",
|
|
183
|
+
"control",
|
|
184
|
+
"incrementTrigger",
|
|
185
|
+
"decrementTrigger",
|
|
186
|
+
"scrubber"
|
|
187
|
+
);
|
|
188
|
+
var parts = anatomy.build();
|
|
189
|
+
|
|
190
|
+
// src/number-input.dom.ts
|
|
191
|
+
var dom = defineDomHelpers({
|
|
192
|
+
getRootId: (ctx) => {
|
|
193
|
+
var _a, _b;
|
|
194
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `number-input:${ctx.id}`;
|
|
195
|
+
},
|
|
196
|
+
getInputId: (ctx) => {
|
|
197
|
+
var _a, _b;
|
|
198
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.input) != null ? _b : `number-input:${ctx.id}:input`;
|
|
199
|
+
},
|
|
200
|
+
getIncrementTriggerId: (ctx) => {
|
|
201
|
+
var _a, _b;
|
|
202
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.incrementTrigger) != null ? _b : `number-input:${ctx.id}:inc`;
|
|
203
|
+
},
|
|
204
|
+
getDecrementTriggerId: (ctx) => {
|
|
205
|
+
var _a, _b;
|
|
206
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.decrementTrigger) != null ? _b : `number-input:${ctx.id}:dec`;
|
|
207
|
+
},
|
|
208
|
+
getScrubberId: (ctx) => {
|
|
209
|
+
var _a, _b;
|
|
210
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.scrubber) != null ? _b : `number-input:${ctx.id}:scrubber`;
|
|
211
|
+
},
|
|
212
|
+
getCursorId: (ctx) => `number-input:${ctx.id}:cursor`,
|
|
213
|
+
getLabelId: (ctx) => {
|
|
214
|
+
var _a, _b;
|
|
215
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `number-input:${ctx.id}:label`;
|
|
216
|
+
},
|
|
217
|
+
getInputEl: (ctx) => dom.getById(ctx, dom.getInputId(ctx)),
|
|
218
|
+
getIncrementTriggerEl: (ctx) => dom.getById(ctx, dom.getIncrementTriggerId(ctx)),
|
|
219
|
+
getDecrementTriggerEl: (ctx) => dom.getById(ctx, dom.getDecrementTriggerId(ctx)),
|
|
220
|
+
getScrubberEl: (ctx) => dom.getById(ctx, dom.getScrubberId(ctx)),
|
|
221
|
+
getCursorEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getCursorId(ctx)),
|
|
222
|
+
getPressedTriggerEl: (ctx, hint = ctx.hint) => {
|
|
223
|
+
let btnEl = null;
|
|
224
|
+
if (hint === "increment") {
|
|
225
|
+
btnEl = dom.getIncrementTriggerEl(ctx);
|
|
226
|
+
}
|
|
227
|
+
if (hint === "decrement") {
|
|
228
|
+
btnEl = dom.getDecrementTriggerEl(ctx);
|
|
229
|
+
}
|
|
230
|
+
return btnEl;
|
|
231
|
+
},
|
|
232
|
+
setupVirtualCursor(ctx) {
|
|
233
|
+
if (isSafari() || !supportsPointerEvent())
|
|
234
|
+
return;
|
|
235
|
+
dom.createVirtualCursor(ctx);
|
|
236
|
+
return () => {
|
|
237
|
+
var _a;
|
|
238
|
+
(_a = dom.getCursorEl(ctx)) == null ? void 0 : _a.remove();
|
|
239
|
+
};
|
|
240
|
+
},
|
|
241
|
+
preventTextSelection(ctx) {
|
|
242
|
+
const doc = dom.getDoc(ctx);
|
|
243
|
+
const html = doc.documentElement;
|
|
244
|
+
const body = doc.body;
|
|
245
|
+
body.style.pointerEvents = "none";
|
|
246
|
+
html.style.userSelect = "none";
|
|
247
|
+
html.style.cursor = "ew-resize";
|
|
248
|
+
return () => {
|
|
249
|
+
body.style.pointerEvents = "";
|
|
250
|
+
html.style.userSelect = "";
|
|
251
|
+
html.style.cursor = "";
|
|
252
|
+
if (!html.style.length) {
|
|
253
|
+
html.removeAttribute("style");
|
|
254
|
+
}
|
|
255
|
+
if (!body.style.length) {
|
|
256
|
+
body.removeAttribute("style");
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
},
|
|
260
|
+
getMousementValue(ctx, event) {
|
|
261
|
+
const x = roundToDevicePixel(event.movementX);
|
|
262
|
+
const y = roundToDevicePixel(event.movementY);
|
|
263
|
+
let hint = x > 0 ? "increment" : x < 0 ? "decrement" : null;
|
|
264
|
+
if (ctx.isRtl && hint === "increment")
|
|
265
|
+
hint = "decrement";
|
|
266
|
+
if (ctx.isRtl && hint === "decrement")
|
|
267
|
+
hint = "increment";
|
|
268
|
+
const point = {
|
|
269
|
+
x: ctx.scrubberCursorPoint.x + x,
|
|
270
|
+
y: ctx.scrubberCursorPoint.y + y
|
|
271
|
+
};
|
|
272
|
+
const win = dom.getWin(ctx);
|
|
273
|
+
const width = win.innerWidth;
|
|
274
|
+
const half = roundToDevicePixel(7.5);
|
|
275
|
+
point.x = wrap(point.x + half, width) - half;
|
|
276
|
+
return { hint, point };
|
|
277
|
+
},
|
|
278
|
+
createVirtualCursor(ctx) {
|
|
279
|
+
const doc = dom.getDoc(ctx);
|
|
280
|
+
const el = doc.createElement("div");
|
|
281
|
+
el.className = "scrubber--cursor";
|
|
282
|
+
el.id = dom.getCursorId(ctx);
|
|
283
|
+
Object.assign(el.style, {
|
|
284
|
+
width: "15px",
|
|
285
|
+
height: "15px",
|
|
286
|
+
position: "fixed",
|
|
287
|
+
pointerEvents: "none",
|
|
288
|
+
left: "0px",
|
|
289
|
+
top: "0px",
|
|
290
|
+
zIndex: MAX_Z_INDEX,
|
|
291
|
+
transform: ctx.scrubberCursorPoint ? `translate3d(${ctx.scrubberCursorPoint.x}px, ${ctx.scrubberCursorPoint.y}px, 0px)` : void 0,
|
|
292
|
+
willChange: "transform"
|
|
293
|
+
});
|
|
294
|
+
el.innerHTML = `
|
|
295
|
+
<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);">
|
|
296
|
+
<g transform="translate(2 3)">
|
|
297
|
+
<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>
|
|
298
|
+
<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>
|
|
299
|
+
</g>
|
|
300
|
+
</svg>`;
|
|
301
|
+
doc.body.appendChild(el);
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
// src/number-input.utils.ts
|
|
306
|
+
var utils = {
|
|
307
|
+
isValidNumericEvent: (ctx, event) => {
|
|
308
|
+
var _a, _b;
|
|
309
|
+
if (event.key == null)
|
|
310
|
+
return true;
|
|
311
|
+
const isModifier = isModifiedEvent(event);
|
|
312
|
+
const isSingleKey = event.key.length === 1;
|
|
313
|
+
if (isModifier || !isSingleKey)
|
|
314
|
+
return true;
|
|
315
|
+
return (_b = (_a = ctx.validateCharacter) == null ? void 0 : _a.call(ctx, event.key)) != null ? _b : utils.isFloatingPoint(event.key);
|
|
316
|
+
},
|
|
317
|
+
isFloatingPoint: (v) => /^[0-9+\-.]$/.test(v),
|
|
318
|
+
sanitize: (ctx, value) => {
|
|
319
|
+
var _a;
|
|
320
|
+
return value.split("").filter((_a = ctx.validateCharacter) != null ? _a : utils.isFloatingPoint).join("");
|
|
321
|
+
},
|
|
322
|
+
increment: (ctx, step) => {
|
|
323
|
+
const value = increment(ctx.value, step != null ? step : ctx.step);
|
|
324
|
+
return formatDecimal(clamp(value, ctx), ctx);
|
|
325
|
+
},
|
|
326
|
+
decrement: (ctx, step) => {
|
|
327
|
+
const value = decrement(ctx.value, step != null ? step : ctx.step);
|
|
328
|
+
return formatDecimal(clamp(value, ctx), ctx);
|
|
329
|
+
},
|
|
330
|
+
clamp: (ctx) => {
|
|
331
|
+
return formatDecimal(clamp(ctx.value, ctx), ctx);
|
|
332
|
+
},
|
|
333
|
+
parse: (ctx, value) => {
|
|
334
|
+
var _a, _b;
|
|
335
|
+
return (_b = (_a = ctx.parse) == null ? void 0 : _a.call(ctx, value)) != null ? _b : value;
|
|
336
|
+
},
|
|
337
|
+
format: (ctx, value) => {
|
|
338
|
+
var _a, _b;
|
|
339
|
+
const _val = value.toString();
|
|
340
|
+
return (_b = (_a = ctx.format) == null ? void 0 : _a.call(ctx, _val)) != null ? _b : _val;
|
|
341
|
+
},
|
|
342
|
+
round: (ctx) => {
|
|
343
|
+
return formatDecimal(ctx.value, ctx);
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
// src/number-input.connect.ts
|
|
348
|
+
function connect(state, send, normalize) {
|
|
349
|
+
const isFocused = state.hasTag("focus");
|
|
350
|
+
const isInvalid = state.context.isOutOfRange || !!state.context.invalid;
|
|
351
|
+
const isDisabled = !!state.context.disabled;
|
|
352
|
+
const isValueEmpty = state.context.isValueEmpty;
|
|
353
|
+
const isIncrementDisabled = isDisabled || !state.context.canIncrement;
|
|
354
|
+
const isDecrementDisabled = isDisabled || !state.context.canDecrement;
|
|
355
|
+
const translations = state.context.translations;
|
|
356
|
+
return {
|
|
357
|
+
isFocused,
|
|
358
|
+
isInvalid,
|
|
359
|
+
isValueEmpty,
|
|
360
|
+
value: state.context.formattedValue,
|
|
361
|
+
valueAsNumber: state.context.valueAsNumber,
|
|
362
|
+
setValue(value) {
|
|
363
|
+
send({ type: "SET_VALUE", value: value.toString() });
|
|
364
|
+
},
|
|
365
|
+
clearValue() {
|
|
366
|
+
send("CLEAR_VALUE");
|
|
367
|
+
},
|
|
368
|
+
increment() {
|
|
369
|
+
send("INCREMENT");
|
|
370
|
+
},
|
|
371
|
+
decrement() {
|
|
372
|
+
send("DECREMENT");
|
|
373
|
+
},
|
|
374
|
+
setToMax() {
|
|
375
|
+
send({ type: "SET_VALUE", value: state.context.max });
|
|
376
|
+
},
|
|
377
|
+
setToMin() {
|
|
378
|
+
send({ type: "SET_VALUE", value: state.context.min });
|
|
379
|
+
},
|
|
380
|
+
focus() {
|
|
381
|
+
var _a;
|
|
382
|
+
(_a = dom.getInputEl(state.context)) == null ? void 0 : _a.focus();
|
|
383
|
+
},
|
|
384
|
+
blur() {
|
|
385
|
+
var _a;
|
|
386
|
+
(_a = dom.getInputEl(state.context)) == null ? void 0 : _a.blur();
|
|
387
|
+
},
|
|
388
|
+
rootProps: normalize.element({
|
|
389
|
+
id: dom.getRootId(state.context),
|
|
390
|
+
...parts.root.attrs,
|
|
391
|
+
"data-disabled": dataAttr(isDisabled)
|
|
392
|
+
}),
|
|
393
|
+
labelProps: normalize.label({
|
|
394
|
+
...parts.label.attrs,
|
|
395
|
+
"data-disabled": dataAttr(isDisabled),
|
|
396
|
+
"data-invalid": dataAttr(isInvalid),
|
|
397
|
+
id: dom.getLabelId(state.context),
|
|
398
|
+
htmlFor: dom.getInputId(state.context)
|
|
399
|
+
}),
|
|
400
|
+
controlProps: normalize.element({
|
|
401
|
+
...parts.control.attrs,
|
|
402
|
+
role: "group",
|
|
403
|
+
"aria-disabled": isDisabled,
|
|
404
|
+
"data-disabled": dataAttr(isDisabled),
|
|
405
|
+
"data-invalid": dataAttr(isInvalid),
|
|
406
|
+
"aria-invalid": ariaAttr(state.context.invalid)
|
|
407
|
+
}),
|
|
408
|
+
inputProps: normalize.input({
|
|
409
|
+
...parts.input.attrs,
|
|
410
|
+
name: state.context.name,
|
|
411
|
+
form: state.context.form,
|
|
412
|
+
id: dom.getInputId(state.context),
|
|
413
|
+
role: "spinbutton",
|
|
414
|
+
defaultValue: state.context.formattedValue,
|
|
415
|
+
pattern: state.context.pattern,
|
|
416
|
+
inputMode: state.context.inputMode,
|
|
417
|
+
"aria-invalid": isInvalid || void 0,
|
|
418
|
+
"data-invalid": dataAttr(isInvalid),
|
|
419
|
+
disabled: isDisabled,
|
|
420
|
+
"data-disabled": dataAttr(isDisabled),
|
|
421
|
+
readOnly: !!state.context.readOnly,
|
|
422
|
+
autoComplete: "off",
|
|
423
|
+
autoCorrect: "off",
|
|
424
|
+
spellCheck: "false",
|
|
425
|
+
type: "text",
|
|
426
|
+
"aria-roledescription": "numberfield",
|
|
427
|
+
"aria-valuemin": state.context.min,
|
|
428
|
+
"aria-valuemax": state.context.max,
|
|
429
|
+
"aria-valuenow": isNaN(state.context.valueAsNumber) ? void 0 : state.context.valueAsNumber,
|
|
430
|
+
"aria-valuetext": state.context.valueText,
|
|
431
|
+
onFocus() {
|
|
432
|
+
send("FOCUS");
|
|
433
|
+
},
|
|
434
|
+
onBlur() {
|
|
435
|
+
send("BLUR");
|
|
436
|
+
},
|
|
437
|
+
onChange(event) {
|
|
438
|
+
const evt = getNativeEvent(event);
|
|
439
|
+
if (evt.isComposing)
|
|
440
|
+
return;
|
|
441
|
+
send({ type: "CHANGE", target: event.currentTarget, hint: "set" });
|
|
442
|
+
},
|
|
443
|
+
onKeyDown(event) {
|
|
444
|
+
const evt = getNativeEvent(event);
|
|
445
|
+
if (evt.isComposing)
|
|
446
|
+
return;
|
|
447
|
+
if (!utils.isValidNumericEvent(state.context, event)) {
|
|
448
|
+
event.preventDefault();
|
|
449
|
+
}
|
|
450
|
+
const step = getEventStep(event) * state.context.step;
|
|
451
|
+
const keyMap = {
|
|
452
|
+
ArrowUp() {
|
|
453
|
+
send({ type: "ARROW_UP", step });
|
|
454
|
+
},
|
|
455
|
+
ArrowDown() {
|
|
456
|
+
send({ type: "ARROW_DOWN", step });
|
|
457
|
+
},
|
|
458
|
+
Home() {
|
|
459
|
+
send("HOME");
|
|
460
|
+
},
|
|
461
|
+
End() {
|
|
462
|
+
send("END");
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
const exec = keyMap[event.key];
|
|
466
|
+
if (exec) {
|
|
467
|
+
exec(event);
|
|
468
|
+
event.preventDefault();
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}),
|
|
472
|
+
decrementTriggerProps: normalize.button({
|
|
473
|
+
...parts.decrementTrigger.attrs,
|
|
474
|
+
id: dom.getDecrementTriggerId(state.context),
|
|
475
|
+
disabled: isDecrementDisabled,
|
|
476
|
+
"data-disabled": dataAttr(isDecrementDisabled),
|
|
477
|
+
"aria-label": translations.decrementLabel,
|
|
478
|
+
type: "button",
|
|
479
|
+
tabIndex: -1,
|
|
480
|
+
"aria-controls": dom.getInputId(state.context),
|
|
481
|
+
onPointerDown(event) {
|
|
482
|
+
if (isDecrementDisabled)
|
|
483
|
+
return;
|
|
484
|
+
send(isLeftClick(event) ? { type: "PRESS_DOWN", hint: "decrement" } : { type: "FOCUS" });
|
|
485
|
+
event.preventDefault();
|
|
486
|
+
},
|
|
487
|
+
onPointerUp() {
|
|
488
|
+
send({ type: "PRESS_UP", hint: "decrement" });
|
|
489
|
+
},
|
|
490
|
+
onPointerLeave() {
|
|
491
|
+
if (isDecrementDisabled)
|
|
492
|
+
return;
|
|
493
|
+
send({ type: "PRESS_UP", hint: "decrement" });
|
|
494
|
+
}
|
|
495
|
+
}),
|
|
496
|
+
incrementTriggerProps: normalize.button({
|
|
497
|
+
...parts.incrementTrigger.attrs,
|
|
498
|
+
id: dom.getIncrementTriggerId(state.context),
|
|
499
|
+
disabled: isIncrementDisabled,
|
|
500
|
+
"data-disabled": dataAttr(isIncrementDisabled),
|
|
501
|
+
"aria-label": translations.incrementLabel,
|
|
502
|
+
type: "button",
|
|
503
|
+
tabIndex: -1,
|
|
504
|
+
"aria-controls": dom.getInputId(state.context),
|
|
505
|
+
onPointerDown(event) {
|
|
506
|
+
if (isIncrementDisabled)
|
|
507
|
+
return;
|
|
508
|
+
send(isLeftClick(event) ? { type: "PRESS_DOWN", hint: "increment" } : { type: "FOCUS" });
|
|
509
|
+
event.preventDefault();
|
|
510
|
+
},
|
|
511
|
+
onPointerUp() {
|
|
512
|
+
send({ type: "PRESS_UP", hint: "increment" });
|
|
513
|
+
},
|
|
514
|
+
onPointerLeave() {
|
|
515
|
+
send({ type: "PRESS_UP", hint: "increment" });
|
|
516
|
+
}
|
|
517
|
+
}),
|
|
518
|
+
scrubberProps: normalize.element({
|
|
519
|
+
...parts.scrubber.attrs,
|
|
520
|
+
"data-disabled": dataAttr(isDisabled),
|
|
521
|
+
id: dom.getScrubberId(state.context),
|
|
522
|
+
role: "presentation",
|
|
523
|
+
onMouseDown(event) {
|
|
524
|
+
if (isDisabled)
|
|
525
|
+
return;
|
|
526
|
+
const evt = getNativeEvent(event);
|
|
527
|
+
event.preventDefault();
|
|
528
|
+
const point = getEventPoint(evt);
|
|
529
|
+
point.x = point.x - roundToDevicePixel(7.5);
|
|
530
|
+
point.y = point.y - roundToDevicePixel(7.5);
|
|
531
|
+
send({ type: "PRESS_DOWN_SCRUBBER", point });
|
|
532
|
+
},
|
|
533
|
+
style: {
|
|
534
|
+
cursor: isDisabled ? void 0 : "ew-resize"
|
|
535
|
+
}
|
|
536
|
+
})
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
540
|
+
0 && (module.exports = {
|
|
541
|
+
connect
|
|
542
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { MachineContext } from './number-input.types.js';
|
|
2
|
+
import '@zag-js/core';
|
|
3
|
+
import '@zag-js/types';
|
|
4
|
+
|
|
5
|
+
declare const dom: {
|
|
6
|
+
getRootNode: (ctx: {
|
|
7
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
8
|
+
}) => Document | ShadowRoot;
|
|
9
|
+
getDoc: (ctx: {
|
|
10
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
11
|
+
}) => Document;
|
|
12
|
+
getWin: (ctx: {
|
|
13
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
14
|
+
}) => Window & typeof globalThis;
|
|
15
|
+
getActiveElement: (ctx: {
|
|
16
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
17
|
+
}) => HTMLElement | null;
|
|
18
|
+
getById: <T = HTMLElement>(ctx: {
|
|
19
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
20
|
+
}, id: string) => T | null;
|
|
21
|
+
} & {
|
|
22
|
+
getRootId: (ctx: MachineContext) => string;
|
|
23
|
+
getInputId: (ctx: MachineContext) => string;
|
|
24
|
+
getIncrementTriggerId: (ctx: MachineContext) => string;
|
|
25
|
+
getDecrementTriggerId: (ctx: MachineContext) => string;
|
|
26
|
+
getScrubberId: (ctx: MachineContext) => string;
|
|
27
|
+
getCursorId: (ctx: MachineContext) => string;
|
|
28
|
+
getLabelId: (ctx: MachineContext) => string;
|
|
29
|
+
getInputEl: (ctx: MachineContext) => HTMLInputElement | null;
|
|
30
|
+
getIncrementTriggerEl: (ctx: MachineContext) => HTMLButtonElement | null;
|
|
31
|
+
getDecrementTriggerEl: (ctx: MachineContext) => HTMLButtonElement | null;
|
|
32
|
+
getScrubberEl: (ctx: MachineContext) => HTMLElement | null;
|
|
33
|
+
getCursorEl: (ctx: MachineContext) => HTMLElement | null;
|
|
34
|
+
getPressedTriggerEl: (ctx: MachineContext, hint?: "set" | "increment" | "decrement" | null) => HTMLButtonElement | null;
|
|
35
|
+
setupVirtualCursor(ctx: MachineContext): (() => void) | undefined;
|
|
36
|
+
preventTextSelection(ctx: MachineContext): () => void;
|
|
37
|
+
getMousementValue(ctx: MachineContext, event: MouseEvent): {
|
|
38
|
+
hint: string | null;
|
|
39
|
+
point: {
|
|
40
|
+
x: number;
|
|
41
|
+
y: number;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
createVirtualCursor(ctx: MachineContext): void;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export { dom };
|