@zag-js/slider 2.0.0-next.2 → 2.0.0-next.4

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,375 @@
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;
43
- };
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
- });
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 normalize = (value, min, max, step, minStepsBetweenThumbs) => {
12
+ return (0, _zag_js_utils.getValueRanges)(value, min, max, minStepsBetweenThumbs * step).map((range) => {
13
+ const snapValue = (0, _zag_js_utils.snapValueToStep)(range.value, range.min, range.max, step);
14
+ const rangeValue = (0, _zag_js_utils.clampValue)(snapValue, range.min, range.max);
15
+ 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");
16
+ return rangeValue;
17
+ });
56
18
  };
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
19
+ const machine = (0, _zag_js_core.createMachine)({
20
+ props({ props }) {
21
+ const min = props.min ?? 0;
22
+ const max = props.max ?? 100;
23
+ const step = props.step ?? 1;
24
+ const defaultValue = props.defaultValue ?? [min];
25
+ const minStepsBetweenThumbs = props.minStepsBetweenThumbs ?? 0;
26
+ return {
27
+ dir: "ltr",
28
+ thumbAlignment: "contain",
29
+ origin: "start",
30
+ orientation: "horizontal",
31
+ thumbCollisionBehavior: "none",
32
+ minStepsBetweenThumbs,
33
+ ...props,
34
+ largeStep: props.largeStep ?? 10 * step,
35
+ defaultValue: normalize(defaultValue, min, max, step, minStepsBetweenThumbs),
36
+ value: props.value ? normalize(props.value, min, max, step, minStepsBetweenThumbs) : void 0,
37
+ max,
38
+ step,
39
+ min
40
+ };
41
+ },
42
+ initialState() {
43
+ return "idle";
44
+ },
45
+ context({ prop, bindable, getContext, getEvent }) {
46
+ return {
47
+ thumbSize: bindable(() => ({ defaultValue: require_slider_utils.toThumbSize(prop("thumbSize")) })),
48
+ value: bindable(() => ({
49
+ defaultValue: prop("defaultValue"),
50
+ value: prop("value"),
51
+ isEqual: _zag_js_utils.isEqual,
52
+ hash(a) {
53
+ return a.join(",");
54
+ },
55
+ onChange(value) {
56
+ prop("onValueChange")?.({
57
+ value,
58
+ reason: getEvent().src
59
+ });
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
+ startValue: null,
79
+ pointerReason: void 0,
80
+ focusFrame: _zag_js_dom_query.AnimationFrame.create()
81
+ };
82
+ },
83
+ computed: {
84
+ isHorizontal: ({ prop }) => prop("orientation") === "horizontal",
85
+ isVertical: ({ prop }) => prop("orientation") === "vertical",
86
+ isRtl: ({ prop }) => prop("orientation") === "horizontal" && prop("dir") === "rtl",
87
+ isDisabled: ({ context, prop }) => !!prop("disabled") || context.get("fieldsetDisabled"),
88
+ isInteractive: ({ prop, computed }) => !(prop("readOnly") || computed("isDisabled")),
89
+ hasMeasuredThumbSize: ({ context }) => context.get("thumbSize") != null,
90
+ valuePercent: (0, _zag_js_core.memo)(({ context, prop }) => [
91
+ context.get("value"),
92
+ prop("min"),
93
+ prop("max")
94
+ ], ([value, min, max]) => value.map((value) => 100 * (0, _zag_js_utils.getValuePercent)(value, min, max)))
95
+ },
96
+ watch({ track, action, context, computed, send }) {
97
+ track([() => context.hash("value")], () => {
98
+ action(["syncInputElements", "dispatchChangeEvent"]);
99
+ });
100
+ track([() => computed("isDisabled")], () => {
101
+ if (computed("isDisabled")) send({ type: "POINTER_CANCEL" });
102
+ });
103
+ },
104
+ effects: ["trackFormControlState", "trackThumbSize"],
105
+ exit: ["cancelFocusFrame"],
106
+ on: {
107
+ SET_VALUE: [{
108
+ guard: "hasIndex",
109
+ actions: [
110
+ "setStartValue",
111
+ "setValueAtIndex",
112
+ "invokeOnChangeEnd"
113
+ ]
114
+ }, { actions: [
115
+ "setStartValue",
116
+ "setValue",
117
+ "invokeOnChangeEnd"
118
+ ] }],
119
+ INCREMENT: { actions: [
120
+ "setStartValue",
121
+ "incrementThumbAtIndex",
122
+ "invokeOnChangeEnd"
123
+ ] },
124
+ DECREMENT: { actions: [
125
+ "setStartValue",
126
+ "decrementThumbAtIndex",
127
+ "invokeOnChangeEnd"
128
+ ] }
129
+ },
130
+ states: {
131
+ idle: { on: {
132
+ POINTER_DOWN: {
133
+ target: "dragging",
134
+ actions: [
135
+ "setClosestThumbIndex",
136
+ "setStartValue",
137
+ "setPointerValue",
138
+ "focusActiveThumb"
139
+ ]
140
+ },
141
+ FOCUS: {
142
+ target: "focus",
143
+ actions: ["setFocusedIndex"]
144
+ },
145
+ THUMB_POINTER_DOWN: {
146
+ target: "dragging",
147
+ actions: [
148
+ "setFocusedIndex",
149
+ "setThumbDragOffset",
150
+ "setStartValue",
151
+ "focusActiveThumb"
152
+ ]
153
+ }
154
+ } },
155
+ focus: {
156
+ entry: ["focusActiveThumb"],
157
+ on: {
158
+ POINTER_DOWN: {
159
+ target: "dragging",
160
+ actions: [
161
+ "setClosestThumbIndex",
162
+ "setStartValue",
163
+ "setPointerValue",
164
+ "focusActiveThumb"
165
+ ]
166
+ },
167
+ THUMB_POINTER_DOWN: {
168
+ target: "dragging",
169
+ actions: [
170
+ "setFocusedIndex",
171
+ "setThumbDragOffset",
172
+ "setStartValue",
173
+ "focusActiveThumb"
174
+ ]
175
+ },
176
+ ARROW_DEC: { actions: [
177
+ "setStartValue",
178
+ "decrementThumbAtIndex",
179
+ "invokeOnChangeEnd"
180
+ ] },
181
+ ARROW_INC: { actions: [
182
+ "setStartValue",
183
+ "incrementThumbAtIndex",
184
+ "invokeOnChangeEnd"
185
+ ] },
186
+ HOME: { actions: [
187
+ "setStartValue",
188
+ "setFocusedThumbToMin",
189
+ "invokeOnChangeEnd"
190
+ ] },
191
+ END: { actions: [
192
+ "setStartValue",
193
+ "setFocusedThumbToMax",
194
+ "invokeOnChangeEnd"
195
+ ] },
196
+ BLUR: {
197
+ target: "idle",
198
+ actions: ["clearFocusedIndex"]
199
+ }
200
+ }
201
+ },
202
+ dragging: {
203
+ entry: ["focusActiveThumb"],
204
+ effects: ["trackPointerMove"],
205
+ on: {
206
+ POINTER_UP: {
207
+ target: "focus",
208
+ actions: ["invokeOnChangeEnd", "clearDragState"]
209
+ },
210
+ POINTER_MOVE: { actions: ["setPointerValue"] },
211
+ POINTER_CANCEL: {
212
+ target: "idle",
213
+ actions: ["clearFocusedIndex", "clearDragState"]
214
+ }
215
+ }
216
+ }
217
+ },
218
+ implementations: {
219
+ guards: { hasIndex: ({ event }) => event.index != null },
220
+ effects: {
221
+ trackFormControlState({ context, scope }) {
222
+ return (0, _zag_js_dom_query.trackFormControl)(require_slider_dom.getRootEl(scope), {
223
+ onFieldsetDisabledChange(disabled) {
224
+ context.set("fieldsetDisabled", disabled);
225
+ },
226
+ onFormReset() {
227
+ context.set("value", context.initial("value"));
228
+ }
229
+ });
230
+ },
231
+ trackPointerMove({ scope, send }) {
232
+ return (0, _zag_js_dom_query.trackPointerMove)(scope.getDoc(), {
233
+ onPointerMove(info) {
234
+ send({
235
+ type: "POINTER_MOVE",
236
+ point: info.point,
237
+ src: "drag"
238
+ });
239
+ },
240
+ onPointerUp() {
241
+ send({ type: "POINTER_UP" });
242
+ }
243
+ });
244
+ },
245
+ trackThumbSize({ context, scope, prop }) {
246
+ if (prop("thumbAlignment") !== "contain" || prop("thumbSize")) return;
247
+ const exec = (el) => {
248
+ const size = {
249
+ width: el.offsetWidth,
250
+ height: el.offsetHeight
251
+ };
252
+ if ((0, _zag_js_utils.isEqual)(context.get("thumbSize"), size)) return;
253
+ context.set("thumbSize", size);
254
+ };
255
+ const thumbEls = require_slider_dom.getThumbEls(scope);
256
+ thumbEls.forEach(exec);
257
+ const cleanups = thumbEls.map((el) => _zag_js_dom_query.resizeObserverBorderBox.observe(el, () => exec(el)));
258
+ return (0, _zag_js_utils.callAll)(...cleanups);
259
+ }
260
+ },
261
+ actions: {
262
+ dispatchChangeEvent({ context, scope }) {
263
+ require_slider_dom.dispatchChangeEvent(scope, context.get("value"));
264
+ },
265
+ syncInputElements({ context, scope }) {
266
+ context.get("value").forEach((value, index) => {
267
+ const inputEl = require_slider_dom.getHiddenInputEl(scope, index);
268
+ (0, _zag_js_dom_query.setElementValue)(inputEl, value.toString());
269
+ });
270
+ },
271
+ invokeOnChangeEnd({ prop, context, refs, event }) {
272
+ const startValue = refs.get("startValue");
273
+ const reason = event.type === "POINTER_UP" ? refs.get("pointerReason") : event.src;
274
+ queueMicrotask(() => {
275
+ const value = context.get("value");
276
+ if (startValue && (0, _zag_js_utils.isEqual)(startValue, value)) return;
277
+ prop("onValueChangeEnd")?.({
278
+ value,
279
+ reason
280
+ });
281
+ });
282
+ },
283
+ setStartValue({ refs, context }) {
284
+ refs.set("startValue", context.get("value").slice());
285
+ },
286
+ clearDragState({ refs }) {
287
+ refs.set("thumbDragOffset", null);
288
+ refs.set("pointerReason", void 0);
289
+ },
290
+ setClosestThumbIndex(params) {
291
+ const { context, event } = params;
292
+ const pointValue = require_slider_dom.getPointValue(params, event.point);
293
+ if (pointValue == null) return;
294
+ const focusedIndex = require_slider_utils.getClosestIndex(params, pointValue, require_slider_dom.getDisabledThumbIndices(params.scope));
295
+ context.set("focusedIndex", focusedIndex);
296
+ },
297
+ setFocusedIndex(params) {
298
+ const { context, event } = params;
299
+ const movableIndex = require_slider_utils.selectMovableThumb(params, event.index, require_slider_dom.getDisabledThumbIndices(params.scope));
300
+ context.set("focusedIndex", movableIndex);
301
+ },
302
+ clearFocusedIndex({ context }) {
303
+ context.set("focusedIndex", -1);
304
+ },
305
+ setThumbDragOffset(params) {
306
+ const { refs, event } = params;
307
+ refs.set("thumbDragOffset", event.offset ?? null);
308
+ },
309
+ setPointerValue(params) {
310
+ queueMicrotask(() => {
311
+ const { context, event, prop, refs, scope } = params;
312
+ const pointValue = require_slider_dom.getPointValue(params, event.point);
313
+ if (pointValue == null) return;
314
+ let focusedIndex = context.get("focusedIndex");
315
+ if (focusedIndex < 0) return;
316
+ const startValues = refs.get("startValue");
317
+ const disabledIndices = require_slider_dom.getDisabledThumbIndices(scope);
318
+ refs.set("pointerReason", event.src);
319
+ let stackedIndex;
320
+ if (prop("thumbCollisionBehavior") === "none") {
321
+ const index = require_slider_utils.resolveStackedThumb(context.get("value"), focusedIndex, pointValue, disabledIndices);
322
+ if (index !== focusedIndex) {
323
+ focusedIndex = index;
324
+ stackedIndex = index;
325
+ context.set("focusedIndex", index);
326
+ }
327
+ }
328
+ const result = require_slider_utils.resolveThumbCollision(prop("thumbCollisionBehavior"), focusedIndex, pointValue, context.get("value"), prop("min"), prop("max"), prop("step"), prop("minStepsBetweenThumbs"), startValues?.[focusedIndex], disabledIndices);
329
+ if (result.swapped) context.set("focusedIndex", result.index);
330
+ context.set("value", result.values);
331
+ if (stackedIndex != null) require_slider_dom.getThumbEl(scope, stackedIndex)?.focus({ preventScroll: true });
332
+ });
333
+ },
334
+ focusActiveThumb({ scope, context, refs }) {
335
+ refs.get("focusFrame").request(() => {
336
+ require_slider_dom.getThumbEl(scope, context.get("focusedIndex"))?.focus({ preventScroll: true });
337
+ });
338
+ },
339
+ cancelFocusFrame({ refs }) {
340
+ refs.get("focusFrame").cancel();
341
+ },
342
+ decrementThumbAtIndex(params) {
343
+ const { context, event, prop } = params;
344
+ context.set("value", require_slider_utils.stepThumb(params, -(event.step ?? prop("step")), event.index));
345
+ },
346
+ incrementThumbAtIndex(params) {
347
+ const { context, event, prop } = params;
348
+ context.set("value", require_slider_utils.stepThumb(params, event.step ?? prop("step"), event.index));
349
+ },
350
+ setFocusedThumbToMin(params) {
351
+ const { context } = params;
352
+ const index = context.get("focusedIndex");
353
+ const { min } = require_slider_utils.getRangeAtIndex(params, index);
354
+ context.set("value", (prev) => (0, _zag_js_utils.setValueAtIndex)(prev, index, min));
355
+ },
356
+ setFocusedThumbToMax(params) {
357
+ const { context } = params;
358
+ const index = context.get("focusedIndex");
359
+ const { max } = require_slider_utils.getRangeAtIndex(params, index);
360
+ context.set("value", (prev) => (0, _zag_js_utils.setValueAtIndex)(prev, index, max));
361
+ },
362
+ setValueAtIndex(params) {
363
+ const { context, event } = params;
364
+ const value = require_slider_utils.constrainValue(params, event.value, event.index);
365
+ context.set("value", (prev) => (0, _zag_js_utils.setValueAtIndex)(prev, event.index, value));
366
+ },
367
+ setValue(params) {
368
+ const { context, event } = params;
369
+ const value = require_slider_utils.normalizeValues(params, event.value);
370
+ context.set("value", value);
371
+ }
372
+ }
373
+ }
371
374
  });
375
+ exports.machine = machine;