@zag-js/slider 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,1093 +1,19 @@
1
- // src/slider.anatomy.ts
2
- import { createAnatomy } from "@zag-js/anatomy";
3
- var anatomy = createAnatomy("slider").parts(
4
- "root",
5
- "label",
6
- "thumb",
7
- "hiddenInput",
8
- "output",
9
- "track",
10
- "range",
11
- "control",
12
- "markerGroup",
13
- "marker"
14
- );
15
- var parts = anatomy.build();
16
-
17
- // ../../utilities/dom/dist/index.mjs
18
- var dataAttr = (guard) => {
19
- return guard ? "" : void 0;
20
- };
21
- var runIfFn = (v, ...a) => {
22
- const res = typeof v === "function" ? v(...a) : v;
23
- return res != null ? res : void 0;
24
- };
25
- var callAll = (...fns) => (...a) => {
26
- fns.forEach(function(fn) {
27
- fn == null ? void 0 : fn(...a);
28
- });
29
- };
30
- var isArray = (v) => Array.isArray(v);
31
- var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
32
- var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
33
- var isDom = () => typeof window !== "undefined";
34
- function getPlatform() {
35
- var _a;
36
- const agent = navigator.userAgentData;
37
- return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
38
- }
39
- var pt = (v) => isDom() && v.test(getPlatform());
40
- var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
41
- var isMac = () => pt(/^Mac/) && !isTouchDevice;
42
- var isApple = () => pt(/mac|iphone|ipad|ipod/i);
43
- var isIos = () => isApple() && !isMac();
44
- function isDocument(el) {
45
- return el.nodeType === Node.DOCUMENT_NODE;
46
- }
47
- function isWindow(value) {
48
- return (value == null ? void 0 : value.toString()) === "[object Window]";
49
- }
50
- function getDocument(el) {
51
- var _a;
52
- if (isWindow(el))
53
- return el.document;
54
- if (isDocument(el))
55
- return el;
56
- return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
57
- }
58
- function defineDomHelpers(helpers) {
59
- const dom2 = {
60
- getRootNode: (ctx) => {
61
- var _a, _b;
62
- return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
63
- },
64
- getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
65
- getWin: (ctx) => {
66
- var _a;
67
- return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
68
- },
69
- getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
70
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
71
- createEmitter: (ctx, target) => {
72
- const win = dom2.getWin(ctx);
73
- return function emit(evt, detail, options) {
74
- const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
75
- const eventName = `zag:${evt}`;
76
- const init = { bubbles, cancelable, composed, detail };
77
- const event = new win.CustomEvent(eventName, init);
78
- target.dispatchEvent(event);
79
- };
80
- },
81
- createListener: (target) => {
82
- return function listen(evt, handler) {
83
- const eventName = `zag:${evt}`;
84
- const listener = (e) => handler(e);
85
- target.addEventListener(eventName, listener);
86
- return () => target.removeEventListener(eventName, listener);
87
- };
88
- }
89
- };
90
- return {
91
- ...dom2,
92
- ...helpers
93
- };
94
- }
95
- function getNativeEvent(e) {
96
- var _a;
97
- return (_a = e.nativeEvent) != null ? _a : e;
98
- }
99
- var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
100
- var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
101
- var supportsMouseEvent = () => isDom() && window.onmousedown === null;
102
- var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
103
- var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
104
- var isLeftClick = (v) => v.button === 0;
105
- var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
106
- function getElementOffset(element) {
107
- let left = 0;
108
- let top = 0;
109
- let el = element;
110
- if (el.parentNode) {
111
- do {
112
- left += el.offsetLeft;
113
- top += el.offsetTop;
114
- } while ((el = el.offsetParent) && el.nodeType < 9);
115
- el = element;
116
- do {
117
- left -= el.scrollLeft;
118
- top -= el.scrollTop;
119
- } while ((el = el.parentNode) && !/body/i.test(el.nodeName));
120
- }
121
- return {
122
- top,
123
- right: innerWidth - left - element.offsetWidth,
124
- bottom: innerHeight - top - element.offsetHeight,
125
- left
126
- };
127
- }
128
- var fallback = {
129
- pageX: 0,
130
- pageY: 0,
131
- clientX: 0,
132
- clientY: 0
133
- };
134
- function getEventPoint(event, type = "page") {
135
- var _a, _b;
136
- const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event;
137
- return { x: point[`${type}X`], y: point[`${type}Y`] };
138
- }
139
- function getPointRelativeToNode(point, element) {
140
- const offset = getElementOffset(element);
141
- const x = point.x - offset.left;
142
- const y = point.y - offset.top;
143
- return { x, y };
144
- }
145
- var rtlKeyMap = {
146
- ArrowLeft: "ArrowRight",
147
- ArrowRight: "ArrowLeft"
148
- };
149
- var sameKeyMap = {
150
- Up: "ArrowUp",
151
- Down: "ArrowDown",
152
- Esc: "Escape",
153
- " ": "Space",
154
- ",": "Comma",
155
- Left: "ArrowLeft",
156
- Right: "ArrowRight"
157
- };
158
- function getEventKey(event, options = {}) {
159
- var _a;
160
- const { dir = "ltr", orientation = "horizontal" } = options;
161
- let { key } = event;
162
- key = (_a = sameKeyMap[key]) != null ? _a : key;
163
- const isRtl = dir === "rtl" && orientation === "horizontal";
164
- if (isRtl && key in rtlKeyMap) {
165
- key = rtlKeyMap[key];
166
- }
167
- return key;
168
- }
169
- var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
170
- var ARROW_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
171
- function getEventStep(event) {
172
- if (event.ctrlKey || event.metaKey) {
173
- return 0.1;
174
- } else {
175
- const isPageKey = PAGE_KEYS.has(event.key);
176
- const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.has(event.key);
177
- return isSkipKey ? 10 : 1;
178
- }
179
- }
180
- var isRef = (v) => hasProp(v, "current");
181
- var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
182
- function extractInfo(event, type = "page") {
183
- const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback2 : event;
184
- return {
185
- point: {
186
- x: point[`${type}X`],
187
- y: point[`${type}Y`]
188
- }
189
- };
190
- }
191
- function addDomEvent(target, eventName, handler, options) {
192
- const node = isRef(target) ? target.current : runIfFn(target);
193
- node == null ? void 0 : node.addEventListener(eventName, handler, options);
194
- return () => {
195
- node == null ? void 0 : node.removeEventListener(eventName, handler, options);
196
- };
197
- }
198
- function addPointerEvent(target, event, listener, options) {
199
- var _a;
200
- const type = (_a = getEventName(event)) != null ? _a : event;
201
- return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
202
- }
203
- function wrapHandler(fn, filter = false) {
204
- const listener = (event) => {
205
- fn(event, extractInfo(event));
206
- };
207
- return filter ? filterPrimaryPointer(listener) : listener;
208
- }
209
- function filterPrimaryPointer(fn) {
210
- return (event) => {
211
- var _a;
212
- const win = (_a = event.view) != null ? _a : window;
213
- const isMouseEvent2 = event instanceof win.MouseEvent;
214
- const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
215
- if (isPrimary)
216
- fn(event);
217
- };
218
- }
219
- var mouseEventNames = {
220
- pointerdown: "mousedown",
221
- pointermove: "mousemove",
222
- pointerup: "mouseup",
223
- pointercancel: "mousecancel",
224
- pointerover: "mouseover",
225
- pointerout: "mouseout",
226
- pointerenter: "mouseenter",
227
- pointerleave: "mouseleave"
228
- };
229
- var touchEventNames = {
230
- pointerdown: "touchstart",
231
- pointermove: "touchmove",
232
- pointerup: "touchend",
233
- pointercancel: "touchcancel"
234
- };
235
- function getEventName(evt) {
236
- if (supportsPointerEvent())
237
- return evt;
238
- if (supportsTouchEvent())
239
- return touchEventNames[evt];
240
- if (supportsMouseEvent())
241
- return mouseEventNames[evt];
242
- return evt;
243
- }
244
- function nextTick(fn) {
245
- const set = /* @__PURE__ */ new Set();
246
- function raf2(fn2) {
247
- const id = globalThis.requestAnimationFrame(fn2);
248
- set.add(() => globalThis.cancelAnimationFrame(id));
249
- }
250
- raf2(() => raf2(fn));
251
- return function cleanup() {
252
- set.forEach(function(fn2) {
253
- fn2();
254
- });
255
- };
256
- }
257
- function raf(fn) {
258
- const id = globalThis.requestAnimationFrame(fn);
259
- return function cleanup() {
260
- globalThis.cancelAnimationFrame(id);
261
- };
262
- }
263
- var state = "default";
264
- var savedUserSelect = "";
265
- var modifiedElementMap = /* @__PURE__ */ new WeakMap();
266
- function disableTextSelection({ target, doc } = {}) {
267
- const _document = doc != null ? doc : document;
268
- if (isIos()) {
269
- if (state === "default") {
270
- savedUserSelect = _document.documentElement.style.webkitUserSelect;
271
- _document.documentElement.style.webkitUserSelect = "none";
272
- }
273
- state = "disabled";
274
- } else if (target) {
275
- modifiedElementMap.set(target, target.style.userSelect);
276
- target.style.userSelect = "none";
277
- }
278
- return () => restoreTextSelection({ target, doc: _document });
279
- }
280
- function restoreTextSelection({ target, doc } = {}) {
281
- const _document = doc != null ? doc : document;
282
- if (isIos()) {
283
- if (state !== "disabled")
284
- return;
285
- state = "restoring";
286
- setTimeout(() => {
287
- nextTick(() => {
288
- if (state === "restoring") {
289
- if (_document.documentElement.style.webkitUserSelect === "none") {
290
- _document.documentElement.style.webkitUserSelect = savedUserSelect || "";
291
- }
292
- savedUserSelect = "";
293
- state = "default";
294
- }
295
- });
296
- }, 300);
297
- } else {
298
- if (target && modifiedElementMap.has(target)) {
299
- let targetOldUserSelect = modifiedElementMap.get(target);
300
- if (target.style.userSelect === "none") {
301
- target.style.userSelect = targetOldUserSelect != null ? targetOldUserSelect : "";
302
- }
303
- if (target.getAttribute("style") === "") {
304
- target.removeAttribute("style");
305
- }
306
- modifiedElementMap.delete(target);
307
- }
308
- }
309
- }
310
- var THRESHOLD = 5;
311
- function trackPointerMove(doc, opts) {
312
- const { onPointerMove, onPointerUp } = opts;
313
- const handlePointerMove = (event, info) => {
314
- const { point: p } = info;
315
- const distance = Math.sqrt(p.x ** 2 + p.y ** 2);
316
- if (distance < THRESHOLD)
317
- return;
318
- if (isMouseEvent(event) && isLeftClick(event)) {
319
- onPointerUp();
320
- return;
321
- }
322
- onPointerMove(info, event);
323
- };
324
- return callAll(
325
- addPointerEvent(doc, "pointermove", handlePointerMove, false),
326
- addPointerEvent(doc, "pointerup", onPointerUp, false),
327
- addPointerEvent(doc, "pointercancel", onPointerUp, false),
328
- addPointerEvent(doc, "contextmenu", onPointerUp, false),
329
- disableTextSelection({ doc })
330
- );
331
- }
332
-
333
- // ../../utilities/number/dist/index.mjs
334
- function round(v, t) {
335
- let num = valueOf(v);
336
- const p = 10 ** (t != null ? t : 10);
337
- num = Math.round(num * p) / p;
338
- return t ? num.toFixed(t) : v.toString();
339
- }
340
- var valueToPercent = (v, r) => (valueOf(v) - r.min) * 100 / (r.max - r.min);
341
- var percentToValue = (v, r) => r.min + (r.max - r.min) * valueOf(v);
342
- function clamp(v, o) {
343
- return Math.min(Math.max(valueOf(v), o.min), o.max);
344
- }
345
- function countDecimals(value) {
346
- if (!Number.isFinite(value))
347
- return 0;
348
- let e = 1, p = 0;
349
- while (Math.round(value * e) / e !== value) {
350
- e *= 10;
351
- p += 1;
352
- }
353
- return p;
354
- }
355
- var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
356
- var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
357
- function snapToStep(value, step) {
358
- const num = valueOf(value);
359
- const p = countDecimals(step);
360
- const v = Math.round(num / step) * step;
361
- return round(v, p);
362
- }
363
- function valueOf(v) {
364
- if (typeof v === "number")
365
- return v;
366
- const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
367
- return !Number.isNaN(num) ? num : 0;
368
- }
369
- function decimalOperation(a, op, b) {
370
- let result = op === "+" ? a + b : a - b;
371
- if (a % 1 !== 0 || b % 1 !== 0) {
372
- const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
373
- a = Math.round(a * multiplier);
374
- b = Math.round(b * multiplier);
375
- result = op === "+" ? a + b : a - b;
376
- result /= multiplier;
377
- }
378
- return result;
379
- }
380
- var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
381
- var transform = (a, b) => {
382
- const i = { min: a[0], max: a[1] };
383
- const o = { min: b[0], max: b[1] };
384
- return (v) => {
385
- if (i.min === i.max || o.min === o.max)
386
- return o.min;
387
- const ratio = (o.max - o.min) / (i.max - i.min);
388
- return o.min + ratio * (v - i.min);
389
- };
390
- };
391
-
392
- // ../../utilities/form-utils/dist/index.mjs
393
- function getWindow(el) {
394
- var _a;
395
- return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
396
- }
397
- function observeAttributes(node, attributes, fn) {
398
- if (!node)
399
- return;
400
- const attrs = Array.isArray(attributes) ? attributes : [attributes];
401
- const win = node.ownerDocument.defaultView || window;
402
- const obs = new win.MutationObserver((changes) => {
403
- for (const change of changes) {
404
- if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
405
- fn(change);
406
- }
407
- }
408
- });
409
- obs.observe(node, { attributes: true, attributeFilter: attrs });
410
- return () => obs.disconnect();
411
- }
412
- function getDescriptor(el, options) {
413
- var _a;
414
- const { type, property = "value" } = options;
415
- const proto = getWindow(el)[type].prototype;
416
- return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
417
- }
418
- function dispatchInputValueEvent(el, value) {
419
- var _a;
420
- if (!el)
421
- return;
422
- const win = getWindow(el);
423
- if (!(el instanceof win.HTMLInputElement))
424
- return;
425
- const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
426
- (_a = desc.set) == null ? void 0 : _a.call(el, value);
427
- const event = new win.Event("input", { bubbles: true });
428
- el.dispatchEvent(event);
429
- }
430
- function getClosestForm(el) {
431
- if (isFormElement(el))
432
- return el.form;
433
- else
434
- return el.closest("form");
435
- }
436
- function isFormElement(el) {
437
- return el.matches("textarea, input, select, button");
438
- }
439
- function trackFormReset(el, callback) {
440
- if (!el)
441
- return;
442
- const form = getClosestForm(el);
443
- form == null ? void 0 : form.addEventListener("reset", callback, { passive: true });
444
- return () => {
445
- form == null ? void 0 : form.removeEventListener("reset", callback);
446
- };
447
- }
448
- function trackFieldsetDisabled(el, callback) {
449
- const fieldset = el == null ? void 0 : el.closest("fieldset");
450
- if (!fieldset)
451
- return;
452
- callback(fieldset.disabled);
453
- return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
454
- }
455
- function trackFormControl(el, options) {
456
- if (!el)
457
- return;
458
- const { onFieldsetDisabled, onFormReset } = options;
459
- const cleanups = [
460
- trackFormReset(el, onFormReset),
461
- trackFieldsetDisabled(el, (disabled) => {
462
- if (disabled)
463
- onFieldsetDisabled();
464
- })
465
- ];
466
- return () => {
467
- cleanups.forEach((cleanup) => cleanup == null ? void 0 : cleanup());
468
- };
469
- }
470
-
471
- // src/slider.style.ts
472
- function getVerticalThumbOffset(ctx) {
473
- var _a;
474
- const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
475
- const getValue = transform([ctx.min, ctx.max], [-height / 2, height / 2]);
476
- return parseFloat(getValue(ctx.value).toFixed(2));
477
- }
478
- function getHorizontalThumbOffset(ctx) {
479
- var _a;
480
- const { width = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
481
- if (ctx.isRtl) {
482
- const getValue2 = transform([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
483
- return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
484
- }
485
- const getValue = transform([ctx.min, ctx.max], [-width / 2, width / 2]);
486
- return parseFloat(getValue(ctx.value).toFixed(2));
487
- }
488
- function getThumbOffset(ctx) {
489
- const percent = valueToPercent(ctx.value, ctx);
490
- if (ctx.thumbAlignment === "center")
491
- return `${percent}%`;
492
- const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
493
- return `calc(${percent}% - ${offset}px)`;
494
- }
495
- function getThumbStyle(ctx) {
496
- const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
497
- return {
498
- visibility: ctx.hasMeasuredThumbSize ? "visible" : "hidden",
499
- position: "absolute",
500
- transform: "var(--slider-thumb-transform)",
501
- [placementProp]: "var(--slider-thumb-offset)"
502
- };
503
- }
504
- function getRangeOffsets(ctx) {
505
- const percent = valueToPercent(ctx.value, ctx);
506
- let start = "0%";
507
- let end = `${100 - percent}%`;
508
- if (ctx.origin === "center") {
509
- const isNegative = percent < 50;
510
- start = isNegative ? `${percent}%` : "50%";
511
- end = isNegative ? "50%" : end;
512
- }
513
- return { start, end };
514
- }
515
- function getRangeStyle(ctx) {
516
- if (ctx.isVertical) {
517
- return {
518
- position: "absolute",
519
- bottom: "var(--slider-range-start)",
520
- top: "var(--slider-range-end)"
521
- };
522
- }
523
- return {
524
- position: "absolute",
525
- [ctx.isRtl ? "right" : "left"]: "var(--slider-range-start)",
526
- [ctx.isRtl ? "left" : "right"]: "var(--slider-range-end)"
527
- };
528
- }
529
- function getControlStyle() {
530
- return {
531
- touchAction: "none",
532
- userSelect: "none",
533
- position: "relative"
534
- };
535
- }
536
- function getRootStyle(ctx) {
537
- const range = getRangeOffsets(ctx);
538
- return {
539
- "--slider-thumb-transform": ctx.isVertical ? "translateY(50%)" : "translateX(-50%)",
540
- "--slider-thumb-offset": getThumbOffset(ctx),
541
- "--slider-range-start": range.start,
542
- "--slider-range-end": range.end
543
- };
544
- }
545
- function getMarkerStyle(ctx, percent) {
546
- return {
547
- position: "absolute",
548
- pointerEvents: "none",
549
- [ctx.isHorizontal ? "left" : "bottom"]: `${ctx.isRtl ? 100 - percent : percent}%`
550
- };
551
- }
552
- function getLabelStyle() {
553
- return { userSelect: "none" };
554
- }
555
- function getTrackStyle() {
556
- return { position: "relative" };
557
- }
558
- function getMarkerGroupStyle() {
559
- return {
560
- userSelect: "none",
561
- pointerEvents: "none",
562
- position: "relative"
563
- };
564
- }
565
- var styles = {
566
- getThumbOffset,
567
- getControlStyle,
568
- getThumbStyle,
569
- getRangeStyle,
570
- getRootStyle,
571
- getMarkerStyle,
572
- getLabelStyle,
573
- getTrackStyle,
574
- getMarkerGroupStyle
575
- };
576
-
577
- // src/slider.utils.ts
578
- var utils = {
579
- fromPercent(ctx, percent) {
580
- percent = clamp(percent, { min: 0, max: 1 });
581
- return parseFloat(snapToStep(percentToValue(percent, ctx), ctx.step));
582
- },
583
- clamp(ctx, value) {
584
- return clamp(value, ctx);
585
- },
586
- convert(ctx, value) {
587
- return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
588
- },
589
- decrement(ctx, step) {
590
- let value = decrement(ctx.value, step != null ? step : ctx.step);
591
- return utils.convert(ctx, value);
592
- },
593
- increment(ctx, step) {
594
- let value = increment(ctx.value, step != null ? step : ctx.step);
595
- return utils.convert(ctx, value);
596
- }
597
- };
598
-
599
- // src/slider.dom.ts
600
- var dom = defineDomHelpers({
601
- ...styles,
602
- getRootId: (ctx) => {
603
- var _a, _b;
604
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `slider:${ctx.id}`;
605
- },
606
- getThumbId: (ctx) => {
607
- var _a, _b;
608
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.thumb) != null ? _b : `slider:${ctx.id}:thumb`;
609
- },
610
- getControlId: (ctx) => {
611
- var _a, _b;
612
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.control) != null ? _b : `slider:${ctx.id}:control`;
613
- },
614
- getHiddenInputId: (ctx) => `slider:${ctx.id}:input`,
615
- getOutputId: (ctx) => {
616
- var _a, _b;
617
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.output) != null ? _b : `slider:${ctx.id}:output`;
618
- },
619
- getTrackId: (ctx) => {
620
- var _a, _b;
621
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}track`;
622
- },
623
- getRangeId: (ctx) => {
624
- var _a, _b;
625
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}:range`;
626
- },
627
- getLabelId: (ctx) => {
628
- var _a, _b;
629
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.id}:label`;
630
- },
631
- getMarkerId: (ctx, value) => `slider:${ctx.id}:marker:${value}`,
632
- getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
633
- getThumbEl: (ctx) => dom.getById(ctx, dom.getThumbId(ctx)),
634
- getControlEl: (ctx) => dom.getById(ctx, dom.getControlId(ctx)),
635
- getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx)),
636
- getValueFromPoint(ctx, point) {
637
- const el = dom.getControlEl(ctx);
638
- if (!el)
639
- return;
640
- const relativePoint = getPointRelativeToNode(point, el);
641
- const percentX = relativePoint.x / el.offsetWidth;
642
- const percentY = relativePoint.y / el.offsetHeight;
643
- let percent;
644
- if (ctx.isHorizontal) {
645
- percent = ctx.isRtl ? 1 - percentX : percentX;
646
- } else {
647
- percent = 1 - percentY;
648
- }
649
- return utils.fromPercent(ctx, percent);
650
- },
651
- dispatchChangeEvent(ctx) {
652
- const input = dom.getHiddenInputEl(ctx);
653
- if (!input)
654
- return;
655
- dispatchInputValueEvent(input, ctx.value);
656
- }
657
- });
658
-
659
- // src/slider.connect.ts
660
- function connect(state2, send, normalize) {
661
- var _a, _b;
662
- const ariaLabel = state2.context["aria-label"];
663
- const ariaLabelledBy = state2.context["aria-labelledby"];
664
- const ariaValueText = (_b = (_a = state2.context).getAriaValueText) == null ? void 0 : _b.call(_a, state2.context.value);
665
- const isFocused = state2.matches("focus");
666
- const isDragging = state2.matches("dragging");
667
- const isDisabled = state2.context.disabled;
668
- const isInteractive = state2.context.isInteractive;
669
- const isInvalid = state2.context.invalid;
670
- return {
671
- isFocused,
672
- isDragging,
673
- value: state2.context.value,
674
- percent: valueToPercent(state2.context.value, state2.context),
675
- setValue(value) {
676
- send({ type: "SET_VALUE", value });
677
- },
678
- getPercentValue(percent) {
679
- return percentToValue(percent, state2.context);
680
- },
681
- focus() {
682
- var _a2;
683
- (_a2 = dom.getThumbEl(state2.context)) == null ? void 0 : _a2.focus();
684
- },
685
- increment() {
686
- send("INCREMENT");
687
- },
688
- decrement() {
689
- send("DECREMENT");
690
- },
691
- rootProps: normalize.element({
692
- ...parts.root.attrs,
693
- "data-disabled": dataAttr(isDisabled),
694
- "data-focus": dataAttr(isFocused),
695
- "data-orientation": state2.context.orientation,
696
- "data-invalid": dataAttr(isInvalid),
697
- id: dom.getRootId(state2.context),
698
- dir: state2.context.dir,
699
- style: dom.getRootStyle(state2.context)
700
- }),
701
- labelProps: normalize.label({
702
- ...parts.label.attrs,
703
- "data-disabled": dataAttr(isDisabled),
704
- "data-invalid": dataAttr(isInvalid),
705
- "data-focus": dataAttr(isFocused),
706
- id: dom.getLabelId(state2.context),
707
- htmlFor: dom.getHiddenInputId(state2.context),
708
- onClick(event) {
709
- var _a2;
710
- if (!isInteractive)
711
- return;
712
- event.preventDefault();
713
- (_a2 = dom.getThumbEl(state2.context)) == null ? void 0 : _a2.focus();
714
- },
715
- style: dom.getLabelStyle()
716
- }),
717
- thumbProps: normalize.element({
718
- ...parts.thumb.attrs,
719
- id: dom.getThumbId(state2.context),
720
- "data-disabled": dataAttr(isDisabled),
721
- "data-orientation": state2.context.orientation,
722
- "data-focus": dataAttr(isFocused),
723
- draggable: false,
724
- "aria-invalid": isInvalid || void 0,
725
- "data-invalid": dataAttr(isInvalid),
726
- "aria-disabled": isDisabled || void 0,
727
- "aria-label": ariaLabel,
728
- "aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy != null ? ariaLabelledBy : dom.getLabelId(state2.context),
729
- "aria-orientation": state2.context.orientation,
730
- "aria-valuemax": state2.context.max,
731
- "aria-valuemin": state2.context.min,
732
- "aria-valuenow": state2.context.value,
733
- "aria-valuetext": ariaValueText,
734
- role: "slider",
735
- tabIndex: isDisabled ? void 0 : 0,
736
- onBlur() {
737
- if (!isInteractive)
738
- return;
739
- send("BLUR");
740
- },
741
- onFocus() {
742
- if (!isInteractive)
743
- return;
744
- send("FOCUS");
745
- },
746
- onKeyDown(event) {
747
- if (!isInteractive)
748
- return;
749
- const step = getEventStep(event) * state2.context.step;
750
- let prevent = true;
751
- const keyMap = {
752
- ArrowUp() {
753
- send({ type: "ARROW_UP", step });
754
- prevent = state2.context.isVertical;
755
- },
756
- ArrowDown() {
757
- send({ type: "ARROW_DOWN", step });
758
- prevent = state2.context.isVertical;
759
- },
760
- ArrowLeft() {
761
- send({ type: "ARROW_LEFT", step });
762
- prevent = state2.context.isHorizontal;
763
- },
764
- ArrowRight() {
765
- send({ type: "ARROW_RIGHT", step });
766
- prevent = state2.context.isHorizontal;
767
- },
768
- PageUp() {
769
- send({ type: "PAGE_UP", step });
770
- },
771
- PageDown() {
772
- send({ type: "PAGE_DOWN", step });
773
- },
774
- Home() {
775
- send("HOME");
776
- },
777
- End() {
778
- send("END");
779
- }
780
- };
781
- const key = getEventKey(event, state2.context);
782
- const exec = keyMap[key];
783
- if (!exec)
784
- return;
785
- exec(event);
786
- if (prevent) {
787
- event.preventDefault();
788
- }
789
- },
790
- style: dom.getThumbStyle(state2.context)
791
- }),
792
- hiddenInputProps: normalize.input({
793
- ...parts.hiddenInput.attrs,
794
- type: "text",
795
- defaultValue: state2.context.value,
796
- name: state2.context.name,
797
- form: state2.context.form,
798
- id: dom.getHiddenInputId(state2.context),
799
- hidden: true
800
- }),
801
- outputProps: normalize.output({
802
- ...parts.output.attrs,
803
- "data-disabled": dataAttr(isDisabled),
804
- "data-invalid": dataAttr(isInvalid),
805
- id: dom.getOutputId(state2.context),
806
- htmlFor: dom.getHiddenInputId(state2.context),
807
- "aria-live": "off"
808
- }),
809
- trackProps: normalize.element({
810
- ...parts.track.attrs,
811
- id: dom.getTrackId(state2.context),
812
- "data-disabled": dataAttr(isDisabled),
813
- "data-focus": dataAttr(isFocused),
814
- "data-invalid": dataAttr(isInvalid),
815
- "data-orientation": state2.context.orientation,
816
- style: dom.getTrackStyle()
817
- }),
818
- rangeProps: normalize.element({
819
- ...parts.range.attrs,
820
- id: dom.getRangeId(state2.context),
821
- "data-focus": dataAttr(isFocused),
822
- "data-invalid": dataAttr(isInvalid),
823
- "data-disabled": dataAttr(isDisabled),
824
- "data-orientation": state2.context.orientation,
825
- style: dom.getRangeStyle(state2.context)
826
- }),
827
- controlProps: normalize.element({
828
- ...parts.control.attrs,
829
- id: dom.getControlId(state2.context),
830
- "data-disabled": dataAttr(isDisabled),
831
- "data-invalid": dataAttr(isInvalid),
832
- "data-orientation": state2.context.orientation,
833
- "data-focus": dataAttr(isFocused),
834
- onPointerDown(event) {
835
- if (!isInteractive)
836
- return;
837
- const evt = getNativeEvent(event);
838
- if (!isLeftClick(evt) || isModifiedEvent(evt))
839
- return;
840
- const point = getEventPoint(evt);
841
- send({ type: "POINTER_DOWN", point });
842
- event.preventDefault();
843
- event.stopPropagation();
844
- },
845
- style: dom.getControlStyle()
846
- }),
847
- markerGroupProps: normalize.element({
848
- ...parts.markerGroup.attrs,
849
- role: "presentation",
850
- "aria-hidden": true,
851
- "data-orientation": state2.context.orientation,
852
- style: dom.getMarkerGroupStyle()
853
- }),
854
- getMarkerProps({ value }) {
855
- const percent = valueToPercent(value, state2.context);
856
- const style = dom.getMarkerStyle(state2.context, percent);
857
- const markerState = value > state2.context.value ? "over-value" : value < state2.context.value ? "under-value" : "at-value";
858
- return normalize.element({
859
- ...parts.marker.attrs,
860
- role: "presentation",
861
- "data-orientation": state2.context.orientation,
862
- id: dom.getMarkerId(state2.context, value),
863
- "data-value": value,
864
- "data-disabled": dataAttr(isDisabled),
865
- "data-state": markerState,
866
- style
867
- });
868
- }
869
- };
870
- }
871
-
872
- // src/slider.machine.ts
873
- import { createMachine } from "@zag-js/core";
874
- import { trackElementSize } from "@zag-js/element-size";
875
-
876
- // ../../utilities/core/dist/index.mjs
877
- var isArray2 = (v) => Array.isArray(v);
878
- var isObject2 = (v) => !(v == null || typeof v !== "object" || isArray2(v));
879
- function compact(obj) {
880
- if (obj === void 0)
881
- return obj;
882
- return Object.fromEntries(
883
- Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject2(value) ? compact(value) : value])
884
- );
885
- }
886
-
887
- // src/slider.machine.ts
888
- function machine(userContext) {
889
- const ctx = compact(userContext);
890
- return createMachine(
891
- {
892
- id: "slider",
893
- initial: "unknown",
894
- context: {
895
- thumbSize: null,
896
- thumbAlignment: "contain",
897
- disabled: false,
898
- threshold: 5,
899
- dir: "ltr",
900
- origin: "start",
901
- orientation: "horizontal",
902
- initialValue: null,
903
- value: 0,
904
- step: 1,
905
- min: 0,
906
- max: 100,
907
- ...ctx
908
- },
909
- computed: {
910
- isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
911
- isVertical: (ctx2) => ctx2.orientation === "vertical",
912
- isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
913
- isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readOnly),
914
- hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null
915
- },
916
- watch: {
917
- value: ["invokeOnChange", "dispatchChangeEvent"]
918
- },
919
- activities: ["trackFormControlState", "trackThumbSize"],
920
- on: {
921
- SET_VALUE: {
922
- actions: "setValue"
923
- },
924
- INCREMENT: {
925
- actions: "increment"
926
- },
927
- DECREMENT: {
928
- actions: "decrement"
929
- }
930
- },
931
- states: {
932
- unknown: {
933
- on: {
934
- SETUP: {
935
- target: "idle",
936
- actions: ["checkValue"]
937
- }
938
- }
939
- },
940
- idle: {
941
- on: {
942
- POINTER_DOWN: {
943
- target: "dragging",
944
- actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
945
- },
946
- FOCUS: "focus"
947
- }
948
- },
949
- focus: {
950
- entry: "focusThumb",
951
- on: {
952
- POINTER_DOWN: {
953
- target: "dragging",
954
- actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
955
- },
956
- ARROW_LEFT: {
957
- guard: "isHorizontal",
958
- actions: "decrement"
959
- },
960
- ARROW_RIGHT: {
961
- guard: "isHorizontal",
962
- actions: "increment"
963
- },
964
- ARROW_UP: {
965
- guard: "isVertical",
966
- actions: "increment"
967
- },
968
- ARROW_DOWN: {
969
- guard: "isVertical",
970
- actions: "decrement"
971
- },
972
- PAGE_UP: {
973
- actions: "increment"
974
- },
975
- PAGE_DOWN: {
976
- actions: "decrement"
977
- },
978
- HOME: {
979
- actions: "setToMin"
980
- },
981
- END: {
982
- actions: "setToMax"
983
- },
984
- BLUR: "idle"
985
- }
986
- },
987
- dragging: {
988
- entry: "focusThumb",
989
- activities: "trackPointerMove",
990
- on: {
991
- POINTER_UP: {
992
- target: "focus",
993
- actions: "invokeOnChangeEnd"
994
- },
995
- POINTER_MOVE: {
996
- actions: "setPointerValue"
997
- }
998
- }
999
- }
1000
- }
1001
- },
1002
- {
1003
- guards: {
1004
- isHorizontal: (ctx2) => ctx2.isHorizontal,
1005
- isVertical: (ctx2) => ctx2.isVertical
1006
- },
1007
- activities: {
1008
- trackFormControlState(ctx2) {
1009
- return trackFormControl(dom.getHiddenInputEl(ctx2), {
1010
- onFieldsetDisabled() {
1011
- ctx2.disabled = true;
1012
- },
1013
- onFormReset() {
1014
- if (ctx2.initialValue != null) {
1015
- ctx2.value = ctx2.initialValue;
1016
- }
1017
- }
1018
- });
1019
- },
1020
- trackPointerMove(ctx2, _evt, { send }) {
1021
- return trackPointerMove(dom.getDoc(ctx2), {
1022
- onPointerMove(info) {
1023
- send({ type: "POINTER_MOVE", point: info.point });
1024
- },
1025
- onPointerUp() {
1026
- send("POINTER_UP");
1027
- }
1028
- });
1029
- },
1030
- trackThumbSize(ctx2, _evt) {
1031
- if (ctx2.thumbAlignment !== "contain")
1032
- return;
1033
- return trackElementSize(dom.getThumbEl(ctx2), (size) => {
1034
- if (size)
1035
- ctx2.thumbSize = size;
1036
- });
1037
- }
1038
- },
1039
- actions: {
1040
- checkValue(ctx2) {
1041
- const value = utils.convert(ctx2, ctx2.value);
1042
- ctx2.value = value;
1043
- ctx2.initialValue = value;
1044
- },
1045
- invokeOnChangeStart(ctx2) {
1046
- var _a;
1047
- (_a = ctx2.onChangeStart) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
1048
- },
1049
- invokeOnChangeEnd(ctx2) {
1050
- var _a;
1051
- (_a = ctx2.onChangeEnd) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
1052
- },
1053
- invokeOnChange(ctx2) {
1054
- var _a;
1055
- (_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
1056
- },
1057
- dispatchChangeEvent(ctx2) {
1058
- dom.dispatchChangeEvent(ctx2);
1059
- },
1060
- setPointerValue(ctx2, evt) {
1061
- const value = dom.getValueFromPoint(ctx2, evt.point);
1062
- if (value == null)
1063
- return;
1064
- ctx2.value = utils.clamp(ctx2, value);
1065
- },
1066
- focusThumb(ctx2) {
1067
- raf(() => {
1068
- var _a;
1069
- return (_a = dom.getThumbEl(ctx2)) == null ? void 0 : _a.focus();
1070
- });
1071
- },
1072
- decrement(ctx2, evt) {
1073
- ctx2.value = utils.decrement(ctx2, evt.step);
1074
- },
1075
- increment(ctx2, evt) {
1076
- ctx2.value = utils.increment(ctx2, evt.step);
1077
- },
1078
- setToMin(ctx2) {
1079
- ctx2.value = ctx2.min;
1080
- },
1081
- setToMax(ctx2) {
1082
- ctx2.value = ctx2.max;
1083
- },
1084
- setValue(ctx2, evt) {
1085
- ctx2.value = utils.convert(ctx2, evt.value);
1086
- }
1087
- }
1088
- }
1089
- );
1090
- }
1
+ import {
2
+ connect
3
+ } from "./chunk-YCRSV2RE.mjs";
4
+ import {
5
+ anatomy
6
+ } from "./chunk-3Y7IIPR5.mjs";
7
+ import {
8
+ machine
9
+ } from "./chunk-3JMGYHB3.mjs";
10
+ import "./chunk-SGCWELVB.mjs";
11
+ import {
12
+ dom
13
+ } from "./chunk-MR2MUD77.mjs";
14
+ import "./chunk-MXJ3RGFD.mjs";
15
+ import "./chunk-FUTBDWTA.mjs";
16
+ import "./chunk-GBYBRQZL.mjs";
1091
17
  export {
1092
18
  anatomy,
1093
19
  connect,