@zag-js/slider 1.46.0 → 1.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,355 +1,322 @@
1
- // src/slider.machine.ts
2
- import { createMachine, memo } from "@zag-js/core";
1
+ import { dispatchChangeEvent, getHiddenInputEl, getOffsetRect, getPointValue, getRootEl, getThumbEl, getThumbEls } from "./slider.dom.mjs";
2
+ import { constrainValue, decrement, getClosestIndex, getRangeAtIndex, increment, normalizeValues, resolveThumbCollision, selectMovableThumb } from "./slider.utils.mjs";
3
3
  import { raf, resizeObserverBorderBox, setElementValue, trackFormControl, trackPointerMove } from "@zag-js/dom-query";
4
- import {
5
- callAll,
6
- clampValue,
7
- getValuePercent,
8
- getValueRanges,
9
- isEqual,
10
- isValueWithinRange,
11
- pick,
12
- setValueAtIndex,
13
- snapValueToStep
14
- } from "@zag-js/utils";
15
- import * as dom from "./slider.dom.mjs";
16
- import {
17
- constrainValue,
18
- decrement,
19
- getClosestIndex,
20
- getRangeAtIndex,
21
- increment,
22
- normalizeValues,
23
- resolveThumbCollision,
24
- selectMovableThumb
25
- } from "./slider.utils.mjs";
26
- var isEqualSize = (a, b) => {
27
- return a?.width === b?.width && a?.height === b?.height;
4
+ import { callAll, clampValue, getValuePercent, getValueRanges, isEqual, isValueWithinRange, pick, setValueAtIndex, snapValueToStep } from "@zag-js/utils";
5
+ import { createMachine, memo } from "@zag-js/core";
6
+ // src/slider.machine.ts
7
+ const isEqualSize = (a, b) => {
8
+ return a?.width === b?.width && a?.height === b?.height;
28
9
  };
29
- var normalize = (value, min, max, step, minStepsBetweenThumbs) => {
30
- const ranges = getValueRanges(value, min, max, minStepsBetweenThumbs * step);
31
- return ranges.map((range) => {
32
- const snapValue = snapValueToStep(range.value, range.min, range.max, step);
33
- const rangeValue = clampValue(snapValue, range.min, range.max);
34
- if (!isValueWithinRange(rangeValue, min, max)) {
35
- throw new Error(
36
- "[zag-js/slider] The configured `min`, `max`, `step` or `minStepsBetweenThumbs` values are invalid"
37
- );
38
- }
39
- return rangeValue;
40
- });
10
+ const normalize = (value, min, max, step, minStepsBetweenThumbs) => {
11
+ return getValueRanges(value, min, max, minStepsBetweenThumbs * step).map((range) => {
12
+ const snapValue = snapValueToStep(range.value, range.min, range.max, step);
13
+ const rangeValue = clampValue(snapValue, range.min, range.max);
14
+ if (!isValueWithinRange(rangeValue, min, max)) throw new Error("[zag-js/slider] The configured `min`, `max`, `step` or `minStepsBetweenThumbs` values are invalid");
15
+ return rangeValue;
16
+ });
41
17
  };
42
- var machine = createMachine({
43
- props({ props }) {
44
- const min = props.min ?? 0;
45
- const max = props.max ?? 100;
46
- const step = props.step ?? 1;
47
- const defaultValue = props.defaultValue ?? [min];
48
- const minStepsBetweenThumbs = props.minStepsBetweenThumbs ?? 0;
49
- return {
50
- dir: "ltr",
51
- thumbAlignment: "contain",
52
- origin: "start",
53
- orientation: "horizontal",
54
- thumbCollisionBehavior: "none",
55
- minStepsBetweenThumbs,
56
- ...props,
57
- largeStep: props.largeStep ?? 10 * step,
58
- defaultValue: normalize(defaultValue, min, max, step, minStepsBetweenThumbs),
59
- value: props.value ? normalize(props.value, min, max, step, minStepsBetweenThumbs) : void 0,
60
- max,
61
- step,
62
- min
63
- };
64
- },
65
- initialState() {
66
- return "idle";
67
- },
68
- context({ prop, bindable, getContext }) {
69
- return {
70
- thumbSize: bindable(() => ({
71
- defaultValue: prop("thumbSize") || null
72
- })),
73
- value: bindable(() => ({
74
- defaultValue: prop("defaultValue"),
75
- value: prop("value"),
76
- isEqual,
77
- hash(a) {
78
- return a.join(",");
79
- },
80
- onChange(value) {
81
- prop("onValueChange")?.({ value });
82
- }
83
- })),
84
- focusedIndex: bindable(() => ({
85
- defaultValue: -1,
86
- onChange(value) {
87
- const ctx = getContext();
88
- prop("onFocusChange")?.({ focusedIndex: value, value: ctx.get("value") });
89
- }
90
- })),
91
- fieldsetDisabled: bindable(() => ({
92
- defaultValue: false
93
- }))
94
- };
95
- },
96
- refs() {
97
- return {
98
- thumbDragOffset: null,
99
- thumbDragStartValue: null
100
- };
101
- },
102
- computed: {
103
- isHorizontal: ({ prop }) => prop("orientation") === "horizontal",
104
- isVertical: ({ prop }) => prop("orientation") === "vertical",
105
- isRtl: ({ prop }) => prop("orientation") === "horizontal" && prop("dir") === "rtl",
106
- isDisabled: ({ context, prop }) => !!prop("disabled") || context.get("fieldsetDisabled"),
107
- isInteractive: ({ prop, computed }) => !(prop("readOnly") || computed("isDisabled")),
108
- hasMeasuredThumbSize: ({ context }) => context.get("thumbSize") != null,
109
- valuePercent: memo(
110
- ({ context, prop }) => [context.get("value"), prop("min"), prop("max")],
111
- ([value, min, max]) => value.map((value2) => 100 * getValuePercent(value2, min, max))
112
- )
113
- },
114
- watch({ track, action, context, computed, send }) {
115
- track([() => context.hash("value")], () => {
116
- action(["syncInputElements", "dispatchChangeEvent"]);
117
- });
118
- track([() => computed("isDisabled")], () => {
119
- if (computed("isDisabled")) {
120
- send({ type: "POINTER_CANCEL" });
121
- }
122
- });
123
- },
124
- effects: ["trackFormControlState", "trackThumbSize"],
125
- on: {
126
- SET_VALUE: [
127
- {
128
- guard: "hasIndex",
129
- actions: ["setValueAtIndex", "invokeOnChangeEnd"]
130
- },
131
- {
132
- actions: ["setValue", "invokeOnChangeEnd"]
133
- }
134
- ],
135
- INCREMENT: {
136
- actions: ["incrementThumbAtIndex", "invokeOnChangeEnd"]
137
- },
138
- DECREMENT: {
139
- actions: ["decrementThumbAtIndex", "invokeOnChangeEnd"]
140
- }
141
- },
142
- states: {
143
- idle: {
144
- on: {
145
- POINTER_DOWN: {
146
- target: "dragging",
147
- actions: ["setClosestThumbIndex", "setThumbDragStartValue", "setPointerValue", "focusActiveThumb"]
148
- },
149
- FOCUS: {
150
- target: "focus",
151
- actions: ["setFocusedIndex"]
152
- },
153
- THUMB_POINTER_DOWN: {
154
- target: "dragging",
155
- actions: ["setFocusedIndex", "setThumbDragOffset", "setThumbDragStartValue", "focusActiveThumb"]
156
- }
157
- }
158
- },
159
- focus: {
160
- entry: ["focusActiveThumb"],
161
- on: {
162
- POINTER_DOWN: {
163
- target: "dragging",
164
- actions: ["setClosestThumbIndex", "setThumbDragStartValue", "setPointerValue", "focusActiveThumb"]
165
- },
166
- THUMB_POINTER_DOWN: {
167
- target: "dragging",
168
- actions: ["setFocusedIndex", "setThumbDragOffset", "setThumbDragStartValue", "focusActiveThumb"]
169
- },
170
- ARROW_DEC: {
171
- actions: ["decrementThumbAtIndex", "invokeOnChangeEnd"]
172
- },
173
- ARROW_INC: {
174
- actions: ["incrementThumbAtIndex", "invokeOnChangeEnd"]
175
- },
176
- HOME: {
177
- actions: ["setFocusedThumbToMin", "invokeOnChangeEnd"]
178
- },
179
- END: {
180
- actions: ["setFocusedThumbToMax", "invokeOnChangeEnd"]
181
- },
182
- BLUR: {
183
- target: "idle",
184
- actions: ["clearFocusedIndex"]
185
- }
186
- }
187
- },
188
- dragging: {
189
- entry: ["focusActiveThumb"],
190
- effects: ["trackPointerMove"],
191
- on: {
192
- POINTER_UP: {
193
- target: "focus",
194
- actions: ["invokeOnChangeEnd", "clearThumbDragOffset", "clearThumbDragStartValue"]
195
- },
196
- POINTER_MOVE: {
197
- actions: ["setPointerValue"]
198
- },
199
- POINTER_CANCEL: {
200
- target: "idle",
201
- actions: ["clearFocusedIndex", "clearThumbDragOffset", "clearThumbDragStartValue"]
202
- }
203
- }
204
- }
205
- },
206
- implementations: {
207
- guards: {
208
- hasIndex: ({ event }) => event.index != null
209
- },
210
- effects: {
211
- trackFormControlState({ context, scope }) {
212
- return trackFormControl(dom.getRootEl(scope), {
213
- onFieldsetDisabledChange(disabled) {
214
- context.set("fieldsetDisabled", disabled);
215
- },
216
- onFormReset() {
217
- context.set("value", context.initial("value"));
218
- }
219
- });
220
- },
221
- trackPointerMove({ scope, send }) {
222
- return trackPointerMove(scope.getDoc(), {
223
- onPointerMove(info) {
224
- send({ type: "POINTER_MOVE", point: info.point });
225
- },
226
- onPointerUp() {
227
- send({ type: "POINTER_UP" });
228
- }
229
- });
230
- },
231
- trackThumbSize({ context, scope, prop }) {
232
- if (prop("thumbAlignment") !== "contain" || prop("thumbSize")) return;
233
- const exec = (el) => {
234
- const rect = dom.getOffsetRect(el);
235
- const size = pick(rect, ["width", "height"]);
236
- if (isEqualSize(context.get("thumbSize"), size)) return;
237
- context.set("thumbSize", size);
238
- };
239
- const thumbEls = dom.getThumbEls(scope);
240
- thumbEls.forEach(exec);
241
- const cleanups = thumbEls.map((el) => resizeObserverBorderBox.observe(el, () => exec(el)));
242
- return callAll(...cleanups);
243
- }
244
- },
245
- actions: {
246
- dispatchChangeEvent({ context, scope }) {
247
- dom.dispatchChangeEvent(scope, context.get("value"));
248
- },
249
- syncInputElements({ context, scope }) {
250
- context.get("value").forEach((value, index) => {
251
- const inputEl = dom.getHiddenInputEl(scope, index);
252
- setElementValue(inputEl, value.toString());
253
- });
254
- },
255
- invokeOnChangeEnd({ prop, context }) {
256
- queueMicrotask(() => {
257
- prop("onValueChangeEnd")?.({ value: context.get("value") });
258
- });
259
- },
260
- setClosestThumbIndex(params) {
261
- const { context, event } = params;
262
- const pointValue = dom.getPointValue(params, event.point);
263
- if (pointValue == null) return;
264
- const focusedIndex = getClosestIndex(params, pointValue);
265
- context.set("focusedIndex", focusedIndex);
266
- },
267
- setFocusedIndex(params) {
268
- const { context, event } = params;
269
- const movableIndex = selectMovableThumb(params, event.index);
270
- context.set("focusedIndex", movableIndex);
271
- },
272
- clearFocusedIndex({ context }) {
273
- context.set("focusedIndex", -1);
274
- },
275
- setThumbDragOffset(params) {
276
- const { refs, event } = params;
277
- refs.set("thumbDragOffset", event.offset ?? null);
278
- },
279
- clearThumbDragOffset({ refs }) {
280
- refs.set("thumbDragOffset", null);
281
- },
282
- setThumbDragStartValue({ refs, context }) {
283
- refs.set("thumbDragStartValue", context.get("value").slice());
284
- },
285
- clearThumbDragStartValue({ refs }) {
286
- refs.set("thumbDragStartValue", null);
287
- },
288
- setPointerValue(params) {
289
- queueMicrotask(() => {
290
- const { context, event, prop, refs } = params;
291
- const pointValue = dom.getPointValue(params, event.point);
292
- if (pointValue == null) return;
293
- const focusedIndex = context.get("focusedIndex");
294
- const startValues = refs.get("thumbDragStartValue");
295
- const result = resolveThumbCollision(
296
- prop("thumbCollisionBehavior"),
297
- focusedIndex,
298
- pointValue,
299
- context.get("value"),
300
- prop("min"),
301
- prop("max"),
302
- prop("step"),
303
- prop("minStepsBetweenThumbs"),
304
- startValues?.[focusedIndex]
305
- );
306
- if (result.swapped) {
307
- context.set("focusedIndex", result.index);
308
- }
309
- context.set("value", result.values);
310
- });
311
- },
312
- focusActiveThumb({ scope, context }) {
313
- raf(() => {
314
- const thumbEl = dom.getThumbEl(scope, context.get("focusedIndex"));
315
- thumbEl?.focus({ preventScroll: true });
316
- });
317
- },
318
- decrementThumbAtIndex(params) {
319
- const { context, event } = params;
320
- const value = decrement(params, event.index, event.step);
321
- context.set("value", value);
322
- },
323
- incrementThumbAtIndex(params) {
324
- const { context, event } = params;
325
- const value = increment(params, event.index, event.step);
326
- context.set("value", value);
327
- },
328
- setFocusedThumbToMin(params) {
329
- const { context } = params;
330
- const index = context.get("focusedIndex");
331
- const { min } = getRangeAtIndex(params, index);
332
- context.set("value", (prev) => setValueAtIndex(prev, index, min));
333
- },
334
- setFocusedThumbToMax(params) {
335
- const { context } = params;
336
- const index = context.get("focusedIndex");
337
- const { max } = getRangeAtIndex(params, index);
338
- context.set("value", (prev) => setValueAtIndex(prev, index, max));
339
- },
340
- setValueAtIndex(params) {
341
- const { context, event } = params;
342
- const value = constrainValue(params, event.value, event.index);
343
- context.set("value", (prev) => setValueAtIndex(prev, event.index, value));
344
- },
345
- setValue(params) {
346
- const { context, event } = params;
347
- const value = normalizeValues(params, event.value);
348
- context.set("value", value);
349
- }
350
- }
351
- }
18
+ const machine = createMachine({
19
+ props({ props }) {
20
+ const min = props.min ?? 0;
21
+ const max = props.max ?? 100;
22
+ const step = props.step ?? 1;
23
+ const defaultValue = props.defaultValue ?? [min];
24
+ const minStepsBetweenThumbs = props.minStepsBetweenThumbs ?? 0;
25
+ return {
26
+ dir: "ltr",
27
+ thumbAlignment: "contain",
28
+ origin: "start",
29
+ orientation: "horizontal",
30
+ thumbCollisionBehavior: "none",
31
+ minStepsBetweenThumbs,
32
+ ...props,
33
+ largeStep: props.largeStep ?? 10 * step,
34
+ defaultValue: normalize(defaultValue, min, max, step, minStepsBetweenThumbs),
35
+ value: props.value ? normalize(props.value, min, max, step, minStepsBetweenThumbs) : void 0,
36
+ max,
37
+ step,
38
+ min
39
+ };
40
+ },
41
+ initialState() {
42
+ return "idle";
43
+ },
44
+ context({ prop, bindable, getContext }) {
45
+ return {
46
+ thumbSize: bindable(() => ({ defaultValue: prop("thumbSize") || null })),
47
+ value: bindable(() => ({
48
+ defaultValue: prop("defaultValue"),
49
+ value: prop("value"),
50
+ isEqual,
51
+ hash(a) {
52
+ return a.join(",");
53
+ },
54
+ onChange(value) {
55
+ prop("onValueChange")?.({ value });
56
+ }
57
+ })),
58
+ focusedIndex: bindable(() => ({
59
+ defaultValue: -1,
60
+ onChange(value) {
61
+ const ctx = getContext();
62
+ prop("onFocusChange")?.({
63
+ focusedIndex: value,
64
+ value: ctx.get("value")
65
+ });
66
+ }
67
+ })),
68
+ fieldsetDisabled: bindable(() => ({ defaultValue: false }))
69
+ };
70
+ },
71
+ refs() {
72
+ return {
73
+ thumbDragOffset: null,
74
+ thumbDragStartValue: null
75
+ };
76
+ },
77
+ computed: {
78
+ isHorizontal: ({ prop }) => prop("orientation") === "horizontal",
79
+ isVertical: ({ prop }) => prop("orientation") === "vertical",
80
+ isRtl: ({ prop }) => prop("orientation") === "horizontal" && prop("dir") === "rtl",
81
+ isDisabled: ({ context, prop }) => !!prop("disabled") || context.get("fieldsetDisabled"),
82
+ isInteractive: ({ prop, computed }) => !(prop("readOnly") || computed("isDisabled")),
83
+ hasMeasuredThumbSize: ({ context }) => context.get("thumbSize") != null,
84
+ valuePercent: memo(({ context, prop }) => [
85
+ context.get("value"),
86
+ prop("min"),
87
+ prop("max")
88
+ ], ([value, min, max]) => value.map((value) => 100 * getValuePercent(value, min, max)))
89
+ },
90
+ watch({ track, action, context, computed, send }) {
91
+ track([() => context.hash("value")], () => {
92
+ action(["syncInputElements", "dispatchChangeEvent"]);
93
+ });
94
+ track([() => computed("isDisabled")], () => {
95
+ if (computed("isDisabled")) send({ type: "POINTER_CANCEL" });
96
+ });
97
+ },
98
+ effects: ["trackFormControlState", "trackThumbSize"],
99
+ on: {
100
+ SET_VALUE: [{
101
+ guard: "hasIndex",
102
+ actions: ["setValueAtIndex", "invokeOnChangeEnd"]
103
+ }, { actions: ["setValue", "invokeOnChangeEnd"] }],
104
+ INCREMENT: { actions: ["incrementThumbAtIndex", "invokeOnChangeEnd"] },
105
+ DECREMENT: { actions: ["decrementThumbAtIndex", "invokeOnChangeEnd"] }
106
+ },
107
+ states: {
108
+ idle: { on: {
109
+ POINTER_DOWN: {
110
+ target: "dragging",
111
+ actions: [
112
+ "setClosestThumbIndex",
113
+ "setThumbDragStartValue",
114
+ "setPointerValue",
115
+ "focusActiveThumb"
116
+ ]
117
+ },
118
+ FOCUS: {
119
+ target: "focus",
120
+ actions: ["setFocusedIndex"]
121
+ },
122
+ THUMB_POINTER_DOWN: {
123
+ target: "dragging",
124
+ actions: [
125
+ "setFocusedIndex",
126
+ "setThumbDragOffset",
127
+ "setThumbDragStartValue",
128
+ "focusActiveThumb"
129
+ ]
130
+ }
131
+ } },
132
+ focus: {
133
+ entry: ["focusActiveThumb"],
134
+ on: {
135
+ POINTER_DOWN: {
136
+ target: "dragging",
137
+ actions: [
138
+ "setClosestThumbIndex",
139
+ "setThumbDragStartValue",
140
+ "setPointerValue",
141
+ "focusActiveThumb"
142
+ ]
143
+ },
144
+ THUMB_POINTER_DOWN: {
145
+ target: "dragging",
146
+ actions: [
147
+ "setFocusedIndex",
148
+ "setThumbDragOffset",
149
+ "setThumbDragStartValue",
150
+ "focusActiveThumb"
151
+ ]
152
+ },
153
+ ARROW_DEC: { actions: ["decrementThumbAtIndex", "invokeOnChangeEnd"] },
154
+ ARROW_INC: { actions: ["incrementThumbAtIndex", "invokeOnChangeEnd"] },
155
+ HOME: { actions: ["setFocusedThumbToMin", "invokeOnChangeEnd"] },
156
+ END: { actions: ["setFocusedThumbToMax", "invokeOnChangeEnd"] },
157
+ BLUR: {
158
+ target: "idle",
159
+ actions: ["clearFocusedIndex"]
160
+ }
161
+ }
162
+ },
163
+ dragging: {
164
+ entry: ["focusActiveThumb"],
165
+ effects: ["trackPointerMove"],
166
+ on: {
167
+ POINTER_UP: {
168
+ target: "focus",
169
+ actions: [
170
+ "invokeOnChangeEnd",
171
+ "clearThumbDragOffset",
172
+ "clearThumbDragStartValue"
173
+ ]
174
+ },
175
+ POINTER_MOVE: { actions: ["setPointerValue"] },
176
+ POINTER_CANCEL: {
177
+ target: "idle",
178
+ actions: [
179
+ "clearFocusedIndex",
180
+ "clearThumbDragOffset",
181
+ "clearThumbDragStartValue"
182
+ ]
183
+ }
184
+ }
185
+ }
186
+ },
187
+ implementations: {
188
+ guards: { hasIndex: ({ event }) => event.index != null },
189
+ effects: {
190
+ trackFormControlState({ context, scope }) {
191
+ return trackFormControl(getRootEl(scope), {
192
+ onFieldsetDisabledChange(disabled) {
193
+ context.set("fieldsetDisabled", disabled);
194
+ },
195
+ onFormReset() {
196
+ context.set("value", context.initial("value"));
197
+ }
198
+ });
199
+ },
200
+ trackPointerMove({ scope, send }) {
201
+ return trackPointerMove(scope.getDoc(), {
202
+ onPointerMove(info) {
203
+ send({
204
+ type: "POINTER_MOVE",
205
+ point: info.point
206
+ });
207
+ },
208
+ onPointerUp() {
209
+ send({ type: "POINTER_UP" });
210
+ }
211
+ });
212
+ },
213
+ trackThumbSize({ context, scope, prop }) {
214
+ if (prop("thumbAlignment") !== "contain" || prop("thumbSize")) return;
215
+ const exec = (el) => {
216
+ const rect = getOffsetRect(el);
217
+ const size = pick(rect, ["width", "height"]);
218
+ if (isEqualSize(context.get("thumbSize"), size)) return;
219
+ context.set("thumbSize", size);
220
+ };
221
+ const thumbEls = getThumbEls(scope);
222
+ thumbEls.forEach(exec);
223
+ const cleanups = thumbEls.map((el) => resizeObserverBorderBox.observe(el, () => exec(el)));
224
+ return callAll(...cleanups);
225
+ }
226
+ },
227
+ actions: {
228
+ dispatchChangeEvent({ context, scope }) {
229
+ dispatchChangeEvent(scope, context.get("value"));
230
+ },
231
+ syncInputElements({ context, scope }) {
232
+ context.get("value").forEach((value, index) => {
233
+ const inputEl = getHiddenInputEl(scope, index);
234
+ setElementValue(inputEl, value.toString());
235
+ });
236
+ },
237
+ invokeOnChangeEnd({ prop, context }) {
238
+ queueMicrotask(() => {
239
+ prop("onValueChangeEnd")?.({ value: context.get("value") });
240
+ });
241
+ },
242
+ setClosestThumbIndex(params) {
243
+ const { context, event } = params;
244
+ const pointValue = getPointValue(params, event.point);
245
+ if (pointValue == null) return;
246
+ const focusedIndex = getClosestIndex(params, pointValue);
247
+ context.set("focusedIndex", focusedIndex);
248
+ },
249
+ setFocusedIndex(params) {
250
+ const { context, event } = params;
251
+ const movableIndex = selectMovableThumb(params, event.index);
252
+ context.set("focusedIndex", movableIndex);
253
+ },
254
+ clearFocusedIndex({ context }) {
255
+ context.set("focusedIndex", -1);
256
+ },
257
+ setThumbDragOffset(params) {
258
+ const { refs, event } = params;
259
+ refs.set("thumbDragOffset", event.offset ?? null);
260
+ },
261
+ clearThumbDragOffset({ refs }) {
262
+ refs.set("thumbDragOffset", null);
263
+ },
264
+ setThumbDragStartValue({ refs, context }) {
265
+ refs.set("thumbDragStartValue", context.get("value").slice());
266
+ },
267
+ clearThumbDragStartValue({ refs }) {
268
+ refs.set("thumbDragStartValue", null);
269
+ },
270
+ setPointerValue(params) {
271
+ queueMicrotask(() => {
272
+ const { context, event, prop, refs } = params;
273
+ const pointValue = getPointValue(params, event.point);
274
+ if (pointValue == null) return;
275
+ const focusedIndex = context.get("focusedIndex");
276
+ const startValues = refs.get("thumbDragStartValue");
277
+ const result = resolveThumbCollision(prop("thumbCollisionBehavior"), focusedIndex, pointValue, context.get("value"), prop("min"), prop("max"), prop("step"), prop("minStepsBetweenThumbs"), startValues?.[focusedIndex]);
278
+ if (result.swapped) context.set("focusedIndex", result.index);
279
+ context.set("value", result.values);
280
+ });
281
+ },
282
+ focusActiveThumb({ scope, context }) {
283
+ raf(() => {
284
+ getThumbEl(scope, context.get("focusedIndex"))?.focus({ preventScroll: true });
285
+ });
286
+ },
287
+ decrementThumbAtIndex(params) {
288
+ const { context, event } = params;
289
+ const value = decrement(params, event.index, event.step);
290
+ context.set("value", value);
291
+ },
292
+ incrementThumbAtIndex(params) {
293
+ const { context, event } = params;
294
+ const value = increment(params, event.index, event.step);
295
+ context.set("value", value);
296
+ },
297
+ setFocusedThumbToMin(params) {
298
+ const { context } = params;
299
+ const index = context.get("focusedIndex");
300
+ const { min } = getRangeAtIndex(params, index);
301
+ context.set("value", (prev) => setValueAtIndex(prev, index, min));
302
+ },
303
+ setFocusedThumbToMax(params) {
304
+ const { context } = params;
305
+ const index = context.get("focusedIndex");
306
+ const { max } = getRangeAtIndex(params, index);
307
+ context.set("value", (prev) => setValueAtIndex(prev, index, max));
308
+ },
309
+ setValueAtIndex(params) {
310
+ const { context, event } = params;
311
+ const value = constrainValue(params, event.value, event.index);
312
+ context.set("value", (prev) => setValueAtIndex(prev, event.index, value));
313
+ },
314
+ setValue(params) {
315
+ const { context, event } = params;
316
+ const value = normalizeValues(params, event.value);
317
+ context.set("value", value);
318
+ }
319
+ }
320
+ }
352
321
  });
353
- export {
354
- machine
355
- };
322
+ export { machine };