@zag-js/slider 0.1.8 → 0.1.11

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,25 +1,8 @@
1
1
  "use strict";
2
2
  var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
- var __spreadValues = (a, b) => {
12
- for (var prop in b || (b = {}))
13
- if (__hasOwnProp.call(b, prop))
14
- __defNormalProp(a, prop, b[prop]);
15
- if (__getOwnPropSymbols)
16
- for (var prop of __getOwnPropSymbols(b)) {
17
- if (__propIsEnum.call(b, prop))
18
- __defNormalProp(a, prop, b[prop]);
19
- }
20
- return a;
21
- };
22
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
6
  var __export = (target, all) => {
24
7
  for (var name in all)
25
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -44,131 +27,76 @@ __export(src_exports, {
44
27
  module.exports = __toCommonJS(src_exports);
45
28
 
46
29
  // ../../utilities/dom/dist/index.mjs
47
- var __pow = Math.pow;
48
30
  var dataAttr = (guard) => {
49
31
  return guard ? "" : void 0;
50
32
  };
51
- var isDom = () => typeof window !== "undefined";
33
+ var runIfFn = (v, ...a) => {
34
+ const res = typeof v === "function" ? v(...a) : v;
35
+ return res ?? void 0;
36
+ };
37
+ var callAll = (...fns) => (...a) => {
38
+ fns.forEach(function(fn) {
39
+ fn == null ? void 0 : fn(...a);
40
+ });
41
+ };
52
42
  var isArray = (v) => Array.isArray(v);
53
43
  var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
54
44
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
45
+ var isDom = () => typeof window !== "undefined";
55
46
  function getPlatform() {
56
- var _a;
57
47
  const agent = navigator.userAgentData;
58
- return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
48
+ return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
59
49
  }
60
50
  var pt = (v) => isDom() && v.test(getPlatform());
61
51
  var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
62
52
  var isMac = () => pt(/^Mac/) && !isTouchDevice;
63
53
  var isApple = () => pt(/mac|iphone|ipad|ipod/i);
64
54
  var isIos = () => isApple() && !isMac();
65
- var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
66
- var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
67
- var supportsMouseEvent = () => isDom() && window.onmousedown === null;
68
- var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
69
- var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
70
- var isLeftClick = (v) => v.button === 0;
71
- var runIfFn = (v, ...a) => {
72
- const res = typeof v === "function" ? v(...a) : v;
73
- return res != null ? res : void 0;
74
- };
75
- var noop = () => {
76
- };
77
- var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
78
- var isRef = (v) => hasProp(v, "current");
79
- var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
80
- function extractInfo(event, type = "page") {
81
- const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback : event;
82
- return {
83
- point: {
84
- x: point[`${type}X`],
85
- y: point[`${type}Y`]
86
- }
87
- };
55
+ function isDocument(el) {
56
+ return el.nodeType === Node.DOCUMENT_NODE;
88
57
  }
89
- function addDomEvent(target, eventName, handler, options) {
90
- const node = isRef(target) ? target.current : runIfFn(target);
91
- node == null ? void 0 : node.addEventListener(eventName, handler, options);
92
- return () => {
93
- node == null ? void 0 : node.removeEventListener(eventName, handler, options);
94
- };
95
- }
96
- function addPointerEvent(target, event, listener, options) {
97
- var _a;
98
- const type = (_a = getEventName(event)) != null ? _a : event;
99
- return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
100
- }
101
- function wrapHandler(fn, filter = false) {
102
- const listener = (event) => {
103
- fn(event, extractInfo(event));
104
- };
105
- return filter ? filterPrimaryPointer(listener) : listener;
58
+ function isWindow(value) {
59
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
106
60
  }
107
- function filterPrimaryPointer(fn) {
108
- return (event) => {
109
- var _a;
110
- const win = (_a = event.view) != null ? _a : window;
111
- const isMouseEvent2 = event instanceof win.MouseEvent;
112
- const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
113
- if (isPrimary)
114
- fn(event);
115
- };
61
+ function getDocument(el) {
62
+ if (isWindow(el))
63
+ return el.document;
64
+ if (isDocument(el))
65
+ return el;
66
+ return (el == null ? void 0 : el.ownerDocument) ?? document;
116
67
  }
117
- var mouseEventNames = {
118
- pointerdown: "mousedown",
119
- pointermove: "mousemove",
120
- pointerup: "mouseup",
121
- pointercancel: "mousecancel",
122
- pointerover: "mouseover",
123
- pointerout: "mouseout",
124
- pointerenter: "mouseenter",
125
- pointerleave: "mouseleave"
126
- };
127
- var touchEventNames = {
128
- pointerdown: "touchstart",
129
- pointermove: "touchmove",
130
- pointerup: "touchend",
131
- pointercancel: "touchcancel"
132
- };
133
- function getEventName(evt) {
134
- if (supportsPointerEvent())
135
- return evt;
136
- if (supportsTouchEvent())
137
- return touchEventNames[evt];
138
- if (supportsMouseEvent())
139
- return mouseEventNames[evt];
140
- return evt;
68
+ function getWindow(el) {
69
+ return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
141
70
  }
142
- function nextTick(fn) {
143
- const set = /* @__PURE__ */ new Set();
144
- function raf2(fn2) {
145
- const id = globalThis.requestAnimationFrame(fn2);
146
- set.add(() => globalThis.cancelAnimationFrame(id));
147
- }
148
- raf2(() => raf2(fn));
149
- return function cleanup() {
150
- set.forEach(function(fn2) {
151
- fn2();
152
- });
71
+ function defineDomHelpers(helpers) {
72
+ const dom2 = {
73
+ getRootNode: (ctx) => {
74
+ var _a;
75
+ return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
76
+ },
77
+ getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
78
+ getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
79
+ getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
80
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
153
81
  };
154
- }
155
- function raf(fn) {
156
- const id = globalThis.requestAnimationFrame(fn);
157
- return function cleanup() {
158
- globalThis.cancelAnimationFrame(id);
82
+ return {
83
+ ...dom2,
84
+ ...helpers
159
85
  };
160
86
  }
161
- function getOwnerWindow(el) {
162
- var _a;
163
- return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
164
- }
165
87
  function getNativeEvent(e) {
166
- var _a;
167
- return (_a = e.nativeEvent) != null ? _a : e;
88
+ return e.nativeEvent ?? e;
168
89
  }
90
+ var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
91
+ var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
92
+ var supportsMouseEvent = () => isDom() && window.onmousedown === null;
93
+ var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
94
+ var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
95
+ var isLeftClick = (v) => v.button === 0;
96
+ var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
169
97
  function observeAttributes(node, attributes, fn) {
170
98
  if (!node)
171
- return noop;
99
+ return;
172
100
  const attrs = Array.isArray(attributes) ? attributes : [attributes];
173
101
  const win = node.ownerDocument.defaultView || window;
174
102
  const obs = new win.MutationObserver((changes) => {
@@ -206,20 +134,57 @@ function trackFieldsetDisabled(el, callback) {
206
134
  callback(fieldset.disabled);
207
135
  return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
208
136
  }
137
+ function getElementOffset(element) {
138
+ let left = 0;
139
+ let top = 0;
140
+ let el = element;
141
+ if (el.parentNode) {
142
+ do {
143
+ left += el.offsetLeft;
144
+ top += el.offsetTop;
145
+ } while ((el = el.offsetParent) && el.nodeType < 9);
146
+ el = element;
147
+ do {
148
+ left -= el.scrollLeft;
149
+ top -= el.scrollTop;
150
+ } while ((el = el.parentNode) && !/body/i.test(el.nodeName));
151
+ }
152
+ return {
153
+ top,
154
+ right: innerWidth - left - element.offsetWidth,
155
+ bottom: innerHeight - top - element.offsetHeight,
156
+ left
157
+ };
158
+ }
159
+ var fallback = {
160
+ pageX: 0,
161
+ pageY: 0,
162
+ clientX: 0,
163
+ clientY: 0
164
+ };
165
+ function getEventPoint(event, type = "page") {
166
+ const point = isTouchEvent(event) ? event.touches[0] ?? event.changedTouches[0] ?? fallback : event;
167
+ return { x: point[`${type}X`], y: point[`${type}Y`] };
168
+ }
169
+ function getPointRelativeToNode(point, element) {
170
+ const offset = getElementOffset(element);
171
+ const x = point.x - offset.left;
172
+ const y = point.y - offset.top;
173
+ return { x, y };
174
+ }
209
175
  function getDescriptor(el, options) {
210
- var _a;
211
176
  const { type, property } = options;
212
- const win = getOwnerWindow(el);
213
- const _type = type === "input" ? "HTMLInputElement" : "HTMLTextAreaElement";
214
- const proto = win[_type].prototype;
215
- return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
177
+ const proto = getWindow(el)[type].prototype;
178
+ return Object.getOwnPropertyDescriptor(proto, property) ?? {};
216
179
  }
217
180
  function dispatchInputValueEvent(el, value) {
218
181
  var _a;
219
- const win = getOwnerWindow(el);
182
+ if (!el)
183
+ return;
184
+ const win = getWindow(el);
220
185
  if (!(el instanceof win.HTMLInputElement))
221
186
  return;
222
- const desc = getDescriptor(el, { type: "input", property: "value" });
187
+ const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
223
188
  (_a = desc.set) == null ? void 0 : _a.call(el, value);
224
189
  const event = new win.Event("input", { bubbles: true });
225
190
  el.dispatchEvent(event);
@@ -240,10 +205,9 @@ var sameKeyMap = {
240
205
  Right: "ArrowRight"
241
206
  };
242
207
  function getEventKey(event, options = {}) {
243
- var _a;
244
208
  const { dir = "ltr", orientation = "horizontal" } = options;
245
209
  let { key } = event;
246
- key = (_a = sameKeyMap[key]) != null ? _a : key;
210
+ key = sameKeyMap[key] ?? key;
247
211
  const isRtl = dir === "rtl" && orientation === "horizontal";
248
212
  if (isRtl && key in rtlKeyMap) {
249
213
  key = rtlKeyMap[key];
@@ -261,11 +225,92 @@ function getEventStep(event) {
261
225
  return isSkipKey ? 10 : 1;
262
226
  }
263
227
  }
228
+ var isRef = (v) => hasProp(v, "current");
229
+ var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
230
+ function extractInfo(event, type = "page") {
231
+ const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback2 : event;
232
+ return {
233
+ point: {
234
+ x: point[`${type}X`],
235
+ y: point[`${type}Y`]
236
+ }
237
+ };
238
+ }
239
+ function addDomEvent(target, eventName, handler, options) {
240
+ const node = isRef(target) ? target.current : runIfFn(target);
241
+ node == null ? void 0 : node.addEventListener(eventName, handler, options);
242
+ return () => {
243
+ node == null ? void 0 : node.removeEventListener(eventName, handler, options);
244
+ };
245
+ }
246
+ function addPointerEvent(target, event, listener, options) {
247
+ const type = getEventName(event) ?? event;
248
+ return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
249
+ }
250
+ function wrapHandler(fn, filter = false) {
251
+ const listener = (event) => {
252
+ fn(event, extractInfo(event));
253
+ };
254
+ return filter ? filterPrimaryPointer(listener) : listener;
255
+ }
256
+ function filterPrimaryPointer(fn) {
257
+ return (event) => {
258
+ const win = event.view ?? window;
259
+ const isMouseEvent2 = event instanceof win.MouseEvent;
260
+ const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
261
+ if (isPrimary)
262
+ fn(event);
263
+ };
264
+ }
265
+ var mouseEventNames = {
266
+ pointerdown: "mousedown",
267
+ pointermove: "mousemove",
268
+ pointerup: "mouseup",
269
+ pointercancel: "mousecancel",
270
+ pointerover: "mouseover",
271
+ pointerout: "mouseout",
272
+ pointerenter: "mouseenter",
273
+ pointerleave: "mouseleave"
274
+ };
275
+ var touchEventNames = {
276
+ pointerdown: "touchstart",
277
+ pointermove: "touchmove",
278
+ pointerup: "touchend",
279
+ pointercancel: "touchcancel"
280
+ };
281
+ function getEventName(evt) {
282
+ if (supportsPointerEvent())
283
+ return evt;
284
+ if (supportsTouchEvent())
285
+ return touchEventNames[evt];
286
+ if (supportsMouseEvent())
287
+ return mouseEventNames[evt];
288
+ return evt;
289
+ }
290
+ function nextTick(fn) {
291
+ const set = /* @__PURE__ */ new Set();
292
+ function raf2(fn2) {
293
+ const id = globalThis.requestAnimationFrame(fn2);
294
+ set.add(() => globalThis.cancelAnimationFrame(id));
295
+ }
296
+ raf2(() => raf2(fn));
297
+ return function cleanup() {
298
+ set.forEach(function(fn2) {
299
+ fn2();
300
+ });
301
+ };
302
+ }
303
+ function raf(fn) {
304
+ const id = globalThis.requestAnimationFrame(fn);
305
+ return function cleanup() {
306
+ globalThis.cancelAnimationFrame(id);
307
+ };
308
+ }
264
309
  var state = "default";
265
310
  var savedUserSelect = "";
266
311
  var modifiedElementMap = /* @__PURE__ */ new WeakMap();
267
312
  function disableTextSelection({ target, doc } = {}) {
268
- const _document = doc != null ? doc : document;
313
+ const _document = doc ?? document;
269
314
  if (isIos()) {
270
315
  if (state === "default") {
271
316
  savedUserSelect = _document.documentElement.style.webkitUserSelect;
@@ -279,7 +324,7 @@ function disableTextSelection({ target, doc } = {}) {
279
324
  return () => restoreTextSelection({ target, doc: _document });
280
325
  }
281
326
  function restoreTextSelection({ target, doc } = {}) {
282
- const _document = doc != null ? doc : document;
327
+ const _document = doc ?? document;
283
328
  if (isIos()) {
284
329
  if (state !== "disabled")
285
330
  return;
@@ -299,7 +344,7 @@ function restoreTextSelection({ target, doc } = {}) {
299
344
  if (target && modifiedElementMap.has(target)) {
300
345
  let targetOldUserSelect = modifiedElementMap.get(target);
301
346
  if (target.style.userSelect === "none") {
302
- target.style.userSelect = targetOldUserSelect != null ? targetOldUserSelect : "";
347
+ target.style.userSelect = targetOldUserSelect ?? "";
303
348
  }
304
349
  if (target.getAttribute("style") === "") {
305
350
  target.removeAttribute("style");
@@ -308,13 +353,13 @@ function restoreTextSelection({ target, doc } = {}) {
308
353
  }
309
354
  }
310
355
  }
311
- function trackPointerMove(opts) {
312
- const { onPointerMove, onPointerUp, ctx } = opts;
313
- const { doc = document, threshold = 5 } = ctx;
356
+ var THRESHOLD = 5;
357
+ function trackPointerMove(doc, opts) {
358
+ const { onPointerMove, onPointerUp } = opts;
314
359
  const handlePointerMove = (event, info) => {
315
360
  const { point: p } = info;
316
- const distance = Math.sqrt(__pow(p.x, 2) + __pow(p.y, 2));
317
- if (distance < threshold)
361
+ const distance = Math.sqrt(p.x ** 2 + p.y ** 2);
362
+ if (distance < THRESHOLD)
318
363
  return;
319
364
  if (isMouseEvent(event) && isLeftClick(event)) {
320
365
  onPointerUp();
@@ -322,33 +367,13 @@ function trackPointerMove(opts) {
322
367
  }
323
368
  onPointerMove(info, event);
324
369
  };
325
- return pipe(addPointerEvent(doc, "pointermove", handlePointerMove, false), addPointerEvent(doc, "pointerup", onPointerUp, false), addPointerEvent(doc, "pointercancel", onPointerUp, false), addPointerEvent(doc, "contextmenu", onPointerUp, false), disableTextSelection({ doc }));
326
- }
327
-
328
- // ../../utilities/rect/dist/index.mjs
329
- var isArray2 = (v) => Array.isArray(v);
330
- var isObject2 = (v) => !(v == null || typeof v !== "object" || isArray2(v));
331
- var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
332
- var isTouchEvent2 = (v) => isObject2(v) && hasProp2(v, "touches");
333
- var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
334
- function getEventPoint(e, t = "page") {
335
- const p = isTouchEvent2(e) ? e.touches[0] || e.changedTouches[0] || fallback2 : e;
336
- return { x: p[`${t}X`], y: p[`${t}Y`] };
337
- }
338
- function relativeToNode(p, el) {
339
- const dx = p.x - el.offsetLeft - el.clientLeft + el.scrollLeft;
340
- const dy = p.y - el.offsetTop - el.clientTop + el.scrollTop;
341
- return {
342
- point: { x: dx, y: dy },
343
- progress: { x: dx / el.offsetWidth, y: dy / el.offsetHeight }
344
- };
370
+ return callAll(addPointerEvent(doc, "pointermove", handlePointerMove, false), addPointerEvent(doc, "pointerup", onPointerUp, false), addPointerEvent(doc, "pointercancel", onPointerUp, false), addPointerEvent(doc, "contextmenu", onPointerUp, false), disableTextSelection({ doc }));
345
371
  }
346
372
 
347
373
  // ../../utilities/number/dist/index.mjs
348
- var __pow2 = Math.pow;
349
374
  function round(v, t) {
350
375
  let num = valueOf(v);
351
- const p = __pow2(10, t != null ? t : 10);
376
+ const p = 10 ** (t ?? 10);
352
377
  num = Math.round(num * p) / p;
353
378
  return t ? num.toFixed(t) : v.toString();
354
379
  }
@@ -384,7 +409,7 @@ function valueOf(v) {
384
409
  function decimalOperation(a, op, b) {
385
410
  let result = op === "+" ? a + b : a - b;
386
411
  if (a % 1 !== 0 || b % 1 !== 0) {
387
- const multiplier = __pow2(10, Math.max(countDecimals(a), countDecimals(b)));
412
+ const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
388
413
  a = Math.round(a * multiplier);
389
414
  b = Math.round(b * multiplier);
390
415
  result = op === "+" ? a + b : a - b;
@@ -406,14 +431,12 @@ var transform = (a, b) => {
406
431
 
407
432
  // src/slider.style.ts
408
433
  function getVerticalThumbOffset(ctx) {
409
- var _a;
410
- const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
434
+ const { height = 0 } = ctx.thumbSize ?? {};
411
435
  const getValue = transform([ctx.min, ctx.max], [-height / 2, height / 2]);
412
436
  return parseFloat(getValue(ctx.value).toFixed(2));
413
437
  }
414
438
  function getHorizontalThumbOffset(ctx) {
415
- var _a;
416
- const { width = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
439
+ const { width = 0 } = ctx.thumbSize ?? {};
417
440
  if (ctx.isRtl) {
418
441
  const getValue2 = transform([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
419
442
  return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
@@ -523,69 +546,64 @@ var utils = {
523
546
  return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
524
547
  },
525
548
  decrement(ctx, step) {
526
- let value = decrement(ctx.value, step != null ? step : ctx.step);
549
+ let value = decrement(ctx.value, step ?? ctx.step);
527
550
  return utils.convert(ctx, value);
528
551
  },
529
552
  increment(ctx, step) {
530
- let value = increment(ctx.value, step != null ? step : ctx.step);
553
+ let value = increment(ctx.value, step ?? ctx.step);
531
554
  return utils.convert(ctx, value);
532
555
  }
533
556
  };
534
557
 
535
558
  // src/slider.dom.ts
536
- var dom = __spreadProps(__spreadValues({}, styles), {
537
- getDoc: (ctx) => {
538
- var _a;
539
- return (_a = ctx.doc) != null ? _a : document;
540
- },
541
- getRootNode: (ctx) => {
542
- var _a;
543
- return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
544
- },
559
+ var dom = defineDomHelpers({
560
+ ...styles,
545
561
  getRootId: (ctx) => {
546
- var _a, _b;
547
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `slider:${ctx.uid}`;
562
+ var _a;
563
+ return ((_a = ctx.ids) == null ? void 0 : _a.root) ?? `slider:${ctx.id}`;
548
564
  },
549
565
  getThumbId: (ctx) => {
550
- var _a, _b;
551
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.thumb) != null ? _b : `slider:${ctx.uid}:thumb`;
566
+ var _a;
567
+ return ((_a = ctx.ids) == null ? void 0 : _a.thumb) ?? `slider:${ctx.id}:thumb`;
552
568
  },
553
569
  getControlId: (ctx) => {
554
- var _a, _b;
555
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.control) != null ? _b : `slider:${ctx.uid}:control`;
570
+ var _a;
571
+ return ((_a = ctx.ids) == null ? void 0 : _a.control) ?? `slider:${ctx.id}:control`;
556
572
  },
557
- getInputId: (ctx) => `slider:${ctx.uid}:input`,
573
+ getInputId: (ctx) => `slider:${ctx.id}:input`,
558
574
  getOutputId: (ctx) => {
559
- var _a, _b;
560
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.output) != null ? _b : `slider:${ctx.uid}:output`;
575
+ var _a;
576
+ return ((_a = ctx.ids) == null ? void 0 : _a.output) ?? `slider:${ctx.id}:output`;
561
577
  },
562
578
  getTrackId: (ctx) => {
563
- var _a, _b;
564
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.uid}track`;
579
+ var _a;
580
+ return ((_a = ctx.ids) == null ? void 0 : _a.track) ?? `slider:${ctx.id}track`;
565
581
  },
566
582
  getRangeId: (ctx) => {
567
- var _a, _b;
568
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.uid}:range`;
583
+ var _a;
584
+ return ((_a = ctx.ids) == null ? void 0 : _a.track) ?? `slider:${ctx.id}:range`;
569
585
  },
570
586
  getLabelId: (ctx) => {
571
- var _a, _b;
572
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.uid}:label`;
587
+ var _a;
588
+ return ((_a = ctx.ids) == null ? void 0 : _a.label) ?? `slider:${ctx.id}:label`;
573
589
  },
574
- getMarkerId: (ctx, value) => `slider:${ctx.uid}:marker:${value}`,
575
- getRootEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getRootId(ctx)),
576
- getThumbEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getThumbId(ctx)),
577
- getControlEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getControlId(ctx)),
578
- getInputEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getInputId(ctx)),
590
+ getMarkerId: (ctx, value) => `slider:${ctx.id}:marker:${value}`,
591
+ getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
592
+ getThumbEl: (ctx) => dom.getById(ctx, dom.getThumbId(ctx)),
593
+ getControlEl: (ctx) => dom.getById(ctx, dom.getControlId(ctx)),
594
+ getInputEl: (ctx) => dom.getById(ctx, dom.getInputId(ctx)),
579
595
  getValueFromPoint(ctx, point) {
580
- const control = dom.getControlEl(ctx);
581
- if (!control)
596
+ const el = dom.getControlEl(ctx);
597
+ if (!el)
582
598
  return;
583
- const { progress } = relativeToNode(point, control);
599
+ const relativePoint = getPointRelativeToNode(point, el);
600
+ const percentX = relativePoint.x / el.offsetWidth;
601
+ const percentY = relativePoint.y / el.offsetHeight;
584
602
  let percent;
585
603
  if (ctx.isHorizontal) {
586
- percent = ctx.isRtl ? 1 - progress.x : progress.x;
604
+ percent = ctx.isRtl ? 1 - percentX : percentX;
587
605
  } else {
588
- percent = 1 - progress.y;
606
+ percent = 1 - percentY;
589
607
  }
590
608
  return utils.fromPercent(ctx, percent);
591
609
  },
@@ -597,22 +615,8 @@ var dom = __spreadProps(__spreadValues({}, styles), {
597
615
  }
598
616
  });
599
617
 
600
- // ../../types/dist/index.mjs
601
- function createNormalizer(fn) {
602
- return new Proxy({}, {
603
- get() {
604
- return fn;
605
- }
606
- });
607
- }
608
- var normalizeProp = createNormalizer((v) => v);
609
-
610
- // ../../utilities/core/dist/index.mjs
611
- var isLeftClick2 = (v) => v.button === 0;
612
- var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
613
-
614
618
  // src/slider.connect.ts
615
- function connect(state2, send, normalize = normalizeProp) {
619
+ function connect(state2, send, normalize) {
616
620
  var _a, _b;
617
621
  const ariaLabel = state2.context["aria-label"];
618
622
  const ariaLabelledBy = state2.context["aria-labelledby"];
@@ -680,7 +684,7 @@ function connect(state2, send, normalize = normalizeProp) {
680
684
  "data-invalid": dataAttr(isInvalid),
681
685
  "aria-disabled": isDisabled || void 0,
682
686
  "aria-label": ariaLabel,
683
- "aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy != null ? ariaLabelledBy : dom.getLabelId(state2.context),
687
+ "aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy ?? dom.getLabelId(state2.context),
684
688
  "aria-orientation": state2.context.orientation,
685
689
  "aria-valuemax": state2.context.max,
686
690
  "aria-valuemin": state2.context.min,
@@ -789,7 +793,7 @@ function connect(state2, send, normalize = normalizeProp) {
789
793
  if (!isInteractive)
790
794
  return;
791
795
  const evt = getNativeEvent(event);
792
- if (!isLeftClick2(evt) || isModifiedEvent(evt))
796
+ if (!isLeftClick(evt) || isModifiedEvent(evt))
793
797
  return;
794
798
  const point = getEventPoint(evt);
795
799
  send({ type: "POINTER_DOWN", point });
@@ -825,14 +829,13 @@ function connect(state2, send, normalize = normalizeProp) {
825
829
 
826
830
  // src/slider.machine.ts
827
831
  var import_core = require("@zag-js/core");
828
- function machine(ctx = {}) {
832
+ function machine(ctx) {
829
833
  return (0, import_core.createMachine)({
830
834
  id: "slider",
831
835
  initial: "unknown",
832
- context: __spreadValues({
836
+ context: {
833
837
  thumbSize: null,
834
838
  thumbAlignment: "contain",
835
- uid: "",
836
839
  disabled: false,
837
840
  threshold: 5,
838
841
  dir: "ltr",
@@ -842,8 +845,9 @@ function machine(ctx = {}) {
842
845
  value: 0,
843
846
  step: 1,
844
847
  min: 0,
845
- max: 100
846
- }, ctx),
848
+ max: 100,
849
+ ...ctx
850
+ },
847
851
  computed: {
848
852
  isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
849
853
  isVertical: (ctx2) => ctx2.orientation === "vertical",
@@ -871,7 +875,7 @@ function machine(ctx = {}) {
871
875
  on: {
872
876
  SETUP: {
873
877
  target: "idle",
874
- actions: ["setupDocument", "setThumbSize", "checkValue"]
878
+ actions: ["setThumbSize", "checkValue"]
875
879
  }
876
880
  }
877
881
  },
@@ -943,30 +947,21 @@ function machine(ctx = {}) {
943
947
  },
944
948
  activities: {
945
949
  trackFieldsetDisabled(ctx2) {
946
- let cleanup;
947
- nextTick(() => {
948
- cleanup = trackFieldsetDisabled(dom.getRootEl(ctx2), (disabled) => {
949
- if (disabled) {
950
- ctx2.disabled = disabled;
951
- }
952
- });
950
+ return trackFieldsetDisabled(dom.getRootEl(ctx2), (disabled) => {
951
+ if (disabled) {
952
+ ctx2.disabled = disabled;
953
+ }
953
954
  });
954
- return () => cleanup == null ? void 0 : cleanup();
955
955
  },
956
956
  trackFormReset(ctx2) {
957
- let cleanup;
958
- nextTick(() => {
959
- cleanup = trackFormReset(dom.getInputEl(ctx2), () => {
960
- if (ctx2.initialValue != null) {
961
- ctx2.value = ctx2.initialValue;
962
- }
963
- });
957
+ return trackFormReset(dom.getInputEl(ctx2), () => {
958
+ if (ctx2.initialValue != null) {
959
+ ctx2.value = ctx2.initialValue;
960
+ }
964
961
  });
965
- return () => cleanup == null ? void 0 : cleanup();
966
962
  },
967
963
  trackPointerMove(ctx2, _evt, { send }) {
968
- return trackPointerMove({
969
- ctx: ctx2,
964
+ return trackPointerMove(dom.getDoc(ctx2), {
970
965
  onPointerMove(info) {
971
966
  send({ type: "POINTER_MOVE", point: info.point });
972
967
  },
@@ -977,13 +972,6 @@ function machine(ctx = {}) {
977
972
  }
978
973
  },
979
974
  actions: {
980
- setupDocument(ctx2, evt) {
981
- if (evt.doc)
982
- ctx2.doc = (0, import_core.ref)(evt.doc);
983
- if (evt.root)
984
- ctx2.rootNode = (0, import_core.ref)(evt.root);
985
- ctx2.uid = evt.id;
986
- },
987
975
  checkValue(ctx2) {
988
976
  const value = utils.convert(ctx2, ctx2.value);
989
977
  Object.assign(ctx2, { value, initialValue: value });
@@ -1043,3 +1031,9 @@ function machine(ctx = {}) {
1043
1031
  }
1044
1032
  });
1045
1033
  }
1034
+ // Annotate the CommonJS export names for ESM import in node:
1035
+ 0 && (module.exports = {
1036
+ connect,
1037
+ machine,
1038
+ unstable__dom
1039
+ });