@zag-js/slider 0.1.6 → 0.1.7

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
@@ -42,19 +42,33 @@ function raf(fn) {
42
42
  globalThis.cancelAnimationFrame(id);
43
43
  };
44
44
  }
45
- var noop = () => {
46
- };
47
- var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
48
- var platform = (v) => isDom() && v.test(navigator.platform);
49
- var isDom = () => !!(typeof window !== "undefined");
50
- var isMac = () => platform(/^Mac/);
51
- var isIPhone = () => platform(/^iPhone/);
52
- var isIPad = () => platform(/^iPad/) || isMac() && navigator.maxTouchPoints > 1;
53
- var isIos = () => isIPhone() || isIPad();
45
+ var isDom = () => typeof window !== "undefined";
54
46
  var isArray = (v) => Array.isArray(v);
55
47
  var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
56
- var isMouseEvent = (v) => isObject(v) && "button" in v;
48
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
49
+ function getPlatform() {
50
+ var _a;
51
+ const agent = navigator.userAgentData;
52
+ return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
53
+ }
54
+ var pt = (v) => isDom() && v.test(getPlatform());
55
+ var isTouchDevice = isDom() && !!navigator.maxTouchPoints;
56
+ var isMac = () => pt(/^Mac/) && !isTouchDevice;
57
+ var isApple = () => pt(/mac|iphone|ipad|ipod/i);
58
+ var isIos = () => isApple() && !isMac();
59
+ var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
60
+ var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
61
+ var supportsMouseEvent = () => isDom() && window.onmousedown === null;
62
+ var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
63
+ var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
57
64
  var isLeftClick = (v) => v.button === 0;
65
+ var runIfFn = (v, ...a) => {
66
+ const res = typeof v === "function" ? v(...a) : v;
67
+ return res != null ? res : void 0;
68
+ };
69
+ var noop = () => {
70
+ };
71
+ var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
58
72
  function getListenerElements() {
59
73
  ;
60
74
  globalThis.__listenerElements__ = globalThis.__listenerElements__ || /* @__PURE__ */ new Map();
@@ -65,7 +79,7 @@ function getListenerCache() {
65
79
  globalThis.__listenerCache__ = globalThis.__listenerCache__ || /* @__PURE__ */ new Map();
66
80
  return globalThis.__listenerCache__;
67
81
  }
68
- function globalEventBus(node, type, handler, options) {
82
+ function addGlobalEventListener(node, type, handler, options) {
69
83
  var _a;
70
84
  if (!node)
71
85
  return noop;
@@ -117,10 +131,7 @@ function globalEventBus(node, type, handler, options) {
117
131
  }
118
132
  };
119
133
  }
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;
134
+ var isRef = (v) => hasProp(v, "current");
124
135
  var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
125
136
  function extractInfo(event, type = "page") {
126
137
  const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback : event;
@@ -133,7 +144,7 @@ function extractInfo(event, type = "page") {
133
144
  }
134
145
  function addDomEvent(target, event, listener, options) {
135
146
  const node = isRef(target) ? target.current : runIfFn(target);
136
- return globalEventBus(node, event, listener, options);
147
+ return addGlobalEventListener(node, event, listener, options);
137
148
  }
138
149
  function addPointerEvent(target, event, listener, options) {
139
150
  var _a;
@@ -156,9 +167,6 @@ function filterPrimaryPointer(fn) {
156
167
  fn(event);
157
168
  };
158
169
  }
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
170
  var mouseEventNames = {
163
171
  pointerdown: "mousedown",
164
172
  pointermove: "mousemove",
@@ -188,27 +196,9 @@ function getOwnerWindow(el) {
188
196
  var _a;
189
197
  return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
190
198
  }
191
- function getDescriptor(el, options) {
199
+ function getNativeEvent(e) {
192
200
  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) {
210
- var _a;
211
- return (_a = event.nativeEvent) != null ? _a : event;
201
+ return (_a = e.nativeEvent) != null ? _a : e;
212
202
  }
213
203
  function observeAttributes(node, attributes, fn) {
214
204
  if (!node)
@@ -250,6 +240,24 @@ function trackFieldsetDisabled(el, callback) {
250
240
  callback(fieldset.disabled);
251
241
  return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
252
242
  }
243
+ function getDescriptor(el, options) {
244
+ var _a;
245
+ const { type, property } = options;
246
+ const win = getOwnerWindow(el);
247
+ const _type = type === "input" ? "HTMLInputElement" : "HTMLTextAreaElement";
248
+ const proto = win[_type].prototype;
249
+ return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
250
+ }
251
+ function dispatchInputValueEvent(el, value) {
252
+ var _a;
253
+ const win = getOwnerWindow(el);
254
+ if (!(el instanceof win.HTMLInputElement))
255
+ return;
256
+ const desc = getDescriptor(el, { type: "input", property: "value" });
257
+ (_a = desc.set) == null ? void 0 : _a.call(el, value);
258
+ const event = new win.Event("input", { bubbles: true });
259
+ el.dispatchEvent(event);
260
+ }
253
261
  var rtlKeyMap = {
254
262
  ArrowLeft: "ArrowRight",
255
263
  ArrowRight: "ArrowLeft",
@@ -405,11 +413,11 @@ findByTypeahead.defaultOptions = {
405
413
 
406
414
  // ../../utilities/number/dist/index.mjs
407
415
  var __pow2 = Math.pow;
408
- function round(v, t2) {
416
+ function round(v, t) {
409
417
  let num = valueOf(v);
410
- const p = __pow2(10, t2 != null ? t2 : 10);
418
+ const p = __pow2(10, t != null ? t : 10);
411
419
  num = Math.round(num * p) / p;
412
- return t2 ? num.toFixed(t2) : v.toString();
420
+ return t ? num.toFixed(t) : v.toString();
413
421
  }
414
422
  var valueToPercent = (v, r) => (valueOf(v) - r.min) * 100 / (r.max - r.min);
415
423
  var percentToValue = (v, r) => r.min + (r.max - r.min) * valueOf(v);
@@ -464,13 +472,16 @@ var transform = (a, b) => {
464
472
  };
465
473
 
466
474
  // ../../utilities/rect/dist/index.mjs
475
+ var isDom2 = () => typeof window !== "undefined";
467
476
  var isArray2 = (v) => Array.isArray(v);
468
477
  var isObject2 = (v) => !(v == null || typeof v !== "object" || isArray2(v));
469
- var isTouchEvent2 = (v) => isObject2(v) && "touches" in v;
478
+ var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
479
+ var isTouchDevice2 = isDom2() && !!navigator.maxTouchPoints;
480
+ var isTouchEvent2 = (v) => isObject2(v) && hasProp2(v, "touches");
470
481
  var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
471
- function getEventPoint(e, t2 = "page") {
482
+ function getEventPoint(e, t = "page") {
472
483
  const p = isTouchEvent2(e) ? e.touches[0] || e.changedTouches[0] || fallback2 : e;
473
- return { x: p[`${t2}X`], y: p[`${t2}Y`] };
484
+ return { x: p[`${t}X`], y: p[`${t}Y`] };
474
485
  }
475
486
  function relativeToNode(p, el) {
476
487
  const dx = p.x - el.offsetLeft - el.clientLeft + el.scrollLeft;
@@ -658,6 +669,8 @@ function createNormalizer(fn) {
658
669
  var normalizeProp = createNormalizer((v) => v);
659
670
 
660
671
  // ../../utilities/core/dist/index.mjs
672
+ var isDom3 = () => typeof window !== "undefined";
673
+ var isTouchDevice3 = isDom3() && !!navigator.maxTouchPoints;
661
674
  var isLeftClick2 = (v) => v.button === 0;
662
675
  var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
663
676