@zag-js/slider 0.1.5 → 0.1.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.
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __defProps = Object.defineProperties;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -47,104 +48,34 @@ var __pow = Math.pow;
47
48
  var dataAttr = (guard) => {
48
49
  return guard ? "" : void 0;
49
50
  };
50
- function nextTick(fn) {
51
- const set = /* @__PURE__ */ new Set();
52
- function raf2(fn2) {
53
- const id = globalThis.requestAnimationFrame(fn2);
54
- set.add(() => globalThis.cancelAnimationFrame(id));
55
- }
56
- raf2(() => raf2(fn));
57
- return function cleanup() {
58
- set.forEach(function(fn2) {
59
- fn2();
60
- });
61
- };
62
- }
63
- function raf(fn) {
64
- const id = globalThis.requestAnimationFrame(fn);
65
- return function cleanup() {
66
- globalThis.cancelAnimationFrame(id);
67
- };
68
- }
69
- var noop = () => {
70
- };
71
- var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
72
- var platform = (v) => isDom() && v.test(navigator.platform);
73
- var isDom = () => !!(typeof window !== "undefined");
74
- var isMac = () => platform(/^Mac/);
75
- var isIPhone = () => platform(/^iPhone/);
76
- var isIPad = () => platform(/^iPad/) || isMac() && navigator.maxTouchPoints > 1;
77
- var isIos = () => isIPhone() || isIPad();
51
+ var isDom = () => typeof window !== "undefined";
78
52
  var isArray = (v) => Array.isArray(v);
79
53
  var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
80
- var isMouseEvent = (v) => isObject(v) && "button" in v;
81
- var isLeftClick = (v) => v.button === 0;
82
- function getListenerElements() {
83
- ;
84
- globalThis.__listenerElements__ = globalThis.__listenerElements__ || /* @__PURE__ */ new Map();
85
- return globalThis.__listenerElements__;
86
- }
87
- function getListenerCache() {
88
- ;
89
- globalThis.__listenerCache__ = globalThis.__listenerCache__ || /* @__PURE__ */ new Map();
90
- return globalThis.__listenerCache__;
91
- }
92
- function globalEventBus(node, type, handler, options) {
54
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
55
+ function getPlatform() {
93
56
  var _a;
94
- if (!node)
95
- return noop;
96
- const hash = JSON.stringify({ type, options });
97
- const listenerElements = getListenerElements();
98
- const listenerCache = getListenerCache();
99
- const group = listenerElements.get(node);
100
- if (!listenerElements.has(node)) {
101
- const group2 = /* @__PURE__ */ new Map([[hash, /* @__PURE__ */ new Set([handler])]]);
102
- listenerElements.set(node, group2);
103
- } else if (group == null ? void 0 : group.has(hash)) {
104
- (_a = group == null ? void 0 : group.get(hash)) == null ? void 0 : _a.add(handler);
105
- } else {
106
- group == null ? void 0 : group.set(hash, /* @__PURE__ */ new Set([handler]));
107
- }
108
- function attach(node2) {
109
- var _a2, _b;
110
- function listener(event) {
111
- var _a3;
112
- const group2 = listenerElements.get(node2);
113
- (_a3 = group2 == null ? void 0 : group2.get(hash)) == null ? void 0 : _a3.forEach((fn) => fn(event));
114
- }
115
- if (!(listenerCache == null ? void 0 : listenerCache.has(node2))) {
116
- listenerCache.set(node2, /* @__PURE__ */ new Map([[hash, listener]]));
117
- node2.addEventListener(type, listener, options);
118
- return;
119
- }
120
- if (!((_a2 = listenerCache == null ? void 0 : listenerCache.get(node2)) == null ? void 0 : _a2.has(hash))) {
121
- (_b = listenerCache.get(node2)) == null ? void 0 : _b.set(hash, listener);
122
- node2.addEventListener(type, listener, options);
123
- }
124
- }
125
- attach(node);
126
- return function remove() {
127
- var _a2, _b, _c, _d;
128
- if (!listenerElements.has(node))
129
- return;
130
- const group2 = listenerElements.get(node);
131
- (_a2 = group2 == null ? void 0 : group2.get(hash)) == null ? void 0 : _a2.delete(handler);
132
- if (((_b = group2 == null ? void 0 : group2.get(hash)) == null ? void 0 : _b.size) === 0) {
133
- const listener = (_c = listenerCache.get(node)) == null ? void 0 : _c.get(hash);
134
- node.removeEventListener(type, listener, options);
135
- group2 == null ? void 0 : group2.delete(hash);
136
- (_d = listenerCache.get(node)) == null ? void 0 : _d.delete(hash);
137
- if ((group2 == null ? void 0 : group2.size) === 0) {
138
- listenerElements.delete(node);
139
- listenerCache.delete(node);
140
- }
141
- }
142
- };
57
+ const agent = navigator.userAgentData;
58
+ return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
143
59
  }
144
- var t = (v) => Object.prototype.toString.call(v).slice(8, -1);
145
- var isRef = (v) => t(v) === "Object" && "current" in v;
146
- var runIfFn = (fn) => t(fn) === "Function" ? fn() : fn;
147
- var isTouchEvent = (v) => t(v) === "Object" && !!v.touches;
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
+ var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
66
+ var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
67
+ var supportsMouseEvent = () => isDom() && window.onmousedown === null;
68
+ var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
69
+ var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
70
+ var isLeftClick = (v) => v.button === 0;
71
+ var runIfFn = (v, ...a) => {
72
+ const res = typeof v === "function" ? v(...a) : v;
73
+ return res != null ? res : void 0;
74
+ };
75
+ var noop = () => {
76
+ };
77
+ var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
78
+ var isRef = (v) => hasProp(v, "current");
148
79
  var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
149
80
  function extractInfo(event, type = "page") {
150
81
  const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback : event;
@@ -155,9 +86,12 @@ function extractInfo(event, type = "page") {
155
86
  }
156
87
  };
157
88
  }
158
- function addDomEvent(target, event, listener, options) {
89
+ function addDomEvent(target, eventName, handler, options) {
159
90
  const node = isRef(target) ? target.current : runIfFn(target);
160
- return globalEventBus(node, event, listener, options);
91
+ node == null ? void 0 : node.addEventListener(eventName, handler, options);
92
+ return () => {
93
+ node == null ? void 0 : node.removeEventListener(eventName, handler, options);
94
+ };
161
95
  }
162
96
  function addPointerEvent(target, event, listener, options) {
163
97
  var _a;
@@ -180,9 +114,6 @@ function filterPrimaryPointer(fn) {
180
114
  fn(event);
181
115
  };
182
116
  }
183
- var supportsPointerEvent = () => typeof window !== "undefined" && window.onpointerdown === null;
184
- var supportsTouchEvent = () => typeof window !== "undefined" && window.ontouchstart === null;
185
- var supportsMouseEvent = () => typeof window !== "undefined" && window.onmousedown === null;
186
117
  var mouseEventNames = {
187
118
  pointerdown: "mousedown",
188
119
  pointermove: "mousemove",
@@ -208,70 +139,91 @@ function getEventName(evt) {
208
139
  return mouseEventNames[evt];
209
140
  return evt;
210
141
  }
142
+ function nextTick(fn) {
143
+ const set = /* @__PURE__ */ new Set();
144
+ function raf2(fn2) {
145
+ const id = globalThis.requestAnimationFrame(fn2);
146
+ set.add(() => globalThis.cancelAnimationFrame(id));
147
+ }
148
+ raf2(() => raf2(fn));
149
+ return function cleanup() {
150
+ set.forEach(function(fn2) {
151
+ fn2();
152
+ });
153
+ };
154
+ }
155
+ function raf(fn) {
156
+ const id = globalThis.requestAnimationFrame(fn);
157
+ return function cleanup() {
158
+ globalThis.cancelAnimationFrame(id);
159
+ };
160
+ }
211
161
  function getOwnerWindow(el) {
212
162
  var _a;
213
163
  return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
214
164
  }
215
- function getDescriptor(el, options) {
216
- var _a;
217
- const { type, property } = options;
218
- const win = getOwnerWindow(el);
219
- const _type = type === "input" ? "HTMLInputElement" : "HTMLTextAreaElement";
220
- const proto = win[_type].prototype;
221
- return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
222
- }
223
- function dispatchInputValueEvent(el, value) {
165
+ function getNativeEvent(e) {
224
166
  var _a;
225
- const win = getOwnerWindow(el);
226
- if (!(el instanceof win.HTMLInputElement))
227
- return;
228
- const desc = getDescriptor(el, { type: "input", property: "value" });
229
- (_a = desc.set) == null ? void 0 : _a.call(el, value);
230
- const event = new win.Event("input", { bubbles: true });
231
- el.dispatchEvent(event);
167
+ return (_a = e.nativeEvent) != null ? _a : e;
232
168
  }
233
- function trackInputPropertyMutation(el, options) {
234
- const { fn, property, type } = options;
235
- if (!fn || !el)
236
- return;
237
- const { get, set } = getDescriptor(el, { property, type });
238
- let run = true;
239
- Object.defineProperty(el, property, {
240
- get() {
241
- return get == null ? void 0 : get.call(this);
242
- },
243
- set(value) {
244
- if (run)
245
- fn(value);
246
- return set == null ? void 0 : set.call(this, value);
169
+ function observeAttributes(node, attributes, fn) {
170
+ if (!node)
171
+ return noop;
172
+ const attrs = Array.isArray(attributes) ? attributes : [attributes];
173
+ const win = node.ownerDocument.defaultView || window;
174
+ const obs = new win.MutationObserver((changes) => {
175
+ for (const change of changes) {
176
+ if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
177
+ fn(change);
178
+ }
247
179
  }
248
180
  });
249
- return function() {
250
- run = false;
251
- };
181
+ obs.observe(node, { attributes: true, attributeFilter: attrs });
182
+ return () => obs.disconnect();
252
183
  }
253
- function getNativeEvent(event) {
254
- var _a;
255
- return (_a = event.nativeEvent) != null ? _a : event;
256
- }
257
- function getClosestFormElement(el) {
184
+ function getClosestForm(el) {
258
185
  if (isFormElement(el))
259
186
  return el.form;
260
187
  else
261
188
  return el.closest("form");
262
189
  }
263
190
  function isFormElement(el) {
264
- return ["textarea", "input", "select", "button"].includes(el.localName);
191
+ return el.matches("textarea, input, select, button");
265
192
  }
266
193
  function trackFormReset(el, callback) {
267
194
  if (!el)
268
195
  return;
269
- const form = getClosestFormElement(el);
196
+ const form = getClosestForm(el);
270
197
  form == null ? void 0 : form.addEventListener("reset", callback, { passive: true });
271
198
  return () => {
272
199
  form == null ? void 0 : form.removeEventListener("reset", callback);
273
200
  };
274
201
  }
202
+ function trackFieldsetDisabled(el, callback) {
203
+ const fieldset = el == null ? void 0 : el.closest("fieldset");
204
+ if (!fieldset)
205
+ return;
206
+ callback(fieldset.disabled);
207
+ return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
208
+ }
209
+ function getDescriptor(el, options) {
210
+ var _a;
211
+ const { type, property } = options;
212
+ const win = getOwnerWindow(el);
213
+ const _type = type === "input" ? "HTMLInputElement" : "HTMLTextAreaElement";
214
+ const proto = win[_type].prototype;
215
+ return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
216
+ }
217
+ function dispatchInputValueEvent(el, value) {
218
+ var _a;
219
+ const win = getOwnerWindow(el);
220
+ if (!(el instanceof win.HTMLInputElement))
221
+ return;
222
+ const desc = getDescriptor(el, { type: "input", property: "value" });
223
+ (_a = desc.set) == null ? void 0 : _a.call(el, value);
224
+ const event = new win.Event("input", { bubbles: true });
225
+ el.dispatchEvent(event);
226
+ }
275
227
  var rtlKeyMap = {
276
228
  ArrowLeft: "ArrowRight",
277
229
  ArrowRight: "ArrowLeft",
@@ -309,30 +261,6 @@ function getEventStep(event) {
309
261
  return isSkipKey ? 10 : 1;
310
262
  }
311
263
  }
312
- function itemById(v, id) {
313
- return v.find((node) => node.id === id);
314
- }
315
- function indexOfId(v, id) {
316
- const item = itemById(v, id);
317
- return item ? v.indexOf(item) : -1;
318
- }
319
- var getValueText = (item) => {
320
- var _a, _b;
321
- return (_b = (_a = item.dataset.valuetext) != null ? _a : item.textContent) != null ? _b : "";
322
- };
323
- var match = (valueText, query2) => valueText.toLowerCase().startsWith(query2.toLowerCase());
324
- var wrap = (v, idx) => {
325
- return v.map((_, index) => v[(Math.max(idx, 0) + index) % v.length]);
326
- };
327
- function findByText(v, text, currentId) {
328
- const index = currentId ? indexOfId(v, currentId) : -1;
329
- let items = currentId ? wrap(v, index) : v;
330
- const isSingleKey = text.length === 1;
331
- if (isSingleKey) {
332
- items = items.filter((item) => item.id !== currentId);
333
- }
334
- return items.find((item) => match(getValueText(item), text));
335
- }
336
264
  var state = "default";
337
265
  var savedUserSelect = "";
338
266
  var modifiedElementMap = /* @__PURE__ */ new WeakMap();
@@ -396,42 +324,33 @@ function trackPointerMove(opts) {
396
324
  };
397
325
  return pipe(addPointerEvent(doc, "pointermove", handlePointerMove, false), addPointerEvent(doc, "pointerup", onPointerUp, false), addPointerEvent(doc, "pointercancel", onPointerUp, false), addPointerEvent(doc, "contextmenu", onPointerUp, false), disableTextSelection({ doc }));
398
326
  }
399
- function findByTypeahead(_items, options) {
400
- const { state: state2, activeId, key, timeout = 350 } = options;
401
- const search = state2.keysSoFar + key;
402
- const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]);
403
- const query2 = isRepeated ? search[0] : search;
404
- let items = _items.slice();
405
- const next = findByText(items, query2, activeId);
406
- function cleanup() {
407
- clearTimeout(state2.timer);
408
- state2.timer = -1;
409
- }
410
- function update(value) {
411
- state2.keysSoFar = value;
412
- cleanup();
413
- if (value !== "") {
414
- state2.timer = +setTimeout(() => {
415
- update("");
416
- cleanup();
417
- }, timeout);
418
- }
419
- }
420
- update(search);
421
- return next;
327
+
328
+ // ../../utilities/rect/dist/index.mjs
329
+ var isArray2 = (v) => Array.isArray(v);
330
+ var isObject2 = (v) => !(v == null || typeof v !== "object" || isArray2(v));
331
+ var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
332
+ var isTouchEvent2 = (v) => isObject2(v) && hasProp2(v, "touches");
333
+ var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
334
+ function getEventPoint(e, t = "page") {
335
+ const p = isTouchEvent2(e) ? e.touches[0] || e.changedTouches[0] || fallback2 : e;
336
+ return { x: p[`${t}X`], y: p[`${t}Y`] };
337
+ }
338
+ function relativeToNode(p, el) {
339
+ const dx = p.x - el.offsetLeft - el.clientLeft + el.scrollLeft;
340
+ const dy = p.y - el.offsetTop - el.clientTop + el.scrollTop;
341
+ return {
342
+ point: { x: dx, y: dy },
343
+ progress: { x: dx / el.offsetWidth, y: dy / el.offsetHeight }
344
+ };
422
345
  }
423
- findByTypeahead.defaultOptions = {
424
- keysSoFar: "",
425
- timer: -1
426
- };
427
346
 
428
347
  // ../../utilities/number/dist/index.mjs
429
348
  var __pow2 = Math.pow;
430
- function round(v, t2) {
349
+ function round(v, t) {
431
350
  let num = valueOf(v);
432
- const p = __pow2(10, t2 != null ? t2 : 10);
351
+ const p = __pow2(10, t != null ? t : 10);
433
352
  num = Math.round(num * p) / p;
434
- return t2 ? num.toFixed(t2) : v.toString();
353
+ return t ? num.toFixed(t) : v.toString();
435
354
  }
436
355
  var valueToPercent = (v, r) => (valueOf(v) - r.min) * 100 / (r.max - r.min);
437
356
  var percentToValue = (v, r) => r.min + (r.max - r.min) * valueOf(v);
@@ -485,47 +404,7 @@ var transform = (a, b) => {
485
404
  };
486
405
  };
487
406
 
488
- // ../../utilities/rect/dist/index.mjs
489
- var isArray2 = (v) => Array.isArray(v);
490
- var isObject2 = (v) => !(v == null || typeof v !== "object" || isArray2(v));
491
- var isTouchEvent2 = (v) => isObject2(v) && "touches" in v;
492
- var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
493
- function getEventPoint(e, t2 = "page") {
494
- const p = isTouchEvent2(e) ? e.touches[0] || e.changedTouches[0] || fallback2 : e;
495
- return { x: p[`${t2}X`], y: p[`${t2}Y`] };
496
- }
497
- function relativeToNode(p, el) {
498
- const dx = p.x - el.offsetLeft - el.clientLeft + el.scrollLeft;
499
- const dy = p.y - el.offsetTop - el.clientTop + el.scrollTop;
500
- return {
501
- point: { x: dx, y: dy },
502
- progress: { x: dx / el.offsetWidth, y: dy / el.offsetHeight }
503
- };
504
- }
505
-
506
- // src/slider.utils.ts
507
- var utils = {
508
- fromPercent(ctx, percent) {
509
- percent = clamp(percent, { min: 0, max: 1 });
510
- return parseFloat(snapToStep(percentToValue(percent, ctx), ctx.step));
511
- },
512
- clamp(ctx, value) {
513
- return clamp(value, ctx);
514
- },
515
- convert(ctx, value) {
516
- return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
517
- },
518
- decrement(ctx, step) {
519
- let value = decrement(ctx.value, step != null ? step : ctx.step);
520
- return utils.convert(ctx, value);
521
- },
522
- increment(ctx, step) {
523
- let value = increment(ctx.value, step != null ? step : ctx.step);
524
- return utils.convert(ctx, value);
525
- }
526
- };
527
-
528
- // src/slider.dom.ts
407
+ // src/slider.style.ts
529
408
  function getVerticalThumbOffset(ctx) {
530
409
  var _a;
531
410
  const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
@@ -542,54 +421,119 @@ function getHorizontalThumbOffset(ctx) {
542
421
  const getValue = transform([ctx.min, ctx.max], [-width / 2, width / 2]);
543
422
  return parseFloat(getValue(ctx.value).toFixed(2));
544
423
  }
545
- function getThumbStyle(ctx) {
424
+ function getThumbOffset(ctx) {
546
425
  const percent = valueToPercent(ctx.value, ctx);
426
+ if (ctx.thumbAlignment === "center")
427
+ return `${percent}%`;
547
428
  const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
548
- const style = {
429
+ return `calc(${percent}% - ${offset}px)`;
430
+ }
431
+ function getThumbStyle(ctx) {
432
+ const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
433
+ return {
549
434
  visibility: ctx.hasMeasuredThumbSize ? "visible" : "hidden",
550
435
  position: "absolute",
551
436
  transform: "var(--slider-thumb-transform)",
552
- "--slider-thumb-placement": `calc(${percent}% - ${offset}px)`
437
+ [placementProp]: "var(--slider-thumb-offset)"
553
438
  };
554
- if (ctx.isVertical) {
555
- style.bottom = "var(--slider-thumb-placement)";
556
- } else {
557
- style[ctx.isRtl ? "right" : "left"] = "var(--slider-thumb-placement)";
558
- }
559
- return style;
560
439
  }
561
- function getRangeStyle(ctx) {
440
+ function getRangeOffsets(ctx) {
562
441
  const percent = valueToPercent(ctx.value, ctx);
563
- const style = {
564
- position: "absolute"
565
- };
566
- let startValue = "0%";
567
- let endValue = `${100 - percent}%`;
442
+ let start = "0%";
443
+ let end = `${100 - percent}%`;
568
444
  if (ctx.origin === "center") {
569
445
  const isNegative = percent < 50;
570
- startValue = isNegative ? `${percent}%` : "50%";
571
- endValue = isNegative ? "50%" : endValue;
446
+ start = isNegative ? `${percent}%` : "50%";
447
+ end = isNegative ? "50%" : end;
572
448
  }
449
+ return { start, end };
450
+ }
451
+ function getRangeStyle(ctx) {
573
452
  if (ctx.isVertical) {
574
- return __spreadProps(__spreadValues({}, style), {
575
- bottom: startValue,
576
- top: endValue
577
- });
453
+ return {
454
+ position: "absolute",
455
+ bottom: "var(--slider-range-start)",
456
+ top: "var(--slider-range-end)"
457
+ };
578
458
  }
579
- return __spreadProps(__spreadValues({}, style), {
580
- [ctx.isRtl ? "right" : "left"]: startValue,
581
- [ctx.isRtl ? "left" : "right"]: endValue
582
- });
459
+ return {
460
+ position: "absolute",
461
+ [ctx.isRtl ? "right" : "left"]: "var(--slider-range-start)",
462
+ [ctx.isRtl ? "left" : "right"]: "var(--slider-range-end)"
463
+ };
583
464
  }
584
- function getControlStyle(ctx) {
465
+ function getControlStyle() {
585
466
  return {
586
467
  touchAction: "none",
587
468
  userSelect: "none",
469
+ position: "relative"
470
+ };
471
+ }
472
+ function getRootStyle(ctx) {
473
+ const range = getRangeOffsets(ctx);
474
+ return {
588
475
  "--slider-thumb-transform": ctx.isVertical ? "translateY(50%)" : "translateX(-50%)",
476
+ "--slider-thumb-offset": getThumbOffset(ctx),
477
+ "--slider-range-start": range.start,
478
+ "--slider-range-end": range.end
479
+ };
480
+ }
481
+ function getMarkerStyle(ctx, percent) {
482
+ return {
483
+ position: "absolute",
484
+ pointerEvents: "none",
485
+ [ctx.isHorizontal ? "left" : "bottom"]: `${ctx.isRtl ? 100 - percent : percent}%`
486
+ };
487
+ }
488
+ function getLabelStyle() {
489
+ return { userSelect: "none" };
490
+ }
491
+ function getTrackStyle() {
492
+ return { position: "relative" };
493
+ }
494
+ function getMarkerGroupStyle() {
495
+ return {
496
+ userSelect: "none",
497
+ pointerEvents: "none",
589
498
  position: "relative"
590
499
  };
591
500
  }
592
- var dom = {
501
+ var styles = {
502
+ getThumbOffset,
503
+ getControlStyle,
504
+ getThumbStyle,
505
+ getRangeStyle,
506
+ getRootStyle,
507
+ getMarkerStyle,
508
+ getLabelStyle,
509
+ getTrackStyle,
510
+ getMarkerGroupStyle
511
+ };
512
+
513
+ // src/slider.utils.ts
514
+ var utils = {
515
+ fromPercent(ctx, percent) {
516
+ percent = clamp(percent, { min: 0, max: 1 });
517
+ return parseFloat(snapToStep(percentToValue(percent, ctx), ctx.step));
518
+ },
519
+ clamp(ctx, value) {
520
+ return clamp(value, ctx);
521
+ },
522
+ convert(ctx, value) {
523
+ return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
524
+ },
525
+ decrement(ctx, step) {
526
+ let value = decrement(ctx.value, step != null ? step : ctx.step);
527
+ return utils.convert(ctx, value);
528
+ },
529
+ increment(ctx, step) {
530
+ let value = increment(ctx.value, step != null ? step : ctx.step);
531
+ return utils.convert(ctx, value);
532
+ }
533
+ };
534
+
535
+ // src/slider.dom.ts
536
+ var dom = __spreadProps(__spreadValues({}, styles), {
593
537
  getDoc: (ctx) => {
594
538
  var _a;
595
539
  return (_a = ctx.doc) != null ? _a : document;
@@ -617,7 +561,7 @@ var dom = {
617
561
  },
618
562
  getTrackId: (ctx) => {
619
563
  var _a, _b;
620
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:-${ctx.uid}track`;
564
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.uid}track`;
621
565
  },
622
566
  getRangeId: (ctx) => {
623
567
  var _a, _b;
@@ -628,12 +572,10 @@ var dom = {
628
572
  return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.uid}:label`;
629
573
  },
630
574
  getMarkerId: (ctx, value) => `slider:${ctx.uid}:marker:${value}`,
575
+ getRootEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getRootId(ctx)),
631
576
  getThumbEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getThumbId(ctx)),
632
577
  getControlEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getControlId(ctx)),
633
578
  getInputEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getInputId(ctx)),
634
- getControlStyle,
635
- getThumbStyle,
636
- getRangeStyle,
637
579
  getValueFromPoint(ctx, point) {
638
580
  const control = dom.getControlEl(ctx);
639
581
  if (!control)
@@ -652,25 +594,16 @@ var dom = {
652
594
  if (!input)
653
595
  return;
654
596
  dispatchInputValueEvent(input, ctx.value);
655
- },
656
- getMarkerStyle(ctx, percent) {
657
- const style = {
658
- position: "absolute",
659
- pointerEvents: "none"
660
- };
661
- if (ctx.isHorizontal) {
662
- percent = ctx.isRtl ? 100 - percent : percent;
663
- style.left = `${percent}%`;
664
- } else {
665
- style.bottom = `${percent}%`;
666
- }
667
- return style;
668
597
  }
669
- };
598
+ });
670
599
 
671
600
  // ../../types/dist/index.mjs
672
601
  function createNormalizer(fn) {
673
- return { button: fn, label: fn, input: fn, output: fn, element: fn };
602
+ return new Proxy({}, {
603
+ get() {
604
+ return fn;
605
+ }
606
+ });
674
607
  }
675
608
  var normalizeProp = createNormalizer((v) => v);
676
609
 
@@ -713,14 +646,18 @@ function connect(state2, send, normalize = normalizeProp) {
713
646
  rootProps: normalize.element({
714
647
  "data-part": "root",
715
648
  "data-disabled": dataAttr(isDisabled),
649
+ "data-focus": dataAttr(isFocused),
716
650
  "data-orientation": state2.context.orientation,
651
+ "data-invalid": dataAttr(isInvalid),
717
652
  id: dom.getRootId(state2.context),
718
- dir: state2.context.dir
653
+ dir: state2.context.dir,
654
+ style: dom.getRootStyle(state2.context)
719
655
  }),
720
656
  labelProps: normalize.label({
721
657
  "data-part": "label",
722
658
  "data-disabled": dataAttr(isDisabled),
723
659
  "data-invalid": dataAttr(isInvalid),
660
+ "data-focus": dataAttr(isFocused),
724
661
  id: dom.getLabelId(state2.context),
725
662
  htmlFor: dom.getInputId(state2.context),
726
663
  onClick(event) {
@@ -730,9 +667,7 @@ function connect(state2, send, normalize = normalizeProp) {
730
667
  event.preventDefault();
731
668
  (_a2 = dom.getThumbEl(state2.context)) == null ? void 0 : _a2.focus();
732
669
  },
733
- style: {
734
- userSelect: "none"
735
- }
670
+ style: dom.getLabelStyle()
736
671
  }),
737
672
  thumbProps: normalize.element({
738
673
  "data-part": "thumb",
@@ -829,14 +764,15 @@ function connect(state2, send, normalize = normalizeProp) {
829
764
  "data-part": "track",
830
765
  id: dom.getTrackId(state2.context),
831
766
  "data-disabled": dataAttr(isDisabled),
767
+ "data-focus": dataAttr(isFocused),
832
768
  "data-invalid": dataAttr(isInvalid),
833
769
  "data-orientation": state2.context.orientation,
834
- "data-focus": dataAttr(isFocused),
835
- style: { position: "relative" }
770
+ style: dom.getTrackStyle()
836
771
  }),
837
772
  rangeProps: normalize.element({
838
773
  "data-part": "range",
839
774
  id: dom.getRangeId(state2.context),
775
+ "data-focus": dataAttr(isFocused),
840
776
  "data-invalid": dataAttr(isInvalid),
841
777
  "data-disabled": dataAttr(isDisabled),
842
778
  "data-orientation": state2.context.orientation,
@@ -860,18 +796,14 @@ function connect(state2, send, normalize = normalizeProp) {
860
796
  event.preventDefault();
861
797
  event.stopPropagation();
862
798
  },
863
- style: dom.getControlStyle(state2.context)
799
+ style: dom.getControlStyle()
864
800
  }),
865
801
  markerGroupProps: normalize.element({
866
802
  "data-part": "marker-group",
867
803
  role: "presentation",
868
804
  "aria-hidden": true,
869
805
  "data-orientation": state2.context.orientation,
870
- style: {
871
- userSelect: "none",
872
- pointerEvents: "none",
873
- position: "relative"
874
- }
806
+ style: dom.getMarkerGroupStyle()
875
807
  }),
876
808
  getMarkerProps({ value }) {
877
809
  const percent = valueToPercent(value, state2.context);
@@ -879,6 +811,7 @@ function connect(state2, send, normalize = normalizeProp) {
879
811
  const markerState = value > state2.context.value ? "over-value" : value < state2.context.value ? "under-value" : "at-value";
880
812
  return normalize.element({
881
813
  "data-part": "marker",
814
+ role: "presentation",
882
815
  "data-orientation": state2.context.orientation,
883
816
  id: dom.getMarkerId(state2.context, value),
884
817
  "data-value": value,
@@ -898,6 +831,7 @@ function machine(ctx = {}) {
898
831
  initial: "unknown",
899
832
  context: __spreadValues({
900
833
  thumbSize: null,
834
+ thumbAlignment: "contain",
901
835
  uid: "",
902
836
  disabled: false,
903
837
  threshold: 5,
@@ -920,7 +854,7 @@ function machine(ctx = {}) {
920
854
  watch: {
921
855
  value: ["invokeOnChange", "dispatchChangeEvent"]
922
856
  },
923
- activities: ["trackFormReset", "trackScriptedUpdate"],
857
+ activities: ["trackFormReset", "trackFieldsetDisabled"],
924
858
  on: {
925
859
  SET_VALUE: {
926
860
  actions: "setValue"
@@ -1008,17 +942,12 @@ function machine(ctx = {}) {
1008
942
  isVertical: (ctx2) => ctx2.isVertical
1009
943
  },
1010
944
  activities: {
1011
- trackScriptedUpdate(ctx2, _, { send }) {
945
+ trackFieldsetDisabled(ctx2) {
1012
946
  let cleanup;
1013
947
  nextTick(() => {
1014
- const el = dom.getInputEl(ctx2);
1015
- if (!el)
1016
- return;
1017
- cleanup = trackInputPropertyMutation(el, {
1018
- type: "input",
1019
- property: "value",
1020
- fn(value) {
1021
- send({ type: "SET_VALUE", value: parseFloat(value) });
948
+ cleanup = trackFieldsetDisabled(dom.getRootEl(ctx2), (disabled) => {
949
+ if (disabled) {
950
+ ctx2.disabled = disabled;
1022
951
  }
1023
952
  });
1024
953
  });
@@ -1027,15 +956,13 @@ function machine(ctx = {}) {
1027
956
  trackFormReset(ctx2) {
1028
957
  let cleanup;
1029
958
  nextTick(() => {
1030
- const el = dom.getInputEl(ctx2);
1031
- if (!el)
1032
- return;
1033
- cleanup = trackFormReset(el, () => {
1034
- if (ctx2.initialValue != null)
959
+ cleanup = trackFormReset(dom.getInputEl(ctx2), () => {
960
+ if (ctx2.initialValue != null) {
1035
961
  ctx2.value = ctx2.initialValue;
962
+ }
1036
963
  });
1037
964
  });
1038
- return cleanup;
965
+ return () => cleanup == null ? void 0 : cleanup();
1039
966
  },
1040
967
  trackPointerMove(ctx2, _evt, { send }) {
1041
968
  return trackPointerMove({
@@ -1077,6 +1004,8 @@ function machine(ctx = {}) {
1077
1004
  dom.dispatchChangeEvent(ctx2);
1078
1005
  },
1079
1006
  setThumbSize(ctx2) {
1007
+ if (ctx2.thumbAlignment !== "contain")
1008
+ return;
1080
1009
  raf(() => {
1081
1010
  const el = dom.getThumbEl(ctx2);
1082
1011
  if (!el)
@@ -1091,7 +1020,7 @@ function machine(ctx = {}) {
1091
1020
  ctx2.value = utils.clamp(ctx2, value);
1092
1021
  },
1093
1022
  focusThumb(ctx2) {
1094
- nextTick(() => {
1023
+ raf(() => {
1095
1024
  var _a;
1096
1025
  return (_a = dom.getThumbEl(ctx2)) == null ? void 0 : _a.focus();
1097
1026
  });
@@ -1114,4 +1043,3 @@ function machine(ctx = {}) {
1114
1043
  }
1115
1044
  });
1116
1045
  }
1117
- //# sourceMappingURL=index.js.map