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