@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.
@@ -0,0 +1,208 @@
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
+ };
71
+ return {
72
+ ...dom2,
73
+ ...helpers
74
+ };
75
+ }
76
+
77
+ // ../../utilities/dom/src/event.ts
78
+ var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
79
+
80
+ // ../../utilities/number/src/number.ts
81
+ function wrap(num, max) {
82
+ return (num % max + max) % max;
83
+ }
84
+ function roundToDevicePixel(num) {
85
+ if (typeof window === "undefined")
86
+ return Math.round(num);
87
+ const dp = window.devicePixelRatio;
88
+ return Math.floor(num * dp + 0.5) / dp;
89
+ }
90
+
91
+ // src/number-input.dom.ts
92
+ var dom = defineDomHelpers({
93
+ getRootId: (ctx) => {
94
+ var _a, _b;
95
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `number-input:${ctx.id}`;
96
+ },
97
+ getInputId: (ctx) => {
98
+ var _a, _b;
99
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.input) != null ? _b : `number-input:${ctx.id}:input`;
100
+ },
101
+ getIncrementTriggerId: (ctx) => {
102
+ var _a, _b;
103
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.incrementTrigger) != null ? _b : `number-input:${ctx.id}:inc`;
104
+ },
105
+ getDecrementTriggerId: (ctx) => {
106
+ var _a, _b;
107
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.decrementTrigger) != null ? _b : `number-input:${ctx.id}:dec`;
108
+ },
109
+ getScrubberId: (ctx) => {
110
+ var _a, _b;
111
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.scrubber) != null ? _b : `number-input:${ctx.id}:scrubber`;
112
+ },
113
+ getCursorId: (ctx) => `number-input:${ctx.id}:cursor`,
114
+ getLabelId: (ctx) => {
115
+ var _a, _b;
116
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `number-input:${ctx.id}:label`;
117
+ },
118
+ getInputEl: (ctx) => dom.getById(ctx, dom.getInputId(ctx)),
119
+ getIncrementTriggerEl: (ctx) => dom.getById(ctx, dom.getIncrementTriggerId(ctx)),
120
+ getDecrementTriggerEl: (ctx) => dom.getById(ctx, dom.getDecrementTriggerId(ctx)),
121
+ getScrubberEl: (ctx) => dom.getById(ctx, dom.getScrubberId(ctx)),
122
+ getCursorEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getCursorId(ctx)),
123
+ getPressedTriggerEl: (ctx, hint = ctx.hint) => {
124
+ let btnEl = null;
125
+ if (hint === "increment") {
126
+ btnEl = dom.getIncrementTriggerEl(ctx);
127
+ }
128
+ if (hint === "decrement") {
129
+ btnEl = dom.getDecrementTriggerEl(ctx);
130
+ }
131
+ return btnEl;
132
+ },
133
+ setupVirtualCursor(ctx) {
134
+ if (isSafari() || !supportsPointerEvent())
135
+ return;
136
+ dom.createVirtualCursor(ctx);
137
+ return () => {
138
+ var _a;
139
+ (_a = dom.getCursorEl(ctx)) == null ? void 0 : _a.remove();
140
+ };
141
+ },
142
+ preventTextSelection(ctx) {
143
+ const doc = dom.getDoc(ctx);
144
+ const html = doc.documentElement;
145
+ const body = doc.body;
146
+ body.style.pointerEvents = "none";
147
+ html.style.userSelect = "none";
148
+ html.style.cursor = "ew-resize";
149
+ return () => {
150
+ body.style.pointerEvents = "";
151
+ html.style.userSelect = "";
152
+ html.style.cursor = "";
153
+ if (!html.style.length) {
154
+ html.removeAttribute("style");
155
+ }
156
+ if (!body.style.length) {
157
+ body.removeAttribute("style");
158
+ }
159
+ };
160
+ },
161
+ getMousementValue(ctx, event) {
162
+ const x = roundToDevicePixel(event.movementX);
163
+ const y = roundToDevicePixel(event.movementY);
164
+ let hint = x > 0 ? "increment" : x < 0 ? "decrement" : null;
165
+ if (ctx.isRtl && hint === "increment")
166
+ hint = "decrement";
167
+ if (ctx.isRtl && hint === "decrement")
168
+ hint = "increment";
169
+ const point = {
170
+ x: ctx.scrubberCursorPoint.x + x,
171
+ y: ctx.scrubberCursorPoint.y + y
172
+ };
173
+ const win = dom.getWin(ctx);
174
+ const width = win.innerWidth;
175
+ const half = roundToDevicePixel(7.5);
176
+ point.x = wrap(point.x + half, width) - half;
177
+ return { hint, point };
178
+ },
179
+ createVirtualCursor(ctx) {
180
+ const doc = dom.getDoc(ctx);
181
+ const el = doc.createElement("div");
182
+ el.className = "scrubber--cursor";
183
+ el.id = dom.getCursorId(ctx);
184
+ Object.assign(el.style, {
185
+ width: "15px",
186
+ height: "15px",
187
+ position: "fixed",
188
+ pointerEvents: "none",
189
+ left: "0px",
190
+ top: "0px",
191
+ zIndex: MAX_Z_INDEX,
192
+ transform: ctx.scrubberCursorPoint ? `translate3d(${ctx.scrubberCursorPoint.x}px, ${ctx.scrubberCursorPoint.y}px, 0px)` : void 0,
193
+ willChange: "transform"
194
+ });
195
+ el.innerHTML = `
196
+ <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);">
197
+ <g transform="translate(2 3)">
198
+ <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>
199
+ <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>
200
+ </g>
201
+ </svg>`;
202
+ doc.body.appendChild(el);
203
+ }
204
+ });
205
+ // Annotate the CommonJS export names for ESM import in node:
206
+ 0 && (module.exports = {
207
+ dom
208
+ });
@@ -0,0 +1,7 @@
1
+ import {
2
+ dom
3
+ } from "./chunk-EUVYGWZ6.mjs";
4
+ import "./chunk-VCZUWKJT.mjs";
5
+ export {
6
+ dom
7
+ };
@@ -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 };