@zag-js/slider 0.1.6 → 0.1.9

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
@@ -23,196 +23,47 @@ var __pow = Math.pow;
23
23
  var dataAttr = (guard) => {
24
24
  return guard ? "" : void 0;
25
25
  };
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 = () => {
26
+ var runIfFn = (v, ...a) => {
27
+ const res = typeof v === "function" ? v(...a) : v;
28
+ return res != null ? res : void 0;
29
+ };
30
+ var callAll = (...fns) => (...a) => {
31
+ fns.forEach(function(fn) {
32
+ fn == null ? void 0 : fn(...a);
33
+ });
46
34
  };
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();
54
35
  var isArray = (v) => Array.isArray(v);
55
36
  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) {
37
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
38
+ var isDom = () => typeof window !== "undefined";
39
+ function getPlatform() {
69
40
  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
- };
41
+ const agent = navigator.userAgentData;
42
+ return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
119
43
  }
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;
124
- var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
125
- function extractInfo(event, type = "page") {
126
- const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback : event;
127
- return {
128
- point: {
129
- x: point[`${type}X`],
130
- y: point[`${type}Y`]
131
- }
132
- };
133
- }
134
- function addDomEvent(target, event, listener, options) {
135
- const node = isRef(target) ? target.current : runIfFn(target);
136
- return globalEventBus(node, event, listener, options);
137
- }
138
- function addPointerEvent(target, event, listener, options) {
139
- var _a;
140
- const type = (_a = getEventName(event)) != null ? _a : event;
141
- return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
142
- }
143
- function wrapHandler(fn, filter = false) {
144
- const listener = (event) => {
145
- fn(event, extractInfo(event));
146
- };
147
- return filter ? filterPrimaryPointer(listener) : listener;
148
- }
149
- function filterPrimaryPointer(fn) {
150
- return (event) => {
151
- var _a;
152
- const win = (_a = event.view) != null ? _a : window;
153
- const isMouseEvent2 = event instanceof win.MouseEvent;
154
- const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
155
- if (isPrimary)
156
- fn(event);
157
- };
158
- }
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
- var mouseEventNames = {
163
- pointerdown: "mousedown",
164
- pointermove: "mousemove",
165
- pointerup: "mouseup",
166
- pointercancel: "mousecancel",
167
- pointerover: "mouseover",
168
- pointerout: "mouseout",
169
- pointerenter: "mouseenter",
170
- pointerleave: "mouseleave"
171
- };
172
- var touchEventNames = {
173
- pointerdown: "touchstart",
174
- pointermove: "touchmove",
175
- pointerup: "touchend",
176
- pointercancel: "touchcancel"
177
- };
178
- function getEventName(evt) {
179
- if (supportsPointerEvent())
180
- return evt;
181
- if (supportsTouchEvent())
182
- return touchEventNames[evt];
183
- if (supportsMouseEvent())
184
- return mouseEventNames[evt];
185
- return evt;
186
- }
187
- function getOwnerWindow(el) {
44
+ var pt = (v) => isDom() && v.test(getPlatform());
45
+ var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
46
+ var isMac = () => pt(/^Mac/) && !isTouchDevice;
47
+ var isApple = () => pt(/mac|iphone|ipad|ipod/i);
48
+ var isIos = () => isApple() && !isMac();
49
+ function getWindow(el) {
188
50
  var _a;
189
51
  return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
190
52
  }
191
- function getDescriptor(el, options) {
192
- 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 : {};
198
- }
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 getNativeEvent(event) {
53
+ function getNativeEvent(e) {
210
54
  var _a;
211
- return (_a = event.nativeEvent) != null ? _a : event;
55
+ return (_a = e.nativeEvent) != null ? _a : e;
212
56
  }
57
+ var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
58
+ var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
59
+ var supportsMouseEvent = () => isDom() && window.onmousedown === null;
60
+ var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
61
+ var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
62
+ var isLeftClick = (v) => v.button === 0;
63
+ var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
213
64
  function observeAttributes(node, attributes, fn) {
214
65
  if (!node)
215
- return noop;
66
+ return;
216
67
  const attrs = Array.isArray(attributes) ? attributes : [attributes];
217
68
  const win = node.ownerDocument.defaultView || window;
218
69
  const obs = new win.MutationObserver((changes) => {
@@ -250,6 +101,61 @@ function trackFieldsetDisabled(el, callback) {
250
101
  callback(fieldset.disabled);
251
102
  return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
252
103
  }
104
+ function getElementOffset(element) {
105
+ let left = 0;
106
+ let top = 0;
107
+ let el = element;
108
+ if (el.parentNode) {
109
+ do {
110
+ left += el.offsetLeft;
111
+ top += el.offsetTop;
112
+ } while ((el = el.offsetParent) && el.nodeType < 9);
113
+ el = element;
114
+ do {
115
+ left -= el.scrollLeft;
116
+ top -= el.scrollTop;
117
+ } while ((el = el.parentNode) && !/body/i.test(el.nodeName));
118
+ }
119
+ return {
120
+ top,
121
+ right: innerWidth - left - element.offsetWidth,
122
+ bottom: innerHeight - top - element.offsetHeight,
123
+ left
124
+ };
125
+ }
126
+ var fallback = {
127
+ pageX: 0,
128
+ pageY: 0,
129
+ clientX: 0,
130
+ clientY: 0
131
+ };
132
+ function getEventPoint(event, type = "page") {
133
+ var _a, _b;
134
+ const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event;
135
+ return { x: point[`${type}X`], y: point[`${type}Y`] };
136
+ }
137
+ function getPointRelativeToNode(point, element) {
138
+ const offset = getElementOffset(element);
139
+ const x = point.x - offset.left;
140
+ const y = point.y - offset.top;
141
+ return { x, y };
142
+ }
143
+ function getDescriptor(el, options) {
144
+ var _a;
145
+ const { type, property } = options;
146
+ const proto = getWindow(el)[type].prototype;
147
+ return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
148
+ }
149
+ function dispatchInputValueEvent(el, value) {
150
+ var _a;
151
+ const win = getWindow(el);
152
+ if (!(el instanceof win.HTMLInputElement))
153
+ return;
154
+ const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
155
+ (_a = desc.set) == null ? void 0 : _a.call(el, value);
156
+ const event = new win.Event("input", { bubbles: true });
157
+ el.dispatchEvent(event);
158
+ }
253
159
  var rtlKeyMap = {
254
160
  ArrowLeft: "ArrowRight",
255
161
  ArrowRight: "ArrowLeft",
@@ -287,29 +193,88 @@ function getEventStep(event) {
287
193
  return isSkipKey ? 10 : 1;
288
194
  }
289
195
  }
290
- function itemById(v, id) {
291
- return v.find((node) => node.id === id);
196
+ var isRef = (v) => hasProp(v, "current");
197
+ var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
198
+ function extractInfo(event, type = "page") {
199
+ const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback2 : event;
200
+ return {
201
+ point: {
202
+ x: point[`${type}X`],
203
+ y: point[`${type}Y`]
204
+ }
205
+ };
292
206
  }
293
- function indexOfId(v, id) {
294
- const item = itemById(v, id);
295
- return item ? v.indexOf(item) : -1;
207
+ function addDomEvent(target, eventName, handler, options) {
208
+ const node = isRef(target) ? target.current : runIfFn(target);
209
+ node == null ? void 0 : node.addEventListener(eventName, handler, options);
210
+ return () => {
211
+ node == null ? void 0 : node.removeEventListener(eventName, handler, options);
212
+ };
296
213
  }
297
- var getValueText = (item) => {
298
- var _a, _b;
299
- return (_b = (_a = item.dataset.valuetext) != null ? _a : item.textContent) != null ? _b : "";
214
+ function addPointerEvent(target, event, listener, options) {
215
+ var _a;
216
+ const type = (_a = getEventName(event)) != null ? _a : event;
217
+ return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
218
+ }
219
+ function wrapHandler(fn, filter = false) {
220
+ const listener = (event) => {
221
+ fn(event, extractInfo(event));
222
+ };
223
+ return filter ? filterPrimaryPointer(listener) : listener;
224
+ }
225
+ function filterPrimaryPointer(fn) {
226
+ return (event) => {
227
+ var _a;
228
+ const win = (_a = event.view) != null ? _a : window;
229
+ const isMouseEvent2 = event instanceof win.MouseEvent;
230
+ const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
231
+ if (isPrimary)
232
+ fn(event);
233
+ };
234
+ }
235
+ var mouseEventNames = {
236
+ pointerdown: "mousedown",
237
+ pointermove: "mousemove",
238
+ pointerup: "mouseup",
239
+ pointercancel: "mousecancel",
240
+ pointerover: "mouseover",
241
+ pointerout: "mouseout",
242
+ pointerenter: "mouseenter",
243
+ pointerleave: "mouseleave"
300
244
  };
301
- var match = (valueText, query2) => valueText.toLowerCase().startsWith(query2.toLowerCase());
302
- var wrap = (v, idx) => {
303
- return v.map((_, index) => v[(Math.max(idx, 0) + index) % v.length]);
245
+ var touchEventNames = {
246
+ pointerdown: "touchstart",
247
+ pointermove: "touchmove",
248
+ pointerup: "touchend",
249
+ pointercancel: "touchcancel"
304
250
  };
305
- function findByText(v, text, currentId) {
306
- const index = currentId ? indexOfId(v, currentId) : -1;
307
- let items = currentId ? wrap(v, index) : v;
308
- const isSingleKey = text.length === 1;
309
- if (isSingleKey) {
310
- items = items.filter((item) => item.id !== currentId);
251
+ function getEventName(evt) {
252
+ if (supportsPointerEvent())
253
+ return evt;
254
+ if (supportsTouchEvent())
255
+ return touchEventNames[evt];
256
+ if (supportsMouseEvent())
257
+ return mouseEventNames[evt];
258
+ return evt;
259
+ }
260
+ function nextTick(fn) {
261
+ const set = /* @__PURE__ */ new Set();
262
+ function raf2(fn2) {
263
+ const id = globalThis.requestAnimationFrame(fn2);
264
+ set.add(() => globalThis.cancelAnimationFrame(id));
311
265
  }
312
- return items.find((item) => match(getValueText(item), text));
266
+ raf2(() => raf2(fn));
267
+ return function cleanup() {
268
+ set.forEach(function(fn2) {
269
+ fn2();
270
+ });
271
+ };
272
+ }
273
+ function raf(fn) {
274
+ const id = globalThis.requestAnimationFrame(fn);
275
+ return function cleanup() {
276
+ globalThis.cancelAnimationFrame(id);
277
+ };
313
278
  }
314
279
  var state = "default";
315
280
  var savedUserSelect = "";
@@ -372,44 +337,16 @@ function trackPointerMove(opts) {
372
337
  }
373
338
  onPointerMove(info, event);
374
339
  };
375
- return pipe(addPointerEvent(doc, "pointermove", handlePointerMove, false), addPointerEvent(doc, "pointerup", onPointerUp, false), addPointerEvent(doc, "pointercancel", onPointerUp, false), addPointerEvent(doc, "contextmenu", onPointerUp, false), disableTextSelection({ doc }));
376
- }
377
- function findByTypeahead(_items, options) {
378
- const { state: state2, activeId, key, timeout = 350 } = options;
379
- const search = state2.keysSoFar + key;
380
- const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]);
381
- const query2 = isRepeated ? search[0] : search;
382
- let items = _items.slice();
383
- const next = findByText(items, query2, activeId);
384
- function cleanup() {
385
- clearTimeout(state2.timer);
386
- state2.timer = -1;
387
- }
388
- function update(value) {
389
- state2.keysSoFar = value;
390
- cleanup();
391
- if (value !== "") {
392
- state2.timer = +setTimeout(() => {
393
- update("");
394
- cleanup();
395
- }, timeout);
396
- }
397
- }
398
- update(search);
399
- return next;
340
+ return callAll(addPointerEvent(doc, "pointermove", handlePointerMove, false), addPointerEvent(doc, "pointerup", onPointerUp, false), addPointerEvent(doc, "pointercancel", onPointerUp, false), addPointerEvent(doc, "contextmenu", onPointerUp, false), disableTextSelection({ doc }));
400
341
  }
401
- findByTypeahead.defaultOptions = {
402
- keysSoFar: "",
403
- timer: -1
404
- };
405
342
 
406
343
  // ../../utilities/number/dist/index.mjs
407
344
  var __pow2 = Math.pow;
408
- function round(v, t2) {
345
+ function round(v, t) {
409
346
  let num = valueOf(v);
410
- const p = __pow2(10, t2 != null ? t2 : 10);
347
+ const p = __pow2(10, t != null ? t : 10);
411
348
  num = Math.round(num * p) / p;
412
- return t2 ? num.toFixed(t2) : v.toString();
349
+ return t ? num.toFixed(t) : v.toString();
413
350
  }
414
351
  var valueToPercent = (v, r) => (valueOf(v) - r.min) * 100 / (r.max - r.min);
415
352
  var percentToValue = (v, r) => r.min + (r.max - r.min) * valueOf(v);
@@ -463,47 +400,7 @@ var transform = (a, b) => {
463
400
  };
464
401
  };
465
402
 
466
- // ../../utilities/rect/dist/index.mjs
467
- var isArray2 = (v) => Array.isArray(v);
468
- var isObject2 = (v) => !(v == null || typeof v !== "object" || isArray2(v));
469
- var isTouchEvent2 = (v) => isObject2(v) && "touches" in v;
470
- var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
471
- function getEventPoint(e, t2 = "page") {
472
- const p = isTouchEvent2(e) ? e.touches[0] || e.changedTouches[0] || fallback2 : e;
473
- return { x: p[`${t2}X`], y: p[`${t2}Y`] };
474
- }
475
- function relativeToNode(p, el) {
476
- const dx = p.x - el.offsetLeft - el.clientLeft + el.scrollLeft;
477
- const dy = p.y - el.offsetTop - el.clientTop + el.scrollTop;
478
- return {
479
- point: { x: dx, y: dy },
480
- progress: { x: dx / el.offsetWidth, y: dy / el.offsetHeight }
481
- };
482
- }
483
-
484
- // src/slider.utils.ts
485
- var utils = {
486
- fromPercent(ctx, percent) {
487
- percent = clamp(percent, { min: 0, max: 1 });
488
- return parseFloat(snapToStep(percentToValue(percent, ctx), ctx.step));
489
- },
490
- clamp(ctx, value) {
491
- return clamp(value, ctx);
492
- },
493
- convert(ctx, value) {
494
- return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
495
- },
496
- decrement(ctx, step) {
497
- let value = decrement(ctx.value, step != null ? step : ctx.step);
498
- return utils.convert(ctx, value);
499
- },
500
- increment(ctx, step) {
501
- let value = increment(ctx.value, step != null ? step : ctx.step);
502
- return utils.convert(ctx, value);
503
- }
504
- };
505
-
506
- // src/slider.dom.ts
403
+ // src/slider.style.ts
507
404
  function getVerticalThumbOffset(ctx) {
508
405
  var _a;
509
406
  const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
@@ -520,54 +417,119 @@ function getHorizontalThumbOffset(ctx) {
520
417
  const getValue = transform([ctx.min, ctx.max], [-width / 2, width / 2]);
521
418
  return parseFloat(getValue(ctx.value).toFixed(2));
522
419
  }
523
- function getThumbStyle(ctx) {
420
+ function getThumbOffset(ctx) {
524
421
  const percent = valueToPercent(ctx.value, ctx);
422
+ if (ctx.thumbAlignment === "center")
423
+ return `${percent}%`;
525
424
  const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
526
- const style = {
425
+ return `calc(${percent}% - ${offset}px)`;
426
+ }
427
+ function getThumbStyle(ctx) {
428
+ const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
429
+ return {
527
430
  visibility: ctx.hasMeasuredThumbSize ? "visible" : "hidden",
528
431
  position: "absolute",
529
432
  transform: "var(--slider-thumb-transform)",
530
- "--slider-thumb-placement": `calc(${percent}% - ${offset}px)`
433
+ [placementProp]: "var(--slider-thumb-offset)"
531
434
  };
532
- if (ctx.isVertical) {
533
- style.bottom = "var(--slider-thumb-placement)";
534
- } else {
535
- style[ctx.isRtl ? "right" : "left"] = "var(--slider-thumb-placement)";
536
- }
537
- return style;
538
435
  }
539
- function getRangeStyle(ctx) {
436
+ function getRangeOffsets(ctx) {
540
437
  const percent = valueToPercent(ctx.value, ctx);
541
- const style = {
542
- position: "absolute"
543
- };
544
- let startValue = "0%";
545
- let endValue = `${100 - percent}%`;
438
+ let start = "0%";
439
+ let end = `${100 - percent}%`;
546
440
  if (ctx.origin === "center") {
547
441
  const isNegative = percent < 50;
548
- startValue = isNegative ? `${percent}%` : "50%";
549
- endValue = isNegative ? "50%" : endValue;
442
+ start = isNegative ? `${percent}%` : "50%";
443
+ end = isNegative ? "50%" : end;
550
444
  }
445
+ return { start, end };
446
+ }
447
+ function getRangeStyle(ctx) {
551
448
  if (ctx.isVertical) {
552
- return __spreadProps(__spreadValues({}, style), {
553
- bottom: startValue,
554
- top: endValue
555
- });
449
+ return {
450
+ position: "absolute",
451
+ bottom: "var(--slider-range-start)",
452
+ top: "var(--slider-range-end)"
453
+ };
556
454
  }
557
- return __spreadProps(__spreadValues({}, style), {
558
- [ctx.isRtl ? "right" : "left"]: startValue,
559
- [ctx.isRtl ? "left" : "right"]: endValue
560
- });
455
+ return {
456
+ position: "absolute",
457
+ [ctx.isRtl ? "right" : "left"]: "var(--slider-range-start)",
458
+ [ctx.isRtl ? "left" : "right"]: "var(--slider-range-end)"
459
+ };
561
460
  }
562
- function getControlStyle(ctx) {
461
+ function getControlStyle() {
563
462
  return {
564
463
  touchAction: "none",
565
464
  userSelect: "none",
465
+ position: "relative"
466
+ };
467
+ }
468
+ function getRootStyle(ctx) {
469
+ const range = getRangeOffsets(ctx);
470
+ return {
566
471
  "--slider-thumb-transform": ctx.isVertical ? "translateY(50%)" : "translateX(-50%)",
472
+ "--slider-thumb-offset": getThumbOffset(ctx),
473
+ "--slider-range-start": range.start,
474
+ "--slider-range-end": range.end
475
+ };
476
+ }
477
+ function getMarkerStyle(ctx, percent) {
478
+ return {
479
+ position: "absolute",
480
+ pointerEvents: "none",
481
+ [ctx.isHorizontal ? "left" : "bottom"]: `${ctx.isRtl ? 100 - percent : percent}%`
482
+ };
483
+ }
484
+ function getLabelStyle() {
485
+ return { userSelect: "none" };
486
+ }
487
+ function getTrackStyle() {
488
+ return { position: "relative" };
489
+ }
490
+ function getMarkerGroupStyle() {
491
+ return {
492
+ userSelect: "none",
493
+ pointerEvents: "none",
567
494
  position: "relative"
568
495
  };
569
496
  }
570
- var dom = {
497
+ var styles = {
498
+ getThumbOffset,
499
+ getControlStyle,
500
+ getThumbStyle,
501
+ getRangeStyle,
502
+ getRootStyle,
503
+ getMarkerStyle,
504
+ getLabelStyle,
505
+ getTrackStyle,
506
+ getMarkerGroupStyle
507
+ };
508
+
509
+ // src/slider.utils.ts
510
+ var utils = {
511
+ fromPercent(ctx, percent) {
512
+ percent = clamp(percent, { min: 0, max: 1 });
513
+ return parseFloat(snapToStep(percentToValue(percent, ctx), ctx.step));
514
+ },
515
+ clamp(ctx, value) {
516
+ return clamp(value, ctx);
517
+ },
518
+ convert(ctx, value) {
519
+ return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
520
+ },
521
+ decrement(ctx, step) {
522
+ let value = decrement(ctx.value, step != null ? step : ctx.step);
523
+ return utils.convert(ctx, value);
524
+ },
525
+ increment(ctx, step) {
526
+ let value = increment(ctx.value, step != null ? step : ctx.step);
527
+ return utils.convert(ctx, value);
528
+ }
529
+ };
530
+
531
+ // src/slider.dom.ts
532
+ var dom = __spreadProps(__spreadValues({}, styles), {
571
533
  getDoc: (ctx) => {
572
534
  var _a;
573
535
  return (_a = ctx.doc) != null ? _a : document;
@@ -595,7 +557,7 @@ var dom = {
595
557
  },
596
558
  getTrackId: (ctx) => {
597
559
  var _a, _b;
598
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:-${ctx.uid}track`;
560
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.uid}track`;
599
561
  },
600
562
  getRangeId: (ctx) => {
601
563
  var _a, _b;
@@ -610,19 +572,18 @@ var dom = {
610
572
  getThumbEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getThumbId(ctx)),
611
573
  getControlEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getControlId(ctx)),
612
574
  getInputEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getInputId(ctx)),
613
- getControlStyle,
614
- getThumbStyle,
615
- getRangeStyle,
616
575
  getValueFromPoint(ctx, point) {
617
- const control = dom.getControlEl(ctx);
618
- if (!control)
576
+ const el = dom.getControlEl(ctx);
577
+ if (!el)
619
578
  return;
620
- const { progress } = relativeToNode(point, control);
579
+ const relativePoint = getPointRelativeToNode(point, el);
580
+ const percentX = relativePoint.x / el.offsetWidth;
581
+ const percentY = relativePoint.y / el.offsetHeight;
621
582
  let percent;
622
583
  if (ctx.isHorizontal) {
623
- percent = ctx.isRtl ? 1 - progress.x : progress.x;
584
+ percent = ctx.isRtl ? 1 - percentX : percentX;
624
585
  } else {
625
- percent = 1 - progress.y;
586
+ percent = 1 - percentY;
626
587
  }
627
588
  return utils.fromPercent(ctx, percent);
628
589
  },
@@ -631,38 +592,11 @@ var dom = {
631
592
  if (!input)
632
593
  return;
633
594
  dispatchInputValueEvent(input, ctx.value);
634
- },
635
- getMarkerStyle(ctx, percent) {
636
- const style = {
637
- position: "absolute",
638
- pointerEvents: "none"
639
- };
640
- if (ctx.isHorizontal) {
641
- percent = ctx.isRtl ? 100 - percent : percent;
642
- style.left = `${percent}%`;
643
- } else {
644
- style.bottom = `${percent}%`;
645
- }
646
- return style;
647
595
  }
648
- };
649
-
650
- // ../../types/dist/index.mjs
651
- function createNormalizer(fn) {
652
- return new Proxy({}, {
653
- get() {
654
- return fn;
655
- }
656
- });
657
- }
658
- var normalizeProp = createNormalizer((v) => v);
659
-
660
- // ../../utilities/core/dist/index.mjs
661
- var isLeftClick2 = (v) => v.button === 0;
662
- var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
596
+ });
663
597
 
664
598
  // src/slider.connect.ts
665
- function connect(state2, send, normalize = normalizeProp) {
599
+ function connect(state2, send, normalize) {
666
600
  var _a, _b;
667
601
  const ariaLabel = state2.context["aria-label"];
668
602
  const ariaLabelledBy = state2.context["aria-labelledby"];
@@ -696,14 +630,18 @@ function connect(state2, send, normalize = normalizeProp) {
696
630
  rootProps: normalize.element({
697
631
  "data-part": "root",
698
632
  "data-disabled": dataAttr(isDisabled),
633
+ "data-focus": dataAttr(isFocused),
699
634
  "data-orientation": state2.context.orientation,
635
+ "data-invalid": dataAttr(isInvalid),
700
636
  id: dom.getRootId(state2.context),
701
- dir: state2.context.dir
637
+ dir: state2.context.dir,
638
+ style: dom.getRootStyle(state2.context)
702
639
  }),
703
640
  labelProps: normalize.label({
704
641
  "data-part": "label",
705
642
  "data-disabled": dataAttr(isDisabled),
706
643
  "data-invalid": dataAttr(isInvalid),
644
+ "data-focus": dataAttr(isFocused),
707
645
  id: dom.getLabelId(state2.context),
708
646
  htmlFor: dom.getInputId(state2.context),
709
647
  onClick(event) {
@@ -713,9 +651,7 @@ function connect(state2, send, normalize = normalizeProp) {
713
651
  event.preventDefault();
714
652
  (_a2 = dom.getThumbEl(state2.context)) == null ? void 0 : _a2.focus();
715
653
  },
716
- style: {
717
- userSelect: "none"
718
- }
654
+ style: dom.getLabelStyle()
719
655
  }),
720
656
  thumbProps: normalize.element({
721
657
  "data-part": "thumb",
@@ -812,14 +748,15 @@ function connect(state2, send, normalize = normalizeProp) {
812
748
  "data-part": "track",
813
749
  id: dom.getTrackId(state2.context),
814
750
  "data-disabled": dataAttr(isDisabled),
751
+ "data-focus": dataAttr(isFocused),
815
752
  "data-invalid": dataAttr(isInvalid),
816
753
  "data-orientation": state2.context.orientation,
817
- "data-focus": dataAttr(isFocused),
818
- style: { position: "relative" }
754
+ style: dom.getTrackStyle()
819
755
  }),
820
756
  rangeProps: normalize.element({
821
757
  "data-part": "range",
822
758
  id: dom.getRangeId(state2.context),
759
+ "data-focus": dataAttr(isFocused),
823
760
  "data-invalid": dataAttr(isInvalid),
824
761
  "data-disabled": dataAttr(isDisabled),
825
762
  "data-orientation": state2.context.orientation,
@@ -836,25 +773,21 @@ function connect(state2, send, normalize = normalizeProp) {
836
773
  if (!isInteractive)
837
774
  return;
838
775
  const evt = getNativeEvent(event);
839
- if (!isLeftClick2(evt) || isModifiedEvent(evt))
776
+ if (!isLeftClick(evt) || isModifiedEvent(evt))
840
777
  return;
841
778
  const point = getEventPoint(evt);
842
779
  send({ type: "POINTER_DOWN", point });
843
780
  event.preventDefault();
844
781
  event.stopPropagation();
845
782
  },
846
- style: dom.getControlStyle(state2.context)
783
+ style: dom.getControlStyle()
847
784
  }),
848
785
  markerGroupProps: normalize.element({
849
786
  "data-part": "marker-group",
850
787
  role: "presentation",
851
788
  "aria-hidden": true,
852
789
  "data-orientation": state2.context.orientation,
853
- style: {
854
- userSelect: "none",
855
- pointerEvents: "none",
856
- position: "relative"
857
- }
790
+ style: dom.getMarkerGroupStyle()
858
791
  }),
859
792
  getMarkerProps({ value }) {
860
793
  const percent = valueToPercent(value, state2.context);
@@ -862,6 +795,7 @@ function connect(state2, send, normalize = normalizeProp) {
862
795
  const markerState = value > state2.context.value ? "over-value" : value < state2.context.value ? "under-value" : "at-value";
863
796
  return normalize.element({
864
797
  "data-part": "marker",
798
+ role: "presentation",
865
799
  "data-orientation": state2.context.orientation,
866
800
  id: dom.getMarkerId(state2.context, value),
867
801
  "data-value": value,
@@ -881,6 +815,7 @@ function machine(ctx = {}) {
881
815
  initial: "unknown",
882
816
  context: __spreadValues({
883
817
  thumbSize: null,
818
+ thumbAlignment: "contain",
884
819
  uid: "",
885
820
  disabled: false,
886
821
  threshold: 5,
@@ -995,7 +930,7 @@ function machine(ctx = {}) {
995
930
  let cleanup;
996
931
  nextTick(() => {
997
932
  cleanup = trackFieldsetDisabled(dom.getRootEl(ctx2), (disabled) => {
998
- if (disabled != ctx2.disabled) {
933
+ if (disabled) {
999
934
  ctx2.disabled = disabled;
1000
935
  }
1001
936
  });
@@ -1053,6 +988,8 @@ function machine(ctx = {}) {
1053
988
  dom.dispatchChangeEvent(ctx2);
1054
989
  },
1055
990
  setThumbSize(ctx2) {
991
+ if (ctx2.thumbAlignment !== "contain")
992
+ return;
1056
993
  raf(() => {
1057
994
  const el = dom.getThumbEl(ctx2);
1058
995
  if (!el)
@@ -1095,4 +1032,3 @@ export {
1095
1032
  machine,
1096
1033
  dom as unstable__dom
1097
1034
  };
1098
- //# sourceMappingURL=index.mjs.map