@zag-js/slider 0.1.9 → 0.1.12
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 +330 -334
- package/dist/index.mjs +325 -338
- package/package.json +16 -12
- package/dist/slider.connect.d.ts +0 -25
- package/dist/slider.dom.d.ts +0 -29
- 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,31 +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 __pow = Math.pow;
|
|
23
2
|
var dataAttr = (guard) => {
|
|
24
3
|
return guard ? "" : void 0;
|
|
25
4
|
};
|
|
26
5
|
var runIfFn = (v, ...a) => {
|
|
27
6
|
const res = typeof v === "function" ? v(...a) : v;
|
|
28
|
-
return res
|
|
7
|
+
return res ?? void 0;
|
|
29
8
|
};
|
|
30
9
|
var callAll = (...fns) => (...a) => {
|
|
31
10
|
fns.forEach(function(fn) {
|
|
@@ -37,22 +16,45 @@ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
|
37
16
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
38
17
|
var isDom = () => typeof window !== "undefined";
|
|
39
18
|
function getPlatform() {
|
|
40
|
-
var _a;
|
|
41
19
|
const agent = navigator.userAgentData;
|
|
42
|
-
return (
|
|
20
|
+
return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
|
|
43
21
|
}
|
|
44
22
|
var pt = (v) => isDom() && v.test(getPlatform());
|
|
45
23
|
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
46
24
|
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
47
25
|
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
48
26
|
var isIos = () => isApple() && !isMac();
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
|
|
27
|
+
function isDocument(el) {
|
|
28
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
29
|
+
}
|
|
30
|
+
function isWindow(value) {
|
|
31
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
32
|
+
}
|
|
33
|
+
function getDocument(el) {
|
|
34
|
+
if (isWindow(el))
|
|
35
|
+
return el.document;
|
|
36
|
+
if (isDocument(el))
|
|
37
|
+
return el;
|
|
38
|
+
return (el == null ? void 0 : el.ownerDocument) ?? document;
|
|
39
|
+
}
|
|
40
|
+
function defineDomHelpers(helpers) {
|
|
41
|
+
const dom2 = {
|
|
42
|
+
getRootNode: (ctx) => {
|
|
43
|
+
var _a;
|
|
44
|
+
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
|
|
45
|
+
},
|
|
46
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
47
|
+
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
48
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
49
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
...dom2,
|
|
53
|
+
...helpers
|
|
54
|
+
};
|
|
52
55
|
}
|
|
53
56
|
function getNativeEvent(e) {
|
|
54
|
-
|
|
55
|
-
return (_a = e.nativeEvent) != null ? _a : e;
|
|
57
|
+
return e.nativeEvent ?? e;
|
|
56
58
|
}
|
|
57
59
|
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
58
60
|
var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
|
|
@@ -61,46 +63,6 @@ var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
|
|
|
61
63
|
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
62
64
|
var isLeftClick = (v) => v.button === 0;
|
|
63
65
|
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
64
|
-
function observeAttributes(node, attributes, fn) {
|
|
65
|
-
if (!node)
|
|
66
|
-
return;
|
|
67
|
-
const attrs = Array.isArray(attributes) ? attributes : [attributes];
|
|
68
|
-
const win = node.ownerDocument.defaultView || window;
|
|
69
|
-
const obs = new win.MutationObserver((changes) => {
|
|
70
|
-
for (const change of changes) {
|
|
71
|
-
if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
|
|
72
|
-
fn(change);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
obs.observe(node, { attributes: true, attributeFilter: attrs });
|
|
77
|
-
return () => obs.disconnect();
|
|
78
|
-
}
|
|
79
|
-
function getClosestForm(el) {
|
|
80
|
-
if (isFormElement(el))
|
|
81
|
-
return el.form;
|
|
82
|
-
else
|
|
83
|
-
return el.closest("form");
|
|
84
|
-
}
|
|
85
|
-
function isFormElement(el) {
|
|
86
|
-
return el.matches("textarea, input, select, button");
|
|
87
|
-
}
|
|
88
|
-
function trackFormReset(el, callback) {
|
|
89
|
-
if (!el)
|
|
90
|
-
return;
|
|
91
|
-
const form = getClosestForm(el);
|
|
92
|
-
form == null ? void 0 : form.addEventListener("reset", callback, { passive: true });
|
|
93
|
-
return () => {
|
|
94
|
-
form == null ? void 0 : form.removeEventListener("reset", callback);
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
function trackFieldsetDisabled(el, callback) {
|
|
98
|
-
const fieldset = el == null ? void 0 : el.closest("fieldset");
|
|
99
|
-
if (!fieldset)
|
|
100
|
-
return;
|
|
101
|
-
callback(fieldset.disabled);
|
|
102
|
-
return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
|
|
103
|
-
}
|
|
104
66
|
function getElementOffset(element) {
|
|
105
67
|
let left = 0;
|
|
106
68
|
let top = 0;
|
|
@@ -130,8 +92,7 @@ var fallback = {
|
|
|
130
92
|
clientY: 0
|
|
131
93
|
};
|
|
132
94
|
function getEventPoint(event, type = "page") {
|
|
133
|
-
|
|
134
|
-
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;
|
|
135
96
|
return { x: point[`${type}X`], y: point[`${type}Y`] };
|
|
136
97
|
}
|
|
137
98
|
function getPointRelativeToNode(point, element) {
|
|
@@ -140,22 +101,6 @@ function getPointRelativeToNode(point, element) {
|
|
|
140
101
|
const y = point.y - offset.top;
|
|
141
102
|
return { x, y };
|
|
142
103
|
}
|
|
143
|
-
function getDescriptor(el, options) {
|
|
144
|
-
var _a;
|
|
145
|
-
const { type, property } = options;
|
|
146
|
-
const proto = getWindow(el)[type].prototype;
|
|
147
|
-
return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
|
|
148
|
-
}
|
|
149
|
-
function dispatchInputValueEvent(el, value) {
|
|
150
|
-
var _a;
|
|
151
|
-
const win = getWindow(el);
|
|
152
|
-
if (!(el instanceof win.HTMLInputElement))
|
|
153
|
-
return;
|
|
154
|
-
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
155
|
-
(_a = desc.set) == null ? void 0 : _a.call(el, value);
|
|
156
|
-
const event = new win.Event("input", { bubbles: true });
|
|
157
|
-
el.dispatchEvent(event);
|
|
158
|
-
}
|
|
159
104
|
var rtlKeyMap = {
|
|
160
105
|
ArrowLeft: "ArrowRight",
|
|
161
106
|
ArrowRight: "ArrowLeft",
|
|
@@ -172,10 +117,9 @@ var sameKeyMap = {
|
|
|
172
117
|
Right: "ArrowRight"
|
|
173
118
|
};
|
|
174
119
|
function getEventKey(event, options = {}) {
|
|
175
|
-
var _a;
|
|
176
120
|
const { dir = "ltr", orientation = "horizontal" } = options;
|
|
177
121
|
let { key } = event;
|
|
178
|
-
key =
|
|
122
|
+
key = sameKeyMap[key] ?? key;
|
|
179
123
|
const isRtl = dir === "rtl" && orientation === "horizontal";
|
|
180
124
|
if (isRtl && key in rtlKeyMap) {
|
|
181
125
|
key = rtlKeyMap[key];
|
|
@@ -212,8 +156,7 @@ function addDomEvent(target, eventName, handler, options) {
|
|
|
212
156
|
};
|
|
213
157
|
}
|
|
214
158
|
function addPointerEvent(target, event, listener, options) {
|
|
215
|
-
|
|
216
|
-
const type = (_a = getEventName(event)) != null ? _a : event;
|
|
159
|
+
const type = getEventName(event) ?? event;
|
|
217
160
|
return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
|
|
218
161
|
}
|
|
219
162
|
function wrapHandler(fn, filter = false) {
|
|
@@ -224,8 +167,7 @@ function wrapHandler(fn, filter = false) {
|
|
|
224
167
|
}
|
|
225
168
|
function filterPrimaryPointer(fn) {
|
|
226
169
|
return (event) => {
|
|
227
|
-
|
|
228
|
-
const win = (_a = event.view) != null ? _a : window;
|
|
170
|
+
const win = event.view ?? window;
|
|
229
171
|
const isMouseEvent2 = event instanceof win.MouseEvent;
|
|
230
172
|
const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
|
|
231
173
|
if (isPrimary)
|
|
@@ -280,7 +222,7 @@ var state = "default";
|
|
|
280
222
|
var savedUserSelect = "";
|
|
281
223
|
var modifiedElementMap = /* @__PURE__ */ new WeakMap();
|
|
282
224
|
function disableTextSelection({ target, doc } = {}) {
|
|
283
|
-
const _document = doc
|
|
225
|
+
const _document = doc ?? document;
|
|
284
226
|
if (isIos()) {
|
|
285
227
|
if (state === "default") {
|
|
286
228
|
savedUserSelect = _document.documentElement.style.webkitUserSelect;
|
|
@@ -294,7 +236,7 @@ function disableTextSelection({ target, doc } = {}) {
|
|
|
294
236
|
return () => restoreTextSelection({ target, doc: _document });
|
|
295
237
|
}
|
|
296
238
|
function restoreTextSelection({ target, doc } = {}) {
|
|
297
|
-
const _document = doc
|
|
239
|
+
const _document = doc ?? document;
|
|
298
240
|
if (isIos()) {
|
|
299
241
|
if (state !== "disabled")
|
|
300
242
|
return;
|
|
@@ -314,7 +256,7 @@ function restoreTextSelection({ target, doc } = {}) {
|
|
|
314
256
|
if (target && modifiedElementMap.has(target)) {
|
|
315
257
|
let targetOldUserSelect = modifiedElementMap.get(target);
|
|
316
258
|
if (target.style.userSelect === "none") {
|
|
317
|
-
target.style.userSelect = targetOldUserSelect
|
|
259
|
+
target.style.userSelect = targetOldUserSelect ?? "";
|
|
318
260
|
}
|
|
319
261
|
if (target.getAttribute("style") === "") {
|
|
320
262
|
target.removeAttribute("style");
|
|
@@ -323,13 +265,13 @@ function restoreTextSelection({ target, doc } = {}) {
|
|
|
323
265
|
}
|
|
324
266
|
}
|
|
325
267
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
const {
|
|
268
|
+
var THRESHOLD = 5;
|
|
269
|
+
function trackPointerMove(doc, opts) {
|
|
270
|
+
const { onPointerMove, onPointerUp } = opts;
|
|
329
271
|
const handlePointerMove = (event, info) => {
|
|
330
272
|
const { point: p } = info;
|
|
331
|
-
const distance = Math.sqrt(
|
|
332
|
-
if (distance <
|
|
273
|
+
const distance = Math.sqrt(p.x ** 2 + p.y ** 2);
|
|
274
|
+
if (distance < THRESHOLD)
|
|
333
275
|
return;
|
|
334
276
|
if (isMouseEvent(event) && isLeftClick(event)) {
|
|
335
277
|
onPointerUp();
|
|
@@ -337,14 +279,81 @@ function trackPointerMove(opts) {
|
|
|
337
279
|
}
|
|
338
280
|
onPointerMove(info, event);
|
|
339
281
|
};
|
|
340
|
-
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));
|
|
341
351
|
}
|
|
342
352
|
|
|
343
353
|
// ../../utilities/number/dist/index.mjs
|
|
344
|
-
var __pow2 = Math.pow;
|
|
345
354
|
function round(v, t) {
|
|
346
355
|
let num = valueOf(v);
|
|
347
|
-
const p =
|
|
356
|
+
const p = 10 ** (t ?? 10);
|
|
348
357
|
num = Math.round(num * p) / p;
|
|
349
358
|
return t ? num.toFixed(t) : v.toString();
|
|
350
359
|
}
|
|
@@ -380,7 +389,7 @@ function valueOf(v) {
|
|
|
380
389
|
function decimalOperation(a, op, b) {
|
|
381
390
|
let result = op === "+" ? a + b : a - b;
|
|
382
391
|
if (a % 1 !== 0 || b % 1 !== 0) {
|
|
383
|
-
const multiplier =
|
|
392
|
+
const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
|
|
384
393
|
a = Math.round(a * multiplier);
|
|
385
394
|
b = Math.round(b * multiplier);
|
|
386
395
|
result = op === "+" ? a + b : a - b;
|
|
@@ -402,14 +411,12 @@ var transform = (a, b) => {
|
|
|
402
411
|
|
|
403
412
|
// src/slider.style.ts
|
|
404
413
|
function getVerticalThumbOffset(ctx) {
|
|
405
|
-
|
|
406
|
-
const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
|
|
414
|
+
const { height = 0 } = ctx.thumbSize ?? {};
|
|
407
415
|
const getValue = transform([ctx.min, ctx.max], [-height / 2, height / 2]);
|
|
408
416
|
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
409
417
|
}
|
|
410
418
|
function getHorizontalThumbOffset(ctx) {
|
|
411
|
-
|
|
412
|
-
const { width = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
|
|
419
|
+
const { width = 0 } = ctx.thumbSize ?? {};
|
|
413
420
|
if (ctx.isRtl) {
|
|
414
421
|
const getValue2 = transform([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
|
|
415
422
|
return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
|
|
@@ -519,59 +526,52 @@ var utils = {
|
|
|
519
526
|
return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
|
|
520
527
|
},
|
|
521
528
|
decrement(ctx, step) {
|
|
522
|
-
let value = decrement(ctx.value, step
|
|
529
|
+
let value = decrement(ctx.value, step ?? ctx.step);
|
|
523
530
|
return utils.convert(ctx, value);
|
|
524
531
|
},
|
|
525
532
|
increment(ctx, step) {
|
|
526
|
-
let value = increment(ctx.value, step
|
|
533
|
+
let value = increment(ctx.value, step ?? ctx.step);
|
|
527
534
|
return utils.convert(ctx, value);
|
|
528
535
|
}
|
|
529
536
|
};
|
|
530
537
|
|
|
531
538
|
// src/slider.dom.ts
|
|
532
|
-
var dom =
|
|
533
|
-
|
|
534
|
-
var _a;
|
|
535
|
-
return (_a = ctx.doc) != null ? _a : document;
|
|
536
|
-
},
|
|
537
|
-
getRootNode: (ctx) => {
|
|
538
|
-
var _a;
|
|
539
|
-
return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
|
|
540
|
-
},
|
|
539
|
+
var dom = defineDomHelpers({
|
|
540
|
+
...styles,
|
|
541
541
|
getRootId: (ctx) => {
|
|
542
|
-
var _a
|
|
543
|
-
return (
|
|
542
|
+
var _a;
|
|
543
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.root) ?? `slider:${ctx.id}`;
|
|
544
544
|
},
|
|
545
545
|
getThumbId: (ctx) => {
|
|
546
|
-
var _a
|
|
547
|
-
return (
|
|
546
|
+
var _a;
|
|
547
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.thumb) ?? `slider:${ctx.id}:thumb`;
|
|
548
548
|
},
|
|
549
549
|
getControlId: (ctx) => {
|
|
550
|
-
var _a
|
|
551
|
-
return (
|
|
550
|
+
var _a;
|
|
551
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.control) ?? `slider:${ctx.id}:control`;
|
|
552
552
|
},
|
|
553
|
-
getInputId: (ctx) => `slider:${ctx.
|
|
553
|
+
getInputId: (ctx) => `slider:${ctx.id}:input`,
|
|
554
554
|
getOutputId: (ctx) => {
|
|
555
|
-
var _a
|
|
556
|
-
return (
|
|
555
|
+
var _a;
|
|
556
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.output) ?? `slider:${ctx.id}:output`;
|
|
557
557
|
},
|
|
558
558
|
getTrackId: (ctx) => {
|
|
559
|
-
var _a
|
|
560
|
-
return (
|
|
559
|
+
var _a;
|
|
560
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.track) ?? `slider:${ctx.id}track`;
|
|
561
561
|
},
|
|
562
562
|
getRangeId: (ctx) => {
|
|
563
|
-
var _a
|
|
564
|
-
return (
|
|
563
|
+
var _a;
|
|
564
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.track) ?? `slider:${ctx.id}:range`;
|
|
565
565
|
},
|
|
566
566
|
getLabelId: (ctx) => {
|
|
567
|
-
var _a
|
|
568
|
-
return (
|
|
567
|
+
var _a;
|
|
568
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.label) ?? `slider:${ctx.id}:label`;
|
|
569
569
|
},
|
|
570
|
-
getMarkerId: (ctx, value) => `slider:${ctx.
|
|
571
|
-
getRootEl: (ctx) => dom.
|
|
572
|
-
getThumbEl: (ctx) => dom.
|
|
573
|
-
getControlEl: (ctx) => dom.
|
|
574
|
-
getInputEl: (ctx) => dom.
|
|
570
|
+
getMarkerId: (ctx, value) => `slider:${ctx.id}:marker:${value}`,
|
|
571
|
+
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
572
|
+
getThumbEl: (ctx) => dom.getById(ctx, dom.getThumbId(ctx)),
|
|
573
|
+
getControlEl: (ctx) => dom.getById(ctx, dom.getControlId(ctx)),
|
|
574
|
+
getInputEl: (ctx) => dom.getById(ctx, dom.getInputId(ctx)),
|
|
575
575
|
getValueFromPoint(ctx, point) {
|
|
576
576
|
const el = dom.getControlEl(ctx);
|
|
577
577
|
if (!el)
|
|
@@ -664,7 +664,7 @@ function connect(state2, send, normalize) {
|
|
|
664
664
|
"data-invalid": dataAttr(isInvalid),
|
|
665
665
|
"aria-disabled": isDisabled || void 0,
|
|
666
666
|
"aria-label": ariaLabel,
|
|
667
|
-
"aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy
|
|
667
|
+
"aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy ?? dom.getLabelId(state2.context),
|
|
668
668
|
"aria-orientation": state2.context.orientation,
|
|
669
669
|
"aria-valuemax": state2.context.max,
|
|
670
670
|
"aria-valuemin": state2.context.min,
|
|
@@ -808,224 +808,211 @@ function connect(state2, send, normalize) {
|
|
|
808
808
|
}
|
|
809
809
|
|
|
810
810
|
// src/slider.machine.ts
|
|
811
|
-
import { createMachine
|
|
812
|
-
function machine(ctx
|
|
813
|
-
return createMachine(
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
computed: {
|
|
832
|
-
isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
|
|
833
|
-
isVertical: (ctx2) => ctx2.orientation === "vertical",
|
|
834
|
-
isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
|
|
835
|
-
isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readonly),
|
|
836
|
-
hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null
|
|
837
|
-
},
|
|
838
|
-
watch: {
|
|
839
|
-
value: ["invokeOnChange", "dispatchChangeEvent"]
|
|
840
|
-
},
|
|
841
|
-
activities: ["trackFormReset", "trackFieldsetDisabled"],
|
|
842
|
-
on: {
|
|
843
|
-
SET_VALUE: {
|
|
844
|
-
actions: "setValue"
|
|
811
|
+
import { createMachine } from "@zag-js/core";
|
|
812
|
+
function machine(ctx) {
|
|
813
|
+
return createMachine(
|
|
814
|
+
{
|
|
815
|
+
id: "slider",
|
|
816
|
+
initial: "unknown",
|
|
817
|
+
context: {
|
|
818
|
+
thumbSize: null,
|
|
819
|
+
thumbAlignment: "contain",
|
|
820
|
+
disabled: false,
|
|
821
|
+
threshold: 5,
|
|
822
|
+
dir: "ltr",
|
|
823
|
+
origin: "start",
|
|
824
|
+
orientation: "horizontal",
|
|
825
|
+
initialValue: null,
|
|
826
|
+
value: 0,
|
|
827
|
+
step: 1,
|
|
828
|
+
min: 0,
|
|
829
|
+
max: 100,
|
|
830
|
+
...ctx
|
|
845
831
|
},
|
|
846
|
-
|
|
847
|
-
|
|
832
|
+
computed: {
|
|
833
|
+
isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
|
|
834
|
+
isVertical: (ctx2) => ctx2.orientation === "vertical",
|
|
835
|
+
isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
|
|
836
|
+
isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readonly),
|
|
837
|
+
hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null
|
|
848
838
|
},
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
}
|
|
852
|
-
},
|
|
853
|
-
states: {
|
|
854
|
-
unknown: {
|
|
855
|
-
on: {
|
|
856
|
-
SETUP: {
|
|
857
|
-
target: "idle",
|
|
858
|
-
actions: ["setupDocument", "setThumbSize", "checkValue"]
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
},
|
|
862
|
-
idle: {
|
|
863
|
-
on: {
|
|
864
|
-
POINTER_DOWN: {
|
|
865
|
-
target: "dragging",
|
|
866
|
-
actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
|
|
867
|
-
},
|
|
868
|
-
FOCUS: "focus"
|
|
869
|
-
}
|
|
839
|
+
watch: {
|
|
840
|
+
value: ["invokeOnChange", "dispatchChangeEvent"]
|
|
870
841
|
},
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
},
|
|
882
|
-
ARROW_RIGHT: {
|
|
883
|
-
guard: "isHorizontal",
|
|
884
|
-
actions: "increment"
|
|
885
|
-
},
|
|
886
|
-
ARROW_UP: {
|
|
887
|
-
guard: "isVertical",
|
|
888
|
-
actions: "increment"
|
|
889
|
-
},
|
|
890
|
-
ARROW_DOWN: {
|
|
891
|
-
guard: "isVertical",
|
|
892
|
-
actions: "decrement"
|
|
893
|
-
},
|
|
894
|
-
PAGE_UP: {
|
|
895
|
-
actions: "increment"
|
|
896
|
-
},
|
|
897
|
-
PAGE_DOWN: {
|
|
898
|
-
actions: "decrement"
|
|
899
|
-
},
|
|
900
|
-
HOME: {
|
|
901
|
-
actions: "setToMin"
|
|
902
|
-
},
|
|
903
|
-
END: {
|
|
904
|
-
actions: "setToMax"
|
|
905
|
-
},
|
|
906
|
-
BLUR: "idle"
|
|
842
|
+
activities: ["trackFormReset", "trackFieldsetDisabled"],
|
|
843
|
+
on: {
|
|
844
|
+
SET_VALUE: {
|
|
845
|
+
actions: "setValue"
|
|
846
|
+
},
|
|
847
|
+
INCREMENT: {
|
|
848
|
+
actions: "increment"
|
|
849
|
+
},
|
|
850
|
+
DECREMENT: {
|
|
851
|
+
actions: "decrement"
|
|
907
852
|
}
|
|
908
853
|
},
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
|
|
854
|
+
states: {
|
|
855
|
+
unknown: {
|
|
856
|
+
on: {
|
|
857
|
+
SETUP: {
|
|
858
|
+
target: "idle",
|
|
859
|
+
actions: ["setThumbSize", "checkValue"]
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
},
|
|
863
|
+
idle: {
|
|
864
|
+
on: {
|
|
865
|
+
POINTER_DOWN: {
|
|
866
|
+
target: "dragging",
|
|
867
|
+
actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
|
|
868
|
+
},
|
|
869
|
+
FOCUS: "focus"
|
|
870
|
+
}
|
|
871
|
+
},
|
|
872
|
+
focus: {
|
|
873
|
+
entry: "focusThumb",
|
|
874
|
+
on: {
|
|
875
|
+
POINTER_DOWN: {
|
|
876
|
+
target: "dragging",
|
|
877
|
+
actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
|
|
878
|
+
},
|
|
879
|
+
ARROW_LEFT: {
|
|
880
|
+
guard: "isHorizontal",
|
|
881
|
+
actions: "decrement"
|
|
882
|
+
},
|
|
883
|
+
ARROW_RIGHT: {
|
|
884
|
+
guard: "isHorizontal",
|
|
885
|
+
actions: "increment"
|
|
886
|
+
},
|
|
887
|
+
ARROW_UP: {
|
|
888
|
+
guard: "isVertical",
|
|
889
|
+
actions: "increment"
|
|
890
|
+
},
|
|
891
|
+
ARROW_DOWN: {
|
|
892
|
+
guard: "isVertical",
|
|
893
|
+
actions: "decrement"
|
|
894
|
+
},
|
|
895
|
+
PAGE_UP: {
|
|
896
|
+
actions: "increment"
|
|
897
|
+
},
|
|
898
|
+
PAGE_DOWN: {
|
|
899
|
+
actions: "decrement"
|
|
900
|
+
},
|
|
901
|
+
HOME: {
|
|
902
|
+
actions: "setToMin"
|
|
903
|
+
},
|
|
904
|
+
END: {
|
|
905
|
+
actions: "setToMax"
|
|
906
|
+
},
|
|
907
|
+
BLUR: "idle"
|
|
908
|
+
}
|
|
909
|
+
},
|
|
910
|
+
dragging: {
|
|
911
|
+
entry: "focusThumb",
|
|
912
|
+
activities: "trackPointerMove",
|
|
913
|
+
on: {
|
|
914
|
+
POINTER_UP: {
|
|
915
|
+
target: "focus",
|
|
916
|
+
actions: "invokeOnChangeEnd"
|
|
917
|
+
},
|
|
918
|
+
POINTER_MOVE: {
|
|
919
|
+
actions: "setPointerValue"
|
|
920
|
+
}
|
|
919
921
|
}
|
|
920
922
|
}
|
|
921
923
|
}
|
|
922
|
-
}
|
|
923
|
-
}, {
|
|
924
|
-
guards: {
|
|
925
|
-
isHorizontal: (ctx2) => ctx2.isHorizontal,
|
|
926
|
-
isVertical: (ctx2) => ctx2.isVertical
|
|
927
924
|
},
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
925
|
+
{
|
|
926
|
+
guards: {
|
|
927
|
+
isHorizontal: (ctx2) => ctx2.isHorizontal,
|
|
928
|
+
isVertical: (ctx2) => ctx2.isVertical
|
|
929
|
+
},
|
|
930
|
+
activities: {
|
|
931
|
+
trackFieldsetDisabled(ctx2) {
|
|
932
|
+
return trackFieldsetDisabled(dom.getRootEl(ctx2), (disabled) => {
|
|
933
933
|
if (disabled) {
|
|
934
934
|
ctx2.disabled = disabled;
|
|
935
935
|
}
|
|
936
936
|
});
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
trackFormReset(ctx2) {
|
|
941
|
-
let cleanup;
|
|
942
|
-
nextTick(() => {
|
|
943
|
-
cleanup = trackFormReset(dom.getInputEl(ctx2), () => {
|
|
937
|
+
},
|
|
938
|
+
trackFormReset(ctx2) {
|
|
939
|
+
return trackFormReset(dom.getInputEl(ctx2), () => {
|
|
944
940
|
if (ctx2.initialValue != null) {
|
|
945
941
|
ctx2.value = ctx2.initialValue;
|
|
946
942
|
}
|
|
947
943
|
});
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
}
|
|
960
|
-
});
|
|
961
|
-
}
|
|
962
|
-
},
|
|
963
|
-
actions: {
|
|
964
|
-
setupDocument(ctx2, evt) {
|
|
965
|
-
if (evt.doc)
|
|
966
|
-
ctx2.doc = ref(evt.doc);
|
|
967
|
-
if (evt.root)
|
|
968
|
-
ctx2.rootNode = ref(evt.root);
|
|
969
|
-
ctx2.uid = evt.id;
|
|
970
|
-
},
|
|
971
|
-
checkValue(ctx2) {
|
|
972
|
-
const value = utils.convert(ctx2, ctx2.value);
|
|
973
|
-
Object.assign(ctx2, { value, initialValue: value });
|
|
974
|
-
},
|
|
975
|
-
invokeOnChangeStart(ctx2) {
|
|
976
|
-
var _a;
|
|
977
|
-
(_a = ctx2.onChangeStart) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
|
|
978
|
-
},
|
|
979
|
-
invokeOnChangeEnd(ctx2) {
|
|
980
|
-
var _a;
|
|
981
|
-
(_a = ctx2.onChangeEnd) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
|
|
982
|
-
},
|
|
983
|
-
invokeOnChange(ctx2) {
|
|
984
|
-
var _a;
|
|
985
|
-
(_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
|
|
986
|
-
},
|
|
987
|
-
dispatchChangeEvent(ctx2) {
|
|
988
|
-
dom.dispatchChangeEvent(ctx2);
|
|
989
|
-
},
|
|
990
|
-
setThumbSize(ctx2) {
|
|
991
|
-
if (ctx2.thumbAlignment !== "contain")
|
|
992
|
-
return;
|
|
993
|
-
raf(() => {
|
|
994
|
-
const el = dom.getThumbEl(ctx2);
|
|
995
|
-
if (!el)
|
|
996
|
-
return;
|
|
997
|
-
ctx2.thumbSize = { width: el.offsetWidth, height: el.offsetHeight };
|
|
998
|
-
});
|
|
999
|
-
},
|
|
1000
|
-
setPointerValue(ctx2, evt) {
|
|
1001
|
-
const value = dom.getValueFromPoint(ctx2, evt.point);
|
|
1002
|
-
if (value == null)
|
|
1003
|
-
return;
|
|
1004
|
-
ctx2.value = utils.clamp(ctx2, value);
|
|
944
|
+
},
|
|
945
|
+
trackPointerMove(ctx2, _evt, { send }) {
|
|
946
|
+
return trackPointerMove(dom.getDoc(ctx2), {
|
|
947
|
+
onPointerMove(info) {
|
|
948
|
+
send({ type: "POINTER_MOVE", point: info.point });
|
|
949
|
+
},
|
|
950
|
+
onPointerUp() {
|
|
951
|
+
send("POINTER_UP");
|
|
952
|
+
}
|
|
953
|
+
});
|
|
954
|
+
}
|
|
1005
955
|
},
|
|
1006
|
-
|
|
1007
|
-
|
|
956
|
+
actions: {
|
|
957
|
+
checkValue(ctx2) {
|
|
958
|
+
const value = utils.convert(ctx2, ctx2.value);
|
|
959
|
+
Object.assign(ctx2, { value, initialValue: value });
|
|
960
|
+
},
|
|
961
|
+
invokeOnChangeStart(ctx2) {
|
|
1008
962
|
var _a;
|
|
1009
|
-
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
ctx2
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
ctx2
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
963
|
+
(_a = ctx2.onChangeStart) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
|
|
964
|
+
},
|
|
965
|
+
invokeOnChangeEnd(ctx2) {
|
|
966
|
+
var _a;
|
|
967
|
+
(_a = ctx2.onChangeEnd) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
|
|
968
|
+
},
|
|
969
|
+
invokeOnChange(ctx2) {
|
|
970
|
+
var _a;
|
|
971
|
+
(_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
|
|
972
|
+
},
|
|
973
|
+
dispatchChangeEvent(ctx2) {
|
|
974
|
+
dom.dispatchChangeEvent(ctx2);
|
|
975
|
+
},
|
|
976
|
+
setThumbSize(ctx2) {
|
|
977
|
+
if (ctx2.thumbAlignment !== "contain")
|
|
978
|
+
return;
|
|
979
|
+
raf(() => {
|
|
980
|
+
const el = dom.getThumbEl(ctx2);
|
|
981
|
+
if (!el)
|
|
982
|
+
return;
|
|
983
|
+
ctx2.thumbSize = { width: el.offsetWidth, height: el.offsetHeight };
|
|
984
|
+
});
|
|
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
|
+
}
|
|
1026
1013
|
}
|
|
1027
1014
|
}
|
|
1028
|
-
|
|
1015
|
+
);
|
|
1029
1016
|
}
|
|
1030
1017
|
export {
|
|
1031
1018
|
connect,
|