@zag-js/slider 0.1.9 → 0.1.12

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,13 +27,12 @@ __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
33
  var runIfFn = (v, ...a) => {
52
34
  const res = typeof v === "function" ? v(...a) : v;
53
- return res != null ? res : void 0;
35
+ return res ?? void 0;
54
36
  };
55
37
  var callAll = (...fns) => (...a) => {
56
38
  fns.forEach(function(fn) {
@@ -62,22 +44,45 @@ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
62
44
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
63
45
  var isDom = () => typeof window !== "undefined";
64
46
  function getPlatform() {
65
- var _a;
66
47
  const agent = navigator.userAgentData;
67
- return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
48
+ return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
68
49
  }
69
50
  var pt = (v) => isDom() && v.test(getPlatform());
70
51
  var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
71
52
  var isMac = () => pt(/^Mac/) && !isTouchDevice;
72
53
  var isApple = () => pt(/mac|iphone|ipad|ipod/i);
73
54
  var isIos = () => isApple() && !isMac();
74
- function getWindow(el) {
75
- var _a;
76
- return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
55
+ function isDocument(el) {
56
+ return el.nodeType === Node.DOCUMENT_NODE;
57
+ }
58
+ function isWindow(value) {
59
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
60
+ }
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;
67
+ }
68
+ function defineDomHelpers(helpers) {
69
+ const dom2 = {
70
+ getRootNode: (ctx) => {
71
+ var _a;
72
+ return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
73
+ },
74
+ getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
75
+ getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
76
+ getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
77
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
78
+ };
79
+ return {
80
+ ...dom2,
81
+ ...helpers
82
+ };
77
83
  }
78
84
  function getNativeEvent(e) {
79
- var _a;
80
- return (_a = e.nativeEvent) != null ? _a : e;
85
+ return e.nativeEvent ?? e;
81
86
  }
82
87
  var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
83
88
  var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
@@ -86,46 +91,6 @@ var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
86
91
  var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
87
92
  var isLeftClick = (v) => v.button === 0;
88
93
  var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
89
- function observeAttributes(node, attributes, fn) {
90
- if (!node)
91
- return;
92
- const attrs = Array.isArray(attributes) ? attributes : [attributes];
93
- const win = node.ownerDocument.defaultView || window;
94
- const obs = new win.MutationObserver((changes) => {
95
- for (const change of changes) {
96
- if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
97
- fn(change);
98
- }
99
- }
100
- });
101
- obs.observe(node, { attributes: true, attributeFilter: attrs });
102
- return () => obs.disconnect();
103
- }
104
- function getClosestForm(el) {
105
- if (isFormElement(el))
106
- return el.form;
107
- else
108
- return el.closest("form");
109
- }
110
- function isFormElement(el) {
111
- return el.matches("textarea, input, select, button");
112
- }
113
- function trackFormReset(el, callback) {
114
- if (!el)
115
- return;
116
- const form = getClosestForm(el);
117
- form == null ? void 0 : form.addEventListener("reset", callback, { passive: true });
118
- return () => {
119
- form == null ? void 0 : form.removeEventListener("reset", callback);
120
- };
121
- }
122
- function trackFieldsetDisabled(el, callback) {
123
- const fieldset = el == null ? void 0 : el.closest("fieldset");
124
- if (!fieldset)
125
- return;
126
- callback(fieldset.disabled);
127
- return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
128
- }
129
94
  function getElementOffset(element) {
130
95
  let left = 0;
131
96
  let top = 0;
@@ -155,8 +120,7 @@ var fallback = {
155
120
  clientY: 0
156
121
  };
157
122
  function getEventPoint(event, type = "page") {
158
- var _a, _b;
159
- const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event;
123
+ const point = isTouchEvent(event) ? event.touches[0] ?? event.changedTouches[0] ?? fallback : event;
160
124
  return { x: point[`${type}X`], y: point[`${type}Y`] };
161
125
  }
162
126
  function getPointRelativeToNode(point, element) {
@@ -165,22 +129,6 @@ function getPointRelativeToNode(point, element) {
165
129
  const y = point.y - offset.top;
166
130
  return { x, y };
167
131
  }
168
- function getDescriptor(el, options) {
169
- var _a;
170
- const { type, property } = options;
171
- const proto = getWindow(el)[type].prototype;
172
- return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
173
- }
174
- function dispatchInputValueEvent(el, value) {
175
- var _a;
176
- const win = getWindow(el);
177
- if (!(el instanceof win.HTMLInputElement))
178
- return;
179
- const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
180
- (_a = desc.set) == null ? void 0 : _a.call(el, value);
181
- const event = new win.Event("input", { bubbles: true });
182
- el.dispatchEvent(event);
183
- }
184
132
  var rtlKeyMap = {
185
133
  ArrowLeft: "ArrowRight",
186
134
  ArrowRight: "ArrowLeft",
@@ -197,10 +145,9 @@ var sameKeyMap = {
197
145
  Right: "ArrowRight"
198
146
  };
199
147
  function getEventKey(event, options = {}) {
200
- var _a;
201
148
  const { dir = "ltr", orientation = "horizontal" } = options;
202
149
  let { key } = event;
203
- key = (_a = sameKeyMap[key]) != null ? _a : key;
150
+ key = sameKeyMap[key] ?? key;
204
151
  const isRtl = dir === "rtl" && orientation === "horizontal";
205
152
  if (isRtl && key in rtlKeyMap) {
206
153
  key = rtlKeyMap[key];
@@ -237,8 +184,7 @@ function addDomEvent(target, eventName, handler, options) {
237
184
  };
238
185
  }
239
186
  function addPointerEvent(target, event, listener, options) {
240
- var _a;
241
- const type = (_a = getEventName(event)) != null ? _a : event;
187
+ const type = getEventName(event) ?? event;
242
188
  return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
243
189
  }
244
190
  function wrapHandler(fn, filter = false) {
@@ -249,8 +195,7 @@ function wrapHandler(fn, filter = false) {
249
195
  }
250
196
  function filterPrimaryPointer(fn) {
251
197
  return (event) => {
252
- var _a;
253
- const win = (_a = event.view) != null ? _a : window;
198
+ const win = event.view ?? window;
254
199
  const isMouseEvent2 = event instanceof win.MouseEvent;
255
200
  const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
256
201
  if (isPrimary)
@@ -305,7 +250,7 @@ var state = "default";
305
250
  var savedUserSelect = "";
306
251
  var modifiedElementMap = /* @__PURE__ */ new WeakMap();
307
252
  function disableTextSelection({ target, doc } = {}) {
308
- const _document = doc != null ? doc : document;
253
+ const _document = doc ?? document;
309
254
  if (isIos()) {
310
255
  if (state === "default") {
311
256
  savedUserSelect = _document.documentElement.style.webkitUserSelect;
@@ -319,7 +264,7 @@ function disableTextSelection({ target, doc } = {}) {
319
264
  return () => restoreTextSelection({ target, doc: _document });
320
265
  }
321
266
  function restoreTextSelection({ target, doc } = {}) {
322
- const _document = doc != null ? doc : document;
267
+ const _document = doc ?? document;
323
268
  if (isIos()) {
324
269
  if (state !== "disabled")
325
270
  return;
@@ -339,7 +284,7 @@ function restoreTextSelection({ target, doc } = {}) {
339
284
  if (target && modifiedElementMap.has(target)) {
340
285
  let targetOldUserSelect = modifiedElementMap.get(target);
341
286
  if (target.style.userSelect === "none") {
342
- target.style.userSelect = targetOldUserSelect != null ? targetOldUserSelect : "";
287
+ target.style.userSelect = targetOldUserSelect ?? "";
343
288
  }
344
289
  if (target.getAttribute("style") === "") {
345
290
  target.removeAttribute("style");
@@ -348,13 +293,13 @@ function restoreTextSelection({ target, doc } = {}) {
348
293
  }
349
294
  }
350
295
  }
351
- function trackPointerMove(opts) {
352
- const { onPointerMove, onPointerUp, ctx } = opts;
353
- const { doc = document, threshold = 5 } = ctx;
296
+ var THRESHOLD = 5;
297
+ function trackPointerMove(doc, opts) {
298
+ const { onPointerMove, onPointerUp } = opts;
354
299
  const handlePointerMove = (event, info) => {
355
300
  const { point: p } = info;
356
- const distance = Math.sqrt(__pow(p.x, 2) + __pow(p.y, 2));
357
- if (distance < threshold)
301
+ const distance = Math.sqrt(p.x ** 2 + p.y ** 2);
302
+ if (distance < THRESHOLD)
358
303
  return;
359
304
  if (isMouseEvent(event) && isLeftClick(event)) {
360
305
  onPointerUp();
@@ -362,14 +307,81 @@ function trackPointerMove(opts) {
362
307
  }
363
308
  onPointerMove(info, event);
364
309
  };
365
- return callAll(addPointerEvent(doc, "pointermove", handlePointerMove, false), addPointerEvent(doc, "pointerup", onPointerUp, false), addPointerEvent(doc, "pointercancel", onPointerUp, false), addPointerEvent(doc, "contextmenu", onPointerUp, false), disableTextSelection({ doc }));
310
+ return callAll(
311
+ addPointerEvent(doc, "pointermove", handlePointerMove, false),
312
+ addPointerEvent(doc, "pointerup", onPointerUp, false),
313
+ addPointerEvent(doc, "pointercancel", onPointerUp, false),
314
+ addPointerEvent(doc, "contextmenu", onPointerUp, false),
315
+ disableTextSelection({ doc })
316
+ );
317
+ }
318
+
319
+ // ../../utilities/form-utils/dist/index.mjs
320
+ function getWindow(el) {
321
+ return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
322
+ }
323
+ function observeAttributes(node, attributes, fn) {
324
+ if (!node)
325
+ return;
326
+ const attrs = Array.isArray(attributes) ? attributes : [attributes];
327
+ const win = node.ownerDocument.defaultView || window;
328
+ const obs = new win.MutationObserver((changes) => {
329
+ for (const change of changes) {
330
+ if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
331
+ fn(change);
332
+ }
333
+ }
334
+ });
335
+ obs.observe(node, { attributes: true, attributeFilter: attrs });
336
+ return () => obs.disconnect();
337
+ }
338
+ function getDescriptor(el, options) {
339
+ const { type, property } = options;
340
+ const proto = getWindow(el)[type].prototype;
341
+ return Object.getOwnPropertyDescriptor(proto, property) ?? {};
342
+ }
343
+ function dispatchInputValueEvent(el, value) {
344
+ var _a;
345
+ if (!el)
346
+ return;
347
+ const win = getWindow(el);
348
+ if (!(el instanceof win.HTMLInputElement))
349
+ return;
350
+ const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
351
+ (_a = desc.set) == null ? void 0 : _a.call(el, value);
352
+ const event = new win.Event("input", { bubbles: true });
353
+ el.dispatchEvent(event);
354
+ }
355
+ function getClosestForm(el) {
356
+ if (isFormElement(el))
357
+ return el.form;
358
+ else
359
+ return el.closest("form");
360
+ }
361
+ function isFormElement(el) {
362
+ return el.matches("textarea, input, select, button");
363
+ }
364
+ function trackFormReset(el, callback) {
365
+ if (!el)
366
+ return;
367
+ const form = getClosestForm(el);
368
+ form == null ? void 0 : form.addEventListener("reset", callback, { passive: true });
369
+ return () => {
370
+ form == null ? void 0 : form.removeEventListener("reset", callback);
371
+ };
372
+ }
373
+ function trackFieldsetDisabled(el, callback) {
374
+ const fieldset = el == null ? void 0 : el.closest("fieldset");
375
+ if (!fieldset)
376
+ return;
377
+ callback(fieldset.disabled);
378
+ return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
366
379
  }
367
380
 
368
381
  // ../../utilities/number/dist/index.mjs
369
- var __pow2 = Math.pow;
370
382
  function round(v, t) {
371
383
  let num = valueOf(v);
372
- const p = __pow2(10, t != null ? t : 10);
384
+ const p = 10 ** (t ?? 10);
373
385
  num = Math.round(num * p) / p;
374
386
  return t ? num.toFixed(t) : v.toString();
375
387
  }
@@ -405,7 +417,7 @@ function valueOf(v) {
405
417
  function decimalOperation(a, op, b) {
406
418
  let result = op === "+" ? a + b : a - b;
407
419
  if (a % 1 !== 0 || b % 1 !== 0) {
408
- const multiplier = __pow2(10, Math.max(countDecimals(a), countDecimals(b)));
420
+ const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
409
421
  a = Math.round(a * multiplier);
410
422
  b = Math.round(b * multiplier);
411
423
  result = op === "+" ? a + b : a - b;
@@ -427,14 +439,12 @@ var transform = (a, b) => {
427
439
 
428
440
  // src/slider.style.ts
429
441
  function getVerticalThumbOffset(ctx) {
430
- var _a;
431
- const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
442
+ const { height = 0 } = ctx.thumbSize ?? {};
432
443
  const getValue = transform([ctx.min, ctx.max], [-height / 2, height / 2]);
433
444
  return parseFloat(getValue(ctx.value).toFixed(2));
434
445
  }
435
446
  function getHorizontalThumbOffset(ctx) {
436
- var _a;
437
- const { width = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
447
+ const { width = 0 } = ctx.thumbSize ?? {};
438
448
  if (ctx.isRtl) {
439
449
  const getValue2 = transform([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
440
450
  return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
@@ -544,59 +554,52 @@ var utils = {
544
554
  return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
545
555
  },
546
556
  decrement(ctx, step) {
547
- let value = decrement(ctx.value, step != null ? step : ctx.step);
557
+ let value = decrement(ctx.value, step ?? ctx.step);
548
558
  return utils.convert(ctx, value);
549
559
  },
550
560
  increment(ctx, step) {
551
- let value = increment(ctx.value, step != null ? step : ctx.step);
561
+ let value = increment(ctx.value, step ?? ctx.step);
552
562
  return utils.convert(ctx, value);
553
563
  }
554
564
  };
555
565
 
556
566
  // src/slider.dom.ts
557
- var dom = __spreadProps(__spreadValues({}, styles), {
558
- getDoc: (ctx) => {
559
- var _a;
560
- return (_a = ctx.doc) != null ? _a : document;
561
- },
562
- getRootNode: (ctx) => {
563
- var _a;
564
- return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
565
- },
567
+ var dom = defineDomHelpers({
568
+ ...styles,
566
569
  getRootId: (ctx) => {
567
- var _a, _b;
568
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `slider:${ctx.uid}`;
570
+ var _a;
571
+ return ((_a = ctx.ids) == null ? void 0 : _a.root) ?? `slider:${ctx.id}`;
569
572
  },
570
573
  getThumbId: (ctx) => {
571
- var _a, _b;
572
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.thumb) != null ? _b : `slider:${ctx.uid}:thumb`;
574
+ var _a;
575
+ return ((_a = ctx.ids) == null ? void 0 : _a.thumb) ?? `slider:${ctx.id}:thumb`;
573
576
  },
574
577
  getControlId: (ctx) => {
575
- var _a, _b;
576
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.control) != null ? _b : `slider:${ctx.uid}:control`;
578
+ var _a;
579
+ return ((_a = ctx.ids) == null ? void 0 : _a.control) ?? `slider:${ctx.id}:control`;
577
580
  },
578
- getInputId: (ctx) => `slider:${ctx.uid}:input`,
581
+ getInputId: (ctx) => `slider:${ctx.id}:input`,
579
582
  getOutputId: (ctx) => {
580
- var _a, _b;
581
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.output) != null ? _b : `slider:${ctx.uid}:output`;
583
+ var _a;
584
+ return ((_a = ctx.ids) == null ? void 0 : _a.output) ?? `slider:${ctx.id}:output`;
582
585
  },
583
586
  getTrackId: (ctx) => {
584
- var _a, _b;
585
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.uid}track`;
587
+ var _a;
588
+ return ((_a = ctx.ids) == null ? void 0 : _a.track) ?? `slider:${ctx.id}track`;
586
589
  },
587
590
  getRangeId: (ctx) => {
588
- var _a, _b;
589
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.uid}:range`;
591
+ var _a;
592
+ return ((_a = ctx.ids) == null ? void 0 : _a.track) ?? `slider:${ctx.id}:range`;
590
593
  },
591
594
  getLabelId: (ctx) => {
592
- var _a, _b;
593
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.uid}:label`;
595
+ var _a;
596
+ return ((_a = ctx.ids) == null ? void 0 : _a.label) ?? `slider:${ctx.id}:label`;
594
597
  },
595
- getMarkerId: (ctx, value) => `slider:${ctx.uid}:marker:${value}`,
596
- getRootEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getRootId(ctx)),
597
- getThumbEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getThumbId(ctx)),
598
- getControlEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getControlId(ctx)),
599
- getInputEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getInputId(ctx)),
598
+ getMarkerId: (ctx, value) => `slider:${ctx.id}:marker:${value}`,
599
+ getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
600
+ getThumbEl: (ctx) => dom.getById(ctx, dom.getThumbId(ctx)),
601
+ getControlEl: (ctx) => dom.getById(ctx, dom.getControlId(ctx)),
602
+ getInputEl: (ctx) => dom.getById(ctx, dom.getInputId(ctx)),
600
603
  getValueFromPoint(ctx, point) {
601
604
  const el = dom.getControlEl(ctx);
602
605
  if (!el)
@@ -689,7 +692,7 @@ function connect(state2, send, normalize) {
689
692
  "data-invalid": dataAttr(isInvalid),
690
693
  "aria-disabled": isDisabled || void 0,
691
694
  "aria-label": ariaLabel,
692
- "aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy != null ? ariaLabelledBy : dom.getLabelId(state2.context),
695
+ "aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy ?? dom.getLabelId(state2.context),
693
696
  "aria-orientation": state2.context.orientation,
694
697
  "aria-valuemax": state2.context.max,
695
698
  "aria-valuemin": state2.context.min,
@@ -834,221 +837,214 @@ function connect(state2, send, normalize) {
834
837
 
835
838
  // src/slider.machine.ts
836
839
  var import_core = require("@zag-js/core");
837
- function machine(ctx = {}) {
838
- return (0, import_core.createMachine)({
839
- id: "slider",
840
- initial: "unknown",
841
- context: __spreadValues({
842
- thumbSize: null,
843
- thumbAlignment: "contain",
844
- uid: "",
845
- disabled: false,
846
- threshold: 5,
847
- dir: "ltr",
848
- origin: "start",
849
- orientation: "horizontal",
850
- initialValue: null,
851
- value: 0,
852
- step: 1,
853
- min: 0,
854
- max: 100
855
- }, ctx),
856
- computed: {
857
- isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
858
- isVertical: (ctx2) => ctx2.orientation === "vertical",
859
- isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
860
- isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readonly),
861
- hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null
862
- },
863
- watch: {
864
- value: ["invokeOnChange", "dispatchChangeEvent"]
865
- },
866
- activities: ["trackFormReset", "trackFieldsetDisabled"],
867
- on: {
868
- SET_VALUE: {
869
- actions: "setValue"
840
+ function machine(ctx) {
841
+ return (0, import_core.createMachine)(
842
+ {
843
+ id: "slider",
844
+ initial: "unknown",
845
+ context: {
846
+ thumbSize: null,
847
+ thumbAlignment: "contain",
848
+ disabled: false,
849
+ threshold: 5,
850
+ dir: "ltr",
851
+ origin: "start",
852
+ orientation: "horizontal",
853
+ initialValue: null,
854
+ value: 0,
855
+ step: 1,
856
+ min: 0,
857
+ max: 100,
858
+ ...ctx
870
859
  },
871
- INCREMENT: {
872
- actions: "increment"
860
+ computed: {
861
+ isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
862
+ isVertical: (ctx2) => ctx2.orientation === "vertical",
863
+ isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
864
+ isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readonly),
865
+ hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null
873
866
  },
874
- DECREMENT: {
875
- actions: "decrement"
876
- }
877
- },
878
- states: {
879
- unknown: {
880
- on: {
881
- SETUP: {
882
- target: "idle",
883
- actions: ["setupDocument", "setThumbSize", "checkValue"]
884
- }
885
- }
867
+ watch: {
868
+ value: ["invokeOnChange", "dispatchChangeEvent"]
886
869
  },
887
- idle: {
888
- on: {
889
- POINTER_DOWN: {
890
- target: "dragging",
891
- actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
892
- },
893
- FOCUS: "focus"
870
+ activities: ["trackFormReset", "trackFieldsetDisabled"],
871
+ on: {
872
+ SET_VALUE: {
873
+ actions: "setValue"
874
+ },
875
+ INCREMENT: {
876
+ actions: "increment"
877
+ },
878
+ DECREMENT: {
879
+ actions: "decrement"
894
880
  }
895
881
  },
896
- focus: {
897
- entry: "focusThumb",
898
- on: {
899
- POINTER_DOWN: {
900
- target: "dragging",
901
- actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
902
- },
903
- ARROW_LEFT: {
904
- guard: "isHorizontal",
905
- actions: "decrement"
906
- },
907
- ARROW_RIGHT: {
908
- guard: "isHorizontal",
909
- actions: "increment"
910
- },
911
- ARROW_UP: {
912
- guard: "isVertical",
913
- actions: "increment"
914
- },
915
- ARROW_DOWN: {
916
- guard: "isVertical",
917
- actions: "decrement"
918
- },
919
- PAGE_UP: {
920
- actions: "increment"
921
- },
922
- PAGE_DOWN: {
923
- actions: "decrement"
924
- },
925
- HOME: {
926
- actions: "setToMin"
927
- },
928
- END: {
929
- actions: "setToMax"
930
- },
931
- BLUR: "idle"
932
- }
933
- },
934
- dragging: {
935
- entry: "focusThumb",
936
- activities: "trackPointerMove",
937
- on: {
938
- POINTER_UP: {
939
- target: "focus",
940
- actions: "invokeOnChangeEnd"
941
- },
942
- POINTER_MOVE: {
943
- actions: "setPointerValue"
882
+ states: {
883
+ unknown: {
884
+ on: {
885
+ SETUP: {
886
+ target: "idle",
887
+ actions: ["setThumbSize", "checkValue"]
888
+ }
889
+ }
890
+ },
891
+ idle: {
892
+ on: {
893
+ POINTER_DOWN: {
894
+ target: "dragging",
895
+ actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
896
+ },
897
+ FOCUS: "focus"
898
+ }
899
+ },
900
+ focus: {
901
+ entry: "focusThumb",
902
+ on: {
903
+ POINTER_DOWN: {
904
+ target: "dragging",
905
+ actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
906
+ },
907
+ ARROW_LEFT: {
908
+ guard: "isHorizontal",
909
+ actions: "decrement"
910
+ },
911
+ ARROW_RIGHT: {
912
+ guard: "isHorizontal",
913
+ actions: "increment"
914
+ },
915
+ ARROW_UP: {
916
+ guard: "isVertical",
917
+ actions: "increment"
918
+ },
919
+ ARROW_DOWN: {
920
+ guard: "isVertical",
921
+ actions: "decrement"
922
+ },
923
+ PAGE_UP: {
924
+ actions: "increment"
925
+ },
926
+ PAGE_DOWN: {
927
+ actions: "decrement"
928
+ },
929
+ HOME: {
930
+ actions: "setToMin"
931
+ },
932
+ END: {
933
+ actions: "setToMax"
934
+ },
935
+ BLUR: "idle"
936
+ }
937
+ },
938
+ dragging: {
939
+ entry: "focusThumb",
940
+ activities: "trackPointerMove",
941
+ on: {
942
+ POINTER_UP: {
943
+ target: "focus",
944
+ actions: "invokeOnChangeEnd"
945
+ },
946
+ POINTER_MOVE: {
947
+ actions: "setPointerValue"
948
+ }
944
949
  }
945
950
  }
946
951
  }
947
- }
948
- }, {
949
- guards: {
950
- isHorizontal: (ctx2) => ctx2.isHorizontal,
951
- isVertical: (ctx2) => ctx2.isVertical
952
952
  },
953
- activities: {
954
- trackFieldsetDisabled(ctx2) {
955
- let cleanup;
956
- nextTick(() => {
957
- cleanup = trackFieldsetDisabled(dom.getRootEl(ctx2), (disabled) => {
953
+ {
954
+ guards: {
955
+ isHorizontal: (ctx2) => ctx2.isHorizontal,
956
+ isVertical: (ctx2) => ctx2.isVertical
957
+ },
958
+ activities: {
959
+ trackFieldsetDisabled(ctx2) {
960
+ return trackFieldsetDisabled(dom.getRootEl(ctx2), (disabled) => {
958
961
  if (disabled) {
959
962
  ctx2.disabled = disabled;
960
963
  }
961
964
  });
962
- });
963
- return () => cleanup == null ? void 0 : cleanup();
964
- },
965
- trackFormReset(ctx2) {
966
- let cleanup;
967
- nextTick(() => {
968
- cleanup = trackFormReset(dom.getInputEl(ctx2), () => {
965
+ },
966
+ trackFormReset(ctx2) {
967
+ return trackFormReset(dom.getInputEl(ctx2), () => {
969
968
  if (ctx2.initialValue != null) {
970
969
  ctx2.value = ctx2.initialValue;
971
970
  }
972
971
  });
973
- });
974
- return () => cleanup == null ? void 0 : cleanup();
975
- },
976
- trackPointerMove(ctx2, _evt, { send }) {
977
- return trackPointerMove({
978
- ctx: ctx2,
979
- onPointerMove(info) {
980
- send({ type: "POINTER_MOVE", point: info.point });
981
- },
982
- onPointerUp() {
983
- send("POINTER_UP");
984
- }
985
- });
986
- }
987
- },
988
- actions: {
989
- setupDocument(ctx2, evt) {
990
- if (evt.doc)
991
- ctx2.doc = (0, import_core.ref)(evt.doc);
992
- if (evt.root)
993
- ctx2.rootNode = (0, import_core.ref)(evt.root);
994
- ctx2.uid = evt.id;
995
- },
996
- checkValue(ctx2) {
997
- const value = utils.convert(ctx2, ctx2.value);
998
- Object.assign(ctx2, { value, initialValue: value });
999
- },
1000
- invokeOnChangeStart(ctx2) {
1001
- var _a;
1002
- (_a = ctx2.onChangeStart) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
1003
- },
1004
- invokeOnChangeEnd(ctx2) {
1005
- var _a;
1006
- (_a = ctx2.onChangeEnd) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
1007
- },
1008
- invokeOnChange(ctx2) {
1009
- var _a;
1010
- (_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
1011
- },
1012
- dispatchChangeEvent(ctx2) {
1013
- dom.dispatchChangeEvent(ctx2);
1014
- },
1015
- setThumbSize(ctx2) {
1016
- if (ctx2.thumbAlignment !== "contain")
1017
- return;
1018
- raf(() => {
1019
- const el = dom.getThumbEl(ctx2);
1020
- if (!el)
1021
- return;
1022
- ctx2.thumbSize = { width: el.offsetWidth, height: el.offsetHeight };
1023
- });
1024
- },
1025
- setPointerValue(ctx2, evt) {
1026
- const value = dom.getValueFromPoint(ctx2, evt.point);
1027
- if (value == null)
1028
- return;
1029
- ctx2.value = utils.clamp(ctx2, value);
972
+ },
973
+ trackPointerMove(ctx2, _evt, { send }) {
974
+ return trackPointerMove(dom.getDoc(ctx2), {
975
+ onPointerMove(info) {
976
+ send({ type: "POINTER_MOVE", point: info.point });
977
+ },
978
+ onPointerUp() {
979
+ send("POINTER_UP");
980
+ }
981
+ });
982
+ }
1030
983
  },
1031
- focusThumb(ctx2) {
1032
- raf(() => {
984
+ actions: {
985
+ checkValue(ctx2) {
986
+ const value = utils.convert(ctx2, ctx2.value);
987
+ Object.assign(ctx2, { value, initialValue: value });
988
+ },
989
+ invokeOnChangeStart(ctx2) {
1033
990
  var _a;
1034
- return (_a = dom.getThumbEl(ctx2)) == null ? void 0 : _a.focus();
1035
- });
1036
- },
1037
- decrement(ctx2, evt) {
1038
- ctx2.value = utils.decrement(ctx2, evt.step);
1039
- },
1040
- increment(ctx2, evt) {
1041
- ctx2.value = utils.increment(ctx2, evt.step);
1042
- },
1043
- setToMin(ctx2) {
1044
- ctx2.value = ctx2.min;
1045
- },
1046
- setToMax(ctx2) {
1047
- ctx2.value = ctx2.max;
1048
- },
1049
- setValue(ctx2, evt) {
1050
- ctx2.value = utils.convert(ctx2, evt.value);
991
+ (_a = ctx2.onChangeStart) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
992
+ },
993
+ invokeOnChangeEnd(ctx2) {
994
+ var _a;
995
+ (_a = ctx2.onChangeEnd) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
996
+ },
997
+ invokeOnChange(ctx2) {
998
+ var _a;
999
+ (_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
1000
+ },
1001
+ dispatchChangeEvent(ctx2) {
1002
+ dom.dispatchChangeEvent(ctx2);
1003
+ },
1004
+ setThumbSize(ctx2) {
1005
+ if (ctx2.thumbAlignment !== "contain")
1006
+ return;
1007
+ raf(() => {
1008
+ const el = dom.getThumbEl(ctx2);
1009
+ if (!el)
1010
+ return;
1011
+ ctx2.thumbSize = { width: el.offsetWidth, height: el.offsetHeight };
1012
+ });
1013
+ },
1014
+ setPointerValue(ctx2, evt) {
1015
+ const value = dom.getValueFromPoint(ctx2, evt.point);
1016
+ if (value == null)
1017
+ return;
1018
+ ctx2.value = utils.clamp(ctx2, value);
1019
+ },
1020
+ focusThumb(ctx2) {
1021
+ raf(() => {
1022
+ var _a;
1023
+ return (_a = dom.getThumbEl(ctx2)) == null ? void 0 : _a.focus();
1024
+ });
1025
+ },
1026
+ decrement(ctx2, evt) {
1027
+ ctx2.value = utils.decrement(ctx2, evt.step);
1028
+ },
1029
+ increment(ctx2, evt) {
1030
+ ctx2.value = utils.increment(ctx2, evt.step);
1031
+ },
1032
+ setToMin(ctx2) {
1033
+ ctx2.value = ctx2.min;
1034
+ },
1035
+ setToMax(ctx2) {
1036
+ ctx2.value = ctx2.max;
1037
+ },
1038
+ setValue(ctx2, evt) {
1039
+ ctx2.value = utils.convert(ctx2, evt.value);
1040
+ }
1051
1041
  }
1052
1042
  }
1053
- });
1043
+ );
1054
1044
  }
1045
+ // Annotate the CommonJS export names for ESM import in node:
1046
+ 0 && (module.exports = {
1047
+ connect,
1048
+ machine,
1049
+ unstable__dom
1050
+ });