@zag-js/slider 0.2.6 → 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.
@@ -0,0 +1,860 @@
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/slider.machine.ts
21
+ var slider_machine_exports = {};
22
+ __export(slider_machine_exports, {
23
+ machine: () => machine
24
+ });
25
+ module.exports = __toCommonJS(slider_machine_exports);
26
+ var import_core = require("@zag-js/core");
27
+
28
+ // ../../utilities/core/src/functions.ts
29
+ var runIfFn = (v, ...a) => {
30
+ const res = typeof v === "function" ? v(...a) : v;
31
+ return res != null ? res : void 0;
32
+ };
33
+ var callAll = (...fns) => (...a) => {
34
+ fns.forEach(function(fn) {
35
+ fn == null ? void 0 : fn(...a);
36
+ });
37
+ };
38
+
39
+ // ../../utilities/core/src/guard.ts
40
+ var isArray = (v) => Array.isArray(v);
41
+ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
42
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
43
+
44
+ // ../../utilities/core/src/object.ts
45
+ function compact(obj) {
46
+ if (obj === void 0)
47
+ return obj;
48
+ return Object.fromEntries(
49
+ Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
50
+ );
51
+ }
52
+
53
+ // ../../utilities/dom/src/platform.ts
54
+ var isDom = () => typeof window !== "undefined";
55
+ function getPlatform() {
56
+ var _a;
57
+ const agent = navigator.userAgentData;
58
+ return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
59
+ }
60
+ var pt = (v) => isDom() && v.test(getPlatform());
61
+ var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
62
+ var isMac = () => pt(/^Mac/) && !isTouchDevice;
63
+ var isApple = () => pt(/mac|iphone|ipad|ipod/i);
64
+ var isIos = () => isApple() && !isMac();
65
+
66
+ // ../../utilities/dom/src/query.ts
67
+ function isDocument(el) {
68
+ return el.nodeType === Node.DOCUMENT_NODE;
69
+ }
70
+ function isWindow(value) {
71
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
72
+ }
73
+ function getDocument(el) {
74
+ var _a;
75
+ if (isWindow(el))
76
+ return el.document;
77
+ if (isDocument(el))
78
+ return el;
79
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
80
+ }
81
+ function getWindow(el) {
82
+ var _a;
83
+ return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
84
+ }
85
+ function defineDomHelpers(helpers) {
86
+ const dom2 = {
87
+ getRootNode: (ctx) => {
88
+ var _a, _b;
89
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
90
+ },
91
+ getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
92
+ getWin: (ctx) => {
93
+ var _a;
94
+ return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
95
+ },
96
+ getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
97
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
98
+ createEmitter: (ctx, target) => {
99
+ const win = dom2.getWin(ctx);
100
+ return function emit(evt, detail, options) {
101
+ const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
102
+ const eventName = `zag:${evt}`;
103
+ const init = { bubbles, cancelable, composed, detail };
104
+ const event = new win.CustomEvent(eventName, init);
105
+ target.dispatchEvent(event);
106
+ };
107
+ },
108
+ createListener: (target) => {
109
+ return function listen(evt, handler) {
110
+ const eventName = `zag:${evt}`;
111
+ const listener = (e) => handler(e);
112
+ target.addEventListener(eventName, listener);
113
+ return () => target.removeEventListener(eventName, listener);
114
+ };
115
+ }
116
+ };
117
+ return {
118
+ ...dom2,
119
+ ...helpers
120
+ };
121
+ }
122
+
123
+ // ../../utilities/dom/src/event.ts
124
+ var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
125
+ var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
126
+ var supportsMouseEvent = () => isDom() && window.onmousedown === null;
127
+ var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
128
+ var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
129
+ var isLeftClick = (v) => v.button === 0;
130
+
131
+ // ../../utilities/dom/src/get-element-offset.ts
132
+ function getElementOffset(element) {
133
+ let left = 0;
134
+ let top = 0;
135
+ let el = element;
136
+ if (el.parentNode) {
137
+ do {
138
+ left += el.offsetLeft;
139
+ top += el.offsetTop;
140
+ } while ((el = el.offsetParent) && el.nodeType < 9);
141
+ el = element;
142
+ do {
143
+ left -= el.scrollLeft;
144
+ top -= el.scrollTop;
145
+ } while ((el = el.parentNode) && !/body/i.test(el.nodeName));
146
+ }
147
+ return {
148
+ top,
149
+ right: innerWidth - left - element.offsetWidth,
150
+ bottom: innerHeight - top - element.offsetHeight,
151
+ left
152
+ };
153
+ }
154
+
155
+ // ../../utilities/dom/src/get-point-relative-to-element.ts
156
+ function getPointRelativeToNode(point, element) {
157
+ const offset = getElementOffset(element);
158
+ const x = point.x - offset.left;
159
+ const y = point.y - offset.top;
160
+ return { x, y };
161
+ }
162
+
163
+ // ../../utilities/dom/src/listener.ts
164
+ var isRef = (v) => hasProp(v, "current");
165
+ var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
166
+ function extractInfo(event, type = "page") {
167
+ const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback : event;
168
+ return {
169
+ point: {
170
+ x: point[`${type}X`],
171
+ y: point[`${type}Y`]
172
+ }
173
+ };
174
+ }
175
+ function addDomEvent(target, eventName, handler, options) {
176
+ const node = isRef(target) ? target.current : runIfFn(target);
177
+ node == null ? void 0 : node.addEventListener(eventName, handler, options);
178
+ return () => {
179
+ node == null ? void 0 : node.removeEventListener(eventName, handler, options);
180
+ };
181
+ }
182
+ function addPointerEvent(target, event, listener, options) {
183
+ var _a;
184
+ const type = (_a = getEventName(event)) != null ? _a : event;
185
+ return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
186
+ }
187
+ function wrapHandler(fn, filter = false) {
188
+ const listener = (event) => {
189
+ fn(event, extractInfo(event));
190
+ };
191
+ return filter ? filterPrimaryPointer(listener) : listener;
192
+ }
193
+ function filterPrimaryPointer(fn) {
194
+ return (event) => {
195
+ var _a;
196
+ const win = (_a = event.view) != null ? _a : window;
197
+ const isMouseEvent2 = event instanceof win.MouseEvent;
198
+ const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
199
+ if (isPrimary)
200
+ fn(event);
201
+ };
202
+ }
203
+ var mouseEventNames = {
204
+ pointerdown: "mousedown",
205
+ pointermove: "mousemove",
206
+ pointerup: "mouseup",
207
+ pointercancel: "mousecancel",
208
+ pointerover: "mouseover",
209
+ pointerout: "mouseout",
210
+ pointerenter: "mouseenter",
211
+ pointerleave: "mouseleave"
212
+ };
213
+ var touchEventNames = {
214
+ pointerdown: "touchstart",
215
+ pointermove: "touchmove",
216
+ pointerup: "touchend",
217
+ pointercancel: "touchcancel"
218
+ };
219
+ function getEventName(evt) {
220
+ if (supportsPointerEvent())
221
+ return evt;
222
+ if (supportsTouchEvent())
223
+ return touchEventNames[evt];
224
+ if (supportsMouseEvent())
225
+ return mouseEventNames[evt];
226
+ return evt;
227
+ }
228
+
229
+ // ../../utilities/dom/src/mutation-observer.ts
230
+ function observeAttributes(node, attributes, fn) {
231
+ if (!node)
232
+ return;
233
+ const attrs = Array.isArray(attributes) ? attributes : [attributes];
234
+ const win = node.ownerDocument.defaultView || window;
235
+ const obs = new win.MutationObserver((changes) => {
236
+ for (const change of changes) {
237
+ if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
238
+ fn(change);
239
+ }
240
+ }
241
+ });
242
+ obs.observe(node, { attributes: true, attributeFilter: attrs });
243
+ return () => obs.disconnect();
244
+ }
245
+
246
+ // ../../utilities/dom/src/next-tick.ts
247
+ function nextTick(fn) {
248
+ const set = /* @__PURE__ */ new Set();
249
+ function raf2(fn2) {
250
+ const id = globalThis.requestAnimationFrame(fn2);
251
+ set.add(() => globalThis.cancelAnimationFrame(id));
252
+ }
253
+ raf2(() => raf2(fn));
254
+ return function cleanup() {
255
+ set.forEach(function(fn2) {
256
+ fn2();
257
+ });
258
+ };
259
+ }
260
+ function raf(fn) {
261
+ const id = globalThis.requestAnimationFrame(fn);
262
+ return function cleanup() {
263
+ globalThis.cancelAnimationFrame(id);
264
+ };
265
+ }
266
+
267
+ // ../../utilities/dom/src/text-selection.ts
268
+ var state = "default";
269
+ var savedUserSelect = "";
270
+ var modifiedElementMap = /* @__PURE__ */ new WeakMap();
271
+ function disableTextSelection({ target, doc } = {}) {
272
+ const _document = doc != null ? doc : document;
273
+ if (isIos()) {
274
+ if (state === "default") {
275
+ savedUserSelect = _document.documentElement.style.webkitUserSelect;
276
+ _document.documentElement.style.webkitUserSelect = "none";
277
+ }
278
+ state = "disabled";
279
+ } else if (target) {
280
+ modifiedElementMap.set(target, target.style.userSelect);
281
+ target.style.userSelect = "none";
282
+ }
283
+ return () => restoreTextSelection({ target, doc: _document });
284
+ }
285
+ function restoreTextSelection({ target, doc } = {}) {
286
+ const _document = doc != null ? doc : document;
287
+ if (isIos()) {
288
+ if (state !== "disabled")
289
+ return;
290
+ state = "restoring";
291
+ setTimeout(() => {
292
+ nextTick(() => {
293
+ if (state === "restoring") {
294
+ if (_document.documentElement.style.webkitUserSelect === "none") {
295
+ _document.documentElement.style.webkitUserSelect = savedUserSelect || "";
296
+ }
297
+ savedUserSelect = "";
298
+ state = "default";
299
+ }
300
+ });
301
+ }, 300);
302
+ } else {
303
+ if (target && modifiedElementMap.has(target)) {
304
+ let targetOldUserSelect = modifiedElementMap.get(target);
305
+ if (target.style.userSelect === "none") {
306
+ target.style.userSelect = targetOldUserSelect != null ? targetOldUserSelect : "";
307
+ }
308
+ if (target.getAttribute("style") === "") {
309
+ target.removeAttribute("style");
310
+ }
311
+ modifiedElementMap.delete(target);
312
+ }
313
+ }
314
+ }
315
+
316
+ // ../../utilities/dom/src/pointer-event.ts
317
+ var THRESHOLD = 5;
318
+ function trackPointerMove(doc, opts) {
319
+ const { onPointerMove, onPointerUp } = opts;
320
+ const handlePointerMove = (event, info) => {
321
+ const { point: p } = info;
322
+ const distance = Math.sqrt(p.x ** 2 + p.y ** 2);
323
+ if (distance < THRESHOLD)
324
+ return;
325
+ if (isMouseEvent(event) && isLeftClick(event)) {
326
+ onPointerUp();
327
+ return;
328
+ }
329
+ onPointerMove(info, event);
330
+ };
331
+ return callAll(
332
+ addPointerEvent(doc, "pointermove", handlePointerMove, false),
333
+ addPointerEvent(doc, "pointerup", onPointerUp, false),
334
+ addPointerEvent(doc, "pointercancel", onPointerUp, false),
335
+ addPointerEvent(doc, "contextmenu", onPointerUp, false),
336
+ disableTextSelection({ doc })
337
+ );
338
+ }
339
+
340
+ // ../../utilities/form-utils/src/input-event.ts
341
+ function getDescriptor(el, options) {
342
+ var _a;
343
+ const { type, property = "value" } = options;
344
+ const proto = getWindow(el)[type].prototype;
345
+ return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
346
+ }
347
+ function dispatchInputValueEvent(el, value) {
348
+ var _a;
349
+ if (!el)
350
+ return;
351
+ const win = getWindow(el);
352
+ if (!(el instanceof win.HTMLInputElement))
353
+ return;
354
+ const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
355
+ (_a = desc.set) == null ? void 0 : _a.call(el, value);
356
+ const event = new win.Event("input", { bubbles: true });
357
+ el.dispatchEvent(event);
358
+ }
359
+
360
+ // ../../utilities/form-utils/src/form.ts
361
+ function getClosestForm(el) {
362
+ if (isFormElement(el))
363
+ return el.form;
364
+ else
365
+ return el.closest("form");
366
+ }
367
+ function isFormElement(el) {
368
+ return el.matches("textarea, input, select, button");
369
+ }
370
+ function trackFormReset(el, callback) {
371
+ if (!el)
372
+ return;
373
+ const form = getClosestForm(el);
374
+ form == null ? void 0 : form.addEventListener("reset", callback, { passive: true });
375
+ return () => {
376
+ form == null ? void 0 : form.removeEventListener("reset", callback);
377
+ };
378
+ }
379
+ function trackFieldsetDisabled(el, callback) {
380
+ const fieldset = el == null ? void 0 : el.closest("fieldset");
381
+ if (!fieldset)
382
+ return;
383
+ callback(fieldset.disabled);
384
+ return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
385
+ }
386
+ function trackFormControl(el, options) {
387
+ if (!el)
388
+ return;
389
+ const { onFieldsetDisabled, onFormReset } = options;
390
+ const cleanups = [
391
+ trackFormReset(el, onFormReset),
392
+ trackFieldsetDisabled(el, (disabled) => {
393
+ if (disabled)
394
+ onFieldsetDisabled();
395
+ })
396
+ ];
397
+ return () => {
398
+ cleanups.forEach((cleanup) => cleanup == null ? void 0 : cleanup());
399
+ };
400
+ }
401
+
402
+ // src/slider.machine.ts
403
+ var import_element_size = require("@zag-js/element-size");
404
+
405
+ // ../../utilities/number/src/number.ts
406
+ function round(v, t) {
407
+ let num = valueOf(v);
408
+ const p = 10 ** (t != null ? t : 10);
409
+ num = Math.round(num * p) / p;
410
+ return t ? num.toFixed(t) : v.toString();
411
+ }
412
+ var valueToPercent = (v, r) => (valueOf(v) - r.min) * 100 / (r.max - r.min);
413
+ var percentToValue = (v, r) => r.min + (r.max - r.min) * valueOf(v);
414
+ function clamp(v, o) {
415
+ return Math.min(Math.max(valueOf(v), o.min), o.max);
416
+ }
417
+ function countDecimals(value) {
418
+ if (!Number.isFinite(value))
419
+ return 0;
420
+ let e = 1, p = 0;
421
+ while (Math.round(value * e) / e !== value) {
422
+ e *= 10;
423
+ p += 1;
424
+ }
425
+ return p;
426
+ }
427
+ var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
428
+ var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
429
+ function snapToStep(value, step) {
430
+ const num = valueOf(value);
431
+ const p = countDecimals(step);
432
+ const v = Math.round(num / step) * step;
433
+ return round(v, p);
434
+ }
435
+ function valueOf(v) {
436
+ if (typeof v === "number")
437
+ return v;
438
+ const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
439
+ return !Number.isNaN(num) ? num : 0;
440
+ }
441
+ function decimalOperation(a, op, b) {
442
+ let result = op === "+" ? a + b : a - b;
443
+ if (a % 1 !== 0 || b % 1 !== 0) {
444
+ const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
445
+ a = Math.round(a * multiplier);
446
+ b = Math.round(b * multiplier);
447
+ result = op === "+" ? a + b : a - b;
448
+ result /= multiplier;
449
+ }
450
+ return result;
451
+ }
452
+
453
+ // ../../utilities/number/src/transform.ts
454
+ var transform = (a, b) => {
455
+ const i = { min: a[0], max: a[1] };
456
+ const o = { min: b[0], max: b[1] };
457
+ return (v) => {
458
+ if (i.min === i.max || o.min === o.max)
459
+ return o.min;
460
+ const ratio = (o.max - o.min) / (i.max - i.min);
461
+ return o.min + ratio * (v - i.min);
462
+ };
463
+ };
464
+
465
+ // src/slider.style.ts
466
+ function getVerticalThumbOffset(ctx) {
467
+ var _a;
468
+ const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
469
+ const getValue = transform([ctx.min, ctx.max], [-height / 2, height / 2]);
470
+ return parseFloat(getValue(ctx.value).toFixed(2));
471
+ }
472
+ function getHorizontalThumbOffset(ctx) {
473
+ var _a;
474
+ const { width = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
475
+ if (ctx.isRtl) {
476
+ const getValue2 = transform([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
477
+ return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
478
+ }
479
+ const getValue = transform([ctx.min, ctx.max], [-width / 2, width / 2]);
480
+ return parseFloat(getValue(ctx.value).toFixed(2));
481
+ }
482
+ function getThumbOffset(ctx) {
483
+ const percent = valueToPercent(ctx.value, ctx);
484
+ if (ctx.thumbAlignment === "center")
485
+ return `${percent}%`;
486
+ const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
487
+ return `calc(${percent}% - ${offset}px)`;
488
+ }
489
+ function getThumbStyle(ctx) {
490
+ const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
491
+ return {
492
+ visibility: ctx.hasMeasuredThumbSize ? "visible" : "hidden",
493
+ position: "absolute",
494
+ transform: "var(--slider-thumb-transform)",
495
+ [placementProp]: "var(--slider-thumb-offset)"
496
+ };
497
+ }
498
+ function getRangeOffsets(ctx) {
499
+ const percent = valueToPercent(ctx.value, ctx);
500
+ let start = "0%";
501
+ let end = `${100 - percent}%`;
502
+ if (ctx.origin === "center") {
503
+ const isNegative = percent < 50;
504
+ start = isNegative ? `${percent}%` : "50%";
505
+ end = isNegative ? "50%" : end;
506
+ }
507
+ return { start, end };
508
+ }
509
+ function getRangeStyle(ctx) {
510
+ if (ctx.isVertical) {
511
+ return {
512
+ position: "absolute",
513
+ bottom: "var(--slider-range-start)",
514
+ top: "var(--slider-range-end)"
515
+ };
516
+ }
517
+ return {
518
+ position: "absolute",
519
+ [ctx.isRtl ? "right" : "left"]: "var(--slider-range-start)",
520
+ [ctx.isRtl ? "left" : "right"]: "var(--slider-range-end)"
521
+ };
522
+ }
523
+ function getControlStyle() {
524
+ return {
525
+ touchAction: "none",
526
+ userSelect: "none",
527
+ position: "relative"
528
+ };
529
+ }
530
+ function getRootStyle(ctx) {
531
+ const range = getRangeOffsets(ctx);
532
+ return {
533
+ "--slider-thumb-transform": ctx.isVertical ? "translateY(50%)" : "translateX(-50%)",
534
+ "--slider-thumb-offset": getThumbOffset(ctx),
535
+ "--slider-range-start": range.start,
536
+ "--slider-range-end": range.end
537
+ };
538
+ }
539
+ function getMarkerStyle(ctx, percent) {
540
+ return {
541
+ position: "absolute",
542
+ pointerEvents: "none",
543
+ [ctx.isHorizontal ? "left" : "bottom"]: `${ctx.isRtl ? 100 - percent : percent}%`
544
+ };
545
+ }
546
+ function getLabelStyle() {
547
+ return { userSelect: "none" };
548
+ }
549
+ function getTrackStyle() {
550
+ return { position: "relative" };
551
+ }
552
+ function getMarkerGroupStyle() {
553
+ return {
554
+ userSelect: "none",
555
+ pointerEvents: "none",
556
+ position: "relative"
557
+ };
558
+ }
559
+ var styles = {
560
+ getThumbOffset,
561
+ getControlStyle,
562
+ getThumbStyle,
563
+ getRangeStyle,
564
+ getRootStyle,
565
+ getMarkerStyle,
566
+ getLabelStyle,
567
+ getTrackStyle,
568
+ getMarkerGroupStyle
569
+ };
570
+
571
+ // src/slider.utils.ts
572
+ var utils = {
573
+ fromPercent(ctx, percent) {
574
+ percent = clamp(percent, { min: 0, max: 1 });
575
+ return parseFloat(snapToStep(percentToValue(percent, ctx), ctx.step));
576
+ },
577
+ clamp(ctx, value) {
578
+ return clamp(value, ctx);
579
+ },
580
+ convert(ctx, value) {
581
+ return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
582
+ },
583
+ decrement(ctx, step) {
584
+ let value = decrement(ctx.value, step != null ? step : ctx.step);
585
+ return utils.convert(ctx, value);
586
+ },
587
+ increment(ctx, step) {
588
+ let value = increment(ctx.value, step != null ? step : ctx.step);
589
+ return utils.convert(ctx, value);
590
+ }
591
+ };
592
+
593
+ // src/slider.dom.ts
594
+ var dom = defineDomHelpers({
595
+ ...styles,
596
+ getRootId: (ctx) => {
597
+ var _a, _b;
598
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `slider:${ctx.id}`;
599
+ },
600
+ getThumbId: (ctx) => {
601
+ var _a, _b;
602
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.thumb) != null ? _b : `slider:${ctx.id}:thumb`;
603
+ },
604
+ getControlId: (ctx) => {
605
+ var _a, _b;
606
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.control) != null ? _b : `slider:${ctx.id}:control`;
607
+ },
608
+ getHiddenInputId: (ctx) => `slider:${ctx.id}:input`,
609
+ getOutputId: (ctx) => {
610
+ var _a, _b;
611
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.output) != null ? _b : `slider:${ctx.id}:output`;
612
+ },
613
+ getTrackId: (ctx) => {
614
+ var _a, _b;
615
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}track`;
616
+ },
617
+ getRangeId: (ctx) => {
618
+ var _a, _b;
619
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}:range`;
620
+ },
621
+ getLabelId: (ctx) => {
622
+ var _a, _b;
623
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.id}:label`;
624
+ },
625
+ getMarkerId: (ctx, value) => `slider:${ctx.id}:marker:${value}`,
626
+ getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
627
+ getThumbEl: (ctx) => dom.getById(ctx, dom.getThumbId(ctx)),
628
+ getControlEl: (ctx) => dom.getById(ctx, dom.getControlId(ctx)),
629
+ getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx)),
630
+ getValueFromPoint(ctx, point) {
631
+ const el = dom.getControlEl(ctx);
632
+ if (!el)
633
+ return;
634
+ const relativePoint = getPointRelativeToNode(point, el);
635
+ const percentX = relativePoint.x / el.offsetWidth;
636
+ const percentY = relativePoint.y / el.offsetHeight;
637
+ let percent;
638
+ if (ctx.isHorizontal) {
639
+ percent = ctx.isRtl ? 1 - percentX : percentX;
640
+ } else {
641
+ percent = 1 - percentY;
642
+ }
643
+ return utils.fromPercent(ctx, percent);
644
+ },
645
+ dispatchChangeEvent(ctx) {
646
+ const input = dom.getHiddenInputEl(ctx);
647
+ if (!input)
648
+ return;
649
+ dispatchInputValueEvent(input, ctx.value);
650
+ }
651
+ });
652
+
653
+ // src/slider.machine.ts
654
+ function machine(userContext) {
655
+ const ctx = compact(userContext);
656
+ return (0, import_core.createMachine)(
657
+ {
658
+ id: "slider",
659
+ initial: "unknown",
660
+ context: {
661
+ thumbSize: null,
662
+ thumbAlignment: "contain",
663
+ disabled: false,
664
+ threshold: 5,
665
+ dir: "ltr",
666
+ origin: "start",
667
+ orientation: "horizontal",
668
+ initialValue: null,
669
+ value: 0,
670
+ step: 1,
671
+ min: 0,
672
+ max: 100,
673
+ ...ctx
674
+ },
675
+ computed: {
676
+ isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
677
+ isVertical: (ctx2) => ctx2.orientation === "vertical",
678
+ isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
679
+ isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readOnly),
680
+ hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null
681
+ },
682
+ watch: {
683
+ value: ["invokeOnChange", "dispatchChangeEvent"]
684
+ },
685
+ activities: ["trackFormControlState", "trackThumbSize"],
686
+ on: {
687
+ SET_VALUE: {
688
+ actions: "setValue"
689
+ },
690
+ INCREMENT: {
691
+ actions: "increment"
692
+ },
693
+ DECREMENT: {
694
+ actions: "decrement"
695
+ }
696
+ },
697
+ states: {
698
+ unknown: {
699
+ on: {
700
+ SETUP: {
701
+ target: "idle",
702
+ actions: ["checkValue"]
703
+ }
704
+ }
705
+ },
706
+ idle: {
707
+ on: {
708
+ POINTER_DOWN: {
709
+ target: "dragging",
710
+ actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
711
+ },
712
+ FOCUS: "focus"
713
+ }
714
+ },
715
+ focus: {
716
+ entry: "focusThumb",
717
+ on: {
718
+ POINTER_DOWN: {
719
+ target: "dragging",
720
+ actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
721
+ },
722
+ ARROW_LEFT: {
723
+ guard: "isHorizontal",
724
+ actions: "decrement"
725
+ },
726
+ ARROW_RIGHT: {
727
+ guard: "isHorizontal",
728
+ actions: "increment"
729
+ },
730
+ ARROW_UP: {
731
+ guard: "isVertical",
732
+ actions: "increment"
733
+ },
734
+ ARROW_DOWN: {
735
+ guard: "isVertical",
736
+ actions: "decrement"
737
+ },
738
+ PAGE_UP: {
739
+ actions: "increment"
740
+ },
741
+ PAGE_DOWN: {
742
+ actions: "decrement"
743
+ },
744
+ HOME: {
745
+ actions: "setToMin"
746
+ },
747
+ END: {
748
+ actions: "setToMax"
749
+ },
750
+ BLUR: "idle"
751
+ }
752
+ },
753
+ dragging: {
754
+ entry: "focusThumb",
755
+ activities: "trackPointerMove",
756
+ on: {
757
+ POINTER_UP: {
758
+ target: "focus",
759
+ actions: "invokeOnChangeEnd"
760
+ },
761
+ POINTER_MOVE: {
762
+ actions: "setPointerValue"
763
+ }
764
+ }
765
+ }
766
+ }
767
+ },
768
+ {
769
+ guards: {
770
+ isHorizontal: (ctx2) => ctx2.isHorizontal,
771
+ isVertical: (ctx2) => ctx2.isVertical
772
+ },
773
+ activities: {
774
+ trackFormControlState(ctx2) {
775
+ return trackFormControl(dom.getHiddenInputEl(ctx2), {
776
+ onFieldsetDisabled() {
777
+ ctx2.disabled = true;
778
+ },
779
+ onFormReset() {
780
+ if (ctx2.initialValue != null) {
781
+ ctx2.value = ctx2.initialValue;
782
+ }
783
+ }
784
+ });
785
+ },
786
+ trackPointerMove(ctx2, _evt, { send }) {
787
+ return trackPointerMove(dom.getDoc(ctx2), {
788
+ onPointerMove(info) {
789
+ send({ type: "POINTER_MOVE", point: info.point });
790
+ },
791
+ onPointerUp() {
792
+ send("POINTER_UP");
793
+ }
794
+ });
795
+ },
796
+ trackThumbSize(ctx2, _evt) {
797
+ if (ctx2.thumbAlignment !== "contain")
798
+ return;
799
+ return (0, import_element_size.trackElementSize)(dom.getThumbEl(ctx2), (size) => {
800
+ if (size)
801
+ ctx2.thumbSize = size;
802
+ });
803
+ }
804
+ },
805
+ actions: {
806
+ checkValue(ctx2) {
807
+ const value = utils.convert(ctx2, ctx2.value);
808
+ ctx2.value = value;
809
+ ctx2.initialValue = value;
810
+ },
811
+ invokeOnChangeStart(ctx2) {
812
+ var _a;
813
+ (_a = ctx2.onChangeStart) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
814
+ },
815
+ invokeOnChangeEnd(ctx2) {
816
+ var _a;
817
+ (_a = ctx2.onChangeEnd) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
818
+ },
819
+ invokeOnChange(ctx2) {
820
+ var _a;
821
+ (_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
822
+ },
823
+ dispatchChangeEvent(ctx2) {
824
+ dom.dispatchChangeEvent(ctx2);
825
+ },
826
+ setPointerValue(ctx2, evt) {
827
+ const value = dom.getValueFromPoint(ctx2, evt.point);
828
+ if (value == null)
829
+ return;
830
+ ctx2.value = utils.clamp(ctx2, value);
831
+ },
832
+ focusThumb(ctx2) {
833
+ raf(() => {
834
+ var _a;
835
+ return (_a = dom.getThumbEl(ctx2)) == null ? void 0 : _a.focus();
836
+ });
837
+ },
838
+ decrement(ctx2, evt) {
839
+ ctx2.value = utils.decrement(ctx2, evt.step);
840
+ },
841
+ increment(ctx2, evt) {
842
+ ctx2.value = utils.increment(ctx2, evt.step);
843
+ },
844
+ setToMin(ctx2) {
845
+ ctx2.value = ctx2.min;
846
+ },
847
+ setToMax(ctx2) {
848
+ ctx2.value = ctx2.max;
849
+ },
850
+ setValue(ctx2, evt) {
851
+ ctx2.value = utils.convert(ctx2, evt.value);
852
+ }
853
+ }
854
+ }
855
+ );
856
+ }
857
+ // Annotate the CommonJS export names for ESM import in node:
858
+ 0 && (module.exports = {
859
+ machine
860
+ });