@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.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __defProps = Object.defineProperties;
3
4
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
@@ -23,104 +24,34 @@ var __pow = Math.pow;
23
24
  var dataAttr = (guard) => {
24
25
  return guard ? "" : void 0;
25
26
  };
26
- function nextTick(fn) {
27
- const set = /* @__PURE__ */ new Set();
28
- function raf2(fn2) {
29
- const id = globalThis.requestAnimationFrame(fn2);
30
- set.add(() => globalThis.cancelAnimationFrame(id));
31
- }
32
- raf2(() => raf2(fn));
33
- return function cleanup() {
34
- set.forEach(function(fn2) {
35
- fn2();
36
- });
37
- };
38
- }
39
- function raf(fn) {
40
- const id = globalThis.requestAnimationFrame(fn);
41
- return function cleanup() {
42
- globalThis.cancelAnimationFrame(id);
43
- };
44
- }
45
- var noop = () => {
46
- };
47
- var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
48
- var platform = (v) => isDom() && v.test(navigator.platform);
49
- var isDom = () => !!(typeof window !== "undefined");
50
- var isMac = () => platform(/^Mac/);
51
- var isIPhone = () => platform(/^iPhone/);
52
- var isIPad = () => platform(/^iPad/) || isMac() && navigator.maxTouchPoints > 1;
53
- var isIos = () => isIPhone() || isIPad();
27
+ var isDom = () => typeof window !== "undefined";
54
28
  var isArray = (v) => Array.isArray(v);
55
29
  var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
56
- var isMouseEvent = (v) => isObject(v) && "button" in v;
57
- var isLeftClick = (v) => v.button === 0;
58
- function getListenerElements() {
59
- ;
60
- globalThis.__listenerElements__ = globalThis.__listenerElements__ || /* @__PURE__ */ new Map();
61
- return globalThis.__listenerElements__;
62
- }
63
- function getListenerCache() {
64
- ;
65
- globalThis.__listenerCache__ = globalThis.__listenerCache__ || /* @__PURE__ */ new Map();
66
- return globalThis.__listenerCache__;
67
- }
68
- function globalEventBus(node, type, handler, options) {
30
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
31
+ function getPlatform() {
69
32
  var _a;
70
- if (!node)
71
- return noop;
72
- const hash = JSON.stringify({ type, options });
73
- const listenerElements = getListenerElements();
74
- const listenerCache = getListenerCache();
75
- const group = listenerElements.get(node);
76
- if (!listenerElements.has(node)) {
77
- const group2 = /* @__PURE__ */ new Map([[hash, /* @__PURE__ */ new Set([handler])]]);
78
- listenerElements.set(node, group2);
79
- } else if (group == null ? void 0 : group.has(hash)) {
80
- (_a = group == null ? void 0 : group.get(hash)) == null ? void 0 : _a.add(handler);
81
- } else {
82
- group == null ? void 0 : group.set(hash, /* @__PURE__ */ new Set([handler]));
83
- }
84
- function attach(node2) {
85
- var _a2, _b;
86
- function listener(event) {
87
- var _a3;
88
- const group2 = listenerElements.get(node2);
89
- (_a3 = group2 == null ? void 0 : group2.get(hash)) == null ? void 0 : _a3.forEach((fn) => fn(event));
90
- }
91
- if (!(listenerCache == null ? void 0 : listenerCache.has(node2))) {
92
- listenerCache.set(node2, /* @__PURE__ */ new Map([[hash, listener]]));
93
- node2.addEventListener(type, listener, options);
94
- return;
95
- }
96
- if (!((_a2 = listenerCache == null ? void 0 : listenerCache.get(node2)) == null ? void 0 : _a2.has(hash))) {
97
- (_b = listenerCache.get(node2)) == null ? void 0 : _b.set(hash, listener);
98
- node2.addEventListener(type, listener, options);
99
- }
100
- }
101
- attach(node);
102
- return function remove() {
103
- var _a2, _b, _c, _d;
104
- if (!listenerElements.has(node))
105
- return;
106
- const group2 = listenerElements.get(node);
107
- (_a2 = group2 == null ? void 0 : group2.get(hash)) == null ? void 0 : _a2.delete(handler);
108
- if (((_b = group2 == null ? void 0 : group2.get(hash)) == null ? void 0 : _b.size) === 0) {
109
- const listener = (_c = listenerCache.get(node)) == null ? void 0 : _c.get(hash);
110
- node.removeEventListener(type, listener, options);
111
- group2 == null ? void 0 : group2.delete(hash);
112
- (_d = listenerCache.get(node)) == null ? void 0 : _d.delete(hash);
113
- if ((group2 == null ? void 0 : group2.size) === 0) {
114
- listenerElements.delete(node);
115
- listenerCache.delete(node);
116
- }
117
- }
118
- };
33
+ const agent = navigator.userAgentData;
34
+ return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
119
35
  }
120
- var t = (v) => Object.prototype.toString.call(v).slice(8, -1);
121
- var isRef = (v) => t(v) === "Object" && "current" in v;
122
- var runIfFn = (fn) => t(fn) === "Function" ? fn() : fn;
123
- var isTouchEvent = (v) => t(v) === "Object" && !!v.touches;
36
+ var pt = (v) => isDom() && v.test(getPlatform());
37
+ var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
38
+ var isMac = () => pt(/^Mac/) && !isTouchDevice;
39
+ var isApple = () => pt(/mac|iphone|ipad|ipod/i);
40
+ var isIos = () => isApple() && !isMac();
41
+ var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
42
+ var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
43
+ var supportsMouseEvent = () => isDom() && window.onmousedown === null;
44
+ var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
45
+ var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
46
+ var isLeftClick = (v) => v.button === 0;
47
+ var runIfFn = (v, ...a) => {
48
+ const res = typeof v === "function" ? v(...a) : v;
49
+ return res != null ? res : void 0;
50
+ };
51
+ var noop = () => {
52
+ };
53
+ var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
54
+ var isRef = (v) => hasProp(v, "current");
124
55
  var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
125
56
  function extractInfo(event, type = "page") {
126
57
  const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback : event;
@@ -131,9 +62,12 @@ function extractInfo(event, type = "page") {
131
62
  }
132
63
  };
133
64
  }
134
- function addDomEvent(target, event, listener, options) {
65
+ function addDomEvent(target, eventName, handler, options) {
135
66
  const node = isRef(target) ? target.current : runIfFn(target);
136
- return globalEventBus(node, event, listener, options);
67
+ node == null ? void 0 : node.addEventListener(eventName, handler, options);
68
+ return () => {
69
+ node == null ? void 0 : node.removeEventListener(eventName, handler, options);
70
+ };
137
71
  }
138
72
  function addPointerEvent(target, event, listener, options) {
139
73
  var _a;
@@ -156,9 +90,6 @@ function filterPrimaryPointer(fn) {
156
90
  fn(event);
157
91
  };
158
92
  }
159
- var supportsPointerEvent = () => typeof window !== "undefined" && window.onpointerdown === null;
160
- var supportsTouchEvent = () => typeof window !== "undefined" && window.ontouchstart === null;
161
- var supportsMouseEvent = () => typeof window !== "undefined" && window.onmousedown === null;
162
93
  var mouseEventNames = {
163
94
  pointerdown: "mousedown",
164
95
  pointermove: "mousemove",
@@ -184,70 +115,91 @@ function getEventName(evt) {
184
115
  return mouseEventNames[evt];
185
116
  return evt;
186
117
  }
118
+ function nextTick(fn) {
119
+ const set = /* @__PURE__ */ new Set();
120
+ function raf2(fn2) {
121
+ const id = globalThis.requestAnimationFrame(fn2);
122
+ set.add(() => globalThis.cancelAnimationFrame(id));
123
+ }
124
+ raf2(() => raf2(fn));
125
+ return function cleanup() {
126
+ set.forEach(function(fn2) {
127
+ fn2();
128
+ });
129
+ };
130
+ }
131
+ function raf(fn) {
132
+ const id = globalThis.requestAnimationFrame(fn);
133
+ return function cleanup() {
134
+ globalThis.cancelAnimationFrame(id);
135
+ };
136
+ }
187
137
  function getOwnerWindow(el) {
188
138
  var _a;
189
139
  return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
190
140
  }
191
- function getDescriptor(el, options) {
141
+ function getNativeEvent(e) {
192
142
  var _a;
193
- const { type, property } = options;
194
- const win = getOwnerWindow(el);
195
- const _type = type === "input" ? "HTMLInputElement" : "HTMLTextAreaElement";
196
- const proto = win[_type].prototype;
197
- return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
143
+ return (_a = e.nativeEvent) != null ? _a : e;
198
144
  }
199
- function dispatchInputValueEvent(el, value) {
200
- var _a;
201
- const win = getOwnerWindow(el);
202
- if (!(el instanceof win.HTMLInputElement))
203
- return;
204
- const desc = getDescriptor(el, { type: "input", property: "value" });
205
- (_a = desc.set) == null ? void 0 : _a.call(el, value);
206
- const event = new win.Event("input", { bubbles: true });
207
- el.dispatchEvent(event);
208
- }
209
- function trackInputPropertyMutation(el, options) {
210
- const { fn, property, type } = options;
211
- if (!fn || !el)
212
- return;
213
- const { get, set } = getDescriptor(el, { property, type });
214
- let run = true;
215
- Object.defineProperty(el, property, {
216
- get() {
217
- return get == null ? void 0 : get.call(this);
218
- },
219
- set(value) {
220
- if (run)
221
- fn(value);
222
- return set == null ? void 0 : set.call(this, value);
145
+ function observeAttributes(node, attributes, fn) {
146
+ if (!node)
147
+ return noop;
148
+ const attrs = Array.isArray(attributes) ? attributes : [attributes];
149
+ const win = node.ownerDocument.defaultView || window;
150
+ const obs = new win.MutationObserver((changes) => {
151
+ for (const change of changes) {
152
+ if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
153
+ fn(change);
154
+ }
223
155
  }
224
156
  });
225
- return function() {
226
- run = false;
227
- };
157
+ obs.observe(node, { attributes: true, attributeFilter: attrs });
158
+ return () => obs.disconnect();
228
159
  }
229
- function getNativeEvent(event) {
230
- var _a;
231
- return (_a = event.nativeEvent) != null ? _a : event;
232
- }
233
- function getClosestFormElement(el) {
160
+ function getClosestForm(el) {
234
161
  if (isFormElement(el))
235
162
  return el.form;
236
163
  else
237
164
  return el.closest("form");
238
165
  }
239
166
  function isFormElement(el) {
240
- return ["textarea", "input", "select", "button"].includes(el.localName);
167
+ return el.matches("textarea, input, select, button");
241
168
  }
242
169
  function trackFormReset(el, callback) {
243
170
  if (!el)
244
171
  return;
245
- const form = getClosestFormElement(el);
172
+ const form = getClosestForm(el);
246
173
  form == null ? void 0 : form.addEventListener("reset", callback, { passive: true });
247
174
  return () => {
248
175
  form == null ? void 0 : form.removeEventListener("reset", callback);
249
176
  };
250
177
  }
178
+ function trackFieldsetDisabled(el, callback) {
179
+ const fieldset = el == null ? void 0 : el.closest("fieldset");
180
+ if (!fieldset)
181
+ return;
182
+ callback(fieldset.disabled);
183
+ return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
184
+ }
185
+ function getDescriptor(el, options) {
186
+ var _a;
187
+ const { type, property } = options;
188
+ const win = getOwnerWindow(el);
189
+ const _type = type === "input" ? "HTMLInputElement" : "HTMLTextAreaElement";
190
+ const proto = win[_type].prototype;
191
+ return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
192
+ }
193
+ function dispatchInputValueEvent(el, value) {
194
+ var _a;
195
+ const win = getOwnerWindow(el);
196
+ if (!(el instanceof win.HTMLInputElement))
197
+ return;
198
+ const desc = getDescriptor(el, { type: "input", property: "value" });
199
+ (_a = desc.set) == null ? void 0 : _a.call(el, value);
200
+ const event = new win.Event("input", { bubbles: true });
201
+ el.dispatchEvent(event);
202
+ }
251
203
  var rtlKeyMap = {
252
204
  ArrowLeft: "ArrowRight",
253
205
  ArrowRight: "ArrowLeft",
@@ -285,30 +237,6 @@ function getEventStep(event) {
285
237
  return isSkipKey ? 10 : 1;
286
238
  }
287
239
  }
288
- function itemById(v, id) {
289
- return v.find((node) => node.id === id);
290
- }
291
- function indexOfId(v, id) {
292
- const item = itemById(v, id);
293
- return item ? v.indexOf(item) : -1;
294
- }
295
- var getValueText = (item) => {
296
- var _a, _b;
297
- return (_b = (_a = item.dataset.valuetext) != null ? _a : item.textContent) != null ? _b : "";
298
- };
299
- var match = (valueText, query2) => valueText.toLowerCase().startsWith(query2.toLowerCase());
300
- var wrap = (v, idx) => {
301
- return v.map((_, index) => v[(Math.max(idx, 0) + index) % v.length]);
302
- };
303
- function findByText(v, text, currentId) {
304
- const index = currentId ? indexOfId(v, currentId) : -1;
305
- let items = currentId ? wrap(v, index) : v;
306
- const isSingleKey = text.length === 1;
307
- if (isSingleKey) {
308
- items = items.filter((item) => item.id !== currentId);
309
- }
310
- return items.find((item) => match(getValueText(item), text));
311
- }
312
240
  var state = "default";
313
241
  var savedUserSelect = "";
314
242
  var modifiedElementMap = /* @__PURE__ */ new WeakMap();
@@ -372,42 +300,33 @@ function trackPointerMove(opts) {
372
300
  };
373
301
  return pipe(addPointerEvent(doc, "pointermove", handlePointerMove, false), addPointerEvent(doc, "pointerup", onPointerUp, false), addPointerEvent(doc, "pointercancel", onPointerUp, false), addPointerEvent(doc, "contextmenu", onPointerUp, false), disableTextSelection({ doc }));
374
302
  }
375
- function findByTypeahead(_items, options) {
376
- const { state: state2, activeId, key, timeout = 350 } = options;
377
- const search = state2.keysSoFar + key;
378
- const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]);
379
- const query2 = isRepeated ? search[0] : search;
380
- let items = _items.slice();
381
- const next = findByText(items, query2, activeId);
382
- function cleanup() {
383
- clearTimeout(state2.timer);
384
- state2.timer = -1;
385
- }
386
- function update(value) {
387
- state2.keysSoFar = value;
388
- cleanup();
389
- if (value !== "") {
390
- state2.timer = +setTimeout(() => {
391
- update("");
392
- cleanup();
393
- }, timeout);
394
- }
395
- }
396
- update(search);
397
- return next;
303
+
304
+ // ../../utilities/rect/dist/index.mjs
305
+ var isArray2 = (v) => Array.isArray(v);
306
+ var isObject2 = (v) => !(v == null || typeof v !== "object" || isArray2(v));
307
+ var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
308
+ var isTouchEvent2 = (v) => isObject2(v) && hasProp2(v, "touches");
309
+ var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
310
+ function getEventPoint(e, t = "page") {
311
+ const p = isTouchEvent2(e) ? e.touches[0] || e.changedTouches[0] || fallback2 : e;
312
+ return { x: p[`${t}X`], y: p[`${t}Y`] };
313
+ }
314
+ function relativeToNode(p, el) {
315
+ const dx = p.x - el.offsetLeft - el.clientLeft + el.scrollLeft;
316
+ const dy = p.y - el.offsetTop - el.clientTop + el.scrollTop;
317
+ return {
318
+ point: { x: dx, y: dy },
319
+ progress: { x: dx / el.offsetWidth, y: dy / el.offsetHeight }
320
+ };
398
321
  }
399
- findByTypeahead.defaultOptions = {
400
- keysSoFar: "",
401
- timer: -1
402
- };
403
322
 
404
323
  // ../../utilities/number/dist/index.mjs
405
324
  var __pow2 = Math.pow;
406
- function round(v, t2) {
325
+ function round(v, t) {
407
326
  let num = valueOf(v);
408
- const p = __pow2(10, t2 != null ? t2 : 10);
327
+ const p = __pow2(10, t != null ? t : 10);
409
328
  num = Math.round(num * p) / p;
410
- return t2 ? num.toFixed(t2) : v.toString();
329
+ return t ? num.toFixed(t) : v.toString();
411
330
  }
412
331
  var valueToPercent = (v, r) => (valueOf(v) - r.min) * 100 / (r.max - r.min);
413
332
  var percentToValue = (v, r) => r.min + (r.max - r.min) * valueOf(v);
@@ -461,47 +380,7 @@ var transform = (a, b) => {
461
380
  };
462
381
  };
463
382
 
464
- // ../../utilities/rect/dist/index.mjs
465
- var isArray2 = (v) => Array.isArray(v);
466
- var isObject2 = (v) => !(v == null || typeof v !== "object" || isArray2(v));
467
- var isTouchEvent2 = (v) => isObject2(v) && "touches" in v;
468
- var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
469
- function getEventPoint(e, t2 = "page") {
470
- const p = isTouchEvent2(e) ? e.touches[0] || e.changedTouches[0] || fallback2 : e;
471
- return { x: p[`${t2}X`], y: p[`${t2}Y`] };
472
- }
473
- function relativeToNode(p, el) {
474
- const dx = p.x - el.offsetLeft - el.clientLeft + el.scrollLeft;
475
- const dy = p.y - el.offsetTop - el.clientTop + el.scrollTop;
476
- return {
477
- point: { x: dx, y: dy },
478
- progress: { x: dx / el.offsetWidth, y: dy / el.offsetHeight }
479
- };
480
- }
481
-
482
- // src/slider.utils.ts
483
- var utils = {
484
- fromPercent(ctx, percent) {
485
- percent = clamp(percent, { min: 0, max: 1 });
486
- return parseFloat(snapToStep(percentToValue(percent, ctx), ctx.step));
487
- },
488
- clamp(ctx, value) {
489
- return clamp(value, ctx);
490
- },
491
- convert(ctx, value) {
492
- return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
493
- },
494
- decrement(ctx, step) {
495
- let value = decrement(ctx.value, step != null ? step : ctx.step);
496
- return utils.convert(ctx, value);
497
- },
498
- increment(ctx, step) {
499
- let value = increment(ctx.value, step != null ? step : ctx.step);
500
- return utils.convert(ctx, value);
501
- }
502
- };
503
-
504
- // src/slider.dom.ts
383
+ // src/slider.style.ts
505
384
  function getVerticalThumbOffset(ctx) {
506
385
  var _a;
507
386
  const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
@@ -518,54 +397,119 @@ function getHorizontalThumbOffset(ctx) {
518
397
  const getValue = transform([ctx.min, ctx.max], [-width / 2, width / 2]);
519
398
  return parseFloat(getValue(ctx.value).toFixed(2));
520
399
  }
521
- function getThumbStyle(ctx) {
400
+ function getThumbOffset(ctx) {
522
401
  const percent = valueToPercent(ctx.value, ctx);
402
+ if (ctx.thumbAlignment === "center")
403
+ return `${percent}%`;
523
404
  const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
524
- const style = {
405
+ return `calc(${percent}% - ${offset}px)`;
406
+ }
407
+ function getThumbStyle(ctx) {
408
+ const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
409
+ return {
525
410
  visibility: ctx.hasMeasuredThumbSize ? "visible" : "hidden",
526
411
  position: "absolute",
527
412
  transform: "var(--slider-thumb-transform)",
528
- "--slider-thumb-placement": `calc(${percent}% - ${offset}px)`
413
+ [placementProp]: "var(--slider-thumb-offset)"
529
414
  };
530
- if (ctx.isVertical) {
531
- style.bottom = "var(--slider-thumb-placement)";
532
- } else {
533
- style[ctx.isRtl ? "right" : "left"] = "var(--slider-thumb-placement)";
534
- }
535
- return style;
536
415
  }
537
- function getRangeStyle(ctx) {
416
+ function getRangeOffsets(ctx) {
538
417
  const percent = valueToPercent(ctx.value, ctx);
539
- const style = {
540
- position: "absolute"
541
- };
542
- let startValue = "0%";
543
- let endValue = `${100 - percent}%`;
418
+ let start = "0%";
419
+ let end = `${100 - percent}%`;
544
420
  if (ctx.origin === "center") {
545
421
  const isNegative = percent < 50;
546
- startValue = isNegative ? `${percent}%` : "50%";
547
- endValue = isNegative ? "50%" : endValue;
422
+ start = isNegative ? `${percent}%` : "50%";
423
+ end = isNegative ? "50%" : end;
548
424
  }
425
+ return { start, end };
426
+ }
427
+ function getRangeStyle(ctx) {
549
428
  if (ctx.isVertical) {
550
- return __spreadProps(__spreadValues({}, style), {
551
- bottom: startValue,
552
- top: endValue
553
- });
429
+ return {
430
+ position: "absolute",
431
+ bottom: "var(--slider-range-start)",
432
+ top: "var(--slider-range-end)"
433
+ };
554
434
  }
555
- return __spreadProps(__spreadValues({}, style), {
556
- [ctx.isRtl ? "right" : "left"]: startValue,
557
- [ctx.isRtl ? "left" : "right"]: endValue
558
- });
435
+ return {
436
+ position: "absolute",
437
+ [ctx.isRtl ? "right" : "left"]: "var(--slider-range-start)",
438
+ [ctx.isRtl ? "left" : "right"]: "var(--slider-range-end)"
439
+ };
559
440
  }
560
- function getControlStyle(ctx) {
441
+ function getControlStyle() {
561
442
  return {
562
443
  touchAction: "none",
563
444
  userSelect: "none",
445
+ position: "relative"
446
+ };
447
+ }
448
+ function getRootStyle(ctx) {
449
+ const range = getRangeOffsets(ctx);
450
+ return {
564
451
  "--slider-thumb-transform": ctx.isVertical ? "translateY(50%)" : "translateX(-50%)",
452
+ "--slider-thumb-offset": getThumbOffset(ctx),
453
+ "--slider-range-start": range.start,
454
+ "--slider-range-end": range.end
455
+ };
456
+ }
457
+ function getMarkerStyle(ctx, percent) {
458
+ return {
459
+ position: "absolute",
460
+ pointerEvents: "none",
461
+ [ctx.isHorizontal ? "left" : "bottom"]: `${ctx.isRtl ? 100 - percent : percent}%`
462
+ };
463
+ }
464
+ function getLabelStyle() {
465
+ return { userSelect: "none" };
466
+ }
467
+ function getTrackStyle() {
468
+ return { position: "relative" };
469
+ }
470
+ function getMarkerGroupStyle() {
471
+ return {
472
+ userSelect: "none",
473
+ pointerEvents: "none",
565
474
  position: "relative"
566
475
  };
567
476
  }
568
- var dom = {
477
+ var styles = {
478
+ getThumbOffset,
479
+ getControlStyle,
480
+ getThumbStyle,
481
+ getRangeStyle,
482
+ getRootStyle,
483
+ getMarkerStyle,
484
+ getLabelStyle,
485
+ getTrackStyle,
486
+ getMarkerGroupStyle
487
+ };
488
+
489
+ // src/slider.utils.ts
490
+ var utils = {
491
+ fromPercent(ctx, percent) {
492
+ percent = clamp(percent, { min: 0, max: 1 });
493
+ return parseFloat(snapToStep(percentToValue(percent, ctx), ctx.step));
494
+ },
495
+ clamp(ctx, value) {
496
+ return clamp(value, ctx);
497
+ },
498
+ convert(ctx, value) {
499
+ return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
500
+ },
501
+ decrement(ctx, step) {
502
+ let value = decrement(ctx.value, step != null ? step : ctx.step);
503
+ return utils.convert(ctx, value);
504
+ },
505
+ increment(ctx, step) {
506
+ let value = increment(ctx.value, step != null ? step : ctx.step);
507
+ return utils.convert(ctx, value);
508
+ }
509
+ };
510
+
511
+ // src/slider.dom.ts
512
+ var dom = __spreadProps(__spreadValues({}, styles), {
569
513
  getDoc: (ctx) => {
570
514
  var _a;
571
515
  return (_a = ctx.doc) != null ? _a : document;
@@ -593,7 +537,7 @@ var dom = {
593
537
  },
594
538
  getTrackId: (ctx) => {
595
539
  var _a, _b;
596
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:-${ctx.uid}track`;
540
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.uid}track`;
597
541
  },
598
542
  getRangeId: (ctx) => {
599
543
  var _a, _b;
@@ -604,12 +548,10 @@ var dom = {
604
548
  return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.uid}:label`;
605
549
  },
606
550
  getMarkerId: (ctx, value) => `slider:${ctx.uid}:marker:${value}`,
551
+ getRootEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getRootId(ctx)),
607
552
  getThumbEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getThumbId(ctx)),
608
553
  getControlEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getControlId(ctx)),
609
554
  getInputEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getInputId(ctx)),
610
- getControlStyle,
611
- getThumbStyle,
612
- getRangeStyle,
613
555
  getValueFromPoint(ctx, point) {
614
556
  const control = dom.getControlEl(ctx);
615
557
  if (!control)
@@ -628,25 +570,16 @@ var dom = {
628
570
  if (!input)
629
571
  return;
630
572
  dispatchInputValueEvent(input, ctx.value);
631
- },
632
- getMarkerStyle(ctx, percent) {
633
- const style = {
634
- position: "absolute",
635
- pointerEvents: "none"
636
- };
637
- if (ctx.isHorizontal) {
638
- percent = ctx.isRtl ? 100 - percent : percent;
639
- style.left = `${percent}%`;
640
- } else {
641
- style.bottom = `${percent}%`;
642
- }
643
- return style;
644
573
  }
645
- };
574
+ });
646
575
 
647
576
  // ../../types/dist/index.mjs
648
577
  function createNormalizer(fn) {
649
- return { button: fn, label: fn, input: fn, output: fn, element: fn };
578
+ return new Proxy({}, {
579
+ get() {
580
+ return fn;
581
+ }
582
+ });
650
583
  }
651
584
  var normalizeProp = createNormalizer((v) => v);
652
585
 
@@ -689,14 +622,18 @@ function connect(state2, send, normalize = normalizeProp) {
689
622
  rootProps: normalize.element({
690
623
  "data-part": "root",
691
624
  "data-disabled": dataAttr(isDisabled),
625
+ "data-focus": dataAttr(isFocused),
692
626
  "data-orientation": state2.context.orientation,
627
+ "data-invalid": dataAttr(isInvalid),
693
628
  id: dom.getRootId(state2.context),
694
- dir: state2.context.dir
629
+ dir: state2.context.dir,
630
+ style: dom.getRootStyle(state2.context)
695
631
  }),
696
632
  labelProps: normalize.label({
697
633
  "data-part": "label",
698
634
  "data-disabled": dataAttr(isDisabled),
699
635
  "data-invalid": dataAttr(isInvalid),
636
+ "data-focus": dataAttr(isFocused),
700
637
  id: dom.getLabelId(state2.context),
701
638
  htmlFor: dom.getInputId(state2.context),
702
639
  onClick(event) {
@@ -706,9 +643,7 @@ function connect(state2, send, normalize = normalizeProp) {
706
643
  event.preventDefault();
707
644
  (_a2 = dom.getThumbEl(state2.context)) == null ? void 0 : _a2.focus();
708
645
  },
709
- style: {
710
- userSelect: "none"
711
- }
646
+ style: dom.getLabelStyle()
712
647
  }),
713
648
  thumbProps: normalize.element({
714
649
  "data-part": "thumb",
@@ -805,14 +740,15 @@ function connect(state2, send, normalize = normalizeProp) {
805
740
  "data-part": "track",
806
741
  id: dom.getTrackId(state2.context),
807
742
  "data-disabled": dataAttr(isDisabled),
743
+ "data-focus": dataAttr(isFocused),
808
744
  "data-invalid": dataAttr(isInvalid),
809
745
  "data-orientation": state2.context.orientation,
810
- "data-focus": dataAttr(isFocused),
811
- style: { position: "relative" }
746
+ style: dom.getTrackStyle()
812
747
  }),
813
748
  rangeProps: normalize.element({
814
749
  "data-part": "range",
815
750
  id: dom.getRangeId(state2.context),
751
+ "data-focus": dataAttr(isFocused),
816
752
  "data-invalid": dataAttr(isInvalid),
817
753
  "data-disabled": dataAttr(isDisabled),
818
754
  "data-orientation": state2.context.orientation,
@@ -836,18 +772,14 @@ function connect(state2, send, normalize = normalizeProp) {
836
772
  event.preventDefault();
837
773
  event.stopPropagation();
838
774
  },
839
- style: dom.getControlStyle(state2.context)
775
+ style: dom.getControlStyle()
840
776
  }),
841
777
  markerGroupProps: normalize.element({
842
778
  "data-part": "marker-group",
843
779
  role: "presentation",
844
780
  "aria-hidden": true,
845
781
  "data-orientation": state2.context.orientation,
846
- style: {
847
- userSelect: "none",
848
- pointerEvents: "none",
849
- position: "relative"
850
- }
782
+ style: dom.getMarkerGroupStyle()
851
783
  }),
852
784
  getMarkerProps({ value }) {
853
785
  const percent = valueToPercent(value, state2.context);
@@ -855,6 +787,7 @@ function connect(state2, send, normalize = normalizeProp) {
855
787
  const markerState = value > state2.context.value ? "over-value" : value < state2.context.value ? "under-value" : "at-value";
856
788
  return normalize.element({
857
789
  "data-part": "marker",
790
+ role: "presentation",
858
791
  "data-orientation": state2.context.orientation,
859
792
  id: dom.getMarkerId(state2.context, value),
860
793
  "data-value": value,
@@ -874,6 +807,7 @@ function machine(ctx = {}) {
874
807
  initial: "unknown",
875
808
  context: __spreadValues({
876
809
  thumbSize: null,
810
+ thumbAlignment: "contain",
877
811
  uid: "",
878
812
  disabled: false,
879
813
  threshold: 5,
@@ -896,7 +830,7 @@ function machine(ctx = {}) {
896
830
  watch: {
897
831
  value: ["invokeOnChange", "dispatchChangeEvent"]
898
832
  },
899
- activities: ["trackFormReset", "trackScriptedUpdate"],
833
+ activities: ["trackFormReset", "trackFieldsetDisabled"],
900
834
  on: {
901
835
  SET_VALUE: {
902
836
  actions: "setValue"
@@ -984,17 +918,12 @@ function machine(ctx = {}) {
984
918
  isVertical: (ctx2) => ctx2.isVertical
985
919
  },
986
920
  activities: {
987
- trackScriptedUpdate(ctx2, _, { send }) {
921
+ trackFieldsetDisabled(ctx2) {
988
922
  let cleanup;
989
923
  nextTick(() => {
990
- const el = dom.getInputEl(ctx2);
991
- if (!el)
992
- return;
993
- cleanup = trackInputPropertyMutation(el, {
994
- type: "input",
995
- property: "value",
996
- fn(value) {
997
- send({ type: "SET_VALUE", value: parseFloat(value) });
924
+ cleanup = trackFieldsetDisabled(dom.getRootEl(ctx2), (disabled) => {
925
+ if (disabled) {
926
+ ctx2.disabled = disabled;
998
927
  }
999
928
  });
1000
929
  });
@@ -1003,15 +932,13 @@ function machine(ctx = {}) {
1003
932
  trackFormReset(ctx2) {
1004
933
  let cleanup;
1005
934
  nextTick(() => {
1006
- const el = dom.getInputEl(ctx2);
1007
- if (!el)
1008
- return;
1009
- cleanup = trackFormReset(el, () => {
1010
- if (ctx2.initialValue != null)
935
+ cleanup = trackFormReset(dom.getInputEl(ctx2), () => {
936
+ if (ctx2.initialValue != null) {
1011
937
  ctx2.value = ctx2.initialValue;
938
+ }
1012
939
  });
1013
940
  });
1014
- return cleanup;
941
+ return () => cleanup == null ? void 0 : cleanup();
1015
942
  },
1016
943
  trackPointerMove(ctx2, _evt, { send }) {
1017
944
  return trackPointerMove({
@@ -1053,6 +980,8 @@ function machine(ctx = {}) {
1053
980
  dom.dispatchChangeEvent(ctx2);
1054
981
  },
1055
982
  setThumbSize(ctx2) {
983
+ if (ctx2.thumbAlignment !== "contain")
984
+ return;
1056
985
  raf(() => {
1057
986
  const el = dom.getThumbEl(ctx2);
1058
987
  if (!el)
@@ -1067,7 +996,7 @@ function machine(ctx = {}) {
1067
996
  ctx2.value = utils.clamp(ctx2, value);
1068
997
  },
1069
998
  focusThumb(ctx2) {
1070
- nextTick(() => {
999
+ raf(() => {
1071
1000
  var _a;
1072
1001
  return (_a = dom.getThumbEl(ctx2)) == null ? void 0 : _a.focus();
1073
1002
  });
@@ -1095,4 +1024,3 @@ export {
1095
1024
  machine,
1096
1025
  dom as unstable__dom
1097
1026
  };
1098
- //# sourceMappingURL=index.mjs.map