@zag-js/slider 0.2.6 → 0.2.8

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.
@@ -0,0 +1,475 @@
1
+ import {
2
+ hasProp,
3
+ isIos,
4
+ isLeftClick,
5
+ isMouseEvent,
6
+ isObject,
7
+ isTouchEvent,
8
+ supportsMouseEvent,
9
+ supportsPointerEvent,
10
+ supportsTouchEvent
11
+ } from "./chunk-SGCWELVB.mjs";
12
+ import {
13
+ dom
14
+ } from "./chunk-J5IGGBVE.mjs";
15
+ import {
16
+ constrainValue,
17
+ decrement,
18
+ increment
19
+ } from "./chunk-DRAPR6JV.mjs";
20
+
21
+ // src/slider.machine.ts
22
+ import { createMachine } from "@zag-js/core";
23
+
24
+ // ../../utilities/core/src/functions.ts
25
+ var runIfFn = (v, ...a) => {
26
+ const res = typeof v === "function" ? v(...a) : v;
27
+ return res != null ? res : void 0;
28
+ };
29
+ var callAll = (...fns) => (...a) => {
30
+ fns.forEach(function(fn) {
31
+ fn == null ? void 0 : fn(...a);
32
+ });
33
+ };
34
+
35
+ // ../../utilities/core/src/object.ts
36
+ function compact(obj) {
37
+ if (obj === void 0)
38
+ return obj;
39
+ return Object.fromEntries(
40
+ Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
41
+ );
42
+ }
43
+
44
+ // ../../utilities/dom/src/listener.ts
45
+ var isRef = (v) => hasProp(v, "current");
46
+ var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
47
+ function extractInfo(event, type = "page") {
48
+ const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback : event;
49
+ return {
50
+ point: {
51
+ x: point[`${type}X`],
52
+ y: point[`${type}Y`]
53
+ }
54
+ };
55
+ }
56
+ function addDomEvent(target, eventName, handler, options) {
57
+ const node = isRef(target) ? target.current : runIfFn(target);
58
+ node == null ? void 0 : node.addEventListener(eventName, handler, options);
59
+ return () => {
60
+ node == null ? void 0 : node.removeEventListener(eventName, handler, options);
61
+ };
62
+ }
63
+ function addPointerEvent(target, event, listener, options) {
64
+ var _a;
65
+ const type = (_a = getEventName(event)) != null ? _a : event;
66
+ return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
67
+ }
68
+ function wrapHandler(fn, filter = false) {
69
+ const listener = (event) => {
70
+ fn(event, extractInfo(event));
71
+ };
72
+ return filter ? filterPrimaryPointer(listener) : listener;
73
+ }
74
+ function filterPrimaryPointer(fn) {
75
+ return (event) => {
76
+ var _a;
77
+ const win = (_a = event.view) != null ? _a : window;
78
+ const isMouseEvent2 = event instanceof win.MouseEvent;
79
+ const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
80
+ if (isPrimary)
81
+ fn(event);
82
+ };
83
+ }
84
+ var mouseEventNames = {
85
+ pointerdown: "mousedown",
86
+ pointermove: "mousemove",
87
+ pointerup: "mouseup",
88
+ pointercancel: "mousecancel",
89
+ pointerover: "mouseover",
90
+ pointerout: "mouseout",
91
+ pointerenter: "mouseenter",
92
+ pointerleave: "mouseleave"
93
+ };
94
+ var touchEventNames = {
95
+ pointerdown: "touchstart",
96
+ pointermove: "touchmove",
97
+ pointerup: "touchend",
98
+ pointercancel: "touchcancel"
99
+ };
100
+ function getEventName(evt) {
101
+ if (supportsPointerEvent())
102
+ return evt;
103
+ if (supportsTouchEvent())
104
+ return touchEventNames[evt];
105
+ if (supportsMouseEvent())
106
+ return mouseEventNames[evt];
107
+ return evt;
108
+ }
109
+
110
+ // ../../utilities/dom/src/mutation-observer.ts
111
+ function observeAttributes(node, attributes, fn) {
112
+ if (!node)
113
+ return;
114
+ const attrs = Array.isArray(attributes) ? attributes : [attributes];
115
+ const win = node.ownerDocument.defaultView || window;
116
+ const obs = new win.MutationObserver((changes) => {
117
+ for (const change of changes) {
118
+ if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
119
+ fn(change);
120
+ }
121
+ }
122
+ });
123
+ obs.observe(node, { attributes: true, attributeFilter: attrs });
124
+ return () => obs.disconnect();
125
+ }
126
+
127
+ // ../../utilities/dom/src/next-tick.ts
128
+ function nextTick(fn) {
129
+ const set = /* @__PURE__ */ new Set();
130
+ function raf2(fn2) {
131
+ const id = globalThis.requestAnimationFrame(fn2);
132
+ set.add(() => globalThis.cancelAnimationFrame(id));
133
+ }
134
+ raf2(() => raf2(fn));
135
+ return function cleanup() {
136
+ set.forEach(function(fn2) {
137
+ fn2();
138
+ });
139
+ };
140
+ }
141
+ function raf(fn) {
142
+ const id = globalThis.requestAnimationFrame(fn);
143
+ return function cleanup() {
144
+ globalThis.cancelAnimationFrame(id);
145
+ };
146
+ }
147
+
148
+ // ../../utilities/dom/src/text-selection.ts
149
+ var state = "default";
150
+ var savedUserSelect = "";
151
+ var modifiedElementMap = /* @__PURE__ */ new WeakMap();
152
+ function disableTextSelection({ target, doc } = {}) {
153
+ const _document = doc != null ? doc : document;
154
+ if (isIos()) {
155
+ if (state === "default") {
156
+ savedUserSelect = _document.documentElement.style.webkitUserSelect;
157
+ _document.documentElement.style.webkitUserSelect = "none";
158
+ }
159
+ state = "disabled";
160
+ } else if (target) {
161
+ modifiedElementMap.set(target, target.style.userSelect);
162
+ target.style.userSelect = "none";
163
+ }
164
+ return () => restoreTextSelection({ target, doc: _document });
165
+ }
166
+ function restoreTextSelection({ target, doc } = {}) {
167
+ const _document = doc != null ? doc : document;
168
+ if (isIos()) {
169
+ if (state !== "disabled")
170
+ return;
171
+ state = "restoring";
172
+ setTimeout(() => {
173
+ nextTick(() => {
174
+ if (state === "restoring") {
175
+ if (_document.documentElement.style.webkitUserSelect === "none") {
176
+ _document.documentElement.style.webkitUserSelect = savedUserSelect || "";
177
+ }
178
+ savedUserSelect = "";
179
+ state = "default";
180
+ }
181
+ });
182
+ }, 300);
183
+ } else {
184
+ if (target && modifiedElementMap.has(target)) {
185
+ let targetOldUserSelect = modifiedElementMap.get(target);
186
+ if (target.style.userSelect === "none") {
187
+ target.style.userSelect = targetOldUserSelect != null ? targetOldUserSelect : "";
188
+ }
189
+ if (target.getAttribute("style") === "") {
190
+ target.removeAttribute("style");
191
+ }
192
+ modifiedElementMap.delete(target);
193
+ }
194
+ }
195
+ }
196
+
197
+ // ../../utilities/dom/src/pointer-event.ts
198
+ var THRESHOLD = 5;
199
+ function trackPointerMove(doc, opts) {
200
+ const { onPointerMove, onPointerUp } = opts;
201
+ const handlePointerMove = (event, info) => {
202
+ const { point: p } = info;
203
+ const distance = Math.sqrt(p.x ** 2 + p.y ** 2);
204
+ if (distance < THRESHOLD)
205
+ return;
206
+ if (isMouseEvent(event) && isLeftClick(event)) {
207
+ onPointerUp();
208
+ return;
209
+ }
210
+ onPointerMove(info, event);
211
+ };
212
+ return callAll(
213
+ addPointerEvent(doc, "pointermove", handlePointerMove, false),
214
+ addPointerEvent(doc, "pointerup", onPointerUp, false),
215
+ addPointerEvent(doc, "pointercancel", onPointerUp, false),
216
+ addPointerEvent(doc, "contextmenu", onPointerUp, false),
217
+ disableTextSelection({ doc })
218
+ );
219
+ }
220
+
221
+ // src/slider.machine.ts
222
+ import { trackElementSize } from "@zag-js/element-size";
223
+
224
+ // ../../utilities/form-utils/src/form.ts
225
+ function getClosestForm(el) {
226
+ if (isFormElement(el))
227
+ return el.form;
228
+ else
229
+ return el.closest("form");
230
+ }
231
+ function isFormElement(el) {
232
+ return el.matches("textarea, input, select, button");
233
+ }
234
+ function trackFormReset(el, callback) {
235
+ if (!el)
236
+ return;
237
+ const form = getClosestForm(el);
238
+ form == null ? void 0 : form.addEventListener("reset", callback, { passive: true });
239
+ return () => {
240
+ form == null ? void 0 : form.removeEventListener("reset", callback);
241
+ };
242
+ }
243
+ function trackFieldsetDisabled(el, callback) {
244
+ const fieldset = el == null ? void 0 : el.closest("fieldset");
245
+ if (!fieldset)
246
+ return;
247
+ callback(fieldset.disabled);
248
+ return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
249
+ }
250
+ function trackFormControl(el, options) {
251
+ if (!el)
252
+ return;
253
+ const { onFieldsetDisabled, onFormReset } = options;
254
+ const cleanups = [
255
+ trackFormReset(el, onFormReset),
256
+ trackFieldsetDisabled(el, (disabled) => {
257
+ if (disabled)
258
+ onFieldsetDisabled();
259
+ })
260
+ ];
261
+ return () => {
262
+ cleanups.forEach((cleanup) => cleanup == null ? void 0 : cleanup());
263
+ };
264
+ }
265
+
266
+ // src/slider.machine.ts
267
+ import { clampValue, getValuePercent } from "@zag-js/numeric-range";
268
+ function machine(userContext) {
269
+ const ctx = compact(userContext);
270
+ return createMachine(
271
+ {
272
+ id: "slider",
273
+ initial: "unknown",
274
+ context: {
275
+ thumbSize: null,
276
+ thumbAlignment: "contain",
277
+ disabled: false,
278
+ threshold: 5,
279
+ dir: "ltr",
280
+ origin: "start",
281
+ orientation: "horizontal",
282
+ initialValue: null,
283
+ value: 0,
284
+ step: 1,
285
+ min: 0,
286
+ max: 100,
287
+ ...ctx
288
+ },
289
+ computed: {
290
+ isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
291
+ isVertical: (ctx2) => ctx2.orientation === "vertical",
292
+ isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
293
+ isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readOnly),
294
+ hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null,
295
+ valuePercent: (ctx2) => 100 * getValuePercent(ctx2.value, ctx2.min, ctx2.max)
296
+ },
297
+ watch: {
298
+ value: ["invokeOnChange", "dispatchChangeEvent"]
299
+ },
300
+ activities: ["trackFormControlState", "trackThumbSize"],
301
+ on: {
302
+ SET_VALUE: {
303
+ actions: "setValue"
304
+ },
305
+ INCREMENT: {
306
+ actions: "increment"
307
+ },
308
+ DECREMENT: {
309
+ actions: "decrement"
310
+ }
311
+ },
312
+ states: {
313
+ unknown: {
314
+ on: {
315
+ SETUP: {
316
+ target: "idle",
317
+ actions: ["checkValue"]
318
+ }
319
+ }
320
+ },
321
+ idle: {
322
+ on: {
323
+ POINTER_DOWN: {
324
+ target: "dragging",
325
+ actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
326
+ },
327
+ FOCUS: "focus"
328
+ }
329
+ },
330
+ focus: {
331
+ entry: "focusThumb",
332
+ on: {
333
+ POINTER_DOWN: {
334
+ target: "dragging",
335
+ actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
336
+ },
337
+ ARROW_LEFT: {
338
+ guard: "isHorizontal",
339
+ actions: "decrement"
340
+ },
341
+ ARROW_RIGHT: {
342
+ guard: "isHorizontal",
343
+ actions: "increment"
344
+ },
345
+ ARROW_UP: {
346
+ guard: "isVertical",
347
+ actions: "increment"
348
+ },
349
+ ARROW_DOWN: {
350
+ guard: "isVertical",
351
+ actions: "decrement"
352
+ },
353
+ PAGE_UP: {
354
+ actions: "increment"
355
+ },
356
+ PAGE_DOWN: {
357
+ actions: "decrement"
358
+ },
359
+ HOME: {
360
+ actions: "setToMin"
361
+ },
362
+ END: {
363
+ actions: "setToMax"
364
+ },
365
+ BLUR: "idle"
366
+ }
367
+ },
368
+ dragging: {
369
+ entry: "focusThumb",
370
+ activities: "trackPointerMove",
371
+ on: {
372
+ POINTER_UP: {
373
+ target: "focus",
374
+ actions: "invokeOnChangeEnd"
375
+ },
376
+ POINTER_MOVE: {
377
+ actions: "setPointerValue"
378
+ }
379
+ }
380
+ }
381
+ }
382
+ },
383
+ {
384
+ guards: {
385
+ isHorizontal: (ctx2) => ctx2.isHorizontal,
386
+ isVertical: (ctx2) => ctx2.isVertical
387
+ },
388
+ activities: {
389
+ trackFormControlState(ctx2) {
390
+ return trackFormControl(dom.getHiddenInputEl(ctx2), {
391
+ onFieldsetDisabled() {
392
+ ctx2.disabled = true;
393
+ },
394
+ onFormReset() {
395
+ if (ctx2.initialValue != null) {
396
+ ctx2.value = ctx2.initialValue;
397
+ }
398
+ }
399
+ });
400
+ },
401
+ trackPointerMove(ctx2, _evt, { send }) {
402
+ return trackPointerMove(dom.getDoc(ctx2), {
403
+ onPointerMove(info) {
404
+ send({ type: "POINTER_MOVE", point: info.point });
405
+ },
406
+ onPointerUp() {
407
+ send("POINTER_UP");
408
+ }
409
+ });
410
+ },
411
+ trackThumbSize(ctx2, _evt) {
412
+ if (ctx2.thumbAlignment !== "contain")
413
+ return;
414
+ return trackElementSize(dom.getThumbEl(ctx2), (size) => {
415
+ if (size)
416
+ ctx2.thumbSize = size;
417
+ });
418
+ }
419
+ },
420
+ actions: {
421
+ checkValue(ctx2) {
422
+ const value = constrainValue(ctx2, ctx2.value);
423
+ ctx2.value = value;
424
+ ctx2.initialValue = value;
425
+ },
426
+ invokeOnChangeStart(ctx2) {
427
+ var _a;
428
+ (_a = ctx2.onChangeStart) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
429
+ },
430
+ invokeOnChangeEnd(ctx2) {
431
+ var _a;
432
+ (_a = ctx2.onChangeEnd) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
433
+ },
434
+ invokeOnChange(ctx2) {
435
+ var _a;
436
+ (_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
437
+ },
438
+ dispatchChangeEvent(ctx2) {
439
+ dom.dispatchChangeEvent(ctx2);
440
+ },
441
+ setPointerValue(ctx2, evt) {
442
+ const value = dom.getValueFromPoint(ctx2, evt.point);
443
+ if (value == null)
444
+ return;
445
+ ctx2.value = clampValue(value, ctx2.min, ctx2.max);
446
+ },
447
+ focusThumb(ctx2) {
448
+ raf(() => {
449
+ var _a;
450
+ return (_a = dom.getThumbEl(ctx2)) == null ? void 0 : _a.focus();
451
+ });
452
+ },
453
+ decrement(ctx2, evt) {
454
+ ctx2.value = decrement(ctx2, evt.step);
455
+ },
456
+ increment(ctx2, evt) {
457
+ ctx2.value = increment(ctx2, evt.step);
458
+ },
459
+ setToMin(ctx2) {
460
+ ctx2.value = ctx2.min;
461
+ },
462
+ setToMax(ctx2) {
463
+ ctx2.value = ctx2.max;
464
+ },
465
+ setValue(ctx2, evt) {
466
+ ctx2.value = constrainValue(ctx2, evt.value);
467
+ }
468
+ }
469
+ }
470
+ );
471
+ }
472
+
473
+ export {
474
+ machine
475
+ };
@@ -0,0 +1,34 @@
1
+ // src/slider.utils.ts
2
+ import { clampValue, getNextStepValue, getPreviousStepValue, snapValueToStep } from "@zag-js/numeric-range";
3
+ function clampPercent(percent) {
4
+ return clampValue(percent, 0, 1);
5
+ }
6
+ function constrainValue(ctx, value) {
7
+ const snapValue = snapValueToStep(value, ctx.min, ctx.max, ctx.step);
8
+ return clampValue(snapValue, ctx.min, ctx.max);
9
+ }
10
+ function decrement(ctx, step) {
11
+ const index = 0;
12
+ const values = getPreviousStepValue(index, {
13
+ ...ctx,
14
+ step: step != null ? step : ctx.step,
15
+ values: [ctx.value]
16
+ });
17
+ return values[index];
18
+ }
19
+ function increment(ctx, step) {
20
+ const index = 0;
21
+ const values = getNextStepValue(index, {
22
+ ...ctx,
23
+ step: step != null ? step : ctx.step,
24
+ values: [ctx.value]
25
+ });
26
+ return values[index];
27
+ }
28
+
29
+ export {
30
+ clampPercent,
31
+ constrainValue,
32
+ decrement,
33
+ increment
34
+ };
@@ -0,0 +1,159 @@
1
+ import {
2
+ styles
3
+ } from "./chunk-YREEXXZP.mjs";
4
+
5
+ // ../../utilities/dom/src/query.ts
6
+ function isDocument(el) {
7
+ return el.nodeType === Node.DOCUMENT_NODE;
8
+ }
9
+ function isWindow(value) {
10
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
11
+ }
12
+ function getDocument(el) {
13
+ var _a;
14
+ if (isWindow(el))
15
+ return el.document;
16
+ if (isDocument(el))
17
+ return el;
18
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
19
+ }
20
+ function getWindow(el) {
21
+ var _a;
22
+ return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
23
+ }
24
+ function defineDomHelpers(helpers) {
25
+ const dom2 = {
26
+ getRootNode: (ctx) => {
27
+ var _a, _b;
28
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
29
+ },
30
+ getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
31
+ getWin: (ctx) => {
32
+ var _a;
33
+ return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
34
+ },
35
+ getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
36
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
37
+ };
38
+ return {
39
+ ...dom2,
40
+ ...helpers
41
+ };
42
+ }
43
+
44
+ // ../../utilities/dom/src/get-element-offset.ts
45
+ function getElementOffset(element) {
46
+ let left = 0;
47
+ let top = 0;
48
+ let el = element;
49
+ if (el.parentNode) {
50
+ do {
51
+ left += el.offsetLeft;
52
+ top += el.offsetTop;
53
+ } while ((el = el.offsetParent) && el.nodeType < 9);
54
+ el = element;
55
+ do {
56
+ left -= el.scrollLeft;
57
+ top -= el.scrollTop;
58
+ } while ((el = el.parentNode) && !/body/i.test(el.nodeName));
59
+ }
60
+ return {
61
+ top,
62
+ right: innerWidth - left - element.offsetWidth,
63
+ bottom: innerHeight - top - element.offsetHeight,
64
+ left
65
+ };
66
+ }
67
+
68
+ // ../../utilities/dom/src/get-point-relative-to-element.ts
69
+ function getPointRelativeToNode(point, element) {
70
+ const offset = getElementOffset(element);
71
+ const x = point.x - offset.left;
72
+ const y = point.y - offset.top;
73
+ return { x, y };
74
+ }
75
+
76
+ // ../../utilities/form-utils/src/input-event.ts
77
+ function getDescriptor(el, options) {
78
+ var _a;
79
+ const { type, property = "value" } = options;
80
+ const proto = getWindow(el)[type].prototype;
81
+ return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
82
+ }
83
+ function dispatchInputValueEvent(el, value) {
84
+ var _a;
85
+ if (!el)
86
+ return;
87
+ const win = getWindow(el);
88
+ if (!(el instanceof win.HTMLInputElement))
89
+ return;
90
+ const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
91
+ (_a = desc.set) == null ? void 0 : _a.call(el, value);
92
+ const event = new win.Event("input", { bubbles: true });
93
+ el.dispatchEvent(event);
94
+ }
95
+
96
+ // src/slider.dom.ts
97
+ import { getPercentValue } from "@zag-js/numeric-range";
98
+ var dom = defineDomHelpers({
99
+ ...styles,
100
+ getRootId: (ctx) => {
101
+ var _a, _b;
102
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `slider:${ctx.id}`;
103
+ },
104
+ getThumbId: (ctx) => {
105
+ var _a, _b;
106
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.thumb) != null ? _b : `slider:${ctx.id}:thumb`;
107
+ },
108
+ getControlId: (ctx) => {
109
+ var _a, _b;
110
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.control) != null ? _b : `slider:${ctx.id}:control`;
111
+ },
112
+ getHiddenInputId: (ctx) => `slider:${ctx.id}:input`,
113
+ getOutputId: (ctx) => {
114
+ var _a, _b;
115
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.output) != null ? _b : `slider:${ctx.id}:output`;
116
+ },
117
+ getTrackId: (ctx) => {
118
+ var _a, _b;
119
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}track`;
120
+ },
121
+ getRangeId: (ctx) => {
122
+ var _a, _b;
123
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}:range`;
124
+ },
125
+ getLabelId: (ctx) => {
126
+ var _a, _b;
127
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.id}:label`;
128
+ },
129
+ getMarkerId: (ctx, value) => `slider:${ctx.id}:marker:${value}`,
130
+ getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
131
+ getThumbEl: (ctx) => dom.getById(ctx, dom.getThumbId(ctx)),
132
+ getControlEl: (ctx) => dom.getById(ctx, dom.getControlId(ctx)),
133
+ getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx)),
134
+ getValueFromPoint(ctx, point) {
135
+ const el = dom.getControlEl(ctx);
136
+ if (!el)
137
+ return;
138
+ const relativePoint = getPointRelativeToNode(point, el);
139
+ const percentX = relativePoint.x / el.offsetWidth;
140
+ const percentY = relativePoint.y / el.offsetHeight;
141
+ let percent;
142
+ if (ctx.isHorizontal) {
143
+ percent = ctx.isRtl ? 1 - percentX : percentX;
144
+ } else {
145
+ percent = 1 - percentY;
146
+ }
147
+ return getPercentValue(percent, ctx.min, ctx.max, ctx.step);
148
+ },
149
+ dispatchChangeEvent(ctx) {
150
+ const input = dom.getHiddenInputEl(ctx);
151
+ if (!input)
152
+ return;
153
+ dispatchInputValueEvent(input, ctx.value);
154
+ }
155
+ });
156
+
157
+ export {
158
+ dom
159
+ };
@@ -0,0 +1,44 @@
1
+ // ../../utilities/core/src/guard.ts
2
+ var isArray = (v) => Array.isArray(v);
3
+ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
4
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
5
+
6
+ // ../../utilities/dom/src/platform.ts
7
+ var isDom = () => typeof window !== "undefined";
8
+ function getPlatform() {
9
+ var _a;
10
+ const agent = navigator.userAgentData;
11
+ return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
12
+ }
13
+ var pt = (v) => isDom() && v.test(getPlatform());
14
+ var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
15
+ var isMac = () => pt(/^Mac/) && !isTouchDevice;
16
+ var isApple = () => pt(/mac|iphone|ipad|ipod/i);
17
+ var isIos = () => isApple() && !isMac();
18
+
19
+ // ../../utilities/dom/src/event.ts
20
+ function getNativeEvent(e) {
21
+ var _a;
22
+ return (_a = e.nativeEvent) != null ? _a : e;
23
+ }
24
+ var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
25
+ var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
26
+ var supportsMouseEvent = () => isDom() && window.onmousedown === null;
27
+ var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
28
+ var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
29
+ var isLeftClick = (v) => v.button === 0;
30
+ var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
31
+
32
+ export {
33
+ isObject,
34
+ hasProp,
35
+ isIos,
36
+ getNativeEvent,
37
+ supportsPointerEvent,
38
+ supportsTouchEvent,
39
+ supportsMouseEvent,
40
+ isMouseEvent,
41
+ isTouchEvent,
42
+ isLeftClick,
43
+ isModifiedEvent
44
+ };