@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.js
CHANGED
|
@@ -1,25 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
-
var __spreadValues = (a, b) => {
|
|
12
|
-
for (var prop in b || (b = {}))
|
|
13
|
-
if (__hasOwnProp.call(b, prop))
|
|
14
|
-
__defNormalProp(a, prop, b[prop]);
|
|
15
|
-
if (__getOwnPropSymbols)
|
|
16
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
-
if (__propIsEnum.call(b, prop))
|
|
18
|
-
__defNormalProp(a, prop, b[prop]);
|
|
19
|
-
}
|
|
20
|
-
return a;
|
|
21
|
-
};
|
|
22
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
6
|
var __export = (target, all) => {
|
|
24
7
|
for (var name in all)
|
|
25
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -44,29 +27,12 @@ __export(src_exports, {
|
|
|
44
27
|
module.exports = __toCommonJS(src_exports);
|
|
45
28
|
|
|
46
29
|
// ../../utilities/dom/dist/index.mjs
|
|
47
|
-
var __defProp2 = Object.defineProperty;
|
|
48
|
-
var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
|
|
49
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
50
|
-
var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
|
|
51
|
-
var __pow = Math.pow;
|
|
52
|
-
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
53
|
-
var __spreadValues2 = (a, b) => {
|
|
54
|
-
for (var prop in b || (b = {}))
|
|
55
|
-
if (__hasOwnProp2.call(b, prop))
|
|
56
|
-
__defNormalProp2(a, prop, b[prop]);
|
|
57
|
-
if (__getOwnPropSymbols2)
|
|
58
|
-
for (var prop of __getOwnPropSymbols2(b)) {
|
|
59
|
-
if (__propIsEnum2.call(b, prop))
|
|
60
|
-
__defNormalProp2(a, prop, b[prop]);
|
|
61
|
-
}
|
|
62
|
-
return a;
|
|
63
|
-
};
|
|
64
30
|
var dataAttr = (guard) => {
|
|
65
31
|
return guard ? "" : void 0;
|
|
66
32
|
};
|
|
67
33
|
var runIfFn = (v, ...a) => {
|
|
68
34
|
const res = typeof v === "function" ? v(...a) : v;
|
|
69
|
-
return res
|
|
35
|
+
return res ?? void 0;
|
|
70
36
|
};
|
|
71
37
|
var callAll = (...fns) => (...a) => {
|
|
72
38
|
fns.forEach(function(fn) {
|
|
@@ -78,9 +44,8 @@ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
|
78
44
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
79
45
|
var isDom = () => typeof window !== "undefined";
|
|
80
46
|
function getPlatform() {
|
|
81
|
-
var _a;
|
|
82
47
|
const agent = navigator.userAgentData;
|
|
83
|
-
return (
|
|
48
|
+
return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
|
|
84
49
|
}
|
|
85
50
|
var pt = (v) => isDom() && v.test(getPlatform());
|
|
86
51
|
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
@@ -94,36 +59,30 @@ function isWindow(value) {
|
|
|
94
59
|
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
95
60
|
}
|
|
96
61
|
function getDocument(el) {
|
|
97
|
-
var _a;
|
|
98
62
|
if (isWindow(el))
|
|
99
63
|
return el.document;
|
|
100
64
|
if (isDocument(el))
|
|
101
65
|
return el;
|
|
102
|
-
return (
|
|
103
|
-
}
|
|
104
|
-
function getWindow(el) {
|
|
105
|
-
var _a;
|
|
106
|
-
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
66
|
+
return (el == null ? void 0 : el.ownerDocument) ?? document;
|
|
107
67
|
}
|
|
108
68
|
function defineDomHelpers(helpers) {
|
|
109
69
|
const dom2 = {
|
|
110
70
|
getRootNode: (ctx) => {
|
|
111
|
-
var _a, _b;
|
|
112
|
-
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
113
|
-
},
|
|
114
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
115
|
-
getWin: (ctx) => {
|
|
116
71
|
var _a;
|
|
117
|
-
return (_a =
|
|
72
|
+
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
|
|
118
73
|
},
|
|
74
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
75
|
+
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
119
76
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
120
77
|
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
121
78
|
};
|
|
122
|
-
return
|
|
79
|
+
return {
|
|
80
|
+
...dom2,
|
|
81
|
+
...helpers
|
|
82
|
+
};
|
|
123
83
|
}
|
|
124
84
|
function getNativeEvent(e) {
|
|
125
|
-
|
|
126
|
-
return (_a = e.nativeEvent) != null ? _a : e;
|
|
85
|
+
return e.nativeEvent ?? e;
|
|
127
86
|
}
|
|
128
87
|
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
129
88
|
var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
|
|
@@ -132,46 +91,6 @@ var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
|
|
|
132
91
|
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
133
92
|
var isLeftClick = (v) => v.button === 0;
|
|
134
93
|
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
135
|
-
function observeAttributes(node, attributes, fn) {
|
|
136
|
-
if (!node)
|
|
137
|
-
return;
|
|
138
|
-
const attrs = Array.isArray(attributes) ? attributes : [attributes];
|
|
139
|
-
const win = node.ownerDocument.defaultView || window;
|
|
140
|
-
const obs = new win.MutationObserver((changes) => {
|
|
141
|
-
for (const change of changes) {
|
|
142
|
-
if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
|
|
143
|
-
fn(change);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
obs.observe(node, { attributes: true, attributeFilter: attrs });
|
|
148
|
-
return () => obs.disconnect();
|
|
149
|
-
}
|
|
150
|
-
function getClosestForm(el) {
|
|
151
|
-
if (isFormElement(el))
|
|
152
|
-
return el.form;
|
|
153
|
-
else
|
|
154
|
-
return el.closest("form");
|
|
155
|
-
}
|
|
156
|
-
function isFormElement(el) {
|
|
157
|
-
return el.matches("textarea, input, select, button");
|
|
158
|
-
}
|
|
159
|
-
function trackFormReset(el, callback) {
|
|
160
|
-
if (!el)
|
|
161
|
-
return;
|
|
162
|
-
const form = getClosestForm(el);
|
|
163
|
-
form == null ? void 0 : form.addEventListener("reset", callback, { passive: true });
|
|
164
|
-
return () => {
|
|
165
|
-
form == null ? void 0 : form.removeEventListener("reset", callback);
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
function trackFieldsetDisabled(el, callback) {
|
|
169
|
-
const fieldset = el == null ? void 0 : el.closest("fieldset");
|
|
170
|
-
if (!fieldset)
|
|
171
|
-
return;
|
|
172
|
-
callback(fieldset.disabled);
|
|
173
|
-
return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
|
|
174
|
-
}
|
|
175
94
|
function getElementOffset(element) {
|
|
176
95
|
let left = 0;
|
|
177
96
|
let top = 0;
|
|
@@ -201,8 +120,7 @@ var fallback = {
|
|
|
201
120
|
clientY: 0
|
|
202
121
|
};
|
|
203
122
|
function getEventPoint(event, type = "page") {
|
|
204
|
-
|
|
205
|
-
const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event;
|
|
123
|
+
const point = isTouchEvent(event) ? event.touches[0] ?? event.changedTouches[0] ?? fallback : event;
|
|
206
124
|
return { x: point[`${type}X`], y: point[`${type}Y`] };
|
|
207
125
|
}
|
|
208
126
|
function getPointRelativeToNode(point, element) {
|
|
@@ -211,24 +129,6 @@ function getPointRelativeToNode(point, element) {
|
|
|
211
129
|
const y = point.y - offset.top;
|
|
212
130
|
return { x, y };
|
|
213
131
|
}
|
|
214
|
-
function getDescriptor(el, options) {
|
|
215
|
-
var _a;
|
|
216
|
-
const { type, property } = options;
|
|
217
|
-
const proto = getWindow(el)[type].prototype;
|
|
218
|
-
return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
|
|
219
|
-
}
|
|
220
|
-
function dispatchInputValueEvent(el, value) {
|
|
221
|
-
var _a;
|
|
222
|
-
if (!el)
|
|
223
|
-
return;
|
|
224
|
-
const win = getWindow(el);
|
|
225
|
-
if (!(el instanceof win.HTMLInputElement))
|
|
226
|
-
return;
|
|
227
|
-
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
228
|
-
(_a = desc.set) == null ? void 0 : _a.call(el, value);
|
|
229
|
-
const event = new win.Event("input", { bubbles: true });
|
|
230
|
-
el.dispatchEvent(event);
|
|
231
|
-
}
|
|
232
132
|
var rtlKeyMap = {
|
|
233
133
|
ArrowLeft: "ArrowRight",
|
|
234
134
|
ArrowRight: "ArrowLeft",
|
|
@@ -245,10 +145,9 @@ var sameKeyMap = {
|
|
|
245
145
|
Right: "ArrowRight"
|
|
246
146
|
};
|
|
247
147
|
function getEventKey(event, options = {}) {
|
|
248
|
-
var _a;
|
|
249
148
|
const { dir = "ltr", orientation = "horizontal" } = options;
|
|
250
149
|
let { key } = event;
|
|
251
|
-
key =
|
|
150
|
+
key = sameKeyMap[key] ?? key;
|
|
252
151
|
const isRtl = dir === "rtl" && orientation === "horizontal";
|
|
253
152
|
if (isRtl && key in rtlKeyMap) {
|
|
254
153
|
key = rtlKeyMap[key];
|
|
@@ -285,8 +184,7 @@ function addDomEvent(target, eventName, handler, options) {
|
|
|
285
184
|
};
|
|
286
185
|
}
|
|
287
186
|
function addPointerEvent(target, event, listener, options) {
|
|
288
|
-
|
|
289
|
-
const type = (_a = getEventName(event)) != null ? _a : event;
|
|
187
|
+
const type = getEventName(event) ?? event;
|
|
290
188
|
return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
|
|
291
189
|
}
|
|
292
190
|
function wrapHandler(fn, filter = false) {
|
|
@@ -297,8 +195,7 @@ function wrapHandler(fn, filter = false) {
|
|
|
297
195
|
}
|
|
298
196
|
function filterPrimaryPointer(fn) {
|
|
299
197
|
return (event) => {
|
|
300
|
-
|
|
301
|
-
const win = (_a = event.view) != null ? _a : window;
|
|
198
|
+
const win = event.view ?? window;
|
|
302
199
|
const isMouseEvent2 = event instanceof win.MouseEvent;
|
|
303
200
|
const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
|
|
304
201
|
if (isPrimary)
|
|
@@ -353,7 +250,7 @@ var state = "default";
|
|
|
353
250
|
var savedUserSelect = "";
|
|
354
251
|
var modifiedElementMap = /* @__PURE__ */ new WeakMap();
|
|
355
252
|
function disableTextSelection({ target, doc } = {}) {
|
|
356
|
-
const _document = doc
|
|
253
|
+
const _document = doc ?? document;
|
|
357
254
|
if (isIos()) {
|
|
358
255
|
if (state === "default") {
|
|
359
256
|
savedUserSelect = _document.documentElement.style.webkitUserSelect;
|
|
@@ -367,7 +264,7 @@ function disableTextSelection({ target, doc } = {}) {
|
|
|
367
264
|
return () => restoreTextSelection({ target, doc: _document });
|
|
368
265
|
}
|
|
369
266
|
function restoreTextSelection({ target, doc } = {}) {
|
|
370
|
-
const _document = doc
|
|
267
|
+
const _document = doc ?? document;
|
|
371
268
|
if (isIos()) {
|
|
372
269
|
if (state !== "disabled")
|
|
373
270
|
return;
|
|
@@ -387,7 +284,7 @@ function restoreTextSelection({ target, doc } = {}) {
|
|
|
387
284
|
if (target && modifiedElementMap.has(target)) {
|
|
388
285
|
let targetOldUserSelect = modifiedElementMap.get(target);
|
|
389
286
|
if (target.style.userSelect === "none") {
|
|
390
|
-
target.style.userSelect = targetOldUserSelect
|
|
287
|
+
target.style.userSelect = targetOldUserSelect ?? "";
|
|
391
288
|
}
|
|
392
289
|
if (target.getAttribute("style") === "") {
|
|
393
290
|
target.removeAttribute("style");
|
|
@@ -396,13 +293,13 @@ function restoreTextSelection({ target, doc } = {}) {
|
|
|
396
293
|
}
|
|
397
294
|
}
|
|
398
295
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
const {
|
|
296
|
+
var THRESHOLD = 5;
|
|
297
|
+
function trackPointerMove(doc, opts) {
|
|
298
|
+
const { onPointerMove, onPointerUp } = opts;
|
|
402
299
|
const handlePointerMove = (event, info) => {
|
|
403
300
|
const { point: p } = info;
|
|
404
|
-
const distance = Math.sqrt(
|
|
405
|
-
if (distance <
|
|
301
|
+
const distance = Math.sqrt(p.x ** 2 + p.y ** 2);
|
|
302
|
+
if (distance < THRESHOLD)
|
|
406
303
|
return;
|
|
407
304
|
if (isMouseEvent(event) && isLeftClick(event)) {
|
|
408
305
|
onPointerUp();
|
|
@@ -410,14 +307,81 @@ function trackPointerMove(opts) {
|
|
|
410
307
|
}
|
|
411
308
|
onPointerMove(info, event);
|
|
412
309
|
};
|
|
413
|
-
return callAll(
|
|
310
|
+
return callAll(
|
|
311
|
+
addPointerEvent(doc, "pointermove", handlePointerMove, false),
|
|
312
|
+
addPointerEvent(doc, "pointerup", onPointerUp, false),
|
|
313
|
+
addPointerEvent(doc, "pointercancel", onPointerUp, false),
|
|
314
|
+
addPointerEvent(doc, "contextmenu", onPointerUp, false),
|
|
315
|
+
disableTextSelection({ doc })
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// ../../utilities/form-utils/dist/index.mjs
|
|
320
|
+
function getWindow(el) {
|
|
321
|
+
return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
|
|
322
|
+
}
|
|
323
|
+
function observeAttributes(node, attributes, fn) {
|
|
324
|
+
if (!node)
|
|
325
|
+
return;
|
|
326
|
+
const attrs = Array.isArray(attributes) ? attributes : [attributes];
|
|
327
|
+
const win = node.ownerDocument.defaultView || window;
|
|
328
|
+
const obs = new win.MutationObserver((changes) => {
|
|
329
|
+
for (const change of changes) {
|
|
330
|
+
if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
|
|
331
|
+
fn(change);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
obs.observe(node, { attributes: true, attributeFilter: attrs });
|
|
336
|
+
return () => obs.disconnect();
|
|
337
|
+
}
|
|
338
|
+
function getDescriptor(el, options) {
|
|
339
|
+
const { type, property } = options;
|
|
340
|
+
const proto = getWindow(el)[type].prototype;
|
|
341
|
+
return Object.getOwnPropertyDescriptor(proto, property) ?? {};
|
|
342
|
+
}
|
|
343
|
+
function dispatchInputValueEvent(el, value) {
|
|
344
|
+
var _a;
|
|
345
|
+
if (!el)
|
|
346
|
+
return;
|
|
347
|
+
const win = getWindow(el);
|
|
348
|
+
if (!(el instanceof win.HTMLInputElement))
|
|
349
|
+
return;
|
|
350
|
+
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
351
|
+
(_a = desc.set) == null ? void 0 : _a.call(el, value);
|
|
352
|
+
const event = new win.Event("input", { bubbles: true });
|
|
353
|
+
el.dispatchEvent(event);
|
|
354
|
+
}
|
|
355
|
+
function getClosestForm(el) {
|
|
356
|
+
if (isFormElement(el))
|
|
357
|
+
return el.form;
|
|
358
|
+
else
|
|
359
|
+
return el.closest("form");
|
|
360
|
+
}
|
|
361
|
+
function isFormElement(el) {
|
|
362
|
+
return el.matches("textarea, input, select, button");
|
|
363
|
+
}
|
|
364
|
+
function trackFormReset(el, callback) {
|
|
365
|
+
if (!el)
|
|
366
|
+
return;
|
|
367
|
+
const form = getClosestForm(el);
|
|
368
|
+
form == null ? void 0 : form.addEventListener("reset", callback, { passive: true });
|
|
369
|
+
return () => {
|
|
370
|
+
form == null ? void 0 : form.removeEventListener("reset", callback);
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
function trackFieldsetDisabled(el, callback) {
|
|
374
|
+
const fieldset = el == null ? void 0 : el.closest("fieldset");
|
|
375
|
+
if (!fieldset)
|
|
376
|
+
return;
|
|
377
|
+
callback(fieldset.disabled);
|
|
378
|
+
return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
|
|
414
379
|
}
|
|
415
380
|
|
|
416
381
|
// ../../utilities/number/dist/index.mjs
|
|
417
|
-
var __pow2 = Math.pow;
|
|
418
382
|
function round(v, t) {
|
|
419
383
|
let num = valueOf(v);
|
|
420
|
-
const p =
|
|
384
|
+
const p = 10 ** (t ?? 10);
|
|
421
385
|
num = Math.round(num * p) / p;
|
|
422
386
|
return t ? num.toFixed(t) : v.toString();
|
|
423
387
|
}
|
|
@@ -453,7 +417,7 @@ function valueOf(v) {
|
|
|
453
417
|
function decimalOperation(a, op, b) {
|
|
454
418
|
let result = op === "+" ? a + b : a - b;
|
|
455
419
|
if (a % 1 !== 0 || b % 1 !== 0) {
|
|
456
|
-
const multiplier =
|
|
420
|
+
const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
|
|
457
421
|
a = Math.round(a * multiplier);
|
|
458
422
|
b = Math.round(b * multiplier);
|
|
459
423
|
result = op === "+" ? a + b : a - b;
|
|
@@ -475,14 +439,12 @@ var transform = (a, b) => {
|
|
|
475
439
|
|
|
476
440
|
// src/slider.style.ts
|
|
477
441
|
function getVerticalThumbOffset(ctx) {
|
|
478
|
-
|
|
479
|
-
const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
|
|
442
|
+
const { height = 0 } = ctx.thumbSize ?? {};
|
|
480
443
|
const getValue = transform([ctx.min, ctx.max], [-height / 2, height / 2]);
|
|
481
444
|
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
482
445
|
}
|
|
483
446
|
function getHorizontalThumbOffset(ctx) {
|
|
484
|
-
|
|
485
|
-
const { width = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
|
|
447
|
+
const { width = 0 } = ctx.thumbSize ?? {};
|
|
486
448
|
if (ctx.isRtl) {
|
|
487
449
|
const getValue2 = transform([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
|
|
488
450
|
return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
|
|
@@ -592,45 +554,46 @@ var utils = {
|
|
|
592
554
|
return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
|
|
593
555
|
},
|
|
594
556
|
decrement(ctx, step) {
|
|
595
|
-
let value = decrement(ctx.value, step
|
|
557
|
+
let value = decrement(ctx.value, step ?? ctx.step);
|
|
596
558
|
return utils.convert(ctx, value);
|
|
597
559
|
},
|
|
598
560
|
increment(ctx, step) {
|
|
599
|
-
let value = increment(ctx.value, step
|
|
561
|
+
let value = increment(ctx.value, step ?? ctx.step);
|
|
600
562
|
return utils.convert(ctx, value);
|
|
601
563
|
}
|
|
602
564
|
};
|
|
603
565
|
|
|
604
566
|
// src/slider.dom.ts
|
|
605
|
-
var dom = defineDomHelpers(
|
|
567
|
+
var dom = defineDomHelpers({
|
|
568
|
+
...styles,
|
|
606
569
|
getRootId: (ctx) => {
|
|
607
|
-
var _a
|
|
608
|
-
return (
|
|
570
|
+
var _a;
|
|
571
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.root) ?? `slider:${ctx.id}`;
|
|
609
572
|
},
|
|
610
573
|
getThumbId: (ctx) => {
|
|
611
|
-
var _a
|
|
612
|
-
return (
|
|
574
|
+
var _a;
|
|
575
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.thumb) ?? `slider:${ctx.id}:thumb`;
|
|
613
576
|
},
|
|
614
577
|
getControlId: (ctx) => {
|
|
615
|
-
var _a
|
|
616
|
-
return (
|
|
578
|
+
var _a;
|
|
579
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.control) ?? `slider:${ctx.id}:control`;
|
|
617
580
|
},
|
|
618
581
|
getInputId: (ctx) => `slider:${ctx.id}:input`,
|
|
619
582
|
getOutputId: (ctx) => {
|
|
620
|
-
var _a
|
|
621
|
-
return (
|
|
583
|
+
var _a;
|
|
584
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.output) ?? `slider:${ctx.id}:output`;
|
|
622
585
|
},
|
|
623
586
|
getTrackId: (ctx) => {
|
|
624
|
-
var _a
|
|
625
|
-
return (
|
|
587
|
+
var _a;
|
|
588
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.track) ?? `slider:${ctx.id}track`;
|
|
626
589
|
},
|
|
627
590
|
getRangeId: (ctx) => {
|
|
628
|
-
var _a
|
|
629
|
-
return (
|
|
591
|
+
var _a;
|
|
592
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.track) ?? `slider:${ctx.id}:range`;
|
|
630
593
|
},
|
|
631
594
|
getLabelId: (ctx) => {
|
|
632
|
-
var _a
|
|
633
|
-
return (
|
|
595
|
+
var _a;
|
|
596
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.label) ?? `slider:${ctx.id}:label`;
|
|
634
597
|
},
|
|
635
598
|
getMarkerId: (ctx, value) => `slider:${ctx.id}:marker:${value}`,
|
|
636
599
|
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
@@ -658,7 +621,7 @@ var dom = defineDomHelpers(__spreadProps(__spreadValues({}, styles), {
|
|
|
658
621
|
return;
|
|
659
622
|
dispatchInputValueEvent(input, ctx.value);
|
|
660
623
|
}
|
|
661
|
-
})
|
|
624
|
+
});
|
|
662
625
|
|
|
663
626
|
// src/slider.connect.ts
|
|
664
627
|
function connect(state2, send, normalize) {
|
|
@@ -729,7 +692,7 @@ function connect(state2, send, normalize) {
|
|
|
729
692
|
"data-invalid": dataAttr(isInvalid),
|
|
730
693
|
"aria-disabled": isDisabled || void 0,
|
|
731
694
|
"aria-label": ariaLabel,
|
|
732
|
-
"aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy
|
|
695
|
+
"aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy ?? dom.getLabelId(state2.context),
|
|
733
696
|
"aria-orientation": state2.context.orientation,
|
|
734
697
|
"aria-valuemax": state2.context.max,
|
|
735
698
|
"aria-valuemin": state2.context.min,
|
|
@@ -874,205 +837,214 @@ function connect(state2, send, normalize) {
|
|
|
874
837
|
|
|
875
838
|
// src/slider.machine.ts
|
|
876
839
|
var import_core = require("@zag-js/core");
|
|
840
|
+
var import_element_size = require("@zag-js/element-size");
|
|
877
841
|
function machine(ctx) {
|
|
878
|
-
return (0, import_core.createMachine)(
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
|
|
897
|
-
isVertical: (ctx2) => ctx2.orientation === "vertical",
|
|
898
|
-
isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
|
|
899
|
-
isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readonly),
|
|
900
|
-
hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null
|
|
901
|
-
},
|
|
902
|
-
watch: {
|
|
903
|
-
value: ["invokeOnChange", "dispatchChangeEvent"]
|
|
904
|
-
},
|
|
905
|
-
activities: ["trackFormReset", "trackFieldsetDisabled"],
|
|
906
|
-
on: {
|
|
907
|
-
SET_VALUE: {
|
|
908
|
-
actions: "setValue"
|
|
842
|
+
return (0, import_core.createMachine)(
|
|
843
|
+
{
|
|
844
|
+
id: "slider",
|
|
845
|
+
initial: "unknown",
|
|
846
|
+
context: {
|
|
847
|
+
thumbSize: null,
|
|
848
|
+
thumbAlignment: "contain",
|
|
849
|
+
disabled: false,
|
|
850
|
+
threshold: 5,
|
|
851
|
+
dir: "ltr",
|
|
852
|
+
origin: "start",
|
|
853
|
+
orientation: "horizontal",
|
|
854
|
+
initialValue: null,
|
|
855
|
+
value: 0,
|
|
856
|
+
step: 1,
|
|
857
|
+
min: 0,
|
|
858
|
+
max: 100,
|
|
859
|
+
...ctx
|
|
909
860
|
},
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
},
|
|
917
|
-
states: {
|
|
918
|
-
unknown: {
|
|
919
|
-
on: {
|
|
920
|
-
SETUP: {
|
|
921
|
-
target: "idle",
|
|
922
|
-
actions: ["setThumbSize", "checkValue"]
|
|
923
|
-
}
|
|
924
|
-
}
|
|
861
|
+
computed: {
|
|
862
|
+
isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
|
|
863
|
+
isVertical: (ctx2) => ctx2.orientation === "vertical",
|
|
864
|
+
isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
|
|
865
|
+
isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readonly),
|
|
866
|
+
hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null
|
|
925
867
|
},
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
POINTER_DOWN: {
|
|
929
|
-
target: "dragging",
|
|
930
|
-
actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
|
|
931
|
-
},
|
|
932
|
-
FOCUS: "focus"
|
|
933
|
-
}
|
|
868
|
+
watch: {
|
|
869
|
+
value: ["invokeOnChange", "dispatchChangeEvent"]
|
|
934
870
|
},
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
},
|
|
946
|
-
ARROW_RIGHT: {
|
|
947
|
-
guard: "isHorizontal",
|
|
948
|
-
actions: "increment"
|
|
949
|
-
},
|
|
950
|
-
ARROW_UP: {
|
|
951
|
-
guard: "isVertical",
|
|
952
|
-
actions: "increment"
|
|
953
|
-
},
|
|
954
|
-
ARROW_DOWN: {
|
|
955
|
-
guard: "isVertical",
|
|
956
|
-
actions: "decrement"
|
|
957
|
-
},
|
|
958
|
-
PAGE_UP: {
|
|
959
|
-
actions: "increment"
|
|
960
|
-
},
|
|
961
|
-
PAGE_DOWN: {
|
|
962
|
-
actions: "decrement"
|
|
963
|
-
},
|
|
964
|
-
HOME: {
|
|
965
|
-
actions: "setToMin"
|
|
966
|
-
},
|
|
967
|
-
END: {
|
|
968
|
-
actions: "setToMax"
|
|
969
|
-
},
|
|
970
|
-
BLUR: "idle"
|
|
871
|
+
activities: ["trackFormReset", "trackFieldsetDisabled", "trackThumbSize"],
|
|
872
|
+
on: {
|
|
873
|
+
SET_VALUE: {
|
|
874
|
+
actions: "setValue"
|
|
875
|
+
},
|
|
876
|
+
INCREMENT: {
|
|
877
|
+
actions: "increment"
|
|
878
|
+
},
|
|
879
|
+
DECREMENT: {
|
|
880
|
+
actions: "decrement"
|
|
971
881
|
}
|
|
972
882
|
},
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
},
|
|
981
|
-
POINTER_MOVE: {
|
|
982
|
-
actions: "setPointerValue"
|
|
883
|
+
states: {
|
|
884
|
+
unknown: {
|
|
885
|
+
on: {
|
|
886
|
+
SETUP: {
|
|
887
|
+
target: "idle",
|
|
888
|
+
actions: ["checkValue"]
|
|
889
|
+
}
|
|
983
890
|
}
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
activities: {
|
|
993
|
-
trackFieldsetDisabled(ctx2) {
|
|
994
|
-
return trackFieldsetDisabled(dom.getRootEl(ctx2), (disabled) => {
|
|
995
|
-
if (disabled) {
|
|
996
|
-
ctx2.disabled = disabled;
|
|
891
|
+
},
|
|
892
|
+
idle: {
|
|
893
|
+
on: {
|
|
894
|
+
POINTER_DOWN: {
|
|
895
|
+
target: "dragging",
|
|
896
|
+
actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
|
|
897
|
+
},
|
|
898
|
+
FOCUS: "focus"
|
|
997
899
|
}
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
900
|
+
},
|
|
901
|
+
focus: {
|
|
902
|
+
entry: "focusThumb",
|
|
903
|
+
on: {
|
|
904
|
+
POINTER_DOWN: {
|
|
905
|
+
target: "dragging",
|
|
906
|
+
actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
|
|
907
|
+
},
|
|
908
|
+
ARROW_LEFT: {
|
|
909
|
+
guard: "isHorizontal",
|
|
910
|
+
actions: "decrement"
|
|
911
|
+
},
|
|
912
|
+
ARROW_RIGHT: {
|
|
913
|
+
guard: "isHorizontal",
|
|
914
|
+
actions: "increment"
|
|
915
|
+
},
|
|
916
|
+
ARROW_UP: {
|
|
917
|
+
guard: "isVertical",
|
|
918
|
+
actions: "increment"
|
|
919
|
+
},
|
|
920
|
+
ARROW_DOWN: {
|
|
921
|
+
guard: "isVertical",
|
|
922
|
+
actions: "decrement"
|
|
923
|
+
},
|
|
924
|
+
PAGE_UP: {
|
|
925
|
+
actions: "increment"
|
|
926
|
+
},
|
|
927
|
+
PAGE_DOWN: {
|
|
928
|
+
actions: "decrement"
|
|
929
|
+
},
|
|
930
|
+
HOME: {
|
|
931
|
+
actions: "setToMin"
|
|
932
|
+
},
|
|
933
|
+
END: {
|
|
934
|
+
actions: "setToMax"
|
|
935
|
+
},
|
|
936
|
+
BLUR: "idle"
|
|
1004
937
|
}
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
938
|
+
},
|
|
939
|
+
dragging: {
|
|
940
|
+
entry: "focusThumb",
|
|
941
|
+
activities: "trackPointerMove",
|
|
942
|
+
on: {
|
|
943
|
+
POINTER_UP: {
|
|
944
|
+
target: "focus",
|
|
945
|
+
actions: "invokeOnChangeEnd"
|
|
946
|
+
},
|
|
947
|
+
POINTER_MOVE: {
|
|
948
|
+
actions: "setPointerValue"
|
|
949
|
+
}
|
|
1015
950
|
}
|
|
1016
|
-
}
|
|
951
|
+
}
|
|
1017
952
|
}
|
|
1018
953
|
},
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
},
|
|
1024
|
-
invokeOnChangeStart(ctx2) {
|
|
1025
|
-
var _a;
|
|
1026
|
-
(_a = ctx2.onChangeStart) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
|
|
1027
|
-
},
|
|
1028
|
-
invokeOnChangeEnd(ctx2) {
|
|
1029
|
-
var _a;
|
|
1030
|
-
(_a = ctx2.onChangeEnd) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
|
|
954
|
+
{
|
|
955
|
+
guards: {
|
|
956
|
+
isHorizontal: (ctx2) => ctx2.isHorizontal,
|
|
957
|
+
isVertical: (ctx2) => ctx2.isVertical
|
|
1031
958
|
},
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
return
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
959
|
+
activities: {
|
|
960
|
+
trackFieldsetDisabled(ctx2) {
|
|
961
|
+
return trackFieldsetDisabled(dom.getRootEl(ctx2), (disabled) => {
|
|
962
|
+
if (disabled) {
|
|
963
|
+
ctx2.disabled = disabled;
|
|
964
|
+
}
|
|
965
|
+
});
|
|
966
|
+
},
|
|
967
|
+
trackFormReset(ctx2) {
|
|
968
|
+
return trackFormReset(dom.getInputEl(ctx2), () => {
|
|
969
|
+
if (ctx2.initialValue != null) {
|
|
970
|
+
ctx2.value = ctx2.initialValue;
|
|
971
|
+
}
|
|
972
|
+
});
|
|
973
|
+
},
|
|
974
|
+
trackPointerMove(ctx2, _evt, { send }) {
|
|
975
|
+
return trackPointerMove(dom.getDoc(ctx2), {
|
|
976
|
+
onPointerMove(info) {
|
|
977
|
+
send({ type: "POINTER_MOVE", point: info.point });
|
|
978
|
+
},
|
|
979
|
+
onPointerUp() {
|
|
980
|
+
send("POINTER_UP");
|
|
981
|
+
}
|
|
982
|
+
});
|
|
983
|
+
},
|
|
984
|
+
trackThumbSize(ctx2, _evt) {
|
|
985
|
+
if (ctx2.thumbAlignment !== "contain")
|
|
1045
986
|
return;
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
if (value == null)
|
|
1052
|
-
return;
|
|
1053
|
-
ctx2.value = utils.clamp(ctx2, value);
|
|
987
|
+
return (0, import_element_size.trackElementSize)(dom.getThumbEl(ctx2), (size) => {
|
|
988
|
+
if (size)
|
|
989
|
+
ctx2.thumbSize = size;
|
|
990
|
+
});
|
|
991
|
+
}
|
|
1054
992
|
},
|
|
1055
|
-
|
|
1056
|
-
|
|
993
|
+
actions: {
|
|
994
|
+
checkValue(ctx2) {
|
|
995
|
+
const value = utils.convert(ctx2, ctx2.value);
|
|
996
|
+
ctx2.value = value;
|
|
997
|
+
ctx2.initialValue = value;
|
|
998
|
+
},
|
|
999
|
+
invokeOnChangeStart(ctx2) {
|
|
1057
1000
|
var _a;
|
|
1058
|
-
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
ctx2
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
ctx2
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1001
|
+
(_a = ctx2.onChangeStart) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
|
|
1002
|
+
},
|
|
1003
|
+
invokeOnChangeEnd(ctx2) {
|
|
1004
|
+
var _a;
|
|
1005
|
+
(_a = ctx2.onChangeEnd) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
|
|
1006
|
+
},
|
|
1007
|
+
invokeOnChange(ctx2) {
|
|
1008
|
+
var _a;
|
|
1009
|
+
(_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
|
|
1010
|
+
},
|
|
1011
|
+
dispatchChangeEvent(ctx2) {
|
|
1012
|
+
dom.dispatchChangeEvent(ctx2);
|
|
1013
|
+
},
|
|
1014
|
+
setPointerValue(ctx2, evt) {
|
|
1015
|
+
const value = dom.getValueFromPoint(ctx2, evt.point);
|
|
1016
|
+
if (value == null)
|
|
1017
|
+
return;
|
|
1018
|
+
ctx2.value = utils.clamp(ctx2, value);
|
|
1019
|
+
},
|
|
1020
|
+
focusThumb(ctx2) {
|
|
1021
|
+
raf(() => {
|
|
1022
|
+
var _a;
|
|
1023
|
+
return (_a = dom.getThumbEl(ctx2)) == null ? void 0 : _a.focus();
|
|
1024
|
+
});
|
|
1025
|
+
},
|
|
1026
|
+
decrement(ctx2, evt) {
|
|
1027
|
+
ctx2.value = utils.decrement(ctx2, evt.step);
|
|
1028
|
+
},
|
|
1029
|
+
increment(ctx2, evt) {
|
|
1030
|
+
ctx2.value = utils.increment(ctx2, evt.step);
|
|
1031
|
+
},
|
|
1032
|
+
setToMin(ctx2) {
|
|
1033
|
+
ctx2.value = ctx2.min;
|
|
1034
|
+
},
|
|
1035
|
+
setToMax(ctx2) {
|
|
1036
|
+
ctx2.value = ctx2.max;
|
|
1037
|
+
},
|
|
1038
|
+
setValue(ctx2, evt) {
|
|
1039
|
+
ctx2.value = utils.convert(ctx2, evt.value);
|
|
1040
|
+
}
|
|
1075
1041
|
}
|
|
1076
1042
|
}
|
|
1077
|
-
|
|
1043
|
+
);
|
|
1078
1044
|
}
|
|
1045
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1046
|
+
0 && (module.exports = {
|
|
1047
|
+
connect,
|
|
1048
|
+
machine,
|
|
1049
|
+
unstable__dom
|
|
1050
|
+
});
|