@zag-js/slider 0.1.7 → 0.1.10

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;
@@ -43,190 +44,97 @@ __export(src_exports, {
43
44
  module.exports = __toCommonJS(src_exports);
44
45
 
45
46
  // ../../utilities/dom/dist/index.mjs
47
+ var __defProp2 = Object.defineProperty;
48
+ var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
49
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
50
+ var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
46
51
  var __pow = Math.pow;
52
+ var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
53
+ var __spreadValues2 = (a, b) => {
54
+ for (var prop in b || (b = {}))
55
+ if (__hasOwnProp2.call(b, prop))
56
+ __defNormalProp2(a, prop, b[prop]);
57
+ if (__getOwnPropSymbols2)
58
+ for (var prop of __getOwnPropSymbols2(b)) {
59
+ if (__propIsEnum2.call(b, prop))
60
+ __defNormalProp2(a, prop, b[prop]);
61
+ }
62
+ return a;
63
+ };
47
64
  var dataAttr = (guard) => {
48
65
  return guard ? "" : void 0;
49
66
  };
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 isDom = () => typeof window !== "undefined";
67
+ var runIfFn = (v, ...a) => {
68
+ const res = typeof v === "function" ? v(...a) : v;
69
+ return res != null ? res : void 0;
70
+ };
71
+ var callAll = (...fns) => (...a) => {
72
+ fns.forEach(function(fn) {
73
+ fn == null ? void 0 : fn(...a);
74
+ });
75
+ };
70
76
  var isArray = (v) => Array.isArray(v);
71
77
  var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
72
78
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
79
+ var isDom = () => typeof window !== "undefined";
73
80
  function getPlatform() {
74
81
  var _a;
75
82
  const agent = navigator.userAgentData;
76
83
  return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
77
84
  }
78
85
  var pt = (v) => isDom() && v.test(getPlatform());
79
- var isTouchDevice = isDom() && !!navigator.maxTouchPoints;
86
+ var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
80
87
  var isMac = () => pt(/^Mac/) && !isTouchDevice;
81
88
  var isApple = () => pt(/mac|iphone|ipad|ipod/i);
82
89
  var isIos = () => isApple() && !isMac();
83
- var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
84
- var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
85
- var supportsMouseEvent = () => isDom() && window.onmousedown === null;
86
- var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
87
- var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
88
- var isLeftClick = (v) => v.button === 0;
89
- var runIfFn = (v, ...a) => {
90
- const res = typeof v === "function" ? v(...a) : v;
91
- return res != null ? res : void 0;
92
- };
93
- var noop = () => {
94
- };
95
- var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
96
- function getListenerElements() {
97
- ;
98
- globalThis.__listenerElements__ = globalThis.__listenerElements__ || /* @__PURE__ */ new Map();
99
- return globalThis.__listenerElements__;
90
+ function isDocument(el) {
91
+ return el.nodeType === Node.DOCUMENT_NODE;
100
92
  }
101
- function getListenerCache() {
102
- ;
103
- globalThis.__listenerCache__ = globalThis.__listenerCache__ || /* @__PURE__ */ new Map();
104
- return globalThis.__listenerCache__;
93
+ function isWindow(value) {
94
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
105
95
  }
106
- function addGlobalEventListener(node, type, handler, options) {
96
+ function getDocument(el) {
107
97
  var _a;
108
- if (!node)
109
- return noop;
110
- const hash = JSON.stringify({ type, options });
111
- const listenerElements = getListenerElements();
112
- const listenerCache = getListenerCache();
113
- const group = listenerElements.get(node);
114
- if (!listenerElements.has(node)) {
115
- const group2 = /* @__PURE__ */ new Map([[hash, /* @__PURE__ */ new Set([handler])]]);
116
- listenerElements.set(node, group2);
117
- } else if (group == null ? void 0 : group.has(hash)) {
118
- (_a = group == null ? void 0 : group.get(hash)) == null ? void 0 : _a.add(handler);
119
- } else {
120
- group == null ? void 0 : group.set(hash, /* @__PURE__ */ new Set([handler]));
121
- }
122
- function attach(node2) {
123
- var _a2, _b;
124
- function listener(event) {
125
- var _a3;
126
- const group2 = listenerElements.get(node2);
127
- (_a3 = group2 == null ? void 0 : group2.get(hash)) == null ? void 0 : _a3.forEach((fn) => fn(event));
128
- }
129
- if (!(listenerCache == null ? void 0 : listenerCache.has(node2))) {
130
- listenerCache.set(node2, /* @__PURE__ */ new Map([[hash, listener]]));
131
- node2.addEventListener(type, listener, options);
132
- return;
133
- }
134
- if (!((_a2 = listenerCache == null ? void 0 : listenerCache.get(node2)) == null ? void 0 : _a2.has(hash))) {
135
- (_b = listenerCache.get(node2)) == null ? void 0 : _b.set(hash, listener);
136
- node2.addEventListener(type, listener, options);
137
- }
138
- }
139
- attach(node);
140
- return function remove() {
141
- var _a2, _b, _c, _d;
142
- if (!listenerElements.has(node))
143
- return;
144
- const group2 = listenerElements.get(node);
145
- (_a2 = group2 == null ? void 0 : group2.get(hash)) == null ? void 0 : _a2.delete(handler);
146
- if (((_b = group2 == null ? void 0 : group2.get(hash)) == null ? void 0 : _b.size) === 0) {
147
- const listener = (_c = listenerCache.get(node)) == null ? void 0 : _c.get(hash);
148
- node.removeEventListener(type, listener, options);
149
- group2 == null ? void 0 : group2.delete(hash);
150
- (_d = listenerCache.get(node)) == null ? void 0 : _d.delete(hash);
151
- if ((group2 == null ? void 0 : group2.size) === 0) {
152
- listenerElements.delete(node);
153
- listenerCache.delete(node);
154
- }
155
- }
156
- };
98
+ if (isWindow(el))
99
+ return el.document;
100
+ if (isDocument(el))
101
+ return el;
102
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
157
103
  }
158
- var isRef = (v) => hasProp(v, "current");
159
- var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
160
- function extractInfo(event, type = "page") {
161
- const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback : event;
162
- return {
163
- point: {
164
- x: point[`${type}X`],
165
- y: point[`${type}Y`]
166
- }
167
- };
168
- }
169
- function addDomEvent(target, event, listener, options) {
170
- const node = isRef(target) ? target.current : runIfFn(target);
171
- return addGlobalEventListener(node, event, listener, options);
172
- }
173
- function addPointerEvent(target, event, listener, options) {
104
+ function getWindow(el) {
174
105
  var _a;
175
- const type = (_a = getEventName(event)) != null ? _a : event;
176
- return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
177
- }
178
- function wrapHandler(fn, filter = false) {
179
- const listener = (event) => {
180
- fn(event, extractInfo(event));
181
- };
182
- return filter ? filterPrimaryPointer(listener) : listener;
106
+ return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
183
107
  }
184
- function filterPrimaryPointer(fn) {
185
- return (event) => {
186
- var _a;
187
- const win = (_a = event.view) != null ? _a : window;
188
- const isMouseEvent2 = event instanceof win.MouseEvent;
189
- const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
190
- if (isPrimary)
191
- fn(event);
108
+ function defineDomHelpers(helpers) {
109
+ const dom2 = {
110
+ getRootNode: (ctx) => {
111
+ var _a, _b;
112
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
113
+ },
114
+ getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
115
+ getWin: (ctx) => {
116
+ var _a;
117
+ return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
118
+ },
119
+ getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
120
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
192
121
  };
193
- }
194
- var mouseEventNames = {
195
- pointerdown: "mousedown",
196
- pointermove: "mousemove",
197
- pointerup: "mouseup",
198
- pointercancel: "mousecancel",
199
- pointerover: "mouseover",
200
- pointerout: "mouseout",
201
- pointerenter: "mouseenter",
202
- pointerleave: "mouseleave"
203
- };
204
- var touchEventNames = {
205
- pointerdown: "touchstart",
206
- pointermove: "touchmove",
207
- pointerup: "touchend",
208
- pointercancel: "touchcancel"
209
- };
210
- function getEventName(evt) {
211
- if (supportsPointerEvent())
212
- return evt;
213
- if (supportsTouchEvent())
214
- return touchEventNames[evt];
215
- if (supportsMouseEvent())
216
- return mouseEventNames[evt];
217
- return evt;
218
- }
219
- function getOwnerWindow(el) {
220
- var _a;
221
- return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
122
+ return __spreadValues2(__spreadValues2({}, dom2), helpers);
222
123
  }
223
124
  function getNativeEvent(e) {
224
125
  var _a;
225
126
  return (_a = e.nativeEvent) != null ? _a : e;
226
127
  }
128
+ var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
129
+ var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
130
+ var supportsMouseEvent = () => isDom() && window.onmousedown === null;
131
+ var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
132
+ var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
133
+ var isLeftClick = (v) => v.button === 0;
134
+ var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
227
135
  function observeAttributes(node, attributes, fn) {
228
136
  if (!node)
229
- return noop;
137
+ return;
230
138
  const attrs = Array.isArray(attributes) ? attributes : [attributes];
231
139
  const win = node.ownerDocument.defaultView || window;
232
140
  const obs = new win.MutationObserver((changes) => {
@@ -264,20 +172,59 @@ function trackFieldsetDisabled(el, callback) {
264
172
  callback(fieldset.disabled);
265
173
  return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
266
174
  }
175
+ function getElementOffset(element) {
176
+ let left = 0;
177
+ let top = 0;
178
+ let el = element;
179
+ if (el.parentNode) {
180
+ do {
181
+ left += el.offsetLeft;
182
+ top += el.offsetTop;
183
+ } while ((el = el.offsetParent) && el.nodeType < 9);
184
+ el = element;
185
+ do {
186
+ left -= el.scrollLeft;
187
+ top -= el.scrollTop;
188
+ } while ((el = el.parentNode) && !/body/i.test(el.nodeName));
189
+ }
190
+ return {
191
+ top,
192
+ right: innerWidth - left - element.offsetWidth,
193
+ bottom: innerHeight - top - element.offsetHeight,
194
+ left
195
+ };
196
+ }
197
+ var fallback = {
198
+ pageX: 0,
199
+ pageY: 0,
200
+ clientX: 0,
201
+ clientY: 0
202
+ };
203
+ function getEventPoint(event, type = "page") {
204
+ var _a, _b;
205
+ const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event;
206
+ return { x: point[`${type}X`], y: point[`${type}Y`] };
207
+ }
208
+ function getPointRelativeToNode(point, element) {
209
+ const offset = getElementOffset(element);
210
+ const x = point.x - offset.left;
211
+ const y = point.y - offset.top;
212
+ return { x, y };
213
+ }
267
214
  function getDescriptor(el, options) {
268
215
  var _a;
269
216
  const { type, property } = options;
270
- const win = getOwnerWindow(el);
271
- const _type = type === "input" ? "HTMLInputElement" : "HTMLTextAreaElement";
272
- const proto = win[_type].prototype;
217
+ const proto = getWindow(el)[type].prototype;
273
218
  return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
274
219
  }
275
220
  function dispatchInputValueEvent(el, value) {
276
221
  var _a;
277
- const win = getOwnerWindow(el);
222
+ if (!el)
223
+ return;
224
+ const win = getWindow(el);
278
225
  if (!(el instanceof win.HTMLInputElement))
279
226
  return;
280
- const desc = getDescriptor(el, { type: "input", property: "value" });
227
+ const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
281
228
  (_a = desc.set) == null ? void 0 : _a.call(el, value);
282
229
  const event = new win.Event("input", { bubbles: true });
283
230
  el.dispatchEvent(event);
@@ -319,29 +266,88 @@ function getEventStep(event) {
319
266
  return isSkipKey ? 10 : 1;
320
267
  }
321
268
  }
322
- function itemById(v, id) {
323
- return v.find((node) => node.id === id);
269
+ var isRef = (v) => hasProp(v, "current");
270
+ var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
271
+ function extractInfo(event, type = "page") {
272
+ const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback2 : event;
273
+ return {
274
+ point: {
275
+ x: point[`${type}X`],
276
+ y: point[`${type}Y`]
277
+ }
278
+ };
324
279
  }
325
- function indexOfId(v, id) {
326
- const item = itemById(v, id);
327
- return item ? v.indexOf(item) : -1;
280
+ function addDomEvent(target, eventName, handler, options) {
281
+ const node = isRef(target) ? target.current : runIfFn(target);
282
+ node == null ? void 0 : node.addEventListener(eventName, handler, options);
283
+ return () => {
284
+ node == null ? void 0 : node.removeEventListener(eventName, handler, options);
285
+ };
328
286
  }
329
- var getValueText = (item) => {
330
- var _a, _b;
331
- return (_b = (_a = item.dataset.valuetext) != null ? _a : item.textContent) != null ? _b : "";
287
+ function addPointerEvent(target, event, listener, options) {
288
+ var _a;
289
+ const type = (_a = getEventName(event)) != null ? _a : event;
290
+ return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
291
+ }
292
+ function wrapHandler(fn, filter = false) {
293
+ const listener = (event) => {
294
+ fn(event, extractInfo(event));
295
+ };
296
+ return filter ? filterPrimaryPointer(listener) : listener;
297
+ }
298
+ function filterPrimaryPointer(fn) {
299
+ return (event) => {
300
+ var _a;
301
+ const win = (_a = event.view) != null ? _a : window;
302
+ const isMouseEvent2 = event instanceof win.MouseEvent;
303
+ const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
304
+ if (isPrimary)
305
+ fn(event);
306
+ };
307
+ }
308
+ var mouseEventNames = {
309
+ pointerdown: "mousedown",
310
+ pointermove: "mousemove",
311
+ pointerup: "mouseup",
312
+ pointercancel: "mousecancel",
313
+ pointerover: "mouseover",
314
+ pointerout: "mouseout",
315
+ pointerenter: "mouseenter",
316
+ pointerleave: "mouseleave"
332
317
  };
333
- var match = (valueText, query2) => valueText.toLowerCase().startsWith(query2.toLowerCase());
334
- var wrap = (v, idx) => {
335
- return v.map((_, index) => v[(Math.max(idx, 0) + index) % v.length]);
318
+ var touchEventNames = {
319
+ pointerdown: "touchstart",
320
+ pointermove: "touchmove",
321
+ pointerup: "touchend",
322
+ pointercancel: "touchcancel"
336
323
  };
337
- function findByText(v, text, currentId) {
338
- const index = currentId ? indexOfId(v, currentId) : -1;
339
- let items = currentId ? wrap(v, index) : v;
340
- const isSingleKey = text.length === 1;
341
- if (isSingleKey) {
342
- items = items.filter((item) => item.id !== currentId);
324
+ function getEventName(evt) {
325
+ if (supportsPointerEvent())
326
+ return evt;
327
+ if (supportsTouchEvent())
328
+ return touchEventNames[evt];
329
+ if (supportsMouseEvent())
330
+ return mouseEventNames[evt];
331
+ return evt;
332
+ }
333
+ function nextTick(fn) {
334
+ const set = /* @__PURE__ */ new Set();
335
+ function raf2(fn2) {
336
+ const id = globalThis.requestAnimationFrame(fn2);
337
+ set.add(() => globalThis.cancelAnimationFrame(id));
343
338
  }
344
- return items.find((item) => match(getValueText(item), text));
339
+ raf2(() => raf2(fn));
340
+ return function cleanup() {
341
+ set.forEach(function(fn2) {
342
+ fn2();
343
+ });
344
+ };
345
+ }
346
+ function raf(fn) {
347
+ const id = globalThis.requestAnimationFrame(fn);
348
+ return function cleanup() {
349
+ globalThis.cancelAnimationFrame(id);
350
+ };
345
351
  }
346
352
  var state = "default";
347
353
  var savedUserSelect = "";
@@ -404,36 +410,8 @@ function trackPointerMove(opts) {
404
410
  }
405
411
  onPointerMove(info, event);
406
412
  };
407
- return pipe(addPointerEvent(doc, "pointermove", handlePointerMove, false), addPointerEvent(doc, "pointerup", onPointerUp, false), addPointerEvent(doc, "pointercancel", onPointerUp, false), addPointerEvent(doc, "contextmenu", onPointerUp, false), disableTextSelection({ doc }));
413
+ return callAll(addPointerEvent(doc, "pointermove", handlePointerMove, false), addPointerEvent(doc, "pointerup", onPointerUp, false), addPointerEvent(doc, "pointercancel", onPointerUp, false), addPointerEvent(doc, "contextmenu", onPointerUp, false), disableTextSelection({ doc }));
408
414
  }
409
- function findByTypeahead(_items, options) {
410
- const { state: state2, activeId, key, timeout = 350 } = options;
411
- const search = state2.keysSoFar + key;
412
- const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]);
413
- const query2 = isRepeated ? search[0] : search;
414
- let items = _items.slice();
415
- const next = findByText(items, query2, activeId);
416
- function cleanup() {
417
- clearTimeout(state2.timer);
418
- state2.timer = -1;
419
- }
420
- function update(value) {
421
- state2.keysSoFar = value;
422
- cleanup();
423
- if (value !== "") {
424
- state2.timer = +setTimeout(() => {
425
- update("");
426
- cleanup();
427
- }, timeout);
428
- }
429
- }
430
- update(search);
431
- return next;
432
- }
433
- findByTypeahead.defaultOptions = {
434
- keysSoFar: "",
435
- timer: -1
436
- };
437
415
 
438
416
  // ../../utilities/number/dist/index.mjs
439
417
  var __pow2 = Math.pow;
@@ -495,50 +473,7 @@ var transform = (a, b) => {
495
473
  };
496
474
  };
497
475
 
498
- // ../../utilities/rect/dist/index.mjs
499
- var isDom2 = () => typeof window !== "undefined";
500
- var isArray2 = (v) => Array.isArray(v);
501
- var isObject2 = (v) => !(v == null || typeof v !== "object" || isArray2(v));
502
- var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
503
- var isTouchDevice2 = isDom2() && !!navigator.maxTouchPoints;
504
- var isTouchEvent2 = (v) => isObject2(v) && hasProp2(v, "touches");
505
- var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
506
- function getEventPoint(e, t = "page") {
507
- const p = isTouchEvent2(e) ? e.touches[0] || e.changedTouches[0] || fallback2 : e;
508
- return { x: p[`${t}X`], y: p[`${t}Y`] };
509
- }
510
- function relativeToNode(p, el) {
511
- const dx = p.x - el.offsetLeft - el.clientLeft + el.scrollLeft;
512
- const dy = p.y - el.offsetTop - el.clientTop + el.scrollTop;
513
- return {
514
- point: { x: dx, y: dy },
515
- progress: { x: dx / el.offsetWidth, y: dy / el.offsetHeight }
516
- };
517
- }
518
-
519
- // src/slider.utils.ts
520
- var utils = {
521
- fromPercent(ctx, percent) {
522
- percent = clamp(percent, { min: 0, max: 1 });
523
- return parseFloat(snapToStep(percentToValue(percent, ctx), ctx.step));
524
- },
525
- clamp(ctx, value) {
526
- return clamp(value, ctx);
527
- },
528
- convert(ctx, value) {
529
- return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
530
- },
531
- decrement(ctx, step) {
532
- let value = decrement(ctx.value, step != null ? step : ctx.step);
533
- return utils.convert(ctx, value);
534
- },
535
- increment(ctx, step) {
536
- let value = increment(ctx.value, step != null ? step : ctx.step);
537
- return utils.convert(ctx, value);
538
- }
539
- };
540
-
541
- // src/slider.dom.ts
476
+ // src/slider.style.ts
542
477
  function getVerticalThumbOffset(ctx) {
543
478
  var _a;
544
479
  const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
@@ -555,109 +490,165 @@ function getHorizontalThumbOffset(ctx) {
555
490
  const getValue = transform([ctx.min, ctx.max], [-width / 2, width / 2]);
556
491
  return parseFloat(getValue(ctx.value).toFixed(2));
557
492
  }
558
- function getThumbStyle(ctx) {
493
+ function getThumbOffset(ctx) {
559
494
  const percent = valueToPercent(ctx.value, ctx);
495
+ if (ctx.thumbAlignment === "center")
496
+ return `${percent}%`;
560
497
  const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
561
- const style = {
498
+ return `calc(${percent}% - ${offset}px)`;
499
+ }
500
+ function getThumbStyle(ctx) {
501
+ const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
502
+ return {
562
503
  visibility: ctx.hasMeasuredThumbSize ? "visible" : "hidden",
563
504
  position: "absolute",
564
505
  transform: "var(--slider-thumb-transform)",
565
- "--slider-thumb-placement": `calc(${percent}% - ${offset}px)`
506
+ [placementProp]: "var(--slider-thumb-offset)"
566
507
  };
567
- if (ctx.isVertical) {
568
- style.bottom = "var(--slider-thumb-placement)";
569
- } else {
570
- style[ctx.isRtl ? "right" : "left"] = "var(--slider-thumb-placement)";
571
- }
572
- return style;
573
508
  }
574
- function getRangeStyle(ctx) {
509
+ function getRangeOffsets(ctx) {
575
510
  const percent = valueToPercent(ctx.value, ctx);
576
- const style = {
577
- position: "absolute"
578
- };
579
- let startValue = "0%";
580
- let endValue = `${100 - percent}%`;
511
+ let start = "0%";
512
+ let end = `${100 - percent}%`;
581
513
  if (ctx.origin === "center") {
582
514
  const isNegative = percent < 50;
583
- startValue = isNegative ? `${percent}%` : "50%";
584
- endValue = isNegative ? "50%" : endValue;
515
+ start = isNegative ? `${percent}%` : "50%";
516
+ end = isNegative ? "50%" : end;
585
517
  }
518
+ return { start, end };
519
+ }
520
+ function getRangeStyle(ctx) {
586
521
  if (ctx.isVertical) {
587
- return __spreadProps(__spreadValues({}, style), {
588
- bottom: startValue,
589
- top: endValue
590
- });
522
+ return {
523
+ position: "absolute",
524
+ bottom: "var(--slider-range-start)",
525
+ top: "var(--slider-range-end)"
526
+ };
591
527
  }
592
- return __spreadProps(__spreadValues({}, style), {
593
- [ctx.isRtl ? "right" : "left"]: startValue,
594
- [ctx.isRtl ? "left" : "right"]: endValue
595
- });
528
+ return {
529
+ position: "absolute",
530
+ [ctx.isRtl ? "right" : "left"]: "var(--slider-range-start)",
531
+ [ctx.isRtl ? "left" : "right"]: "var(--slider-range-end)"
532
+ };
596
533
  }
597
- function getControlStyle(ctx) {
534
+ function getControlStyle() {
598
535
  return {
599
536
  touchAction: "none",
600
537
  userSelect: "none",
538
+ position: "relative"
539
+ };
540
+ }
541
+ function getRootStyle(ctx) {
542
+ const range = getRangeOffsets(ctx);
543
+ return {
601
544
  "--slider-thumb-transform": ctx.isVertical ? "translateY(50%)" : "translateX(-50%)",
545
+ "--slider-thumb-offset": getThumbOffset(ctx),
546
+ "--slider-range-start": range.start,
547
+ "--slider-range-end": range.end
548
+ };
549
+ }
550
+ function getMarkerStyle(ctx, percent) {
551
+ return {
552
+ position: "absolute",
553
+ pointerEvents: "none",
554
+ [ctx.isHorizontal ? "left" : "bottom"]: `${ctx.isRtl ? 100 - percent : percent}%`
555
+ };
556
+ }
557
+ function getLabelStyle() {
558
+ return { userSelect: "none" };
559
+ }
560
+ function getTrackStyle() {
561
+ return { position: "relative" };
562
+ }
563
+ function getMarkerGroupStyle() {
564
+ return {
565
+ userSelect: "none",
566
+ pointerEvents: "none",
602
567
  position: "relative"
603
568
  };
604
569
  }
605
- var dom = {
606
- getDoc: (ctx) => {
607
- var _a;
608
- return (_a = ctx.doc) != null ? _a : document;
570
+ var styles = {
571
+ getThumbOffset,
572
+ getControlStyle,
573
+ getThumbStyle,
574
+ getRangeStyle,
575
+ getRootStyle,
576
+ getMarkerStyle,
577
+ getLabelStyle,
578
+ getTrackStyle,
579
+ getMarkerGroupStyle
580
+ };
581
+
582
+ // src/slider.utils.ts
583
+ var utils = {
584
+ fromPercent(ctx, percent) {
585
+ percent = clamp(percent, { min: 0, max: 1 });
586
+ return parseFloat(snapToStep(percentToValue(percent, ctx), ctx.step));
609
587
  },
610
- getRootNode: (ctx) => {
611
- var _a;
612
- return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
588
+ clamp(ctx, value) {
589
+ return clamp(value, ctx);
613
590
  },
591
+ convert(ctx, value) {
592
+ return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
593
+ },
594
+ decrement(ctx, step) {
595
+ let value = decrement(ctx.value, step != null ? step : ctx.step);
596
+ return utils.convert(ctx, value);
597
+ },
598
+ increment(ctx, step) {
599
+ let value = increment(ctx.value, step != null ? step : ctx.step);
600
+ return utils.convert(ctx, value);
601
+ }
602
+ };
603
+
604
+ // src/slider.dom.ts
605
+ var dom = defineDomHelpers(__spreadProps(__spreadValues({}, styles), {
614
606
  getRootId: (ctx) => {
615
607
  var _a, _b;
616
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `slider:${ctx.uid}`;
608
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `slider:${ctx.id}`;
617
609
  },
618
610
  getThumbId: (ctx) => {
619
611
  var _a, _b;
620
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.thumb) != null ? _b : `slider:${ctx.uid}:thumb`;
612
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.thumb) != null ? _b : `slider:${ctx.id}:thumb`;
621
613
  },
622
614
  getControlId: (ctx) => {
623
615
  var _a, _b;
624
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.control) != null ? _b : `slider:${ctx.uid}:control`;
616
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.control) != null ? _b : `slider:${ctx.id}:control`;
625
617
  },
626
- getInputId: (ctx) => `slider:${ctx.uid}:input`,
618
+ getInputId: (ctx) => `slider:${ctx.id}:input`,
627
619
  getOutputId: (ctx) => {
628
620
  var _a, _b;
629
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.output) != null ? _b : `slider:${ctx.uid}:output`;
621
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.output) != null ? _b : `slider:${ctx.id}:output`;
630
622
  },
631
623
  getTrackId: (ctx) => {
632
624
  var _a, _b;
633
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:-${ctx.uid}track`;
625
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}track`;
634
626
  },
635
627
  getRangeId: (ctx) => {
636
628
  var _a, _b;
637
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.uid}:range`;
629
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}:range`;
638
630
  },
639
631
  getLabelId: (ctx) => {
640
632
  var _a, _b;
641
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.uid}:label`;
633
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.id}:label`;
642
634
  },
643
- getMarkerId: (ctx, value) => `slider:${ctx.uid}:marker:${value}`,
644
- getRootEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getRootId(ctx)),
645
- getThumbEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getThumbId(ctx)),
646
- getControlEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getControlId(ctx)),
647
- getInputEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getInputId(ctx)),
648
- getControlStyle,
649
- getThumbStyle,
650
- getRangeStyle,
635
+ getMarkerId: (ctx, value) => `slider:${ctx.id}:marker:${value}`,
636
+ getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
637
+ getThumbEl: (ctx) => dom.getById(ctx, dom.getThumbId(ctx)),
638
+ getControlEl: (ctx) => dom.getById(ctx, dom.getControlId(ctx)),
639
+ getInputEl: (ctx) => dom.getById(ctx, dom.getInputId(ctx)),
651
640
  getValueFromPoint(ctx, point) {
652
- const control = dom.getControlEl(ctx);
653
- if (!control)
641
+ const el = dom.getControlEl(ctx);
642
+ if (!el)
654
643
  return;
655
- const { progress } = relativeToNode(point, control);
644
+ const relativePoint = getPointRelativeToNode(point, el);
645
+ const percentX = relativePoint.x / el.offsetWidth;
646
+ const percentY = relativePoint.y / el.offsetHeight;
656
647
  let percent;
657
648
  if (ctx.isHorizontal) {
658
- percent = ctx.isRtl ? 1 - progress.x : progress.x;
649
+ percent = ctx.isRtl ? 1 - percentX : percentX;
659
650
  } else {
660
- percent = 1 - progress.y;
651
+ percent = 1 - percentY;
661
652
  }
662
653
  return utils.fromPercent(ctx, percent);
663
654
  },
@@ -666,40 +657,11 @@ var dom = {
666
657
  if (!input)
667
658
  return;
668
659
  dispatchInputValueEvent(input, ctx.value);
669
- },
670
- getMarkerStyle(ctx, percent) {
671
- const style = {
672
- position: "absolute",
673
- pointerEvents: "none"
674
- };
675
- if (ctx.isHorizontal) {
676
- percent = ctx.isRtl ? 100 - percent : percent;
677
- style.left = `${percent}%`;
678
- } else {
679
- style.bottom = `${percent}%`;
680
- }
681
- return style;
682
660
  }
683
- };
684
-
685
- // ../../types/dist/index.mjs
686
- function createNormalizer(fn) {
687
- return new Proxy({}, {
688
- get() {
689
- return fn;
690
- }
691
- });
692
- }
693
- var normalizeProp = createNormalizer((v) => v);
694
-
695
- // ../../utilities/core/dist/index.mjs
696
- var isDom3 = () => typeof window !== "undefined";
697
- var isTouchDevice3 = isDom3() && !!navigator.maxTouchPoints;
698
- var isLeftClick2 = (v) => v.button === 0;
699
- var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
661
+ }));
700
662
 
701
663
  // src/slider.connect.ts
702
- function connect(state2, send, normalize = normalizeProp) {
664
+ function connect(state2, send, normalize) {
703
665
  var _a, _b;
704
666
  const ariaLabel = state2.context["aria-label"];
705
667
  const ariaLabelledBy = state2.context["aria-labelledby"];
@@ -733,14 +695,18 @@ function connect(state2, send, normalize = normalizeProp) {
733
695
  rootProps: normalize.element({
734
696
  "data-part": "root",
735
697
  "data-disabled": dataAttr(isDisabled),
698
+ "data-focus": dataAttr(isFocused),
736
699
  "data-orientation": state2.context.orientation,
700
+ "data-invalid": dataAttr(isInvalid),
737
701
  id: dom.getRootId(state2.context),
738
- dir: state2.context.dir
702
+ dir: state2.context.dir,
703
+ style: dom.getRootStyle(state2.context)
739
704
  }),
740
705
  labelProps: normalize.label({
741
706
  "data-part": "label",
742
707
  "data-disabled": dataAttr(isDisabled),
743
708
  "data-invalid": dataAttr(isInvalid),
709
+ "data-focus": dataAttr(isFocused),
744
710
  id: dom.getLabelId(state2.context),
745
711
  htmlFor: dom.getInputId(state2.context),
746
712
  onClick(event) {
@@ -750,9 +716,7 @@ function connect(state2, send, normalize = normalizeProp) {
750
716
  event.preventDefault();
751
717
  (_a2 = dom.getThumbEl(state2.context)) == null ? void 0 : _a2.focus();
752
718
  },
753
- style: {
754
- userSelect: "none"
755
- }
719
+ style: dom.getLabelStyle()
756
720
  }),
757
721
  thumbProps: normalize.element({
758
722
  "data-part": "thumb",
@@ -849,14 +813,15 @@ function connect(state2, send, normalize = normalizeProp) {
849
813
  "data-part": "track",
850
814
  id: dom.getTrackId(state2.context),
851
815
  "data-disabled": dataAttr(isDisabled),
816
+ "data-focus": dataAttr(isFocused),
852
817
  "data-invalid": dataAttr(isInvalid),
853
818
  "data-orientation": state2.context.orientation,
854
- "data-focus": dataAttr(isFocused),
855
- style: { position: "relative" }
819
+ style: dom.getTrackStyle()
856
820
  }),
857
821
  rangeProps: normalize.element({
858
822
  "data-part": "range",
859
823
  id: dom.getRangeId(state2.context),
824
+ "data-focus": dataAttr(isFocused),
860
825
  "data-invalid": dataAttr(isInvalid),
861
826
  "data-disabled": dataAttr(isDisabled),
862
827
  "data-orientation": state2.context.orientation,
@@ -873,25 +838,21 @@ function connect(state2, send, normalize = normalizeProp) {
873
838
  if (!isInteractive)
874
839
  return;
875
840
  const evt = getNativeEvent(event);
876
- if (!isLeftClick2(evt) || isModifiedEvent(evt))
841
+ if (!isLeftClick(evt) || isModifiedEvent(evt))
877
842
  return;
878
843
  const point = getEventPoint(evt);
879
844
  send({ type: "POINTER_DOWN", point });
880
845
  event.preventDefault();
881
846
  event.stopPropagation();
882
847
  },
883
- style: dom.getControlStyle(state2.context)
848
+ style: dom.getControlStyle()
884
849
  }),
885
850
  markerGroupProps: normalize.element({
886
851
  "data-part": "marker-group",
887
852
  role: "presentation",
888
853
  "aria-hidden": true,
889
854
  "data-orientation": state2.context.orientation,
890
- style: {
891
- userSelect: "none",
892
- pointerEvents: "none",
893
- position: "relative"
894
- }
855
+ style: dom.getMarkerGroupStyle()
895
856
  }),
896
857
  getMarkerProps({ value }) {
897
858
  const percent = valueToPercent(value, state2.context);
@@ -899,6 +860,7 @@ function connect(state2, send, normalize = normalizeProp) {
899
860
  const markerState = value > state2.context.value ? "over-value" : value < state2.context.value ? "under-value" : "at-value";
900
861
  return normalize.element({
901
862
  "data-part": "marker",
863
+ role: "presentation",
902
864
  "data-orientation": state2.context.orientation,
903
865
  id: dom.getMarkerId(state2.context, value),
904
866
  "data-value": value,
@@ -912,13 +874,13 @@ function connect(state2, send, normalize = normalizeProp) {
912
874
 
913
875
  // src/slider.machine.ts
914
876
  var import_core = require("@zag-js/core");
915
- function machine(ctx = {}) {
877
+ function machine(ctx) {
916
878
  return (0, import_core.createMachine)({
917
879
  id: "slider",
918
880
  initial: "unknown",
919
881
  context: __spreadValues({
920
882
  thumbSize: null,
921
- uid: "",
883
+ thumbAlignment: "contain",
922
884
  disabled: false,
923
885
  threshold: 5,
924
886
  dir: "ltr",
@@ -957,7 +919,7 @@ function machine(ctx = {}) {
957
919
  on: {
958
920
  SETUP: {
959
921
  target: "idle",
960
- actions: ["setupDocument", "setThumbSize", "checkValue"]
922
+ actions: ["setThumbSize", "checkValue"]
961
923
  }
962
924
  }
963
925
  },
@@ -1029,26 +991,18 @@ function machine(ctx = {}) {
1029
991
  },
1030
992
  activities: {
1031
993
  trackFieldsetDisabled(ctx2) {
1032
- let cleanup;
1033
- nextTick(() => {
1034
- cleanup = trackFieldsetDisabled(dom.getRootEl(ctx2), (disabled) => {
1035
- if (disabled != ctx2.disabled) {
1036
- ctx2.disabled = disabled;
1037
- }
1038
- });
994
+ return trackFieldsetDisabled(dom.getRootEl(ctx2), (disabled) => {
995
+ if (disabled) {
996
+ ctx2.disabled = disabled;
997
+ }
1039
998
  });
1040
- return () => cleanup == null ? void 0 : cleanup();
1041
999
  },
1042
1000
  trackFormReset(ctx2) {
1043
- let cleanup;
1044
- nextTick(() => {
1045
- cleanup = trackFormReset(dom.getInputEl(ctx2), () => {
1046
- if (ctx2.initialValue != null) {
1047
- ctx2.value = ctx2.initialValue;
1048
- }
1049
- });
1001
+ return trackFormReset(dom.getInputEl(ctx2), () => {
1002
+ if (ctx2.initialValue != null) {
1003
+ ctx2.value = ctx2.initialValue;
1004
+ }
1050
1005
  });
1051
- return () => cleanup == null ? void 0 : cleanup();
1052
1006
  },
1053
1007
  trackPointerMove(ctx2, _evt, { send }) {
1054
1008
  return trackPointerMove({
@@ -1063,13 +1017,6 @@ function machine(ctx = {}) {
1063
1017
  }
1064
1018
  },
1065
1019
  actions: {
1066
- setupDocument(ctx2, evt) {
1067
- if (evt.doc)
1068
- ctx2.doc = (0, import_core.ref)(evt.doc);
1069
- if (evt.root)
1070
- ctx2.rootNode = (0, import_core.ref)(evt.root);
1071
- ctx2.uid = evt.id;
1072
- },
1073
1020
  checkValue(ctx2) {
1074
1021
  const value = utils.convert(ctx2, ctx2.value);
1075
1022
  Object.assign(ctx2, { value, initialValue: value });
@@ -1090,6 +1037,8 @@ function machine(ctx = {}) {
1090
1037
  dom.dispatchChangeEvent(ctx2);
1091
1038
  },
1092
1039
  setThumbSize(ctx2) {
1040
+ if (ctx2.thumbAlignment !== "contain")
1041
+ return;
1093
1042
  raf(() => {
1094
1043
  const el = dom.getThumbEl(ctx2);
1095
1044
  if (!el)
@@ -1127,4 +1076,3 @@ function machine(ctx = {}) {
1127
1076
  }
1128
1077
  });
1129
1078
  }
1130
- //# sourceMappingURL=index.js.map