@zag-js/slider 0.1.10 → 0.1.13
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/LICENSE +21 -0
- package/dist/index.d.ts +228 -4
- package/dist/index.js +308 -336
- package/dist/index.mjs +302 -339
- package/package.json +14 -12
- package/dist/slider.connect.d.ts +0 -25
- package/dist/slider.dom.d.ts +0 -43
- package/dist/slider.machine.d.ts +0 -2
- package/dist/slider.style.d.ts +0 -23
- package/dist/slider.types.d.ts +0 -173
- package/dist/slider.utils.d.ts +0 -8
package/dist/index.mjs
CHANGED
|
@@ -1,47 +1,10 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
|
|
21
1
|
// ../../utilities/dom/dist/index.mjs
|
|
22
|
-
var __defProp2 = Object.defineProperty;
|
|
23
|
-
var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
|
|
24
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
25
|
-
var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
|
|
26
|
-
var __pow = Math.pow;
|
|
27
|
-
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
28
|
-
var __spreadValues2 = (a, b) => {
|
|
29
|
-
for (var prop in b || (b = {}))
|
|
30
|
-
if (__hasOwnProp2.call(b, prop))
|
|
31
|
-
__defNormalProp2(a, prop, b[prop]);
|
|
32
|
-
if (__getOwnPropSymbols2)
|
|
33
|
-
for (var prop of __getOwnPropSymbols2(b)) {
|
|
34
|
-
if (__propIsEnum2.call(b, prop))
|
|
35
|
-
__defNormalProp2(a, prop, b[prop]);
|
|
36
|
-
}
|
|
37
|
-
return a;
|
|
38
|
-
};
|
|
39
2
|
var dataAttr = (guard) => {
|
|
40
3
|
return guard ? "" : void 0;
|
|
41
4
|
};
|
|
42
5
|
var runIfFn = (v, ...a) => {
|
|
43
6
|
const res = typeof v === "function" ? v(...a) : v;
|
|
44
|
-
return res
|
|
7
|
+
return res ?? void 0;
|
|
45
8
|
};
|
|
46
9
|
var callAll = (...fns) => (...a) => {
|
|
47
10
|
fns.forEach(function(fn) {
|
|
@@ -53,9 +16,8 @@ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
|
53
16
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
54
17
|
var isDom = () => typeof window !== "undefined";
|
|
55
18
|
function getPlatform() {
|
|
56
|
-
var _a;
|
|
57
19
|
const agent = navigator.userAgentData;
|
|
58
|
-
return (
|
|
20
|
+
return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
|
|
59
21
|
}
|
|
60
22
|
var pt = (v) => isDom() && v.test(getPlatform());
|
|
61
23
|
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
@@ -69,36 +31,30 @@ function isWindow(value) {
|
|
|
69
31
|
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
70
32
|
}
|
|
71
33
|
function getDocument(el) {
|
|
72
|
-
var _a;
|
|
73
34
|
if (isWindow(el))
|
|
74
35
|
return el.document;
|
|
75
36
|
if (isDocument(el))
|
|
76
37
|
return el;
|
|
77
|
-
return (
|
|
78
|
-
}
|
|
79
|
-
function getWindow(el) {
|
|
80
|
-
var _a;
|
|
81
|
-
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
38
|
+
return (el == null ? void 0 : el.ownerDocument) ?? document;
|
|
82
39
|
}
|
|
83
40
|
function defineDomHelpers(helpers) {
|
|
84
41
|
const dom2 = {
|
|
85
42
|
getRootNode: (ctx) => {
|
|
86
|
-
var _a, _b;
|
|
87
|
-
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
88
|
-
},
|
|
89
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
90
|
-
getWin: (ctx) => {
|
|
91
43
|
var _a;
|
|
92
|
-
return (_a =
|
|
44
|
+
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
|
|
93
45
|
},
|
|
46
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
47
|
+
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
94
48
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
95
49
|
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
96
50
|
};
|
|
97
|
-
return
|
|
51
|
+
return {
|
|
52
|
+
...dom2,
|
|
53
|
+
...helpers
|
|
54
|
+
};
|
|
98
55
|
}
|
|
99
56
|
function getNativeEvent(e) {
|
|
100
|
-
|
|
101
|
-
return (_a = e.nativeEvent) != null ? _a : e;
|
|
57
|
+
return e.nativeEvent ?? e;
|
|
102
58
|
}
|
|
103
59
|
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
104
60
|
var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
|
|
@@ -107,46 +63,6 @@ var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
|
|
|
107
63
|
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
108
64
|
var isLeftClick = (v) => v.button === 0;
|
|
109
65
|
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
110
|
-
function observeAttributes(node, attributes, fn) {
|
|
111
|
-
if (!node)
|
|
112
|
-
return;
|
|
113
|
-
const attrs = Array.isArray(attributes) ? attributes : [attributes];
|
|
114
|
-
const win = node.ownerDocument.defaultView || window;
|
|
115
|
-
const obs = new win.MutationObserver((changes) => {
|
|
116
|
-
for (const change of changes) {
|
|
117
|
-
if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
|
|
118
|
-
fn(change);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
obs.observe(node, { attributes: true, attributeFilter: attrs });
|
|
123
|
-
return () => obs.disconnect();
|
|
124
|
-
}
|
|
125
|
-
function getClosestForm(el) {
|
|
126
|
-
if (isFormElement(el))
|
|
127
|
-
return el.form;
|
|
128
|
-
else
|
|
129
|
-
return el.closest("form");
|
|
130
|
-
}
|
|
131
|
-
function isFormElement(el) {
|
|
132
|
-
return el.matches("textarea, input, select, button");
|
|
133
|
-
}
|
|
134
|
-
function trackFormReset(el, callback) {
|
|
135
|
-
if (!el)
|
|
136
|
-
return;
|
|
137
|
-
const form = getClosestForm(el);
|
|
138
|
-
form == null ? void 0 : form.addEventListener("reset", callback, { passive: true });
|
|
139
|
-
return () => {
|
|
140
|
-
form == null ? void 0 : form.removeEventListener("reset", callback);
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
function trackFieldsetDisabled(el, callback) {
|
|
144
|
-
const fieldset = el == null ? void 0 : el.closest("fieldset");
|
|
145
|
-
if (!fieldset)
|
|
146
|
-
return;
|
|
147
|
-
callback(fieldset.disabled);
|
|
148
|
-
return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
|
|
149
|
-
}
|
|
150
66
|
function getElementOffset(element) {
|
|
151
67
|
let left = 0;
|
|
152
68
|
let top = 0;
|
|
@@ -176,8 +92,7 @@ var fallback = {
|
|
|
176
92
|
clientY: 0
|
|
177
93
|
};
|
|
178
94
|
function getEventPoint(event, type = "page") {
|
|
179
|
-
|
|
180
|
-
const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event;
|
|
95
|
+
const point = isTouchEvent(event) ? event.touches[0] ?? event.changedTouches[0] ?? fallback : event;
|
|
181
96
|
return { x: point[`${type}X`], y: point[`${type}Y`] };
|
|
182
97
|
}
|
|
183
98
|
function getPointRelativeToNode(point, element) {
|
|
@@ -186,24 +101,6 @@ function getPointRelativeToNode(point, element) {
|
|
|
186
101
|
const y = point.y - offset.top;
|
|
187
102
|
return { x, y };
|
|
188
103
|
}
|
|
189
|
-
function getDescriptor(el, options) {
|
|
190
|
-
var _a;
|
|
191
|
-
const { type, property } = options;
|
|
192
|
-
const proto = getWindow(el)[type].prototype;
|
|
193
|
-
return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
|
|
194
|
-
}
|
|
195
|
-
function dispatchInputValueEvent(el, value) {
|
|
196
|
-
var _a;
|
|
197
|
-
if (!el)
|
|
198
|
-
return;
|
|
199
|
-
const win = getWindow(el);
|
|
200
|
-
if (!(el instanceof win.HTMLInputElement))
|
|
201
|
-
return;
|
|
202
|
-
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
203
|
-
(_a = desc.set) == null ? void 0 : _a.call(el, value);
|
|
204
|
-
const event = new win.Event("input", { bubbles: true });
|
|
205
|
-
el.dispatchEvent(event);
|
|
206
|
-
}
|
|
207
104
|
var rtlKeyMap = {
|
|
208
105
|
ArrowLeft: "ArrowRight",
|
|
209
106
|
ArrowRight: "ArrowLeft",
|
|
@@ -220,10 +117,9 @@ var sameKeyMap = {
|
|
|
220
117
|
Right: "ArrowRight"
|
|
221
118
|
};
|
|
222
119
|
function getEventKey(event, options = {}) {
|
|
223
|
-
var _a;
|
|
224
120
|
const { dir = "ltr", orientation = "horizontal" } = options;
|
|
225
121
|
let { key } = event;
|
|
226
|
-
key =
|
|
122
|
+
key = sameKeyMap[key] ?? key;
|
|
227
123
|
const isRtl = dir === "rtl" && orientation === "horizontal";
|
|
228
124
|
if (isRtl && key in rtlKeyMap) {
|
|
229
125
|
key = rtlKeyMap[key];
|
|
@@ -260,8 +156,7 @@ function addDomEvent(target, eventName, handler, options) {
|
|
|
260
156
|
};
|
|
261
157
|
}
|
|
262
158
|
function addPointerEvent(target, event, listener, options) {
|
|
263
|
-
|
|
264
|
-
const type = (_a = getEventName(event)) != null ? _a : event;
|
|
159
|
+
const type = getEventName(event) ?? event;
|
|
265
160
|
return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
|
|
266
161
|
}
|
|
267
162
|
function wrapHandler(fn, filter = false) {
|
|
@@ -272,8 +167,7 @@ function wrapHandler(fn, filter = false) {
|
|
|
272
167
|
}
|
|
273
168
|
function filterPrimaryPointer(fn) {
|
|
274
169
|
return (event) => {
|
|
275
|
-
|
|
276
|
-
const win = (_a = event.view) != null ? _a : window;
|
|
170
|
+
const win = event.view ?? window;
|
|
277
171
|
const isMouseEvent2 = event instanceof win.MouseEvent;
|
|
278
172
|
const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
|
|
279
173
|
if (isPrimary)
|
|
@@ -328,7 +222,7 @@ var state = "default";
|
|
|
328
222
|
var savedUserSelect = "";
|
|
329
223
|
var modifiedElementMap = /* @__PURE__ */ new WeakMap();
|
|
330
224
|
function disableTextSelection({ target, doc } = {}) {
|
|
331
|
-
const _document = doc
|
|
225
|
+
const _document = doc ?? document;
|
|
332
226
|
if (isIos()) {
|
|
333
227
|
if (state === "default") {
|
|
334
228
|
savedUserSelect = _document.documentElement.style.webkitUserSelect;
|
|
@@ -342,7 +236,7 @@ function disableTextSelection({ target, doc } = {}) {
|
|
|
342
236
|
return () => restoreTextSelection({ target, doc: _document });
|
|
343
237
|
}
|
|
344
238
|
function restoreTextSelection({ target, doc } = {}) {
|
|
345
|
-
const _document = doc
|
|
239
|
+
const _document = doc ?? document;
|
|
346
240
|
if (isIos()) {
|
|
347
241
|
if (state !== "disabled")
|
|
348
242
|
return;
|
|
@@ -362,7 +256,7 @@ function restoreTextSelection({ target, doc } = {}) {
|
|
|
362
256
|
if (target && modifiedElementMap.has(target)) {
|
|
363
257
|
let targetOldUserSelect = modifiedElementMap.get(target);
|
|
364
258
|
if (target.style.userSelect === "none") {
|
|
365
|
-
target.style.userSelect = targetOldUserSelect
|
|
259
|
+
target.style.userSelect = targetOldUserSelect ?? "";
|
|
366
260
|
}
|
|
367
261
|
if (target.getAttribute("style") === "") {
|
|
368
262
|
target.removeAttribute("style");
|
|
@@ -371,13 +265,13 @@ function restoreTextSelection({ target, doc } = {}) {
|
|
|
371
265
|
}
|
|
372
266
|
}
|
|
373
267
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
const {
|
|
268
|
+
var THRESHOLD = 5;
|
|
269
|
+
function trackPointerMove(doc, opts) {
|
|
270
|
+
const { onPointerMove, onPointerUp } = opts;
|
|
377
271
|
const handlePointerMove = (event, info) => {
|
|
378
272
|
const { point: p } = info;
|
|
379
|
-
const distance = Math.sqrt(
|
|
380
|
-
if (distance <
|
|
273
|
+
const distance = Math.sqrt(p.x ** 2 + p.y ** 2);
|
|
274
|
+
if (distance < THRESHOLD)
|
|
381
275
|
return;
|
|
382
276
|
if (isMouseEvent(event) && isLeftClick(event)) {
|
|
383
277
|
onPointerUp();
|
|
@@ -385,14 +279,81 @@ function trackPointerMove(opts) {
|
|
|
385
279
|
}
|
|
386
280
|
onPointerMove(info, event);
|
|
387
281
|
};
|
|
388
|
-
return callAll(
|
|
282
|
+
return callAll(
|
|
283
|
+
addPointerEvent(doc, "pointermove", handlePointerMove, false),
|
|
284
|
+
addPointerEvent(doc, "pointerup", onPointerUp, false),
|
|
285
|
+
addPointerEvent(doc, "pointercancel", onPointerUp, false),
|
|
286
|
+
addPointerEvent(doc, "contextmenu", onPointerUp, false),
|
|
287
|
+
disableTextSelection({ doc })
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// ../../utilities/form-utils/dist/index.mjs
|
|
292
|
+
function getWindow(el) {
|
|
293
|
+
return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
|
|
294
|
+
}
|
|
295
|
+
function observeAttributes(node, attributes, fn) {
|
|
296
|
+
if (!node)
|
|
297
|
+
return;
|
|
298
|
+
const attrs = Array.isArray(attributes) ? attributes : [attributes];
|
|
299
|
+
const win = node.ownerDocument.defaultView || window;
|
|
300
|
+
const obs = new win.MutationObserver((changes) => {
|
|
301
|
+
for (const change of changes) {
|
|
302
|
+
if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
|
|
303
|
+
fn(change);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
obs.observe(node, { attributes: true, attributeFilter: attrs });
|
|
308
|
+
return () => obs.disconnect();
|
|
309
|
+
}
|
|
310
|
+
function getDescriptor(el, options) {
|
|
311
|
+
const { type, property } = options;
|
|
312
|
+
const proto = getWindow(el)[type].prototype;
|
|
313
|
+
return Object.getOwnPropertyDescriptor(proto, property) ?? {};
|
|
314
|
+
}
|
|
315
|
+
function dispatchInputValueEvent(el, value) {
|
|
316
|
+
var _a;
|
|
317
|
+
if (!el)
|
|
318
|
+
return;
|
|
319
|
+
const win = getWindow(el);
|
|
320
|
+
if (!(el instanceof win.HTMLInputElement))
|
|
321
|
+
return;
|
|
322
|
+
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
323
|
+
(_a = desc.set) == null ? void 0 : _a.call(el, value);
|
|
324
|
+
const event = new win.Event("input", { bubbles: true });
|
|
325
|
+
el.dispatchEvent(event);
|
|
326
|
+
}
|
|
327
|
+
function getClosestForm(el) {
|
|
328
|
+
if (isFormElement(el))
|
|
329
|
+
return el.form;
|
|
330
|
+
else
|
|
331
|
+
return el.closest("form");
|
|
332
|
+
}
|
|
333
|
+
function isFormElement(el) {
|
|
334
|
+
return el.matches("textarea, input, select, button");
|
|
335
|
+
}
|
|
336
|
+
function trackFormReset(el, callback) {
|
|
337
|
+
if (!el)
|
|
338
|
+
return;
|
|
339
|
+
const form = getClosestForm(el);
|
|
340
|
+
form == null ? void 0 : form.addEventListener("reset", callback, { passive: true });
|
|
341
|
+
return () => {
|
|
342
|
+
form == null ? void 0 : form.removeEventListener("reset", callback);
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
function trackFieldsetDisabled(el, callback) {
|
|
346
|
+
const fieldset = el == null ? void 0 : el.closest("fieldset");
|
|
347
|
+
if (!fieldset)
|
|
348
|
+
return;
|
|
349
|
+
callback(fieldset.disabled);
|
|
350
|
+
return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
|
|
389
351
|
}
|
|
390
352
|
|
|
391
353
|
// ../../utilities/number/dist/index.mjs
|
|
392
|
-
var __pow2 = Math.pow;
|
|
393
354
|
function round(v, t) {
|
|
394
355
|
let num = valueOf(v);
|
|
395
|
-
const p =
|
|
356
|
+
const p = 10 ** (t ?? 10);
|
|
396
357
|
num = Math.round(num * p) / p;
|
|
397
358
|
return t ? num.toFixed(t) : v.toString();
|
|
398
359
|
}
|
|
@@ -428,7 +389,7 @@ function valueOf(v) {
|
|
|
428
389
|
function decimalOperation(a, op, b) {
|
|
429
390
|
let result = op === "+" ? a + b : a - b;
|
|
430
391
|
if (a % 1 !== 0 || b % 1 !== 0) {
|
|
431
|
-
const multiplier =
|
|
392
|
+
const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
|
|
432
393
|
a = Math.round(a * multiplier);
|
|
433
394
|
b = Math.round(b * multiplier);
|
|
434
395
|
result = op === "+" ? a + b : a - b;
|
|
@@ -450,14 +411,12 @@ var transform = (a, b) => {
|
|
|
450
411
|
|
|
451
412
|
// src/slider.style.ts
|
|
452
413
|
function getVerticalThumbOffset(ctx) {
|
|
453
|
-
|
|
454
|
-
const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
|
|
414
|
+
const { height = 0 } = ctx.thumbSize ?? {};
|
|
455
415
|
const getValue = transform([ctx.min, ctx.max], [-height / 2, height / 2]);
|
|
456
416
|
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
457
417
|
}
|
|
458
418
|
function getHorizontalThumbOffset(ctx) {
|
|
459
|
-
|
|
460
|
-
const { width = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
|
|
419
|
+
const { width = 0 } = ctx.thumbSize ?? {};
|
|
461
420
|
if (ctx.isRtl) {
|
|
462
421
|
const getValue2 = transform([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
|
|
463
422
|
return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
|
|
@@ -567,45 +526,46 @@ var utils = {
|
|
|
567
526
|
return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
|
|
568
527
|
},
|
|
569
528
|
decrement(ctx, step) {
|
|
570
|
-
let value = decrement(ctx.value, step
|
|
529
|
+
let value = decrement(ctx.value, step ?? ctx.step);
|
|
571
530
|
return utils.convert(ctx, value);
|
|
572
531
|
},
|
|
573
532
|
increment(ctx, step) {
|
|
574
|
-
let value = increment(ctx.value, step
|
|
533
|
+
let value = increment(ctx.value, step ?? ctx.step);
|
|
575
534
|
return utils.convert(ctx, value);
|
|
576
535
|
}
|
|
577
536
|
};
|
|
578
537
|
|
|
579
538
|
// src/slider.dom.ts
|
|
580
|
-
var dom = defineDomHelpers(
|
|
539
|
+
var dom = defineDomHelpers({
|
|
540
|
+
...styles,
|
|
581
541
|
getRootId: (ctx) => {
|
|
582
|
-
var _a
|
|
583
|
-
return (
|
|
542
|
+
var _a;
|
|
543
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.root) ?? `slider:${ctx.id}`;
|
|
584
544
|
},
|
|
585
545
|
getThumbId: (ctx) => {
|
|
586
|
-
var _a
|
|
587
|
-
return (
|
|
546
|
+
var _a;
|
|
547
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.thumb) ?? `slider:${ctx.id}:thumb`;
|
|
588
548
|
},
|
|
589
549
|
getControlId: (ctx) => {
|
|
590
|
-
var _a
|
|
591
|
-
return (
|
|
550
|
+
var _a;
|
|
551
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.control) ?? `slider:${ctx.id}:control`;
|
|
592
552
|
},
|
|
593
553
|
getInputId: (ctx) => `slider:${ctx.id}:input`,
|
|
594
554
|
getOutputId: (ctx) => {
|
|
595
|
-
var _a
|
|
596
|
-
return (
|
|
555
|
+
var _a;
|
|
556
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.output) ?? `slider:${ctx.id}:output`;
|
|
597
557
|
},
|
|
598
558
|
getTrackId: (ctx) => {
|
|
599
|
-
var _a
|
|
600
|
-
return (
|
|
559
|
+
var _a;
|
|
560
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.track) ?? `slider:${ctx.id}track`;
|
|
601
561
|
},
|
|
602
562
|
getRangeId: (ctx) => {
|
|
603
|
-
var _a
|
|
604
|
-
return (
|
|
563
|
+
var _a;
|
|
564
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.track) ?? `slider:${ctx.id}:range`;
|
|
605
565
|
},
|
|
606
566
|
getLabelId: (ctx) => {
|
|
607
|
-
var _a
|
|
608
|
-
return (
|
|
567
|
+
var _a;
|
|
568
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.label) ?? `slider:${ctx.id}:label`;
|
|
609
569
|
},
|
|
610
570
|
getMarkerId: (ctx, value) => `slider:${ctx.id}:marker:${value}`,
|
|
611
571
|
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
@@ -633,7 +593,7 @@ var dom = defineDomHelpers(__spreadProps(__spreadValues({}, styles), {
|
|
|
633
593
|
return;
|
|
634
594
|
dispatchInputValueEvent(input, ctx.value);
|
|
635
595
|
}
|
|
636
|
-
})
|
|
596
|
+
});
|
|
637
597
|
|
|
638
598
|
// src/slider.connect.ts
|
|
639
599
|
function connect(state2, send, normalize) {
|
|
@@ -704,7 +664,7 @@ function connect(state2, send, normalize) {
|
|
|
704
664
|
"data-invalid": dataAttr(isInvalid),
|
|
705
665
|
"aria-disabled": isDisabled || void 0,
|
|
706
666
|
"aria-label": ariaLabel,
|
|
707
|
-
"aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy
|
|
667
|
+
"aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy ?? dom.getLabelId(state2.context),
|
|
708
668
|
"aria-orientation": state2.context.orientation,
|
|
709
669
|
"aria-valuemax": state2.context.max,
|
|
710
670
|
"aria-valuemin": state2.context.min,
|
|
@@ -849,207 +809,210 @@ function connect(state2, send, normalize) {
|
|
|
849
809
|
|
|
850
810
|
// src/slider.machine.ts
|
|
851
811
|
import { createMachine } from "@zag-js/core";
|
|
812
|
+
import { trackElementSize } from "@zag-js/element-size";
|
|
852
813
|
function machine(ctx) {
|
|
853
|
-
return createMachine(
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
|
|
872
|
-
isVertical: (ctx2) => ctx2.orientation === "vertical",
|
|
873
|
-
isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
|
|
874
|
-
isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readonly),
|
|
875
|
-
hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null
|
|
876
|
-
},
|
|
877
|
-
watch: {
|
|
878
|
-
value: ["invokeOnChange", "dispatchChangeEvent"]
|
|
879
|
-
},
|
|
880
|
-
activities: ["trackFormReset", "trackFieldsetDisabled"],
|
|
881
|
-
on: {
|
|
882
|
-
SET_VALUE: {
|
|
883
|
-
actions: "setValue"
|
|
884
|
-
},
|
|
885
|
-
INCREMENT: {
|
|
886
|
-
actions: "increment"
|
|
814
|
+
return createMachine(
|
|
815
|
+
{
|
|
816
|
+
id: "slider",
|
|
817
|
+
initial: "unknown",
|
|
818
|
+
context: {
|
|
819
|
+
thumbSize: null,
|
|
820
|
+
thumbAlignment: "contain",
|
|
821
|
+
disabled: false,
|
|
822
|
+
threshold: 5,
|
|
823
|
+
dir: "ltr",
|
|
824
|
+
origin: "start",
|
|
825
|
+
orientation: "horizontal",
|
|
826
|
+
initialValue: null,
|
|
827
|
+
value: 0,
|
|
828
|
+
step: 1,
|
|
829
|
+
min: 0,
|
|
830
|
+
max: 100,
|
|
831
|
+
...ctx
|
|
887
832
|
},
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
on: {
|
|
895
|
-
SETUP: {
|
|
896
|
-
target: "idle",
|
|
897
|
-
actions: ["setThumbSize", "checkValue"]
|
|
898
|
-
}
|
|
899
|
-
}
|
|
833
|
+
computed: {
|
|
834
|
+
isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
|
|
835
|
+
isVertical: (ctx2) => ctx2.orientation === "vertical",
|
|
836
|
+
isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
|
|
837
|
+
isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readonly),
|
|
838
|
+
hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null
|
|
900
839
|
},
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
POINTER_DOWN: {
|
|
904
|
-
target: "dragging",
|
|
905
|
-
actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
|
|
906
|
-
},
|
|
907
|
-
FOCUS: "focus"
|
|
908
|
-
}
|
|
840
|
+
watch: {
|
|
841
|
+
value: ["invokeOnChange", "dispatchChangeEvent"]
|
|
909
842
|
},
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
},
|
|
921
|
-
ARROW_RIGHT: {
|
|
922
|
-
guard: "isHorizontal",
|
|
923
|
-
actions: "increment"
|
|
924
|
-
},
|
|
925
|
-
ARROW_UP: {
|
|
926
|
-
guard: "isVertical",
|
|
927
|
-
actions: "increment"
|
|
928
|
-
},
|
|
929
|
-
ARROW_DOWN: {
|
|
930
|
-
guard: "isVertical",
|
|
931
|
-
actions: "decrement"
|
|
932
|
-
},
|
|
933
|
-
PAGE_UP: {
|
|
934
|
-
actions: "increment"
|
|
935
|
-
},
|
|
936
|
-
PAGE_DOWN: {
|
|
937
|
-
actions: "decrement"
|
|
938
|
-
},
|
|
939
|
-
HOME: {
|
|
940
|
-
actions: "setToMin"
|
|
941
|
-
},
|
|
942
|
-
END: {
|
|
943
|
-
actions: "setToMax"
|
|
944
|
-
},
|
|
945
|
-
BLUR: "idle"
|
|
843
|
+
activities: ["trackFormReset", "trackFieldsetDisabled", "trackThumbSize"],
|
|
844
|
+
on: {
|
|
845
|
+
SET_VALUE: {
|
|
846
|
+
actions: "setValue"
|
|
847
|
+
},
|
|
848
|
+
INCREMENT: {
|
|
849
|
+
actions: "increment"
|
|
850
|
+
},
|
|
851
|
+
DECREMENT: {
|
|
852
|
+
actions: "decrement"
|
|
946
853
|
}
|
|
947
854
|
},
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
},
|
|
956
|
-
POINTER_MOVE: {
|
|
957
|
-
actions: "setPointerValue"
|
|
855
|
+
states: {
|
|
856
|
+
unknown: {
|
|
857
|
+
on: {
|
|
858
|
+
SETUP: {
|
|
859
|
+
target: "idle",
|
|
860
|
+
actions: ["checkValue"]
|
|
861
|
+
}
|
|
958
862
|
}
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
activities: {
|
|
968
|
-
trackFieldsetDisabled(ctx2) {
|
|
969
|
-
return trackFieldsetDisabled(dom.getRootEl(ctx2), (disabled) => {
|
|
970
|
-
if (disabled) {
|
|
971
|
-
ctx2.disabled = disabled;
|
|
863
|
+
},
|
|
864
|
+
idle: {
|
|
865
|
+
on: {
|
|
866
|
+
POINTER_DOWN: {
|
|
867
|
+
target: "dragging",
|
|
868
|
+
actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
|
|
869
|
+
},
|
|
870
|
+
FOCUS: "focus"
|
|
972
871
|
}
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
872
|
+
},
|
|
873
|
+
focus: {
|
|
874
|
+
entry: "focusThumb",
|
|
875
|
+
on: {
|
|
876
|
+
POINTER_DOWN: {
|
|
877
|
+
target: "dragging",
|
|
878
|
+
actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
|
|
879
|
+
},
|
|
880
|
+
ARROW_LEFT: {
|
|
881
|
+
guard: "isHorizontal",
|
|
882
|
+
actions: "decrement"
|
|
883
|
+
},
|
|
884
|
+
ARROW_RIGHT: {
|
|
885
|
+
guard: "isHorizontal",
|
|
886
|
+
actions: "increment"
|
|
887
|
+
},
|
|
888
|
+
ARROW_UP: {
|
|
889
|
+
guard: "isVertical",
|
|
890
|
+
actions: "increment"
|
|
891
|
+
},
|
|
892
|
+
ARROW_DOWN: {
|
|
893
|
+
guard: "isVertical",
|
|
894
|
+
actions: "decrement"
|
|
895
|
+
},
|
|
896
|
+
PAGE_UP: {
|
|
897
|
+
actions: "increment"
|
|
898
|
+
},
|
|
899
|
+
PAGE_DOWN: {
|
|
900
|
+
actions: "decrement"
|
|
901
|
+
},
|
|
902
|
+
HOME: {
|
|
903
|
+
actions: "setToMin"
|
|
904
|
+
},
|
|
905
|
+
END: {
|
|
906
|
+
actions: "setToMax"
|
|
907
|
+
},
|
|
908
|
+
BLUR: "idle"
|
|
979
909
|
}
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
910
|
+
},
|
|
911
|
+
dragging: {
|
|
912
|
+
entry: "focusThumb",
|
|
913
|
+
activities: "trackPointerMove",
|
|
914
|
+
on: {
|
|
915
|
+
POINTER_UP: {
|
|
916
|
+
target: "focus",
|
|
917
|
+
actions: "invokeOnChangeEnd"
|
|
918
|
+
},
|
|
919
|
+
POINTER_MOVE: {
|
|
920
|
+
actions: "setPointerValue"
|
|
921
|
+
}
|
|
990
922
|
}
|
|
991
|
-
}
|
|
923
|
+
}
|
|
992
924
|
}
|
|
993
925
|
},
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
},
|
|
999
|
-
invokeOnChangeStart(ctx2) {
|
|
1000
|
-
var _a;
|
|
1001
|
-
(_a = ctx2.onChangeStart) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
|
|
926
|
+
{
|
|
927
|
+
guards: {
|
|
928
|
+
isHorizontal: (ctx2) => ctx2.isHorizontal,
|
|
929
|
+
isVertical: (ctx2) => ctx2.isVertical
|
|
1002
930
|
},
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
931
|
+
activities: {
|
|
932
|
+
trackFieldsetDisabled(ctx2) {
|
|
933
|
+
return trackFieldsetDisabled(dom.getRootEl(ctx2), (disabled) => {
|
|
934
|
+
if (disabled) {
|
|
935
|
+
ctx2.disabled = disabled;
|
|
936
|
+
}
|
|
937
|
+
});
|
|
938
|
+
},
|
|
939
|
+
trackFormReset(ctx2) {
|
|
940
|
+
return trackFormReset(dom.getInputEl(ctx2), () => {
|
|
941
|
+
if (ctx2.initialValue != null) {
|
|
942
|
+
ctx2.value = ctx2.initialValue;
|
|
943
|
+
}
|
|
944
|
+
});
|
|
945
|
+
},
|
|
946
|
+
trackPointerMove(ctx2, _evt, { send }) {
|
|
947
|
+
return trackPointerMove(dom.getDoc(ctx2), {
|
|
948
|
+
onPointerMove(info) {
|
|
949
|
+
send({ type: "POINTER_MOVE", point: info.point });
|
|
950
|
+
},
|
|
951
|
+
onPointerUp() {
|
|
952
|
+
send("POINTER_UP");
|
|
953
|
+
}
|
|
954
|
+
});
|
|
955
|
+
},
|
|
956
|
+
trackThumbSize(ctx2, _evt) {
|
|
957
|
+
if (ctx2.thumbAlignment !== "contain")
|
|
1020
958
|
return;
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
if (value == null)
|
|
1027
|
-
return;
|
|
1028
|
-
ctx2.value = utils.clamp(ctx2, value);
|
|
959
|
+
return trackElementSize(dom.getThumbEl(ctx2), (size) => {
|
|
960
|
+
if (size)
|
|
961
|
+
ctx2.thumbSize = size;
|
|
962
|
+
});
|
|
963
|
+
}
|
|
1029
964
|
},
|
|
1030
|
-
|
|
1031
|
-
|
|
965
|
+
actions: {
|
|
966
|
+
checkValue(ctx2) {
|
|
967
|
+
const value = utils.convert(ctx2, ctx2.value);
|
|
968
|
+
ctx2.value = value;
|
|
969
|
+
ctx2.initialValue = value;
|
|
970
|
+
},
|
|
971
|
+
invokeOnChangeStart(ctx2) {
|
|
1032
972
|
var _a;
|
|
1033
|
-
|
|
1034
|
-
}
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
ctx2
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
ctx2
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
973
|
+
(_a = ctx2.onChangeStart) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
|
|
974
|
+
},
|
|
975
|
+
invokeOnChangeEnd(ctx2) {
|
|
976
|
+
var _a;
|
|
977
|
+
(_a = ctx2.onChangeEnd) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
|
|
978
|
+
},
|
|
979
|
+
invokeOnChange(ctx2) {
|
|
980
|
+
var _a;
|
|
981
|
+
(_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
|
|
982
|
+
},
|
|
983
|
+
dispatchChangeEvent(ctx2) {
|
|
984
|
+
dom.dispatchChangeEvent(ctx2);
|
|
985
|
+
},
|
|
986
|
+
setPointerValue(ctx2, evt) {
|
|
987
|
+
const value = dom.getValueFromPoint(ctx2, evt.point);
|
|
988
|
+
if (value == null)
|
|
989
|
+
return;
|
|
990
|
+
ctx2.value = utils.clamp(ctx2, value);
|
|
991
|
+
},
|
|
992
|
+
focusThumb(ctx2) {
|
|
993
|
+
raf(() => {
|
|
994
|
+
var _a;
|
|
995
|
+
return (_a = dom.getThumbEl(ctx2)) == null ? void 0 : _a.focus();
|
|
996
|
+
});
|
|
997
|
+
},
|
|
998
|
+
decrement(ctx2, evt) {
|
|
999
|
+
ctx2.value = utils.decrement(ctx2, evt.step);
|
|
1000
|
+
},
|
|
1001
|
+
increment(ctx2, evt) {
|
|
1002
|
+
ctx2.value = utils.increment(ctx2, evt.step);
|
|
1003
|
+
},
|
|
1004
|
+
setToMin(ctx2) {
|
|
1005
|
+
ctx2.value = ctx2.min;
|
|
1006
|
+
},
|
|
1007
|
+
setToMax(ctx2) {
|
|
1008
|
+
ctx2.value = ctx2.max;
|
|
1009
|
+
},
|
|
1010
|
+
setValue(ctx2, evt) {
|
|
1011
|
+
ctx2.value = utils.convert(ctx2, evt.value);
|
|
1012
|
+
}
|
|
1050
1013
|
}
|
|
1051
1014
|
}
|
|
1052
|
-
|
|
1015
|
+
);
|
|
1053
1016
|
}
|
|
1054
1017
|
export {
|
|
1055
1018
|
connect,
|