@zag-js/slider 0.2.13 → 0.2.15
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-5CWNUPC7.mjs +50 -0
- package/dist/chunk-VTUEW45P.mjs +212 -0
- package/dist/{chunk-X363CZYV.mjs → chunk-XHNKYJMN.mjs} +36 -63
- package/dist/index.js +125 -486
- package/dist/index.mjs +3 -4
- package/dist/slider.connect.d.ts +30 -0
- package/dist/slider.connect.js +66 -180
- package/dist/slider.connect.mjs +2 -3
- package/dist/slider.dom.d.ts +9 -6
- package/dist/slider.dom.js +6 -86
- package/dist/slider.dom.mjs +1 -1
- package/dist/slider.machine.js +14 -354
- package/dist/slider.machine.mjs +2 -3
- package/package.json +7 -6
- package/dist/chunk-3UP6QL6A.mjs +0 -42
- package/dist/chunk-55KEN77D.mjs +0 -128
- package/dist/chunk-5XVLG734.mjs +0 -460
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
connect
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-XHNKYJMN.mjs";
|
|
4
4
|
import {
|
|
5
5
|
anatomy
|
|
6
6
|
} from "./chunk-3Y7IIPR5.mjs";
|
|
7
7
|
import {
|
|
8
8
|
machine
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-3UP6QL6A.mjs";
|
|
9
|
+
} from "./chunk-VTUEW45P.mjs";
|
|
11
10
|
import {
|
|
12
11
|
dom
|
|
13
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-5CWNUPC7.mjs";
|
|
14
13
|
import "./chunk-IJAAAKZQ.mjs";
|
|
15
14
|
import "./chunk-YGFSMEUO.mjs";
|
|
16
15
|
export {
|
package/dist/slider.connect.d.ts
CHANGED
|
@@ -3,15 +3,45 @@ import { State, Send } from './slider.types.js';
|
|
|
3
3
|
import '@zag-js/core';
|
|
4
4
|
|
|
5
5
|
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
6
|
+
/**
|
|
7
|
+
* Whether the slider is focused.
|
|
8
|
+
*/
|
|
6
9
|
isFocused: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Whether the slider is being dragged.
|
|
12
|
+
*/
|
|
7
13
|
isDragging: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* The value of the slider.
|
|
16
|
+
*/
|
|
8
17
|
value: number;
|
|
18
|
+
/**
|
|
19
|
+
* The value of the slider as a percent.
|
|
20
|
+
*/
|
|
9
21
|
percent: number;
|
|
22
|
+
/**
|
|
23
|
+
* Function to set the value of the slider.
|
|
24
|
+
*/
|
|
10
25
|
setValue(value: number): void;
|
|
26
|
+
/**
|
|
27
|
+
* Returns the value of the slider at the given percent.
|
|
28
|
+
*/
|
|
11
29
|
getPercentValue: (percent: number) => number;
|
|
30
|
+
/**
|
|
31
|
+
* Returns the percent of the slider at the given value.
|
|
32
|
+
*/
|
|
12
33
|
getValuePercent: (value: number) => number;
|
|
34
|
+
/**
|
|
35
|
+
* Function to focus the slider.
|
|
36
|
+
*/
|
|
13
37
|
focus(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Function to increment the value of the slider by the step.
|
|
40
|
+
*/
|
|
14
41
|
increment(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Function to decrement the value of the slider by the step.
|
|
44
|
+
*/
|
|
15
45
|
decrement(): void;
|
|
16
46
|
rootProps: T["element"];
|
|
17
47
|
labelProps: T["label"];
|
package/dist/slider.connect.js
CHANGED
|
@@ -23,137 +23,8 @@ __export(slider_connect_exports, {
|
|
|
23
23
|
connect: () => connect
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(slider_connect_exports);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var dataAttr = (guard) => {
|
|
29
|
-
return guard ? "" : void 0;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
// ../../utilities/core/src/guard.ts
|
|
33
|
-
var isArray = (v) => Array.isArray(v);
|
|
34
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
35
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
36
|
-
|
|
37
|
-
// ../../utilities/dom/src/query.ts
|
|
38
|
-
function isDocument(el) {
|
|
39
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
40
|
-
}
|
|
41
|
-
function isWindow(value) {
|
|
42
|
-
return value?.toString() === "[object Window]";
|
|
43
|
-
}
|
|
44
|
-
function getDocument(el) {
|
|
45
|
-
if (isWindow(el))
|
|
46
|
-
return el.document;
|
|
47
|
-
if (isDocument(el))
|
|
48
|
-
return el;
|
|
49
|
-
return el?.ownerDocument ?? document;
|
|
50
|
-
}
|
|
51
|
-
function getWindow(el) {
|
|
52
|
-
return el?.ownerDocument.defaultView ?? window;
|
|
53
|
-
}
|
|
54
|
-
function defineDomHelpers(helpers) {
|
|
55
|
-
const dom2 = {
|
|
56
|
-
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
57
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
58
|
-
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
59
|
-
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
60
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
61
|
-
};
|
|
62
|
-
return {
|
|
63
|
-
...dom2,
|
|
64
|
-
...helpers
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// ../../utilities/dom/src/event.ts
|
|
69
|
-
function getNativeEvent(e) {
|
|
70
|
-
return e.nativeEvent ?? e;
|
|
71
|
-
}
|
|
72
|
-
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
73
|
-
var isLeftClick = (v) => v.button === 0;
|
|
74
|
-
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
75
|
-
|
|
76
|
-
// ../../utilities/dom/src/get-element-offset.ts
|
|
77
|
-
function getElementOffset(element) {
|
|
78
|
-
let left = 0;
|
|
79
|
-
let top = 0;
|
|
80
|
-
let el = element;
|
|
81
|
-
if (el.parentNode) {
|
|
82
|
-
do {
|
|
83
|
-
left += el.offsetLeft;
|
|
84
|
-
top += el.offsetTop;
|
|
85
|
-
} while ((el = el.offsetParent) && el.nodeType < 9);
|
|
86
|
-
el = element;
|
|
87
|
-
do {
|
|
88
|
-
left -= el.scrollLeft;
|
|
89
|
-
top -= el.scrollTop;
|
|
90
|
-
} while ((el = el.parentNode) && !/body/i.test(el.nodeName));
|
|
91
|
-
}
|
|
92
|
-
return {
|
|
93
|
-
top,
|
|
94
|
-
right: innerWidth - left - element.offsetWidth,
|
|
95
|
-
bottom: innerHeight - top - element.offsetHeight,
|
|
96
|
-
left
|
|
97
|
-
};
|
|
98
|
-
}
|
|
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
|
-
const point = isTouchEvent(event) ? event.touches[0] ?? event.changedTouches[0] ?? fallback : event;
|
|
109
|
-
return { x: point[`${type}X`], y: point[`${type}Y`] };
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// ../../utilities/dom/src/get-point-relative-to-element.ts
|
|
113
|
-
function getPointRelativeToNode(point, element) {
|
|
114
|
-
const offset = getElementOffset(element);
|
|
115
|
-
const x = point.x - offset.left;
|
|
116
|
-
const y = point.y - offset.top;
|
|
117
|
-
return { x, y };
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// ../../utilities/dom/src/keyboard-event.ts
|
|
121
|
-
var rtlKeyMap = {
|
|
122
|
-
ArrowLeft: "ArrowRight",
|
|
123
|
-
ArrowRight: "ArrowLeft"
|
|
124
|
-
};
|
|
125
|
-
var sameKeyMap = {
|
|
126
|
-
Up: "ArrowUp",
|
|
127
|
-
Down: "ArrowDown",
|
|
128
|
-
Esc: "Escape",
|
|
129
|
-
" ": "Space",
|
|
130
|
-
",": "Comma",
|
|
131
|
-
Left: "ArrowLeft",
|
|
132
|
-
Right: "ArrowRight"
|
|
133
|
-
};
|
|
134
|
-
function getEventKey(event, options = {}) {
|
|
135
|
-
const { dir = "ltr", orientation = "horizontal" } = options;
|
|
136
|
-
let { key } = event;
|
|
137
|
-
key = sameKeyMap[key] ?? key;
|
|
138
|
-
const isRtl = dir === "rtl" && orientation === "horizontal";
|
|
139
|
-
if (isRtl && key in rtlKeyMap) {
|
|
140
|
-
key = rtlKeyMap[key];
|
|
141
|
-
}
|
|
142
|
-
return key;
|
|
143
|
-
}
|
|
144
|
-
var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
|
|
145
|
-
var ARROW_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
|
|
146
|
-
function getEventStep(event) {
|
|
147
|
-
if (event.ctrlKey || event.metaKey) {
|
|
148
|
-
return 0.1;
|
|
149
|
-
} else {
|
|
150
|
-
const isPageKey = PAGE_KEYS.has(event.key);
|
|
151
|
-
const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.has(event.key);
|
|
152
|
-
return isSkipKey ? 10 : 1;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// src/slider.connect.ts
|
|
26
|
+
var import_dom_event2 = require("@zag-js/dom-event");
|
|
27
|
+
var import_dom_query2 = require("@zag-js/dom-query");
|
|
157
28
|
var import_numeric_range3 = require("@zag-js/numeric-range");
|
|
158
29
|
|
|
159
30
|
// src/slider.anatomy.ts
|
|
@@ -172,25 +43,10 @@ var anatomy = (0, import_anatomy.createAnatomy)("slider").parts(
|
|
|
172
43
|
);
|
|
173
44
|
var parts = anatomy.build();
|
|
174
45
|
|
|
175
|
-
// ../../utilities/form-utils/src/input-event.ts
|
|
176
|
-
function getDescriptor(el, options) {
|
|
177
|
-
const { type, property = "value" } = options;
|
|
178
|
-
const proto = getWindow(el)[type].prototype;
|
|
179
|
-
return Object.getOwnPropertyDescriptor(proto, property) ?? {};
|
|
180
|
-
}
|
|
181
|
-
function dispatchInputValueEvent(el, value) {
|
|
182
|
-
if (!el)
|
|
183
|
-
return;
|
|
184
|
-
const win = getWindow(el);
|
|
185
|
-
if (!(el instanceof win.HTMLInputElement))
|
|
186
|
-
return;
|
|
187
|
-
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
188
|
-
desc.set?.call(el, value);
|
|
189
|
-
const event = new win.Event("input", { bubbles: true });
|
|
190
|
-
el.dispatchEvent(event);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
46
|
// src/slider.dom.ts
|
|
47
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
48
|
+
var import_dom_event = require("@zag-js/dom-event");
|
|
49
|
+
var import_form_utils = require("@zag-js/form-utils");
|
|
194
50
|
var import_numeric_range2 = require("@zag-js/numeric-range");
|
|
195
51
|
|
|
196
52
|
// src/slider.style.ts
|
|
@@ -306,7 +162,7 @@ var styles = {
|
|
|
306
162
|
};
|
|
307
163
|
|
|
308
164
|
// src/slider.dom.ts
|
|
309
|
-
var dom =
|
|
165
|
+
var dom = (0, import_dom_query.createScope)({
|
|
310
166
|
...styles,
|
|
311
167
|
getRootId: (ctx) => ctx.ids?.root ?? `slider:${ctx.id}`,
|
|
312
168
|
getThumbId: (ctx) => ctx.ids?.thumb ?? `slider:${ctx.id}:thumb`,
|
|
@@ -325,7 +181,7 @@ var dom = defineDomHelpers({
|
|
|
325
181
|
const el = dom.getControlEl(ctx);
|
|
326
182
|
if (!el)
|
|
327
183
|
return;
|
|
328
|
-
const relativePoint =
|
|
184
|
+
const relativePoint = (0, import_dom_event.getRelativePointValue)(point, el);
|
|
329
185
|
const percentX = relativePoint.x / el.offsetWidth;
|
|
330
186
|
const percentY = relativePoint.y / el.offsetHeight;
|
|
331
187
|
let percent;
|
|
@@ -340,7 +196,7 @@ var dom = defineDomHelpers({
|
|
|
340
196
|
const input = dom.getHiddenInputEl(ctx);
|
|
341
197
|
if (!input)
|
|
342
198
|
return;
|
|
343
|
-
dispatchInputValueEvent(input, ctx.value);
|
|
199
|
+
(0, import_form_utils.dispatchInputValueEvent)(input, ctx.value);
|
|
344
200
|
}
|
|
345
201
|
});
|
|
346
202
|
|
|
@@ -361,39 +217,69 @@ function connect(state, send, normalize) {
|
|
|
361
217
|
return (0, import_numeric_range3.getValuePercent)(value, state.context.min, state.context.max);
|
|
362
218
|
}
|
|
363
219
|
return {
|
|
220
|
+
/**
|
|
221
|
+
* Whether the slider is focused.
|
|
222
|
+
*/
|
|
364
223
|
isFocused,
|
|
224
|
+
/**
|
|
225
|
+
* Whether the slider is being dragged.
|
|
226
|
+
*/
|
|
365
227
|
isDragging,
|
|
228
|
+
/**
|
|
229
|
+
* The value of the slider.
|
|
230
|
+
*/
|
|
366
231
|
value: state.context.value,
|
|
232
|
+
/**
|
|
233
|
+
* The value of the slider as a percent.
|
|
234
|
+
*/
|
|
367
235
|
percent: (0, import_numeric_range3.getValuePercent)(state.context.value, state.context.min, state.context.max),
|
|
236
|
+
/**
|
|
237
|
+
* Function to set the value of the slider.
|
|
238
|
+
*/
|
|
368
239
|
setValue(value) {
|
|
369
240
|
send({ type: "SET_VALUE", value });
|
|
370
241
|
},
|
|
242
|
+
/**
|
|
243
|
+
* Returns the value of the slider at the given percent.
|
|
244
|
+
*/
|
|
371
245
|
getPercentValue: getPercentValueFn,
|
|
246
|
+
/**
|
|
247
|
+
* Returns the percent of the slider at the given value.
|
|
248
|
+
*/
|
|
372
249
|
getValuePercent: getValuePercentFn,
|
|
250
|
+
/**
|
|
251
|
+
* Function to focus the slider.
|
|
252
|
+
*/
|
|
373
253
|
focus() {
|
|
374
254
|
dom.getThumbEl(state.context)?.focus();
|
|
375
255
|
},
|
|
256
|
+
/**
|
|
257
|
+
* Function to increment the value of the slider by the step.
|
|
258
|
+
*/
|
|
376
259
|
increment() {
|
|
377
260
|
send("INCREMENT");
|
|
378
261
|
},
|
|
262
|
+
/**
|
|
263
|
+
* Function to decrement the value of the slider by the step.
|
|
264
|
+
*/
|
|
379
265
|
decrement() {
|
|
380
266
|
send("DECREMENT");
|
|
381
267
|
},
|
|
382
268
|
rootProps: normalize.element({
|
|
383
269
|
...parts.root.attrs,
|
|
384
|
-
"data-disabled": dataAttr(isDisabled),
|
|
385
|
-
"data-focus": dataAttr(isFocused),
|
|
270
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
271
|
+
"data-focus": (0, import_dom_query2.dataAttr)(isFocused),
|
|
386
272
|
"data-orientation": state.context.orientation,
|
|
387
|
-
"data-invalid": dataAttr(isInvalid),
|
|
273
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
388
274
|
id: dom.getRootId(state.context),
|
|
389
275
|
dir: state.context.dir,
|
|
390
276
|
style: dom.getRootStyle(state.context)
|
|
391
277
|
}),
|
|
392
278
|
labelProps: normalize.label({
|
|
393
279
|
...parts.label.attrs,
|
|
394
|
-
"data-disabled": dataAttr(isDisabled),
|
|
395
|
-
"data-invalid": dataAttr(isInvalid),
|
|
396
|
-
"data-focus": dataAttr(isFocused),
|
|
280
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
281
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
282
|
+
"data-focus": (0, import_dom_query2.dataAttr)(isFocused),
|
|
397
283
|
id: dom.getLabelId(state.context),
|
|
398
284
|
htmlFor: dom.getHiddenInputId(state.context),
|
|
399
285
|
onClick(event) {
|
|
@@ -407,13 +293,13 @@ function connect(state, send, normalize) {
|
|
|
407
293
|
thumbProps: normalize.element({
|
|
408
294
|
...parts.thumb.attrs,
|
|
409
295
|
id: dom.getThumbId(state.context),
|
|
410
|
-
"data-disabled": dataAttr(isDisabled),
|
|
296
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
411
297
|
"data-orientation": state.context.orientation,
|
|
412
|
-
"data-focus": dataAttr(isFocused),
|
|
298
|
+
"data-focus": (0, import_dom_query2.dataAttr)(isFocused),
|
|
413
299
|
draggable: false,
|
|
414
|
-
"aria-invalid":
|
|
415
|
-
"data-invalid": dataAttr(isInvalid),
|
|
416
|
-
"aria-disabled":
|
|
300
|
+
"aria-invalid": (0, import_dom_query2.ariaAttr)(isInvalid),
|
|
301
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
302
|
+
"aria-disabled": (0, import_dom_query2.ariaAttr)(isDisabled),
|
|
417
303
|
"aria-label": ariaLabel,
|
|
418
304
|
"aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy ?? dom.getLabelId(state.context),
|
|
419
305
|
"aria-orientation": state.context.orientation,
|
|
@@ -436,7 +322,7 @@ function connect(state, send, normalize) {
|
|
|
436
322
|
onKeyDown(event) {
|
|
437
323
|
if (!isInteractive)
|
|
438
324
|
return;
|
|
439
|
-
const step = getEventStep(event) * state.context.step;
|
|
325
|
+
const step = (0, import_dom_event2.getEventStep)(event) * state.context.step;
|
|
440
326
|
let prevent = true;
|
|
441
327
|
const keyMap = {
|
|
442
328
|
ArrowUp() {
|
|
@@ -468,7 +354,7 @@ function connect(state, send, normalize) {
|
|
|
468
354
|
send("END");
|
|
469
355
|
}
|
|
470
356
|
};
|
|
471
|
-
const key = getEventKey(event, state.context);
|
|
357
|
+
const key = (0, import_dom_event2.getEventKey)(event, state.context);
|
|
472
358
|
const exec = keyMap[key];
|
|
473
359
|
if (!exec)
|
|
474
360
|
return;
|
|
@@ -490,8 +376,8 @@ function connect(state, send, normalize) {
|
|
|
490
376
|
}),
|
|
491
377
|
outputProps: normalize.output({
|
|
492
378
|
...parts.output.attrs,
|
|
493
|
-
"data-disabled": dataAttr(isDisabled),
|
|
494
|
-
"data-invalid": dataAttr(isInvalid),
|
|
379
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
380
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
495
381
|
id: dom.getOutputId(state.context),
|
|
496
382
|
htmlFor: dom.getHiddenInputId(state.context),
|
|
497
383
|
"aria-live": "off"
|
|
@@ -499,35 +385,35 @@ function connect(state, send, normalize) {
|
|
|
499
385
|
trackProps: normalize.element({
|
|
500
386
|
...parts.track.attrs,
|
|
501
387
|
id: dom.getTrackId(state.context),
|
|
502
|
-
"data-disabled": dataAttr(isDisabled),
|
|
503
|
-
"data-focus": dataAttr(isFocused),
|
|
504
|
-
"data-invalid": dataAttr(isInvalid),
|
|
388
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
389
|
+
"data-focus": (0, import_dom_query2.dataAttr)(isFocused),
|
|
390
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
505
391
|
"data-orientation": state.context.orientation,
|
|
506
392
|
style: dom.getTrackStyle()
|
|
507
393
|
}),
|
|
508
394
|
rangeProps: normalize.element({
|
|
509
395
|
...parts.range.attrs,
|
|
510
396
|
id: dom.getRangeId(state.context),
|
|
511
|
-
"data-focus": dataAttr(isFocused),
|
|
512
|
-
"data-invalid": dataAttr(isInvalid),
|
|
513
|
-
"data-disabled": dataAttr(isDisabled),
|
|
397
|
+
"data-focus": (0, import_dom_query2.dataAttr)(isFocused),
|
|
398
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
399
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
514
400
|
"data-orientation": state.context.orientation,
|
|
515
401
|
style: dom.getRangeStyle(state.context)
|
|
516
402
|
}),
|
|
517
403
|
controlProps: normalize.element({
|
|
518
404
|
...parts.control.attrs,
|
|
519
405
|
id: dom.getControlId(state.context),
|
|
520
|
-
"data-disabled": dataAttr(isDisabled),
|
|
521
|
-
"data-invalid": dataAttr(isInvalid),
|
|
406
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
407
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
522
408
|
"data-orientation": state.context.orientation,
|
|
523
|
-
"data-focus": dataAttr(isFocused),
|
|
409
|
+
"data-focus": (0, import_dom_query2.dataAttr)(isFocused),
|
|
524
410
|
onPointerDown(event) {
|
|
525
411
|
if (!isInteractive)
|
|
526
412
|
return;
|
|
527
|
-
const evt = getNativeEvent(event);
|
|
528
|
-
if (!isLeftClick(evt) || isModifiedEvent(evt))
|
|
413
|
+
const evt = (0, import_dom_event2.getNativeEvent)(event);
|
|
414
|
+
if (!(0, import_dom_event2.isLeftClick)(evt) || (0, import_dom_event2.isModifiedEvent)(evt))
|
|
529
415
|
return;
|
|
530
|
-
const point =
|
|
416
|
+
const point = { x: evt.clientX, y: evt.clientY };
|
|
531
417
|
send({ type: "POINTER_DOWN", point });
|
|
532
418
|
event.preventDefault();
|
|
533
419
|
event.stopPropagation();
|
|
@@ -551,7 +437,7 @@ function connect(state, send, normalize) {
|
|
|
551
437
|
"data-orientation": state.context.orientation,
|
|
552
438
|
id: dom.getMarkerId(state.context, value),
|
|
553
439
|
"data-value": value,
|
|
554
|
-
"data-disabled": dataAttr(isDisabled),
|
|
440
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
555
441
|
"data-state": markerState,
|
|
556
442
|
style
|
|
557
443
|
});
|
package/dist/slider.connect.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
connect
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-XHNKYJMN.mjs";
|
|
4
4
|
import "./chunk-3Y7IIPR5.mjs";
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-55KEN77D.mjs";
|
|
5
|
+
import "./chunk-5CWNUPC7.mjs";
|
|
7
6
|
import "./chunk-IJAAAKZQ.mjs";
|
|
8
7
|
export {
|
|
9
8
|
connect
|
package/dist/slider.dom.d.ts
CHANGED
|
@@ -4,20 +4,23 @@ import '@zag-js/core';
|
|
|
4
4
|
|
|
5
5
|
declare const dom: {
|
|
6
6
|
getRootNode: (ctx: {
|
|
7
|
-
getRootNode?: (() =>
|
|
7
|
+
getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
|
|
8
8
|
}) => Document | ShadowRoot;
|
|
9
9
|
getDoc: (ctx: {
|
|
10
|
-
getRootNode?: (() =>
|
|
10
|
+
getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
|
|
11
11
|
}) => Document;
|
|
12
12
|
getWin: (ctx: {
|
|
13
|
-
getRootNode?: (() =>
|
|
13
|
+
getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
|
|
14
14
|
}) => Window & typeof globalThis;
|
|
15
15
|
getActiveElement: (ctx: {
|
|
16
|
-
getRootNode?: (() =>
|
|
16
|
+
getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
|
|
17
17
|
}) => HTMLElement | null;
|
|
18
|
-
getById: <T = HTMLElement>(ctx: {
|
|
19
|
-
getRootNode?: (() =>
|
|
18
|
+
getById: <T extends HTMLElement = HTMLElement>(ctx: {
|
|
19
|
+
getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
|
|
20
20
|
}, id: string) => T | null;
|
|
21
|
+
queryById: <T_1 extends HTMLElement = HTMLElement>(ctx: {
|
|
22
|
+
getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
|
|
23
|
+
}, id: string) => T_1;
|
|
21
24
|
} & {
|
|
22
25
|
getRootId: (ctx: MachineContext) => string;
|
|
23
26
|
getThumbId: (ctx: MachineContext) => string;
|
package/dist/slider.dom.js
CHANGED
|
@@ -23,89 +23,9 @@ __export(slider_dom_exports, {
|
|
|
23
23
|
dom: () => dom
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(slider_dom_exports);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
30
|
-
}
|
|
31
|
-
function isWindow(value) {
|
|
32
|
-
return value?.toString() === "[object Window]";
|
|
33
|
-
}
|
|
34
|
-
function getDocument(el) {
|
|
35
|
-
if (isWindow(el))
|
|
36
|
-
return el.document;
|
|
37
|
-
if (isDocument(el))
|
|
38
|
-
return el;
|
|
39
|
-
return el?.ownerDocument ?? document;
|
|
40
|
-
}
|
|
41
|
-
function getWindow(el) {
|
|
42
|
-
return el?.ownerDocument.defaultView ?? window;
|
|
43
|
-
}
|
|
44
|
-
function defineDomHelpers(helpers) {
|
|
45
|
-
const dom2 = {
|
|
46
|
-
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
47
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
48
|
-
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
49
|
-
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
50
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
51
|
-
};
|
|
52
|
-
return {
|
|
53
|
-
...dom2,
|
|
54
|
-
...helpers
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// ../../utilities/dom/src/get-element-offset.ts
|
|
59
|
-
function getElementOffset(element) {
|
|
60
|
-
let left = 0;
|
|
61
|
-
let top = 0;
|
|
62
|
-
let el = element;
|
|
63
|
-
if (el.parentNode) {
|
|
64
|
-
do {
|
|
65
|
-
left += el.offsetLeft;
|
|
66
|
-
top += el.offsetTop;
|
|
67
|
-
} while ((el = el.offsetParent) && el.nodeType < 9);
|
|
68
|
-
el = element;
|
|
69
|
-
do {
|
|
70
|
-
left -= el.scrollLeft;
|
|
71
|
-
top -= el.scrollTop;
|
|
72
|
-
} while ((el = el.parentNode) && !/body/i.test(el.nodeName));
|
|
73
|
-
}
|
|
74
|
-
return {
|
|
75
|
-
top,
|
|
76
|
-
right: innerWidth - left - element.offsetWidth,
|
|
77
|
-
bottom: innerHeight - top - element.offsetHeight,
|
|
78
|
-
left
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// ../../utilities/dom/src/get-point-relative-to-element.ts
|
|
83
|
-
function getPointRelativeToNode(point, element) {
|
|
84
|
-
const offset = getElementOffset(element);
|
|
85
|
-
const x = point.x - offset.left;
|
|
86
|
-
const y = point.y - offset.top;
|
|
87
|
-
return { x, y };
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// ../../utilities/form-utils/src/input-event.ts
|
|
91
|
-
function getDescriptor(el, options) {
|
|
92
|
-
const { type, property = "value" } = options;
|
|
93
|
-
const proto = getWindow(el)[type].prototype;
|
|
94
|
-
return Object.getOwnPropertyDescriptor(proto, property) ?? {};
|
|
95
|
-
}
|
|
96
|
-
function dispatchInputValueEvent(el, value) {
|
|
97
|
-
if (!el)
|
|
98
|
-
return;
|
|
99
|
-
const win = getWindow(el);
|
|
100
|
-
if (!(el instanceof win.HTMLInputElement))
|
|
101
|
-
return;
|
|
102
|
-
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
103
|
-
desc.set?.call(el, value);
|
|
104
|
-
const event = new win.Event("input", { bubbles: true });
|
|
105
|
-
el.dispatchEvent(event);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// src/slider.dom.ts
|
|
26
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
27
|
+
var import_dom_event = require("@zag-js/dom-event");
|
|
28
|
+
var import_form_utils = require("@zag-js/form-utils");
|
|
109
29
|
var import_numeric_range2 = require("@zag-js/numeric-range");
|
|
110
30
|
|
|
111
31
|
// src/slider.style.ts
|
|
@@ -221,7 +141,7 @@ var styles = {
|
|
|
221
141
|
};
|
|
222
142
|
|
|
223
143
|
// src/slider.dom.ts
|
|
224
|
-
var dom =
|
|
144
|
+
var dom = (0, import_dom_query.createScope)({
|
|
225
145
|
...styles,
|
|
226
146
|
getRootId: (ctx) => ctx.ids?.root ?? `slider:${ctx.id}`,
|
|
227
147
|
getThumbId: (ctx) => ctx.ids?.thumb ?? `slider:${ctx.id}:thumb`,
|
|
@@ -240,7 +160,7 @@ var dom = defineDomHelpers({
|
|
|
240
160
|
const el = dom.getControlEl(ctx);
|
|
241
161
|
if (!el)
|
|
242
162
|
return;
|
|
243
|
-
const relativePoint =
|
|
163
|
+
const relativePoint = (0, import_dom_event.getRelativePointValue)(point, el);
|
|
244
164
|
const percentX = relativePoint.x / el.offsetWidth;
|
|
245
165
|
const percentY = relativePoint.y / el.offsetHeight;
|
|
246
166
|
let percent;
|
|
@@ -255,7 +175,7 @@ var dom = defineDomHelpers({
|
|
|
255
175
|
const input = dom.getHiddenInputEl(ctx);
|
|
256
176
|
if (!input)
|
|
257
177
|
return;
|
|
258
|
-
dispatchInputValueEvent(input, ctx.value);
|
|
178
|
+
(0, import_form_utils.dispatchInputValueEvent)(input, ctx.value);
|
|
259
179
|
}
|
|
260
180
|
});
|
|
261
181
|
// Annotate the CommonJS export names for ESM import in node:
|