@zag-js/slider 0.2.6 → 0.2.8

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