@zag-js/slider 0.0.0-dev-20220526121406 → 0.0.0-dev-20220604091726

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
@@ -66,18 +66,27 @@ function raf(fn) {
66
66
  globalThis.cancelAnimationFrame(id);
67
67
  };
68
68
  }
69
+ var runIfFn = (v, ...a) => {
70
+ const res = typeof v === "function" ? v(...a) : v;
71
+ return res != null ? res : void 0;
72
+ };
69
73
  var noop = () => {
70
74
  };
71
75
  var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
72
76
  var platform = (v) => isDom() && v.test(navigator.platform);
73
- var isDom = () => !!(typeof window !== "undefined");
77
+ var isDom = () => typeof window !== "undefined";
74
78
  var isMac = () => platform(/^Mac/);
75
79
  var isIPhone = () => platform(/^iPhone/);
76
80
  var isIPad = () => platform(/^iPad/) || isMac() && navigator.maxTouchPoints > 1;
77
81
  var isIos = () => isIPhone() || isIPad();
78
82
  var isArray = (v) => Array.isArray(v);
79
83
  var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
80
- var isMouseEvent = (v) => isObject(v) && "button" in v;
84
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
85
+ var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
86
+ var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
87
+ var supportsMouseEvent = () => isDom() && window.onmousedown === null;
88
+ var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
89
+ var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
81
90
  var isLeftClick = (v) => v.button === 0;
82
91
  function getListenerElements() {
83
92
  ;
@@ -89,7 +98,7 @@ function getListenerCache() {
89
98
  globalThis.__listenerCache__ = globalThis.__listenerCache__ || /* @__PURE__ */ new Map();
90
99
  return globalThis.__listenerCache__;
91
100
  }
92
- function globalEventBus(node, type, handler, options) {
101
+ function addGlobalEventListener(node, type, handler, options) {
93
102
  var _a;
94
103
  if (!node)
95
104
  return noop;
@@ -141,10 +150,7 @@ function globalEventBus(node, type, handler, options) {
141
150
  }
142
151
  };
143
152
  }
144
- var t = (v) => Object.prototype.toString.call(v).slice(8, -1);
145
- var isRef = (v) => t(v) === "Object" && "current" in v;
146
- var runIfFn = (fn) => t(fn) === "Function" ? fn() : fn;
147
- var isTouchEvent = (v) => t(v) === "Object" && !!v.touches;
153
+ var isRef = (v) => hasProp(v, "current");
148
154
  var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
149
155
  function extractInfo(event, type = "page") {
150
156
  const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback : event;
@@ -157,7 +163,7 @@ function extractInfo(event, type = "page") {
157
163
  }
158
164
  function addDomEvent(target, event, listener, options) {
159
165
  const node = isRef(target) ? target.current : runIfFn(target);
160
- return globalEventBus(node, event, listener, options);
166
+ return addGlobalEventListener(node, event, listener, options);
161
167
  }
162
168
  function addPointerEvent(target, event, listener, options) {
163
169
  var _a;
@@ -180,9 +186,6 @@ function filterPrimaryPointer(fn) {
180
186
  fn(event);
181
187
  };
182
188
  }
183
- var supportsPointerEvent = () => typeof window !== "undefined" && window.onpointerdown === null;
184
- var supportsTouchEvent = () => typeof window !== "undefined" && window.ontouchstart === null;
185
- var supportsMouseEvent = () => typeof window !== "undefined" && window.onmousedown === null;
186
189
  var mouseEventNames = {
187
190
  pointerdown: "mousedown",
188
191
  pointermove: "mousemove",
@@ -212,27 +215,9 @@ function getOwnerWindow(el) {
212
215
  var _a;
213
216
  return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
214
217
  }
215
- function getDescriptor(el, options) {
216
- var _a;
217
- const { type, property } = options;
218
- const win = getOwnerWindow(el);
219
- const _type = type === "input" ? "HTMLInputElement" : "HTMLTextAreaElement";
220
- const proto = win[_type].prototype;
221
- return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
222
- }
223
- function dispatchInputValueEvent(el, value) {
224
- var _a;
225
- const win = getOwnerWindow(el);
226
- if (!(el instanceof win.HTMLInputElement))
227
- return;
228
- const desc = getDescriptor(el, { type: "input", property: "value" });
229
- (_a = desc.set) == null ? void 0 : _a.call(el, value);
230
- const event = new win.Event("input", { bubbles: true });
231
- el.dispatchEvent(event);
232
- }
233
- function getNativeEvent(event) {
218
+ function getNativeEvent(e) {
234
219
  var _a;
235
- return (_a = event.nativeEvent) != null ? _a : event;
220
+ return (_a = e.nativeEvent) != null ? _a : e;
236
221
  }
237
222
  function observeAttributes(node, attributes, fn) {
238
223
  if (!node)
@@ -274,6 +259,24 @@ function trackFieldsetDisabled(el, callback) {
274
259
  callback(fieldset.disabled);
275
260
  return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
276
261
  }
262
+ function getDescriptor(el, options) {
263
+ var _a;
264
+ const { type, property } = options;
265
+ const win = getOwnerWindow(el);
266
+ const _type = type === "input" ? "HTMLInputElement" : "HTMLTextAreaElement";
267
+ const proto = win[_type].prototype;
268
+ return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
269
+ }
270
+ function dispatchInputValueEvent(el, value) {
271
+ var _a;
272
+ const win = getOwnerWindow(el);
273
+ if (!(el instanceof win.HTMLInputElement))
274
+ return;
275
+ const desc = getDescriptor(el, { type: "input", property: "value" });
276
+ (_a = desc.set) == null ? void 0 : _a.call(el, value);
277
+ const event = new win.Event("input", { bubbles: true });
278
+ el.dispatchEvent(event);
279
+ }
277
280
  var rtlKeyMap = {
278
281
  ArrowLeft: "ArrowRight",
279
282
  ArrowRight: "ArrowLeft",
@@ -429,11 +432,11 @@ findByTypeahead.defaultOptions = {
429
432
 
430
433
  // ../../utilities/number/dist/index.mjs
431
434
  var __pow2 = Math.pow;
432
- function round(v, t2) {
435
+ function round(v, t) {
433
436
  let num = valueOf(v);
434
- const p = __pow2(10, t2 != null ? t2 : 10);
437
+ const p = __pow2(10, t != null ? t : 10);
435
438
  num = Math.round(num * p) / p;
436
- return t2 ? num.toFixed(t2) : v.toString();
439
+ return t ? num.toFixed(t) : v.toString();
437
440
  }
438
441
  var valueToPercent = (v, r) => (valueOf(v) - r.min) * 100 / (r.max - r.min);
439
442
  var percentToValue = (v, r) => r.min + (r.max - r.min) * valueOf(v);
@@ -490,11 +493,12 @@ var transform = (a, b) => {
490
493
  // ../../utilities/rect/dist/index.mjs
491
494
  var isArray2 = (v) => Array.isArray(v);
492
495
  var isObject2 = (v) => !(v == null || typeof v !== "object" || isArray2(v));
493
- var isTouchEvent2 = (v) => isObject2(v) && "touches" in v;
496
+ var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
497
+ var isTouchEvent2 = (v) => isObject2(v) && hasProp2(v, "touches");
494
498
  var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
495
- function getEventPoint(e, t2 = "page") {
499
+ function getEventPoint(e, t = "page") {
496
500
  const p = isTouchEvent2(e) ? e.touches[0] || e.changedTouches[0] || fallback2 : e;
497
- return { x: p[`${t2}X`], y: p[`${t2}Y`] };
501
+ return { x: p[`${t}X`], y: p[`${t}Y`] };
498
502
  }
499
503
  function relativeToNode(p, el) {
500
504
  const dx = p.x - el.offsetLeft - el.clientLeft + el.scrollLeft;