@zag-js/slider 0.1.10 → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Chakra UI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,228 @@
1
- export { dom as unstable__dom } from "./slider.dom";
2
- export { connect } from "./slider.connect";
3
- export { machine } from "./slider.machine";
4
- export type { UserDefinedContext as Context } from "./slider.types";
1
+ import * as _zag_js_types from '@zag-js/types';
2
+ import { RequiredBy, DirectionProperty, CommonProperties, Context, PropTypes, NormalizeProps } from '@zag-js/types';
3
+ import * as _zag_js_core from '@zag-js/core';
4
+ import { StateMachine } from '@zag-js/core';
5
+
6
+ declare type ElementIds = Partial<{
7
+ root: string;
8
+ thumb: string;
9
+ control: string;
10
+ track: string;
11
+ range: string;
12
+ label: string;
13
+ output: string;
14
+ }>;
15
+ declare type PublicContext = DirectionProperty & CommonProperties & {
16
+ /**
17
+ * The ids of the elements in the slider. Useful for composition.
18
+ */
19
+ ids?: ElementIds;
20
+ /**
21
+ * The value of the slider
22
+ */
23
+ value: number;
24
+ /**
25
+ * The name associated with the slider (when used in a form)
26
+ */
27
+ name?: string;
28
+ /**
29
+ * Whether the slider is disabled
30
+ */
31
+ disabled?: boolean;
32
+ /**
33
+ * Whether the slider is read-only
34
+ */
35
+ readonly?: boolean;
36
+ /**
37
+ * Whether the slider value is invalid
38
+ */
39
+ invalid?: boolean;
40
+ /**
41
+ * The minimum value of the slider
42
+ */
43
+ min: number;
44
+ /**
45
+ * The maximum value of the slider
46
+ */
47
+ max: number;
48
+ /**
49
+ * The step value of the slider
50
+ */
51
+ step: number;
52
+ /**
53
+ * The orientation of the slider
54
+ */
55
+ orientation?: "vertical" | "horizontal";
56
+ /**
57
+ * - "start": Useful when the value represents an absolute value
58
+ * - "center": Useful when the value represents an offset (relative)
59
+ */
60
+ origin?: "start" | "center";
61
+ /**
62
+ * The aria-label of the slider. Useful for providing an accessible name to the slider
63
+ */
64
+ "aria-label"?: string;
65
+ /**
66
+ * The `id` of the element that labels the slider. Useful for providing an accessible name to the slider
67
+ */
68
+ "aria-labelledby"?: string;
69
+ /**
70
+ * Whether to focus the slider thumb after interaction (scrub and keyboard)
71
+ */
72
+ focusThumbOnChange?: boolean;
73
+ /**
74
+ * Function that returns a human readable value for the slider
75
+ */
76
+ getAriaValueText?(value: number): string;
77
+ /**
78
+ * Function invoked when the value of the slider changes
79
+ */
80
+ onChange?(details: {
81
+ value: number;
82
+ }): void;
83
+ /**
84
+ * Function invoked when the slider value change is done
85
+ */
86
+ onChangeEnd?(details: {
87
+ value: number;
88
+ }): void;
89
+ /**
90
+ * Function invoked when the slider value change is started
91
+ */
92
+ onChangeStart?(details: {
93
+ value: number;
94
+ }): void;
95
+ /**
96
+ * The alignment of the slider thumb relative to the track
97
+ * - `center`: the thumb will extend beyond the bounds of the slider track.
98
+ * - `contain`: the thumb will be contained within the bounds of the track.
99
+ */
100
+ thumbAlignment?: "contain" | "center";
101
+ };
102
+ declare type UserDefinedContext = RequiredBy<PublicContext, "id">;
103
+ declare type ComputedContext = Readonly<{
104
+ /**
105
+ * @computed
106
+ * Whether the slider is interactive
107
+ */
108
+ readonly isInteractive: boolean;
109
+ /**
110
+ * @computed
111
+ * Whether the thumb size has been measured
112
+ */
113
+ readonly hasMeasuredThumbSize: boolean;
114
+ /**
115
+ * @computed
116
+ * Whether the slider is horizontal
117
+ */
118
+ readonly isHorizontal: boolean;
119
+ /**
120
+ * @computed
121
+ * Whether the slider is vertical
122
+ */
123
+ readonly isVertical: boolean;
124
+ /**
125
+ * @computed
126
+ * Whether the slider is in RTL mode
127
+ */
128
+ readonly isRtl: boolean;
129
+ }>;
130
+ declare type PrivateContext = Context<{}>;
131
+ declare type MachineContext = PublicContext & ComputedContext & PrivateContext;
132
+ declare type MachineState = {
133
+ value: "unknown" | "idle" | "dragging" | "focus";
134
+ };
135
+ declare type State = StateMachine.State<MachineContext, MachineState>;
136
+ declare type Send = StateMachine.Send<StateMachine.AnyEventObject>;
137
+ declare type SharedContext = {
138
+ min: number;
139
+ max: number;
140
+ step: number;
141
+ dir?: "ltr" | "rtl";
142
+ isRtl: boolean;
143
+ isVertical: boolean;
144
+ isHorizontal: boolean;
145
+ value: number;
146
+ thumbSize: {
147
+ width: number;
148
+ height: number;
149
+ } | null;
150
+ thumbAlignment?: "contain" | "center";
151
+ orientation?: "horizontal" | "vertical";
152
+ readonly hasMeasuredThumbSize: boolean;
153
+ };
154
+ declare type Point = {
155
+ x: number;
156
+ y: number;
157
+ };
158
+
159
+ declare const dom: {
160
+ getRootNode: (ctx: {
161
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
162
+ }) => Document | ShadowRoot;
163
+ getDoc: (ctx: {
164
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
165
+ }) => Document;
166
+ getWin: (ctx: {
167
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
168
+ }) => Window & typeof globalThis;
169
+ getActiveElement: (ctx: {
170
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
171
+ }) => HTMLElement | null;
172
+ getById: <T_1 = HTMLElement>(ctx: {
173
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
174
+ }, id: string) => T_1 | null;
175
+ } & {
176
+ getRootId: (ctx: MachineContext) => string;
177
+ getThumbId: (ctx: MachineContext) => string;
178
+ getControlId: (ctx: MachineContext) => string;
179
+ getInputId: (ctx: MachineContext) => string;
180
+ getOutputId: (ctx: MachineContext) => string;
181
+ getTrackId: (ctx: MachineContext) => string;
182
+ getRangeId: (ctx: MachineContext) => string;
183
+ getLabelId: (ctx: MachineContext) => string;
184
+ getMarkerId: (ctx: MachineContext, value: number) => string;
185
+ getRootEl: (ctx: MachineContext) => HTMLElement | null;
186
+ getThumbEl: (ctx: MachineContext) => HTMLElement | null;
187
+ getControlEl: (ctx: MachineContext) => HTMLElement | null;
188
+ getInputEl: (ctx: MachineContext) => HTMLInputElement | null;
189
+ getValueFromPoint(ctx: MachineContext, point: Point): number | undefined;
190
+ dispatchChangeEvent(ctx: MachineContext): void;
191
+ getThumbOffset: (ctx: SharedContext) => string;
192
+ getControlStyle: () => _zag_js_types.JSX.CSSProperties;
193
+ getThumbStyle: (ctx: SharedContext) => _zag_js_types.JSX.CSSProperties;
194
+ getRangeStyle: (ctx: Pick<SharedContext, "isVertical" | "isRtl">) => _zag_js_types.JSX.CSSProperties;
195
+ getRootStyle: (ctx: MachineContext) => _zag_js_types.JSX.CSSProperties;
196
+ getMarkerStyle: (ctx: Pick<SharedContext, "isHorizontal" | "isRtl">, percent: number) => _zag_js_types.JSX.CSSProperties;
197
+ getLabelStyle: () => _zag_js_types.JSX.CSSProperties;
198
+ getTrackStyle: () => _zag_js_types.JSX.CSSProperties;
199
+ getMarkerGroupStyle: () => _zag_js_types.JSX.CSSProperties;
200
+ };
201
+
202
+ declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
203
+ isFocused: boolean;
204
+ isDragging: boolean;
205
+ value: number;
206
+ percent: number;
207
+ setValue(value: number): void;
208
+ getPercentValue(percent: number): number;
209
+ focus(): void;
210
+ increment(): void;
211
+ decrement(): void;
212
+ rootProps: T["element"];
213
+ labelProps: T["label"];
214
+ thumbProps: T["element"];
215
+ inputProps: T["input"];
216
+ outputProps: T["output"];
217
+ trackProps: T["element"];
218
+ rangeProps: T["element"];
219
+ controlProps: T["element"];
220
+ markerGroupProps: T["element"];
221
+ getMarkerProps({ value }: {
222
+ value: number;
223
+ }): T["element"];
224
+ };
225
+
226
+ declare function machine(ctx: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
227
+
228
+ export { UserDefinedContext as Context, connect, machine, dom as unstable__dom };
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,29 +27,12 @@ __export(src_exports, {
44
27
  module.exports = __toCommonJS(src_exports);
45
28
 
46
29
  // ../../utilities/dom/dist/index.mjs
47
- var __defProp2 = Object.defineProperty;
48
- var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
49
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
50
- var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
51
- var __pow = Math.pow;
52
- var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
53
- var __spreadValues2 = (a, b) => {
54
- for (var prop in b || (b = {}))
55
- if (__hasOwnProp2.call(b, prop))
56
- __defNormalProp2(a, prop, b[prop]);
57
- if (__getOwnPropSymbols2)
58
- for (var prop of __getOwnPropSymbols2(b)) {
59
- if (__propIsEnum2.call(b, prop))
60
- __defNormalProp2(a, prop, b[prop]);
61
- }
62
- return a;
63
- };
64
30
  var dataAttr = (guard) => {
65
31
  return guard ? "" : void 0;
66
32
  };
67
33
  var runIfFn = (v, ...a) => {
68
34
  const res = typeof v === "function" ? v(...a) : v;
69
- return res != null ? res : void 0;
35
+ return res ?? void 0;
70
36
  };
71
37
  var callAll = (...fns) => (...a) => {
72
38
  fns.forEach(function(fn) {
@@ -78,9 +44,8 @@ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
78
44
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
79
45
  var isDom = () => typeof window !== "undefined";
80
46
  function getPlatform() {
81
- var _a;
82
47
  const agent = navigator.userAgentData;
83
- return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
48
+ return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
84
49
  }
85
50
  var pt = (v) => isDom() && v.test(getPlatform());
86
51
  var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
@@ -94,36 +59,33 @@ function isWindow(value) {
94
59
  return (value == null ? void 0 : value.toString()) === "[object Window]";
95
60
  }
96
61
  function getDocument(el) {
97
- var _a;
98
62
  if (isWindow(el))
99
63
  return el.document;
100
64
  if (isDocument(el))
101
65
  return el;
102
- return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
66
+ return (el == null ? void 0 : el.ownerDocument) ?? document;
103
67
  }
104
68
  function getWindow(el) {
105
- var _a;
106
- return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
69
+ return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
107
70
  }
108
71
  function defineDomHelpers(helpers) {
109
72
  const dom2 = {
110
73
  getRootNode: (ctx) => {
111
- var _a, _b;
112
- return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
113
- },
114
- getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
115
- getWin: (ctx) => {
116
74
  var _a;
117
- return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
75
+ return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
118
76
  },
77
+ getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
78
+ getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
119
79
  getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
120
80
  getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
121
81
  };
122
- return __spreadValues2(__spreadValues2({}, dom2), helpers);
82
+ return {
83
+ ...dom2,
84
+ ...helpers
85
+ };
123
86
  }
124
87
  function getNativeEvent(e) {
125
- var _a;
126
- return (_a = e.nativeEvent) != null ? _a : e;
88
+ return e.nativeEvent ?? e;
127
89
  }
128
90
  var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
129
91
  var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
@@ -201,8 +163,7 @@ var fallback = {
201
163
  clientY: 0
202
164
  };
203
165
  function getEventPoint(event, type = "page") {
204
- var _a, _b;
205
- const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event;
166
+ const point = isTouchEvent(event) ? event.touches[0] ?? event.changedTouches[0] ?? fallback : event;
206
167
  return { x: point[`${type}X`], y: point[`${type}Y`] };
207
168
  }
208
169
  function getPointRelativeToNode(point, element) {
@@ -212,10 +173,9 @@ function getPointRelativeToNode(point, element) {
212
173
  return { x, y };
213
174
  }
214
175
  function getDescriptor(el, options) {
215
- var _a;
216
176
  const { type, property } = options;
217
177
  const proto = getWindow(el)[type].prototype;
218
- return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
178
+ return Object.getOwnPropertyDescriptor(proto, property) ?? {};
219
179
  }
220
180
  function dispatchInputValueEvent(el, value) {
221
181
  var _a;
@@ -245,10 +205,9 @@ var sameKeyMap = {
245
205
  Right: "ArrowRight"
246
206
  };
247
207
  function getEventKey(event, options = {}) {
248
- var _a;
249
208
  const { dir = "ltr", orientation = "horizontal" } = options;
250
209
  let { key } = event;
251
- key = (_a = sameKeyMap[key]) != null ? _a : key;
210
+ key = sameKeyMap[key] ?? key;
252
211
  const isRtl = dir === "rtl" && orientation === "horizontal";
253
212
  if (isRtl && key in rtlKeyMap) {
254
213
  key = rtlKeyMap[key];
@@ -285,8 +244,7 @@ function addDomEvent(target, eventName, handler, options) {
285
244
  };
286
245
  }
287
246
  function addPointerEvent(target, event, listener, options) {
288
- var _a;
289
- const type = (_a = getEventName(event)) != null ? _a : event;
247
+ const type = getEventName(event) ?? event;
290
248
  return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
291
249
  }
292
250
  function wrapHandler(fn, filter = false) {
@@ -297,8 +255,7 @@ function wrapHandler(fn, filter = false) {
297
255
  }
298
256
  function filterPrimaryPointer(fn) {
299
257
  return (event) => {
300
- var _a;
301
- const win = (_a = event.view) != null ? _a : window;
258
+ const win = event.view ?? window;
302
259
  const isMouseEvent2 = event instanceof win.MouseEvent;
303
260
  const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
304
261
  if (isPrimary)
@@ -353,7 +310,7 @@ var state = "default";
353
310
  var savedUserSelect = "";
354
311
  var modifiedElementMap = /* @__PURE__ */ new WeakMap();
355
312
  function disableTextSelection({ target, doc } = {}) {
356
- const _document = doc != null ? doc : document;
313
+ const _document = doc ?? document;
357
314
  if (isIos()) {
358
315
  if (state === "default") {
359
316
  savedUserSelect = _document.documentElement.style.webkitUserSelect;
@@ -367,7 +324,7 @@ function disableTextSelection({ target, doc } = {}) {
367
324
  return () => restoreTextSelection({ target, doc: _document });
368
325
  }
369
326
  function restoreTextSelection({ target, doc } = {}) {
370
- const _document = doc != null ? doc : document;
327
+ const _document = doc ?? document;
371
328
  if (isIos()) {
372
329
  if (state !== "disabled")
373
330
  return;
@@ -387,7 +344,7 @@ function restoreTextSelection({ target, doc } = {}) {
387
344
  if (target && modifiedElementMap.has(target)) {
388
345
  let targetOldUserSelect = modifiedElementMap.get(target);
389
346
  if (target.style.userSelect === "none") {
390
- target.style.userSelect = targetOldUserSelect != null ? targetOldUserSelect : "";
347
+ target.style.userSelect = targetOldUserSelect ?? "";
391
348
  }
392
349
  if (target.getAttribute("style") === "") {
393
350
  target.removeAttribute("style");
@@ -396,13 +353,13 @@ function restoreTextSelection({ target, doc } = {}) {
396
353
  }
397
354
  }
398
355
  }
399
- function trackPointerMove(opts) {
400
- const { onPointerMove, onPointerUp, ctx } = opts;
401
- const { doc = document, threshold = 5 } = ctx;
356
+ var THRESHOLD = 5;
357
+ function trackPointerMove(doc, opts) {
358
+ const { onPointerMove, onPointerUp } = opts;
402
359
  const handlePointerMove = (event, info) => {
403
360
  const { point: p } = info;
404
- const distance = Math.sqrt(__pow(p.x, 2) + __pow(p.y, 2));
405
- if (distance < threshold)
361
+ const distance = Math.sqrt(p.x ** 2 + p.y ** 2);
362
+ if (distance < THRESHOLD)
406
363
  return;
407
364
  if (isMouseEvent(event) && isLeftClick(event)) {
408
365
  onPointerUp();
@@ -414,10 +371,9 @@ function trackPointerMove(opts) {
414
371
  }
415
372
 
416
373
  // ../../utilities/number/dist/index.mjs
417
- var __pow2 = Math.pow;
418
374
  function round(v, t) {
419
375
  let num = valueOf(v);
420
- const p = __pow2(10, t != null ? t : 10);
376
+ const p = 10 ** (t ?? 10);
421
377
  num = Math.round(num * p) / p;
422
378
  return t ? num.toFixed(t) : v.toString();
423
379
  }
@@ -453,7 +409,7 @@ function valueOf(v) {
453
409
  function decimalOperation(a, op, b) {
454
410
  let result = op === "+" ? a + b : a - b;
455
411
  if (a % 1 !== 0 || b % 1 !== 0) {
456
- const multiplier = __pow2(10, Math.max(countDecimals(a), countDecimals(b)));
412
+ const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
457
413
  a = Math.round(a * multiplier);
458
414
  b = Math.round(b * multiplier);
459
415
  result = op === "+" ? a + b : a - b;
@@ -475,14 +431,12 @@ var transform = (a, b) => {
475
431
 
476
432
  // src/slider.style.ts
477
433
  function getVerticalThumbOffset(ctx) {
478
- var _a;
479
- const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
434
+ const { height = 0 } = ctx.thumbSize ?? {};
480
435
  const getValue = transform([ctx.min, ctx.max], [-height / 2, height / 2]);
481
436
  return parseFloat(getValue(ctx.value).toFixed(2));
482
437
  }
483
438
  function getHorizontalThumbOffset(ctx) {
484
- var _a;
485
- const { width = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
439
+ const { width = 0 } = ctx.thumbSize ?? {};
486
440
  if (ctx.isRtl) {
487
441
  const getValue2 = transform([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
488
442
  return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
@@ -592,45 +546,46 @@ var utils = {
592
546
  return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
593
547
  },
594
548
  decrement(ctx, step) {
595
- let value = decrement(ctx.value, step != null ? step : ctx.step);
549
+ let value = decrement(ctx.value, step ?? ctx.step);
596
550
  return utils.convert(ctx, value);
597
551
  },
598
552
  increment(ctx, step) {
599
- let value = increment(ctx.value, step != null ? step : ctx.step);
553
+ let value = increment(ctx.value, step ?? ctx.step);
600
554
  return utils.convert(ctx, value);
601
555
  }
602
556
  };
603
557
 
604
558
  // src/slider.dom.ts
605
- var dom = defineDomHelpers(__spreadProps(__spreadValues({}, styles), {
559
+ var dom = defineDomHelpers({
560
+ ...styles,
606
561
  getRootId: (ctx) => {
607
- var _a, _b;
608
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `slider:${ctx.id}`;
562
+ var _a;
563
+ return ((_a = ctx.ids) == null ? void 0 : _a.root) ?? `slider:${ctx.id}`;
609
564
  },
610
565
  getThumbId: (ctx) => {
611
- var _a, _b;
612
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.thumb) != null ? _b : `slider:${ctx.id}:thumb`;
566
+ var _a;
567
+ return ((_a = ctx.ids) == null ? void 0 : _a.thumb) ?? `slider:${ctx.id}:thumb`;
613
568
  },
614
569
  getControlId: (ctx) => {
615
- var _a, _b;
616
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.control) != null ? _b : `slider:${ctx.id}:control`;
570
+ var _a;
571
+ return ((_a = ctx.ids) == null ? void 0 : _a.control) ?? `slider:${ctx.id}:control`;
617
572
  },
618
573
  getInputId: (ctx) => `slider:${ctx.id}:input`,
619
574
  getOutputId: (ctx) => {
620
- var _a, _b;
621
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.output) != null ? _b : `slider:${ctx.id}:output`;
575
+ var _a;
576
+ return ((_a = ctx.ids) == null ? void 0 : _a.output) ?? `slider:${ctx.id}:output`;
622
577
  },
623
578
  getTrackId: (ctx) => {
624
- var _a, _b;
625
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}track`;
579
+ var _a;
580
+ return ((_a = ctx.ids) == null ? void 0 : _a.track) ?? `slider:${ctx.id}track`;
626
581
  },
627
582
  getRangeId: (ctx) => {
628
- var _a, _b;
629
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}:range`;
583
+ var _a;
584
+ return ((_a = ctx.ids) == null ? void 0 : _a.track) ?? `slider:${ctx.id}:range`;
630
585
  },
631
586
  getLabelId: (ctx) => {
632
- var _a, _b;
633
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.id}:label`;
587
+ var _a;
588
+ return ((_a = ctx.ids) == null ? void 0 : _a.label) ?? `slider:${ctx.id}:label`;
634
589
  },
635
590
  getMarkerId: (ctx, value) => `slider:${ctx.id}:marker:${value}`,
636
591
  getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
@@ -658,7 +613,7 @@ var dom = defineDomHelpers(__spreadProps(__spreadValues({}, styles), {
658
613
  return;
659
614
  dispatchInputValueEvent(input, ctx.value);
660
615
  }
661
- }));
616
+ });
662
617
 
663
618
  // src/slider.connect.ts
664
619
  function connect(state2, send, normalize) {
@@ -729,7 +684,7 @@ function connect(state2, send, normalize) {
729
684
  "data-invalid": dataAttr(isInvalid),
730
685
  "aria-disabled": isDisabled || void 0,
731
686
  "aria-label": ariaLabel,
732
- "aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy != null ? ariaLabelledBy : dom.getLabelId(state2.context),
687
+ "aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy ?? dom.getLabelId(state2.context),
733
688
  "aria-orientation": state2.context.orientation,
734
689
  "aria-valuemax": state2.context.max,
735
690
  "aria-valuemin": state2.context.min,
@@ -878,7 +833,7 @@ function machine(ctx) {
878
833
  return (0, import_core.createMachine)({
879
834
  id: "slider",
880
835
  initial: "unknown",
881
- context: __spreadValues({
836
+ context: {
882
837
  thumbSize: null,
883
838
  thumbAlignment: "contain",
884
839
  disabled: false,
@@ -890,8 +845,9 @@ function machine(ctx) {
890
845
  value: 0,
891
846
  step: 1,
892
847
  min: 0,
893
- max: 100
894
- }, ctx),
848
+ max: 100,
849
+ ...ctx
850
+ },
895
851
  computed: {
896
852
  isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
897
853
  isVertical: (ctx2) => ctx2.orientation === "vertical",
@@ -1005,8 +961,7 @@ function machine(ctx) {
1005
961
  });
1006
962
  },
1007
963
  trackPointerMove(ctx2, _evt, { send }) {
1008
- return trackPointerMove({
1009
- ctx: ctx2,
964
+ return trackPointerMove(dom.getDoc(ctx2), {
1010
965
  onPointerMove(info) {
1011
966
  send({ type: "POINTER_MOVE", point: info.point });
1012
967
  },
@@ -1076,3 +1031,9 @@ function machine(ctx) {
1076
1031
  }
1077
1032
  });
1078
1033
  }
1034
+ // Annotate the CommonJS export names for ESM import in node:
1035
+ 0 && (module.exports = {
1036
+ connect,
1037
+ machine,
1038
+ unstable__dom
1039
+ });
package/dist/index.mjs CHANGED
@@ -1,47 +1,10 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
-
21
1
  // ../../utilities/dom/dist/index.mjs
22
- var __defProp2 = Object.defineProperty;
23
- var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
24
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
25
- var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
26
- var __pow = Math.pow;
27
- var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
28
- var __spreadValues2 = (a, b) => {
29
- for (var prop in b || (b = {}))
30
- if (__hasOwnProp2.call(b, prop))
31
- __defNormalProp2(a, prop, b[prop]);
32
- if (__getOwnPropSymbols2)
33
- for (var prop of __getOwnPropSymbols2(b)) {
34
- if (__propIsEnum2.call(b, prop))
35
- __defNormalProp2(a, prop, b[prop]);
36
- }
37
- return a;
38
- };
39
2
  var dataAttr = (guard) => {
40
3
  return guard ? "" : void 0;
41
4
  };
42
5
  var runIfFn = (v, ...a) => {
43
6
  const res = typeof v === "function" ? v(...a) : v;
44
- return res != null ? res : void 0;
7
+ return res ?? void 0;
45
8
  };
46
9
  var callAll = (...fns) => (...a) => {
47
10
  fns.forEach(function(fn) {
@@ -53,9 +16,8 @@ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
53
16
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
54
17
  var isDom = () => typeof window !== "undefined";
55
18
  function getPlatform() {
56
- var _a;
57
19
  const agent = navigator.userAgentData;
58
- return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
20
+ return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
59
21
  }
60
22
  var pt = (v) => isDom() && v.test(getPlatform());
61
23
  var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
@@ -69,36 +31,33 @@ function isWindow(value) {
69
31
  return (value == null ? void 0 : value.toString()) === "[object Window]";
70
32
  }
71
33
  function getDocument(el) {
72
- var _a;
73
34
  if (isWindow(el))
74
35
  return el.document;
75
36
  if (isDocument(el))
76
37
  return el;
77
- return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
38
+ return (el == null ? void 0 : el.ownerDocument) ?? document;
78
39
  }
79
40
  function getWindow(el) {
80
- var _a;
81
- return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
41
+ return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
82
42
  }
83
43
  function defineDomHelpers(helpers) {
84
44
  const dom2 = {
85
45
  getRootNode: (ctx) => {
86
- var _a, _b;
87
- return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
88
- },
89
- getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
90
- getWin: (ctx) => {
91
46
  var _a;
92
- return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
47
+ return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
93
48
  },
49
+ getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
50
+ getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
94
51
  getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
95
52
  getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
96
53
  };
97
- return __spreadValues2(__spreadValues2({}, dom2), helpers);
54
+ return {
55
+ ...dom2,
56
+ ...helpers
57
+ };
98
58
  }
99
59
  function getNativeEvent(e) {
100
- var _a;
101
- return (_a = e.nativeEvent) != null ? _a : e;
60
+ return e.nativeEvent ?? e;
102
61
  }
103
62
  var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
104
63
  var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
@@ -176,8 +135,7 @@ var fallback = {
176
135
  clientY: 0
177
136
  };
178
137
  function getEventPoint(event, type = "page") {
179
- var _a, _b;
180
- const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event;
138
+ const point = isTouchEvent(event) ? event.touches[0] ?? event.changedTouches[0] ?? fallback : event;
181
139
  return { x: point[`${type}X`], y: point[`${type}Y`] };
182
140
  }
183
141
  function getPointRelativeToNode(point, element) {
@@ -187,10 +145,9 @@ function getPointRelativeToNode(point, element) {
187
145
  return { x, y };
188
146
  }
189
147
  function getDescriptor(el, options) {
190
- var _a;
191
148
  const { type, property } = options;
192
149
  const proto = getWindow(el)[type].prototype;
193
- return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
150
+ return Object.getOwnPropertyDescriptor(proto, property) ?? {};
194
151
  }
195
152
  function dispatchInputValueEvent(el, value) {
196
153
  var _a;
@@ -220,10 +177,9 @@ var sameKeyMap = {
220
177
  Right: "ArrowRight"
221
178
  };
222
179
  function getEventKey(event, options = {}) {
223
- var _a;
224
180
  const { dir = "ltr", orientation = "horizontal" } = options;
225
181
  let { key } = event;
226
- key = (_a = sameKeyMap[key]) != null ? _a : key;
182
+ key = sameKeyMap[key] ?? key;
227
183
  const isRtl = dir === "rtl" && orientation === "horizontal";
228
184
  if (isRtl && key in rtlKeyMap) {
229
185
  key = rtlKeyMap[key];
@@ -260,8 +216,7 @@ function addDomEvent(target, eventName, handler, options) {
260
216
  };
261
217
  }
262
218
  function addPointerEvent(target, event, listener, options) {
263
- var _a;
264
- const type = (_a = getEventName(event)) != null ? _a : event;
219
+ const type = getEventName(event) ?? event;
265
220
  return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
266
221
  }
267
222
  function wrapHandler(fn, filter = false) {
@@ -272,8 +227,7 @@ function wrapHandler(fn, filter = false) {
272
227
  }
273
228
  function filterPrimaryPointer(fn) {
274
229
  return (event) => {
275
- var _a;
276
- const win = (_a = event.view) != null ? _a : window;
230
+ const win = event.view ?? window;
277
231
  const isMouseEvent2 = event instanceof win.MouseEvent;
278
232
  const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
279
233
  if (isPrimary)
@@ -328,7 +282,7 @@ var state = "default";
328
282
  var savedUserSelect = "";
329
283
  var modifiedElementMap = /* @__PURE__ */ new WeakMap();
330
284
  function disableTextSelection({ target, doc } = {}) {
331
- const _document = doc != null ? doc : document;
285
+ const _document = doc ?? document;
332
286
  if (isIos()) {
333
287
  if (state === "default") {
334
288
  savedUserSelect = _document.documentElement.style.webkitUserSelect;
@@ -342,7 +296,7 @@ function disableTextSelection({ target, doc } = {}) {
342
296
  return () => restoreTextSelection({ target, doc: _document });
343
297
  }
344
298
  function restoreTextSelection({ target, doc } = {}) {
345
- const _document = doc != null ? doc : document;
299
+ const _document = doc ?? document;
346
300
  if (isIos()) {
347
301
  if (state !== "disabled")
348
302
  return;
@@ -362,7 +316,7 @@ function restoreTextSelection({ target, doc } = {}) {
362
316
  if (target && modifiedElementMap.has(target)) {
363
317
  let targetOldUserSelect = modifiedElementMap.get(target);
364
318
  if (target.style.userSelect === "none") {
365
- target.style.userSelect = targetOldUserSelect != null ? targetOldUserSelect : "";
319
+ target.style.userSelect = targetOldUserSelect ?? "";
366
320
  }
367
321
  if (target.getAttribute("style") === "") {
368
322
  target.removeAttribute("style");
@@ -371,13 +325,13 @@ function restoreTextSelection({ target, doc } = {}) {
371
325
  }
372
326
  }
373
327
  }
374
- function trackPointerMove(opts) {
375
- const { onPointerMove, onPointerUp, ctx } = opts;
376
- const { doc = document, threshold = 5 } = ctx;
328
+ var THRESHOLD = 5;
329
+ function trackPointerMove(doc, opts) {
330
+ const { onPointerMove, onPointerUp } = opts;
377
331
  const handlePointerMove = (event, info) => {
378
332
  const { point: p } = info;
379
- const distance = Math.sqrt(__pow(p.x, 2) + __pow(p.y, 2));
380
- if (distance < threshold)
333
+ const distance = Math.sqrt(p.x ** 2 + p.y ** 2);
334
+ if (distance < THRESHOLD)
381
335
  return;
382
336
  if (isMouseEvent(event) && isLeftClick(event)) {
383
337
  onPointerUp();
@@ -389,10 +343,9 @@ function trackPointerMove(opts) {
389
343
  }
390
344
 
391
345
  // ../../utilities/number/dist/index.mjs
392
- var __pow2 = Math.pow;
393
346
  function round(v, t) {
394
347
  let num = valueOf(v);
395
- const p = __pow2(10, t != null ? t : 10);
348
+ const p = 10 ** (t ?? 10);
396
349
  num = Math.round(num * p) / p;
397
350
  return t ? num.toFixed(t) : v.toString();
398
351
  }
@@ -428,7 +381,7 @@ function valueOf(v) {
428
381
  function decimalOperation(a, op, b) {
429
382
  let result = op === "+" ? a + b : a - b;
430
383
  if (a % 1 !== 0 || b % 1 !== 0) {
431
- const multiplier = __pow2(10, Math.max(countDecimals(a), countDecimals(b)));
384
+ const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
432
385
  a = Math.round(a * multiplier);
433
386
  b = Math.round(b * multiplier);
434
387
  result = op === "+" ? a + b : a - b;
@@ -450,14 +403,12 @@ var transform = (a, b) => {
450
403
 
451
404
  // src/slider.style.ts
452
405
  function getVerticalThumbOffset(ctx) {
453
- var _a;
454
- const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
406
+ const { height = 0 } = ctx.thumbSize ?? {};
455
407
  const getValue = transform([ctx.min, ctx.max], [-height / 2, height / 2]);
456
408
  return parseFloat(getValue(ctx.value).toFixed(2));
457
409
  }
458
410
  function getHorizontalThumbOffset(ctx) {
459
- var _a;
460
- const { width = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
411
+ const { width = 0 } = ctx.thumbSize ?? {};
461
412
  if (ctx.isRtl) {
462
413
  const getValue2 = transform([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
463
414
  return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
@@ -567,45 +518,46 @@ var utils = {
567
518
  return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
568
519
  },
569
520
  decrement(ctx, step) {
570
- let value = decrement(ctx.value, step != null ? step : ctx.step);
521
+ let value = decrement(ctx.value, step ?? ctx.step);
571
522
  return utils.convert(ctx, value);
572
523
  },
573
524
  increment(ctx, step) {
574
- let value = increment(ctx.value, step != null ? step : ctx.step);
525
+ let value = increment(ctx.value, step ?? ctx.step);
575
526
  return utils.convert(ctx, value);
576
527
  }
577
528
  };
578
529
 
579
530
  // src/slider.dom.ts
580
- var dom = defineDomHelpers(__spreadProps(__spreadValues({}, styles), {
531
+ var dom = defineDomHelpers({
532
+ ...styles,
581
533
  getRootId: (ctx) => {
582
- var _a, _b;
583
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `slider:${ctx.id}`;
534
+ var _a;
535
+ return ((_a = ctx.ids) == null ? void 0 : _a.root) ?? `slider:${ctx.id}`;
584
536
  },
585
537
  getThumbId: (ctx) => {
586
- var _a, _b;
587
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.thumb) != null ? _b : `slider:${ctx.id}:thumb`;
538
+ var _a;
539
+ return ((_a = ctx.ids) == null ? void 0 : _a.thumb) ?? `slider:${ctx.id}:thumb`;
588
540
  },
589
541
  getControlId: (ctx) => {
590
- var _a, _b;
591
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.control) != null ? _b : `slider:${ctx.id}:control`;
542
+ var _a;
543
+ return ((_a = ctx.ids) == null ? void 0 : _a.control) ?? `slider:${ctx.id}:control`;
592
544
  },
593
545
  getInputId: (ctx) => `slider:${ctx.id}:input`,
594
546
  getOutputId: (ctx) => {
595
- var _a, _b;
596
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.output) != null ? _b : `slider:${ctx.id}:output`;
547
+ var _a;
548
+ return ((_a = ctx.ids) == null ? void 0 : _a.output) ?? `slider:${ctx.id}:output`;
597
549
  },
598
550
  getTrackId: (ctx) => {
599
- var _a, _b;
600
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}track`;
551
+ var _a;
552
+ return ((_a = ctx.ids) == null ? void 0 : _a.track) ?? `slider:${ctx.id}track`;
601
553
  },
602
554
  getRangeId: (ctx) => {
603
- var _a, _b;
604
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}:range`;
555
+ var _a;
556
+ return ((_a = ctx.ids) == null ? void 0 : _a.track) ?? `slider:${ctx.id}:range`;
605
557
  },
606
558
  getLabelId: (ctx) => {
607
- var _a, _b;
608
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.id}:label`;
559
+ var _a;
560
+ return ((_a = ctx.ids) == null ? void 0 : _a.label) ?? `slider:${ctx.id}:label`;
609
561
  },
610
562
  getMarkerId: (ctx, value) => `slider:${ctx.id}:marker:${value}`,
611
563
  getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
@@ -633,7 +585,7 @@ var dom = defineDomHelpers(__spreadProps(__spreadValues({}, styles), {
633
585
  return;
634
586
  dispatchInputValueEvent(input, ctx.value);
635
587
  }
636
- }));
588
+ });
637
589
 
638
590
  // src/slider.connect.ts
639
591
  function connect(state2, send, normalize) {
@@ -704,7 +656,7 @@ function connect(state2, send, normalize) {
704
656
  "data-invalid": dataAttr(isInvalid),
705
657
  "aria-disabled": isDisabled || void 0,
706
658
  "aria-label": ariaLabel,
707
- "aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy != null ? ariaLabelledBy : dom.getLabelId(state2.context),
659
+ "aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy ?? dom.getLabelId(state2.context),
708
660
  "aria-orientation": state2.context.orientation,
709
661
  "aria-valuemax": state2.context.max,
710
662
  "aria-valuemin": state2.context.min,
@@ -853,7 +805,7 @@ function machine(ctx) {
853
805
  return createMachine({
854
806
  id: "slider",
855
807
  initial: "unknown",
856
- context: __spreadValues({
808
+ context: {
857
809
  thumbSize: null,
858
810
  thumbAlignment: "contain",
859
811
  disabled: false,
@@ -865,8 +817,9 @@ function machine(ctx) {
865
817
  value: 0,
866
818
  step: 1,
867
819
  min: 0,
868
- max: 100
869
- }, ctx),
820
+ max: 100,
821
+ ...ctx
822
+ },
870
823
  computed: {
871
824
  isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
872
825
  isVertical: (ctx2) => ctx2.orientation === "vertical",
@@ -980,8 +933,7 @@ function machine(ctx) {
980
933
  });
981
934
  },
982
935
  trackPointerMove(ctx2, _evt, { send }) {
983
- return trackPointerMove({
984
- ctx: ctx2,
936
+ return trackPointerMove(dom.getDoc(ctx2), {
985
937
  onPointerMove(info) {
986
938
  send({ type: "POINTER_MOVE", point: info.point });
987
939
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/slider",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "Core logic for the slider widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -29,21 +29,22 @@
29
29
  "url": "https://github.com/chakra-ui/zag/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@zag-js/core": "0.1.8",
33
- "@zag-js/types": "0.2.2"
32
+ "@zag-js/core": "0.1.9",
33
+ "@zag-js/types": "0.2.3"
34
34
  },
35
35
  "devDependencies": {
36
- "@zag-js/dom-utils": "0.1.7",
37
- "@zag-js/number-utils": "0.1.2",
38
- "@zag-js/utils": "0.1.2"
36
+ "@zag-js/dom-utils": "0.1.8",
37
+ "@zag-js/number-utils": "0.1.3",
38
+ "@zag-js/utils": "0.1.3"
39
39
  },
40
40
  "scripts": {
41
- "build:fast": "zag build",
42
- "start": "zag build --watch",
43
- "build": "zag build --prod",
41
+ "build-fast": "tsup src/index.ts --format=esm,cjs",
42
+ "start": "pnpm build --watch",
43
+ "build": "tsup src/index.ts --format=esm,cjs --dts",
44
44
  "test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
45
45
  "lint": "eslint src --ext .ts,.tsx",
46
- "test:ci": "yarn test --ci --runInBand",
47
- "test:watch": "yarn test --watch --updateSnapshot"
46
+ "test-ci": "pnpm test --ci --runInBand",
47
+ "test-watch": "pnpm test --watch -u",
48
+ "typecheck": "tsc --noEmit"
48
49
  }
49
- }
50
+ }
@@ -1,25 +0,0 @@
1
- import type { NormalizeProps, PropTypes } from "@zag-js/types";
2
- import type { Send, State } from "./slider.types";
3
- export declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
4
- isFocused: boolean;
5
- isDragging: boolean;
6
- value: number;
7
- percent: number;
8
- setValue(value: number): void;
9
- getPercentValue(percent: number): number;
10
- focus(): void;
11
- increment(): void;
12
- decrement(): void;
13
- rootProps: T["element"];
14
- labelProps: T["label"];
15
- thumbProps: T["element"];
16
- inputProps: T["input"];
17
- outputProps: T["output"];
18
- trackProps: T["element"];
19
- rangeProps: T["element"];
20
- controlProps: T["element"];
21
- markerGroupProps: T["element"];
22
- getMarkerProps({ value }: {
23
- value: number;
24
- }): T["element"];
25
- };
@@ -1,43 +0,0 @@
1
- import type { MachineContext as Ctx, Point } from "./slider.types";
2
- export declare const dom: {
3
- getRootNode: (ctx: {
4
- getRootNode?: () => Node | Document | ShadowRoot;
5
- }) => Document | ShadowRoot;
6
- getDoc: (ctx: {
7
- getRootNode?: () => Node | Document | ShadowRoot;
8
- }) => Document;
9
- getWin: (ctx: {
10
- getRootNode?: () => Node | Document | ShadowRoot;
11
- }) => Window & typeof globalThis;
12
- getActiveElement: (ctx: {
13
- getRootNode?: () => Node | Document | ShadowRoot;
14
- }) => HTMLElement;
15
- getById: <T_1 = HTMLElement>(ctx: {
16
- getRootNode?: () => Node | Document | ShadowRoot;
17
- }, id: string) => T_1;
18
- } & {
19
- getRootId: (ctx: Ctx) => string;
20
- getThumbId: (ctx: Ctx) => string;
21
- getControlId: (ctx: Ctx) => string;
22
- getInputId: (ctx: Ctx) => string;
23
- getOutputId: (ctx: Ctx) => string;
24
- getTrackId: (ctx: Ctx) => string;
25
- getRangeId: (ctx: Ctx) => string;
26
- getLabelId: (ctx: Ctx) => string;
27
- getMarkerId: (ctx: Ctx, value: number) => string;
28
- getRootEl: (ctx: Ctx) => HTMLElement;
29
- getThumbEl: (ctx: Ctx) => HTMLElement;
30
- getControlEl: (ctx: Ctx) => HTMLElement;
31
- getInputEl: (ctx: Ctx) => HTMLInputElement;
32
- getValueFromPoint(ctx: Ctx, point: Point): number | undefined;
33
- dispatchChangeEvent(ctx: Ctx): void;
34
- getThumbOffset: (ctx: import("./slider.types").SharedContext) => string;
35
- getControlStyle: () => import("@zag-js/types").JSX.CSSProperties;
36
- getThumbStyle: (ctx: import("./slider.types").SharedContext) => import("@zag-js/types").JSX.CSSProperties;
37
- getRangeStyle: (ctx: Pick<import("./slider.types").SharedContext, "isVertical" | "isRtl">) => import("@zag-js/types").JSX.CSSProperties;
38
- getRootStyle: (ctx: Ctx) => import("@zag-js/types").JSX.CSSProperties;
39
- getMarkerStyle: (ctx: Pick<import("./slider.types").SharedContext, "isHorizontal" | "isRtl">, percent: number) => import("@zag-js/types").JSX.CSSProperties;
40
- getLabelStyle: () => import("@zag-js/types").JSX.CSSProperties;
41
- getTrackStyle: () => import("@zag-js/types").JSX.CSSProperties;
42
- getMarkerGroupStyle: () => import("@zag-js/types").JSX.CSSProperties;
43
- };
@@ -1,2 +0,0 @@
1
- import type { MachineContext, MachineState, UserDefinedContext } from "./slider.types";
2
- export declare function machine(ctx: UserDefinedContext): import("@zag-js/core").Machine<MachineContext, MachineState, import("@zag-js/core").StateMachine.AnyEventObject>;
@@ -1,23 +0,0 @@
1
- import type { Style } from "@zag-js/types";
2
- import type { MachineContext as Ctx, SharedContext } from "./slider.types";
3
- declare function getThumbOffset(ctx: SharedContext): string;
4
- declare function getThumbStyle(ctx: SharedContext): Style;
5
- declare function getRangeStyle(ctx: Pick<SharedContext, "isVertical" | "isRtl">): Style;
6
- declare function getControlStyle(): Style;
7
- declare function getRootStyle(ctx: Ctx): Style;
8
- declare function getMarkerStyle(ctx: Pick<SharedContext, "isHorizontal" | "isRtl">, percent: number): Style;
9
- declare function getLabelStyle(): Style;
10
- declare function getTrackStyle(): Style;
11
- declare function getMarkerGroupStyle(): Style;
12
- export declare const styles: {
13
- getThumbOffset: typeof getThumbOffset;
14
- getControlStyle: typeof getControlStyle;
15
- getThumbStyle: typeof getThumbStyle;
16
- getRangeStyle: typeof getRangeStyle;
17
- getRootStyle: typeof getRootStyle;
18
- getMarkerStyle: typeof getMarkerStyle;
19
- getLabelStyle: typeof getLabelStyle;
20
- getTrackStyle: typeof getTrackStyle;
21
- getMarkerGroupStyle: typeof getMarkerGroupStyle;
22
- };
23
- export {};
@@ -1,173 +0,0 @@
1
- import type { StateMachine as S } from "@zag-js/core";
2
- import type { CommonProperties, Context, DirectionProperty, RequiredBy } from "@zag-js/types";
3
- declare type ElementIds = Partial<{
4
- root: string;
5
- thumb: string;
6
- control: string;
7
- track: string;
8
- range: string;
9
- label: string;
10
- output: string;
11
- }>;
12
- declare type PublicContext = DirectionProperty & CommonProperties & {
13
- /**
14
- * The ids of the elements in the slider. Useful for composition.
15
- */
16
- ids?: ElementIds;
17
- /**
18
- * The value of the slider
19
- */
20
- value: number;
21
- /**
22
- * The name associated with the slider (when used in a form)
23
- */
24
- name?: string;
25
- /**
26
- * Whether the slider is disabled
27
- */
28
- disabled?: boolean;
29
- /**
30
- * Whether the slider is read-only
31
- */
32
- readonly?: boolean;
33
- /**
34
- * Whether the slider value is invalid
35
- */
36
- invalid?: boolean;
37
- /**
38
- * The minimum value of the slider
39
- */
40
- min: number;
41
- /**
42
- * The maximum value of the slider
43
- */
44
- max: number;
45
- /**
46
- * The step value of the slider
47
- */
48
- step: number;
49
- /**
50
- * The orientation of the slider
51
- */
52
- orientation?: "vertical" | "horizontal";
53
- /**
54
- * - "start": Useful when the value represents an absolute value
55
- * - "center": Useful when the value represents an offset (relative)
56
- */
57
- origin?: "start" | "center";
58
- /**
59
- * The aria-label of the slider. Useful for providing an accessible name to the slider
60
- */
61
- "aria-label"?: string;
62
- /**
63
- * The `id` of the element that labels the slider. Useful for providing an accessible name to the slider
64
- */
65
- "aria-labelledby"?: string;
66
- /**
67
- * Whether to focus the slider thumb after interaction (scrub and keyboard)
68
- */
69
- focusThumbOnChange?: boolean;
70
- /**
71
- * Function that returns a human readable value for the slider
72
- */
73
- getAriaValueText?(value: number): string;
74
- /**
75
- * Function invoked when the value of the slider changes
76
- */
77
- onChange?(details: {
78
- value: number;
79
- }): void;
80
- /**
81
- * Function invoked when the slider value change is done
82
- */
83
- onChangeEnd?(details: {
84
- value: number;
85
- }): void;
86
- /**
87
- * Function invoked when the slider value change is started
88
- */
89
- onChangeStart?(details: {
90
- value: number;
91
- }): void;
92
- /**
93
- * The alignment of the slider thumb relative to the track
94
- * - `center`: the thumb will extend beyond the bounds of the slider track.
95
- * - `contain`: the thumb will be contained within the bounds of the track.
96
- */
97
- thumbAlignment?: "contain" | "center";
98
- };
99
- export declare type UserDefinedContext = RequiredBy<PublicContext, "id">;
100
- declare type ComputedContext = Readonly<{
101
- /**
102
- * @computed
103
- * Whether the slider is interactive
104
- */
105
- readonly isInteractive: boolean;
106
- /**
107
- * @computed
108
- * Whether the thumb size has been measured
109
- */
110
- readonly hasMeasuredThumbSize: boolean;
111
- /**
112
- * @computed
113
- * Whether the slider is horizontal
114
- */
115
- readonly isHorizontal: boolean;
116
- /**
117
- * @computed
118
- * Whether the slider is vertical
119
- */
120
- readonly isVertical: boolean;
121
- /**
122
- * @computed
123
- * Whether the slider is in RTL mode
124
- */
125
- readonly isRtl: boolean;
126
- }>;
127
- declare type PrivateContext = Context<{
128
- /**
129
- * @internal The move threshold of the slider thumb before it is considered to be moved
130
- */
131
- threshold: number;
132
- /**
133
- * @internal The slider thumb dimensions
134
- */
135
- thumbSize: {
136
- width: number;
137
- height: number;
138
- } | null;
139
- /**
140
- * @internal
141
- * The value of the slider when it was initially rendered.
142
- * Used when the `form.reset(...)` is called.
143
- */
144
- initialValue: number | null;
145
- }>;
146
- export declare type MachineContext = PublicContext & ComputedContext & PrivateContext;
147
- export declare type MachineState = {
148
- value: "unknown" | "idle" | "dragging" | "focus";
149
- };
150
- export declare type State = S.State<MachineContext, MachineState>;
151
- export declare type Send = S.Send<S.AnyEventObject>;
152
- export declare type SharedContext = {
153
- min: number;
154
- max: number;
155
- step: number;
156
- dir?: "ltr" | "rtl";
157
- isRtl: boolean;
158
- isVertical: boolean;
159
- isHorizontal: boolean;
160
- value: number;
161
- thumbSize: {
162
- width: number;
163
- height: number;
164
- } | null;
165
- thumbAlignment?: "contain" | "center";
166
- orientation?: "horizontal" | "vertical";
167
- readonly hasMeasuredThumbSize: boolean;
168
- };
169
- export declare type Point = {
170
- x: number;
171
- y: number;
172
- };
173
- export {};
@@ -1,8 +0,0 @@
1
- import type { MachineContext as Ctx } from "./slider.types";
2
- export declare const utils: {
3
- fromPercent(ctx: Ctx, percent: number): number;
4
- clamp(ctx: Ctx, value: number): number;
5
- convert(ctx: Ctx, value: number): number;
6
- decrement(ctx: Ctx, step?: number): number;
7
- increment(ctx: Ctx, step?: number): number;
8
- };