@zag-js/slider 0.0.0-20220809065420

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