@zag-js/slider 0.1.15 → 0.2.0

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.d.ts CHANGED
@@ -172,6 +172,10 @@ declare const dom: {
172
172
  getById: <T_1 = HTMLElement>(ctx: {
173
173
  getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
174
174
  }, id: string) => T_1 | null;
175
+ createEmitter: (ctx: {
176
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
177
+ }, target: HTMLElement) => (evt: string, detail: Record<string, any>, options?: EventInit | undefined) => void;
178
+ createListener: (target: HTMLElement) => <T_2 = any>(evt: string, handler: (e: CustomEvent<T_2>) => void) => () => void;
175
179
  } & {
176
180
  getRootId: (ctx: MachineContext) => string;
177
181
  getThumbId: (ctx: MachineContext) => string;
package/dist/index.js CHANGED
@@ -1,10 +1,38 @@
1
- // ../../utilities/dom/dist/index.js
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ connect: () => connect,
24
+ machine: () => machine,
25
+ unstable__dom: () => dom
26
+ });
27
+ module.exports = __toCommonJS(src_exports);
28
+
29
+ // ../../utilities/dom/dist/index.mjs
2
30
  var dataAttr = (guard) => {
3
31
  return guard ? "" : void 0;
4
32
  };
5
33
  var runIfFn = (v, ...a) => {
6
34
  const res = typeof v === "function" ? v(...a) : v;
7
- return res ?? void 0;
35
+ return res != null ? res : void 0;
8
36
  };
9
37
  var callAll = (...fns) => (...a) => {
10
38
  fns.forEach(function(fn) {
@@ -16,8 +44,9 @@ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
16
44
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
17
45
  var isDom = () => typeof window !== "undefined";
18
46
  function getPlatform() {
47
+ var _a;
19
48
  const agent = navigator.userAgentData;
20
- return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
49
+ return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
21
50
  }
22
51
  var pt = (v) => isDom() && v.test(getPlatform());
23
52
  var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
@@ -31,22 +60,44 @@ function isWindow(value) {
31
60
  return (value == null ? void 0 : value.toString()) === "[object Window]";
32
61
  }
33
62
  function getDocument(el) {
63
+ var _a;
34
64
  if (isWindow(el))
35
65
  return el.document;
36
66
  if (isDocument(el))
37
67
  return el;
38
- return (el == null ? void 0 : el.ownerDocument) ?? document;
68
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
39
69
  }
40
70
  function defineDomHelpers(helpers) {
41
71
  const dom2 = {
42
72
  getRootNode: (ctx) => {
43
- var _a;
44
- return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
73
+ var _a, _b;
74
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
45
75
  },
46
76
  getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
47
- getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
77
+ getWin: (ctx) => {
78
+ var _a;
79
+ return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
80
+ },
48
81
  getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
49
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
82
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
83
+ createEmitter: (ctx, target) => {
84
+ const win = dom2.getWin(ctx);
85
+ return function emit(evt, detail, options) {
86
+ const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
87
+ const eventName = `zag:${evt}`;
88
+ const init = { bubbles, cancelable, composed, detail };
89
+ const event = new win.CustomEvent(eventName, init);
90
+ target.dispatchEvent(event);
91
+ };
92
+ },
93
+ createListener: (target) => {
94
+ return function listen(evt, handler) {
95
+ const eventName = `zag:${evt}`;
96
+ const listener = (e) => handler(e);
97
+ target.addEventListener(eventName, listener);
98
+ return () => target.removeEventListener(eventName, listener);
99
+ };
100
+ }
50
101
  };
51
102
  return {
52
103
  ...dom2,
@@ -54,7 +105,8 @@ function defineDomHelpers(helpers) {
54
105
  };
55
106
  }
56
107
  function getNativeEvent(e) {
57
- return e.nativeEvent ?? e;
108
+ var _a;
109
+ return (_a = e.nativeEvent) != null ? _a : e;
58
110
  }
59
111
  var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
60
112
  var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
@@ -92,7 +144,8 @@ var fallback = {
92
144
  clientY: 0
93
145
  };
94
146
  function getEventPoint(event, type = "page") {
95
- const point = isTouchEvent(event) ? event.touches[0] ?? event.changedTouches[0] ?? fallback : event;
147
+ var _a, _b;
148
+ const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event;
96
149
  return { x: point[`${type}X`], y: point[`${type}Y`] };
97
150
  }
98
151
  function getPointRelativeToNode(point, element) {
@@ -115,9 +168,10 @@ var sameKeyMap = {
115
168
  Right: "ArrowRight"
116
169
  };
117
170
  function getEventKey(event, options = {}) {
171
+ var _a;
118
172
  const { dir = "ltr", orientation = "horizontal" } = options;
119
173
  let { key } = event;
120
- key = sameKeyMap[key] ?? key;
174
+ key = (_a = sameKeyMap[key]) != null ? _a : key;
121
175
  const isRtl = dir === "rtl" && orientation === "horizontal";
122
176
  if (isRtl && key in rtlKeyMap) {
123
177
  key = rtlKeyMap[key];
@@ -154,7 +208,8 @@ function addDomEvent(target, eventName, handler, options) {
154
208
  };
155
209
  }
156
210
  function addPointerEvent(target, event, listener, options) {
157
- const type = getEventName(event) ?? event;
211
+ var _a;
212
+ const type = (_a = getEventName(event)) != null ? _a : event;
158
213
  return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
159
214
  }
160
215
  function wrapHandler(fn, filter = false) {
@@ -165,7 +220,8 @@ function wrapHandler(fn, filter = false) {
165
220
  }
166
221
  function filterPrimaryPointer(fn) {
167
222
  return (event) => {
168
- const win = event.view ?? window;
223
+ var _a;
224
+ const win = (_a = event.view) != null ? _a : window;
169
225
  const isMouseEvent2 = event instanceof win.MouseEvent;
170
226
  const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
171
227
  if (isPrimary)
@@ -220,7 +276,7 @@ var state = "default";
220
276
  var savedUserSelect = "";
221
277
  var modifiedElementMap = /* @__PURE__ */ new WeakMap();
222
278
  function disableTextSelection({ target, doc } = {}) {
223
- const _document = doc ?? document;
279
+ const _document = doc != null ? doc : document;
224
280
  if (isIos()) {
225
281
  if (state === "default") {
226
282
  savedUserSelect = _document.documentElement.style.webkitUserSelect;
@@ -234,7 +290,7 @@ function disableTextSelection({ target, doc } = {}) {
234
290
  return () => restoreTextSelection({ target, doc: _document });
235
291
  }
236
292
  function restoreTextSelection({ target, doc } = {}) {
237
- const _document = doc ?? document;
293
+ const _document = doc != null ? doc : document;
238
294
  if (isIos()) {
239
295
  if (state !== "disabled")
240
296
  return;
@@ -254,7 +310,7 @@ function restoreTextSelection({ target, doc } = {}) {
254
310
  if (target && modifiedElementMap.has(target)) {
255
311
  let targetOldUserSelect = modifiedElementMap.get(target);
256
312
  if (target.style.userSelect === "none") {
257
- target.style.userSelect = targetOldUserSelect ?? "";
313
+ target.style.userSelect = targetOldUserSelect != null ? targetOldUserSelect : "";
258
314
  }
259
315
  if (target.getAttribute("style") === "") {
260
316
  target.removeAttribute("style");
@@ -286,9 +342,10 @@ function trackPointerMove(doc, opts) {
286
342
  );
287
343
  }
288
344
 
289
- // ../../utilities/form-utils/dist/index.js
345
+ // ../../utilities/form-utils/dist/index.mjs
290
346
  function getWindow(el) {
291
- return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
347
+ var _a;
348
+ return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
292
349
  }
293
350
  function observeAttributes(node, attributes, fn) {
294
351
  if (!node)
@@ -306,9 +363,10 @@ function observeAttributes(node, attributes, fn) {
306
363
  return () => obs.disconnect();
307
364
  }
308
365
  function getDescriptor(el, options) {
366
+ var _a;
309
367
  const { type, property } = options;
310
368
  const proto = getWindow(el)[type].prototype;
311
- return Object.getOwnPropertyDescriptor(proto, property) ?? {};
369
+ return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
312
370
  }
313
371
  function dispatchInputValueEvent(el, value) {
314
372
  var _a;
@@ -348,10 +406,10 @@ function trackFieldsetDisabled(el, callback) {
348
406
  return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
349
407
  }
350
408
 
351
- // ../../utilities/number/dist/index.js
409
+ // ../../utilities/number/dist/index.mjs
352
410
  function round(v, t) {
353
411
  let num = valueOf(v);
354
- const p = 10 ** (t ?? 10);
412
+ const p = 10 ** (t != null ? t : 10);
355
413
  num = Math.round(num * p) / p;
356
414
  return t ? num.toFixed(t) : v.toString();
357
415
  }
@@ -409,12 +467,14 @@ var transform = (a, b) => {
409
467
 
410
468
  // src/slider.style.ts
411
469
  function getVerticalThumbOffset(ctx) {
412
- const { height = 0 } = ctx.thumbSize ?? {};
470
+ var _a;
471
+ const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
413
472
  const getValue = transform([ctx.min, ctx.max], [-height / 2, height / 2]);
414
473
  return parseFloat(getValue(ctx.value).toFixed(2));
415
474
  }
416
475
  function getHorizontalThumbOffset(ctx) {
417
- const { width = 0 } = ctx.thumbSize ?? {};
476
+ var _a;
477
+ const { width = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
418
478
  if (ctx.isRtl) {
419
479
  const getValue2 = transform([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
420
480
  return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
@@ -524,11 +584,11 @@ var utils = {
524
584
  return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
525
585
  },
526
586
  decrement(ctx, step) {
527
- let value = decrement(ctx.value, step ?? ctx.step);
587
+ let value = decrement(ctx.value, step != null ? step : ctx.step);
528
588
  return utils.convert(ctx, value);
529
589
  },
530
590
  increment(ctx, step) {
531
- let value = increment(ctx.value, step ?? ctx.step);
591
+ let value = increment(ctx.value, step != null ? step : ctx.step);
532
592
  return utils.convert(ctx, value);
533
593
  }
534
594
  };
@@ -537,33 +597,33 @@ var utils = {
537
597
  var dom = defineDomHelpers({
538
598
  ...styles,
539
599
  getRootId: (ctx) => {
540
- var _a;
541
- return ((_a = ctx.ids) == null ? void 0 : _a.root) ?? `slider:${ctx.id}`;
600
+ var _a, _b;
601
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `slider:${ctx.id}`;
542
602
  },
543
603
  getThumbId: (ctx) => {
544
- var _a;
545
- return ((_a = ctx.ids) == null ? void 0 : _a.thumb) ?? `slider:${ctx.id}:thumb`;
604
+ var _a, _b;
605
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.thumb) != null ? _b : `slider:${ctx.id}:thumb`;
546
606
  },
547
607
  getControlId: (ctx) => {
548
- var _a;
549
- return ((_a = ctx.ids) == null ? void 0 : _a.control) ?? `slider:${ctx.id}:control`;
608
+ var _a, _b;
609
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.control) != null ? _b : `slider:${ctx.id}:control`;
550
610
  },
551
611
  getInputId: (ctx) => `slider:${ctx.id}:input`,
552
612
  getOutputId: (ctx) => {
553
- var _a;
554
- return ((_a = ctx.ids) == null ? void 0 : _a.output) ?? `slider:${ctx.id}:output`;
613
+ var _a, _b;
614
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.output) != null ? _b : `slider:${ctx.id}:output`;
555
615
  },
556
616
  getTrackId: (ctx) => {
557
- var _a;
558
- return ((_a = ctx.ids) == null ? void 0 : _a.track) ?? `slider:${ctx.id}track`;
617
+ var _a, _b;
618
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}track`;
559
619
  },
560
620
  getRangeId: (ctx) => {
561
- var _a;
562
- return ((_a = ctx.ids) == null ? void 0 : _a.track) ?? `slider:${ctx.id}:range`;
621
+ var _a, _b;
622
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}:range`;
563
623
  },
564
624
  getLabelId: (ctx) => {
565
- var _a;
566
- return ((_a = ctx.ids) == null ? void 0 : _a.label) ?? `slider:${ctx.id}:label`;
625
+ var _a, _b;
626
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.id}:label`;
567
627
  },
568
628
  getMarkerId: (ctx, value) => `slider:${ctx.id}:marker:${value}`,
569
629
  getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
@@ -662,7 +722,7 @@ function connect(state2, send, normalize) {
662
722
  "data-invalid": dataAttr(isInvalid),
663
723
  "aria-disabled": isDisabled || void 0,
664
724
  "aria-label": ariaLabel,
665
- "aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy ?? dom.getLabelId(state2.context),
725
+ "aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy != null ? ariaLabelledBy : dom.getLabelId(state2.context),
666
726
  "aria-orientation": state2.context.orientation,
667
727
  "aria-valuemax": state2.context.max,
668
728
  "aria-valuemin": state2.context.min,
@@ -806,10 +866,10 @@ function connect(state2, send, normalize) {
806
866
  }
807
867
 
808
868
  // src/slider.machine.ts
809
- import { createMachine } from "@zag-js/core";
810
- import { trackElementSize } from "@zag-js/element-size";
869
+ var import_core = require("@zag-js/core");
870
+ var import_element_size = require("@zag-js/element-size");
811
871
  function machine(ctx) {
812
- return createMachine(
872
+ return (0, import_core.createMachine)(
813
873
  {
814
874
  id: "slider",
815
875
  initial: "unknown",
@@ -954,7 +1014,7 @@ function machine(ctx) {
954
1014
  trackThumbSize(ctx2, _evt) {
955
1015
  if (ctx2.thumbAlignment !== "contain")
956
1016
  return;
957
- return trackElementSize(dom.getThumbEl(ctx2), (size) => {
1017
+ return (0, import_element_size.trackElementSize)(dom.getThumbEl(ctx2), (size) => {
958
1018
  if (size)
959
1019
  ctx2.thumbSize = size;
960
1020
  });
@@ -1012,8 +1072,9 @@ function machine(ctx) {
1012
1072
  }
1013
1073
  );
1014
1074
  }
1015
- export {
1075
+ // Annotate the CommonJS export names for ESM import in node:
1076
+ 0 && (module.exports = {
1016
1077
  connect,
1017
1078
  machine,
1018
- dom as unstable__dom
1019
- };
1079
+ unstable__dom
1080
+ });