@zag-js/number-input 0.2.5 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-2SIS62IB.mjs +129 -0
- package/dist/chunk-7E3ZO263.mjs +540 -0
- package/dist/chunk-DDNK5RLW.mjs +169 -0
- package/dist/chunk-GWZPUXGU.mjs +53 -0
- package/dist/chunk-TSELS3UE.mjs +246 -0
- package/dist/chunk-XHRILSH3.mjs +17 -0
- package/dist/index.d.ts +7 -1092
- package/dist/index.js +41 -25
- package/dist/index.mjs +12 -1049
- package/dist/number-input.anatomy.d.ts +6 -0
- package/dist/number-input.anatomy.js +42 -0
- package/dist/number-input.anatomy.mjs +8 -0
- package/dist/number-input.connect.d.ts +28 -0
- package/dist/number-input.connect.js +560 -0
- package/dist/number-input.connect.mjs +10 -0
- package/dist/number-input.dom.d.ts +51 -0
- package/dist/number-input.dom.js +226 -0
- package/dist/number-input.dom.mjs +7 -0
- package/dist/number-input.machine.d.ts +7 -0
- package/dist/number-input.machine.js +847 -0
- package/dist/number-input.machine.mjs +9 -0
- package/dist/number-input.types.d.ts +217 -0
- package/dist/number-input.types.js +18 -0
- package/dist/number-input.types.mjs +0 -0
- package/dist/number-input.utils.d.ts +17 -0
- package/dist/number-input.utils.js +116 -0
- package/dist/number-input.utils.mjs +7 -0
- package/package.json +23 -13
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
createEmitter: (ctx: {
|
|
22
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
23
|
+
}, target: HTMLElement) => (evt: string, detail: Record<string, any>, options?: EventInit | undefined) => void;
|
|
24
|
+
createListener: (target: HTMLElement) => <T_1 = any>(evt: string, handler: (e: CustomEvent<T_1>) => void) => () => void;
|
|
25
|
+
} & {
|
|
26
|
+
getRootId: (ctx: MachineContext) => string;
|
|
27
|
+
getInputId: (ctx: MachineContext) => string;
|
|
28
|
+
getIncrementTriggerId: (ctx: MachineContext) => string;
|
|
29
|
+
getDecrementTriggerId: (ctx: MachineContext) => string;
|
|
30
|
+
getScrubberId: (ctx: MachineContext) => string;
|
|
31
|
+
getCursorId: (ctx: MachineContext) => string;
|
|
32
|
+
getLabelId: (ctx: MachineContext) => string;
|
|
33
|
+
getInputEl: (ctx: MachineContext) => HTMLInputElement | null;
|
|
34
|
+
getIncrementTriggerEl: (ctx: MachineContext) => HTMLButtonElement | null;
|
|
35
|
+
getDecrementTriggerEl: (ctx: MachineContext) => HTMLButtonElement | null;
|
|
36
|
+
getScrubberEl: (ctx: MachineContext) => HTMLElement | null;
|
|
37
|
+
getCursorEl: (ctx: MachineContext) => HTMLElement | null;
|
|
38
|
+
getPressedTriggerEl: (ctx: MachineContext, hint?: "set" | "increment" | "decrement" | null) => HTMLButtonElement | null;
|
|
39
|
+
setupVirtualCursor(ctx: MachineContext): (() => void) | undefined;
|
|
40
|
+
preventTextSelection(ctx: MachineContext): () => void;
|
|
41
|
+
getMousementValue(ctx: MachineContext, event: MouseEvent): {
|
|
42
|
+
hint: string | null;
|
|
43
|
+
point: {
|
|
44
|
+
x: number;
|
|
45
|
+
y: number;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
createVirtualCursor(ctx: MachineContext): void;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export { dom };
|
|
@@ -0,0 +1,226 @@
|
|
|
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.dom.ts
|
|
21
|
+
var number_input_dom_exports = {};
|
|
22
|
+
__export(number_input_dom_exports, {
|
|
23
|
+
dom: () => dom
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(number_input_dom_exports);
|
|
26
|
+
|
|
27
|
+
// ../../utilities/dom/src/constants.ts
|
|
28
|
+
var MAX_Z_INDEX = 2147483647;
|
|
29
|
+
|
|
30
|
+
// ../../utilities/dom/src/platform.ts
|
|
31
|
+
var isDom = () => typeof window !== "undefined";
|
|
32
|
+
function getPlatform() {
|
|
33
|
+
var _a;
|
|
34
|
+
const agent = navigator.userAgentData;
|
|
35
|
+
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
36
|
+
}
|
|
37
|
+
var pt = (v) => isDom() && v.test(getPlatform());
|
|
38
|
+
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
39
|
+
var isSafari = () => isApple() && vn(/apple/i);
|
|
40
|
+
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
41
|
+
|
|
42
|
+
// ../../utilities/dom/src/query.ts
|
|
43
|
+
function isDocument(el) {
|
|
44
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
45
|
+
}
|
|
46
|
+
function isWindow(value) {
|
|
47
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
48
|
+
}
|
|
49
|
+
function getDocument(el) {
|
|
50
|
+
var _a;
|
|
51
|
+
if (isWindow(el))
|
|
52
|
+
return el.document;
|
|
53
|
+
if (isDocument(el))
|
|
54
|
+
return el;
|
|
55
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
56
|
+
}
|
|
57
|
+
function defineDomHelpers(helpers) {
|
|
58
|
+
const dom2 = {
|
|
59
|
+
getRootNode: (ctx) => {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
62
|
+
},
|
|
63
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
64
|
+
getWin: (ctx) => {
|
|
65
|
+
var _a;
|
|
66
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
67
|
+
},
|
|
68
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
69
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
|
|
70
|
+
createEmitter: (ctx, target) => {
|
|
71
|
+
const win = dom2.getWin(ctx);
|
|
72
|
+
return function emit(evt, detail, options) {
|
|
73
|
+
const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
|
|
74
|
+
const eventName = `zag:${evt}`;
|
|
75
|
+
const init = { bubbles, cancelable, composed, detail };
|
|
76
|
+
const event = new win.CustomEvent(eventName, init);
|
|
77
|
+
target.dispatchEvent(event);
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
createListener: (target) => {
|
|
81
|
+
return function listen(evt, handler) {
|
|
82
|
+
const eventName = `zag:${evt}`;
|
|
83
|
+
const listener = (e) => handler(e);
|
|
84
|
+
target.addEventListener(eventName, listener);
|
|
85
|
+
return () => target.removeEventListener(eventName, listener);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
...dom2,
|
|
91
|
+
...helpers
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// ../../utilities/dom/src/event.ts
|
|
96
|
+
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
97
|
+
|
|
98
|
+
// ../../utilities/number/src/number.ts
|
|
99
|
+
function wrap(num, max) {
|
|
100
|
+
return (num % max + max) % max;
|
|
101
|
+
}
|
|
102
|
+
function roundToDevicePixel(num) {
|
|
103
|
+
if (typeof window === "undefined")
|
|
104
|
+
return Math.round(num);
|
|
105
|
+
const dp = window.devicePixelRatio;
|
|
106
|
+
return Math.floor(num * dp + 0.5) / dp;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/number-input.dom.ts
|
|
110
|
+
var dom = defineDomHelpers({
|
|
111
|
+
getRootId: (ctx) => {
|
|
112
|
+
var _a, _b;
|
|
113
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `number-input:${ctx.id}`;
|
|
114
|
+
},
|
|
115
|
+
getInputId: (ctx) => {
|
|
116
|
+
var _a, _b;
|
|
117
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.input) != null ? _b : `number-input:${ctx.id}:input`;
|
|
118
|
+
},
|
|
119
|
+
getIncrementTriggerId: (ctx) => {
|
|
120
|
+
var _a, _b;
|
|
121
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.incrementTrigger) != null ? _b : `number-input:${ctx.id}:inc`;
|
|
122
|
+
},
|
|
123
|
+
getDecrementTriggerId: (ctx) => {
|
|
124
|
+
var _a, _b;
|
|
125
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.decrementTrigger) != null ? _b : `number-input:${ctx.id}:dec`;
|
|
126
|
+
},
|
|
127
|
+
getScrubberId: (ctx) => {
|
|
128
|
+
var _a, _b;
|
|
129
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.scrubber) != null ? _b : `number-input:${ctx.id}:scrubber`;
|
|
130
|
+
},
|
|
131
|
+
getCursorId: (ctx) => `number-input:${ctx.id}:cursor`,
|
|
132
|
+
getLabelId: (ctx) => {
|
|
133
|
+
var _a, _b;
|
|
134
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `number-input:${ctx.id}:label`;
|
|
135
|
+
},
|
|
136
|
+
getInputEl: (ctx) => dom.getById(ctx, dom.getInputId(ctx)),
|
|
137
|
+
getIncrementTriggerEl: (ctx) => dom.getById(ctx, dom.getIncrementTriggerId(ctx)),
|
|
138
|
+
getDecrementTriggerEl: (ctx) => dom.getById(ctx, dom.getDecrementTriggerId(ctx)),
|
|
139
|
+
getScrubberEl: (ctx) => dom.getById(ctx, dom.getScrubberId(ctx)),
|
|
140
|
+
getCursorEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getCursorId(ctx)),
|
|
141
|
+
getPressedTriggerEl: (ctx, hint = ctx.hint) => {
|
|
142
|
+
let btnEl = null;
|
|
143
|
+
if (hint === "increment") {
|
|
144
|
+
btnEl = dom.getIncrementTriggerEl(ctx);
|
|
145
|
+
}
|
|
146
|
+
if (hint === "decrement") {
|
|
147
|
+
btnEl = dom.getDecrementTriggerEl(ctx);
|
|
148
|
+
}
|
|
149
|
+
return btnEl;
|
|
150
|
+
},
|
|
151
|
+
setupVirtualCursor(ctx) {
|
|
152
|
+
if (isSafari() || !supportsPointerEvent())
|
|
153
|
+
return;
|
|
154
|
+
dom.createVirtualCursor(ctx);
|
|
155
|
+
return () => {
|
|
156
|
+
var _a;
|
|
157
|
+
(_a = dom.getCursorEl(ctx)) == null ? void 0 : _a.remove();
|
|
158
|
+
};
|
|
159
|
+
},
|
|
160
|
+
preventTextSelection(ctx) {
|
|
161
|
+
const doc = dom.getDoc(ctx);
|
|
162
|
+
const html = doc.documentElement;
|
|
163
|
+
const body = doc.body;
|
|
164
|
+
body.style.pointerEvents = "none";
|
|
165
|
+
html.style.userSelect = "none";
|
|
166
|
+
html.style.cursor = "ew-resize";
|
|
167
|
+
return () => {
|
|
168
|
+
body.style.pointerEvents = "";
|
|
169
|
+
html.style.userSelect = "";
|
|
170
|
+
html.style.cursor = "";
|
|
171
|
+
if (!html.style.length) {
|
|
172
|
+
html.removeAttribute("style");
|
|
173
|
+
}
|
|
174
|
+
if (!body.style.length) {
|
|
175
|
+
body.removeAttribute("style");
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
},
|
|
179
|
+
getMousementValue(ctx, event) {
|
|
180
|
+
const x = roundToDevicePixel(event.movementX);
|
|
181
|
+
const y = roundToDevicePixel(event.movementY);
|
|
182
|
+
let hint = x > 0 ? "increment" : x < 0 ? "decrement" : null;
|
|
183
|
+
if (ctx.isRtl && hint === "increment")
|
|
184
|
+
hint = "decrement";
|
|
185
|
+
if (ctx.isRtl && hint === "decrement")
|
|
186
|
+
hint = "increment";
|
|
187
|
+
const point = {
|
|
188
|
+
x: ctx.scrubberCursorPoint.x + x,
|
|
189
|
+
y: ctx.scrubberCursorPoint.y + y
|
|
190
|
+
};
|
|
191
|
+
const win = dom.getWin(ctx);
|
|
192
|
+
const width = win.innerWidth;
|
|
193
|
+
const half = roundToDevicePixel(7.5);
|
|
194
|
+
point.x = wrap(point.x + half, width) - half;
|
|
195
|
+
return { hint, point };
|
|
196
|
+
},
|
|
197
|
+
createVirtualCursor(ctx) {
|
|
198
|
+
const doc = dom.getDoc(ctx);
|
|
199
|
+
const el = doc.createElement("div");
|
|
200
|
+
el.className = "scrubber--cursor";
|
|
201
|
+
el.id = dom.getCursorId(ctx);
|
|
202
|
+
Object.assign(el.style, {
|
|
203
|
+
width: "15px",
|
|
204
|
+
height: "15px",
|
|
205
|
+
position: "fixed",
|
|
206
|
+
pointerEvents: "none",
|
|
207
|
+
left: "0px",
|
|
208
|
+
top: "0px",
|
|
209
|
+
zIndex: MAX_Z_INDEX,
|
|
210
|
+
transform: ctx.scrubberCursorPoint ? `translate3d(${ctx.scrubberCursorPoint.x}px, ${ctx.scrubberCursorPoint.y}px, 0px)` : void 0,
|
|
211
|
+
willChange: "transform"
|
|
212
|
+
});
|
|
213
|
+
el.innerHTML = `
|
|
214
|
+
<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);">
|
|
215
|
+
<g transform="translate(2 3)">
|
|
216
|
+
<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>
|
|
217
|
+
<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>
|
|
218
|
+
</g>
|
|
219
|
+
</svg>`;
|
|
220
|
+
doc.body.appendChild(el);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
224
|
+
0 && (module.exports = {
|
|
225
|
+
dom
|
|
226
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as _zag_js_core from '@zag-js/core';
|
|
2
|
+
import { UserDefinedContext, MachineContext, MachineState } from './number-input.types.js';
|
|
3
|
+
import '@zag-js/types';
|
|
4
|
+
|
|
5
|
+
declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
|
|
6
|
+
|
|
7
|
+
export { machine };
|