@zag-js/slider 0.10.4 → 0.11.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.
- package/dist/index.d.mts +275 -0
- package/dist/index.d.ts +275 -5
- package/dist/index.js +675 -10
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +657 -4
- package/dist/index.mjs.map +1 -0
- package/package.json +11 -11
- package/dist/slider.anatomy.d.ts +0 -3
- package/dist/slider.anatomy.js +0 -22
- package/dist/slider.anatomy.mjs +0 -17
- package/dist/slider.connect.d.ts +0 -56
- package/dist/slider.connect.js +0 -255
- package/dist/slider.connect.mjs +0 -251
- package/dist/slider.dom.d.ts +0 -47
- package/dist/slider.dom.js +0 -43
- package/dist/slider.dom.mjs +0 -39
- package/dist/slider.machine.d.ts +0 -3
- package/dist/slider.machine.js +0 -207
- package/dist/slider.machine.mjs +0 -203
- package/dist/slider.style.d.ts +0 -23
- package/dist/slider.style.js +0 -117
- package/dist/slider.style.mjs +0 -113
- package/dist/slider.types.d.ts +0 -165
- package/dist/slider.utils.d.ts +0 -5
- package/dist/slider.utils.js +0 -32
- package/dist/slider.utils.mjs +0 -26
package/dist/index.js
CHANGED
|
@@ -1,15 +1,680 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
2
19
|
|
|
3
|
-
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
anatomy: () => anatomy,
|
|
24
|
+
connect: () => connect,
|
|
25
|
+
machine: () => machine,
|
|
26
|
+
unstable__dom: () => dom
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(src_exports);
|
|
4
29
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
30
|
+
// src/slider.anatomy.ts
|
|
31
|
+
var import_anatomy = require("@zag-js/anatomy");
|
|
32
|
+
var anatomy = (0, import_anatomy.createAnatomy)("slider").parts(
|
|
33
|
+
"root",
|
|
34
|
+
"label",
|
|
35
|
+
"thumb",
|
|
36
|
+
"hiddenInput",
|
|
37
|
+
"output",
|
|
38
|
+
"track",
|
|
39
|
+
"range",
|
|
40
|
+
"control",
|
|
41
|
+
"markerGroup",
|
|
42
|
+
"marker"
|
|
43
|
+
);
|
|
44
|
+
var parts = anatomy.build();
|
|
9
45
|
|
|
46
|
+
// src/slider.connect.ts
|
|
47
|
+
var import_dom_event2 = require("@zag-js/dom-event");
|
|
48
|
+
var import_dom_query2 = require("@zag-js/dom-query");
|
|
49
|
+
var import_numeric_range3 = require("@zag-js/numeric-range");
|
|
10
50
|
|
|
51
|
+
// src/slider.dom.ts
|
|
52
|
+
var import_dom_event = require("@zag-js/dom-event");
|
|
53
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
54
|
+
var import_form_utils = require("@zag-js/form-utils");
|
|
55
|
+
var import_numeric_range2 = require("@zag-js/numeric-range");
|
|
11
56
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
57
|
+
// src/slider.style.ts
|
|
58
|
+
var import_numeric_range = require("@zag-js/numeric-range");
|
|
59
|
+
function getVerticalThumbOffset(ctx) {
|
|
60
|
+
const { height = 0 } = ctx.thumbSize ?? {};
|
|
61
|
+
const getValue = (0, import_numeric_range.getValueTransformer)([ctx.min, ctx.max], [-height / 2, height / 2]);
|
|
62
|
+
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
63
|
+
}
|
|
64
|
+
function getHorizontalThumbOffset(ctx) {
|
|
65
|
+
const { width = 0 } = ctx.thumbSize ?? {};
|
|
66
|
+
if (ctx.isRtl) {
|
|
67
|
+
const getValue2 = (0, import_numeric_range.getValueTransformer)([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
|
|
68
|
+
return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
|
|
69
|
+
}
|
|
70
|
+
const getValue = (0, import_numeric_range.getValueTransformer)([ctx.min, ctx.max], [-width / 2, width / 2]);
|
|
71
|
+
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
72
|
+
}
|
|
73
|
+
function getThumbOffset(ctx) {
|
|
74
|
+
const percent = (0, import_numeric_range.getValuePercent)(ctx.value, ctx.min, ctx.max) * 100;
|
|
75
|
+
if (ctx.thumbAlignment === "center") {
|
|
76
|
+
return `${percent}%`;
|
|
77
|
+
}
|
|
78
|
+
const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
|
|
79
|
+
return `calc(${percent}% - ${offset}px)`;
|
|
80
|
+
}
|
|
81
|
+
function getVisibility(ctx) {
|
|
82
|
+
let visibility = "visible";
|
|
83
|
+
if (ctx.thumbAlignment === "contain" && !ctx.hasMeasuredThumbSize) {
|
|
84
|
+
visibility = "hidden";
|
|
85
|
+
}
|
|
86
|
+
return visibility;
|
|
87
|
+
}
|
|
88
|
+
function getThumbStyle(ctx) {
|
|
89
|
+
const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
|
|
90
|
+
return {
|
|
91
|
+
visibility: getVisibility(ctx),
|
|
92
|
+
position: "absolute",
|
|
93
|
+
transform: "var(--slider-thumb-transform)",
|
|
94
|
+
[placementProp]: "var(--slider-thumb-offset)"
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function getRangeOffsets(ctx) {
|
|
98
|
+
let start = "0%";
|
|
99
|
+
let end = `${100 - ctx.valuePercent}%`;
|
|
100
|
+
if (ctx.origin === "center") {
|
|
101
|
+
const isNegative = ctx.valuePercent < 50;
|
|
102
|
+
start = isNegative ? `${ctx.valuePercent}%` : "50%";
|
|
103
|
+
end = isNegative ? "50%" : end;
|
|
104
|
+
}
|
|
105
|
+
return { start, end };
|
|
106
|
+
}
|
|
107
|
+
function getRangeStyle(ctx) {
|
|
108
|
+
if (ctx.isVertical) {
|
|
109
|
+
return {
|
|
110
|
+
position: "absolute",
|
|
111
|
+
bottom: "var(--slider-range-start)",
|
|
112
|
+
top: "var(--slider-range-end)"
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
position: "absolute",
|
|
117
|
+
[ctx.isRtl ? "right" : "left"]: "var(--slider-range-start)",
|
|
118
|
+
[ctx.isRtl ? "left" : "right"]: "var(--slider-range-end)"
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function getControlStyle() {
|
|
122
|
+
return {
|
|
123
|
+
touchAction: "none",
|
|
124
|
+
userSelect: "none",
|
|
125
|
+
position: "relative"
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function getRootStyle(ctx) {
|
|
129
|
+
const range = getRangeOffsets(ctx);
|
|
130
|
+
return {
|
|
131
|
+
"--slider-thumb-transform": ctx.isVertical ? "translateY(50%)" : "translateX(-50%)",
|
|
132
|
+
"--slider-thumb-offset": getThumbOffset(ctx),
|
|
133
|
+
"--slider-range-start": range.start,
|
|
134
|
+
"--slider-range-end": range.end
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function getMarkerStyle(ctx, percent) {
|
|
138
|
+
return {
|
|
139
|
+
position: "absolute",
|
|
140
|
+
pointerEvents: "none",
|
|
141
|
+
[ctx.isHorizontal ? "left" : "bottom"]: `${(ctx.isRtl ? 1 - percent : percent) * 100}%`
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function getLabelStyle() {
|
|
145
|
+
return { userSelect: "none" };
|
|
146
|
+
}
|
|
147
|
+
function getTrackStyle() {
|
|
148
|
+
return { position: "relative" };
|
|
149
|
+
}
|
|
150
|
+
function getMarkerGroupStyle() {
|
|
151
|
+
return {
|
|
152
|
+
userSelect: "none",
|
|
153
|
+
pointerEvents: "none",
|
|
154
|
+
position: "relative"
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
var styles = {
|
|
158
|
+
getThumbOffset,
|
|
159
|
+
getControlStyle,
|
|
160
|
+
getThumbStyle,
|
|
161
|
+
getRangeStyle,
|
|
162
|
+
getRootStyle,
|
|
163
|
+
getMarkerStyle,
|
|
164
|
+
getLabelStyle,
|
|
165
|
+
getTrackStyle,
|
|
166
|
+
getMarkerGroupStyle
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// src/slider.dom.ts
|
|
170
|
+
var dom = (0, import_dom_query.createScope)({
|
|
171
|
+
...styles,
|
|
172
|
+
getRootId: (ctx) => ctx.ids?.root ?? `slider:${ctx.id}`,
|
|
173
|
+
getThumbId: (ctx) => ctx.ids?.thumb ?? `slider:${ctx.id}:thumb`,
|
|
174
|
+
getControlId: (ctx) => ctx.ids?.control ?? `slider:${ctx.id}:control`,
|
|
175
|
+
getHiddenInputId: (ctx) => ctx.ids?.hiddenInput ?? `slider:${ctx.id}:input`,
|
|
176
|
+
getOutputId: (ctx) => ctx.ids?.output ?? `slider:${ctx.id}:output`,
|
|
177
|
+
getTrackId: (ctx) => ctx.ids?.track ?? `slider:${ctx.id}track`,
|
|
178
|
+
getRangeId: (ctx) => ctx.ids?.track ?? `slider:${ctx.id}:range`,
|
|
179
|
+
getLabelId: (ctx) => ctx.ids?.label ?? `slider:${ctx.id}:label`,
|
|
180
|
+
getMarkerId: (ctx, value) => `slider:${ctx.id}:marker:${value}`,
|
|
181
|
+
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
182
|
+
getThumbEl: (ctx) => dom.getById(ctx, dom.getThumbId(ctx)),
|
|
183
|
+
getControlEl: (ctx) => dom.queryById(ctx, dom.getControlId(ctx)),
|
|
184
|
+
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx)),
|
|
185
|
+
getValueFromPoint(ctx, point) {
|
|
186
|
+
const relativePoint = (0, import_dom_event.getRelativePoint)(point, dom.getControlEl(ctx));
|
|
187
|
+
const percent = relativePoint.getPercentValue({
|
|
188
|
+
orientation: ctx.orientation,
|
|
189
|
+
dir: ctx.dir,
|
|
190
|
+
inverted: { y: true }
|
|
191
|
+
});
|
|
192
|
+
return (0, import_numeric_range2.getPercentValue)(percent, ctx.min, ctx.max, ctx.step);
|
|
193
|
+
},
|
|
194
|
+
dispatchChangeEvent(ctx) {
|
|
195
|
+
const input = dom.getHiddenInputEl(ctx);
|
|
196
|
+
if (!input)
|
|
197
|
+
return;
|
|
198
|
+
(0, import_form_utils.dispatchInputValueEvent)(input, { value: ctx.value });
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// src/slider.connect.ts
|
|
203
|
+
function connect(state, send, normalize) {
|
|
204
|
+
const ariaLabel = state.context["aria-label"];
|
|
205
|
+
const ariaLabelledBy = state.context["aria-labelledby"];
|
|
206
|
+
const ariaValueText = state.context.getAriaValueText?.(state.context.value);
|
|
207
|
+
const isFocused = state.matches("focus");
|
|
208
|
+
const isDragging = state.matches("dragging");
|
|
209
|
+
const isDisabled = state.context.disabled;
|
|
210
|
+
const isInteractive = state.context.isInteractive;
|
|
211
|
+
const isInvalid = state.context.invalid;
|
|
212
|
+
function getPercentValueFn(percent) {
|
|
213
|
+
return (0, import_numeric_range3.getPercentValue)(percent, state.context.min, state.context.max, state.context.step);
|
|
214
|
+
}
|
|
215
|
+
function getValuePercentFn(value) {
|
|
216
|
+
return (0, import_numeric_range3.getValuePercent)(value, state.context.min, state.context.max);
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
/**
|
|
220
|
+
* Whether the slider is focused.
|
|
221
|
+
*/
|
|
222
|
+
isFocused,
|
|
223
|
+
/**
|
|
224
|
+
* Whether the slider is being dragged.
|
|
225
|
+
*/
|
|
226
|
+
isDragging,
|
|
227
|
+
/**
|
|
228
|
+
* The value of the slider.
|
|
229
|
+
*/
|
|
230
|
+
value: state.context.value,
|
|
231
|
+
/**
|
|
232
|
+
* The value of the slider as a percent.
|
|
233
|
+
*/
|
|
234
|
+
percent: (0, import_numeric_range3.getValuePercent)(state.context.value, state.context.min, state.context.max),
|
|
235
|
+
/**
|
|
236
|
+
* Function to set the value of the slider.
|
|
237
|
+
*/
|
|
238
|
+
setValue(value) {
|
|
239
|
+
send({ type: "SET_VALUE", value });
|
|
240
|
+
},
|
|
241
|
+
/**
|
|
242
|
+
* Returns the value of the slider at the given percent.
|
|
243
|
+
*/
|
|
244
|
+
getPercentValue: getPercentValueFn,
|
|
245
|
+
/**
|
|
246
|
+
* Returns the percent of the slider at the given value.
|
|
247
|
+
*/
|
|
248
|
+
getValuePercent: getValuePercentFn,
|
|
249
|
+
/**
|
|
250
|
+
* Function to focus the slider.
|
|
251
|
+
*/
|
|
252
|
+
focus() {
|
|
253
|
+
dom.getThumbEl(state.context)?.focus();
|
|
254
|
+
},
|
|
255
|
+
/**
|
|
256
|
+
* Function to increment the value of the slider by the step.
|
|
257
|
+
*/
|
|
258
|
+
increment() {
|
|
259
|
+
send("INCREMENT");
|
|
260
|
+
},
|
|
261
|
+
/**
|
|
262
|
+
* Function to decrement the value of the slider by the step.
|
|
263
|
+
*/
|
|
264
|
+
decrement() {
|
|
265
|
+
send("DECREMENT");
|
|
266
|
+
},
|
|
267
|
+
rootProps: normalize.element({
|
|
268
|
+
...parts.root.attrs,
|
|
269
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
270
|
+
"data-focus": (0, import_dom_query2.dataAttr)(isFocused),
|
|
271
|
+
"data-orientation": state.context.orientation,
|
|
272
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
273
|
+
id: dom.getRootId(state.context),
|
|
274
|
+
dir: state.context.dir,
|
|
275
|
+
style: dom.getRootStyle(state.context)
|
|
276
|
+
}),
|
|
277
|
+
labelProps: normalize.label({
|
|
278
|
+
...parts.label.attrs,
|
|
279
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
280
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
281
|
+
"data-focus": (0, import_dom_query2.dataAttr)(isFocused),
|
|
282
|
+
id: dom.getLabelId(state.context),
|
|
283
|
+
htmlFor: dom.getHiddenInputId(state.context),
|
|
284
|
+
onClick(event) {
|
|
285
|
+
if (!isInteractive)
|
|
286
|
+
return;
|
|
287
|
+
event.preventDefault();
|
|
288
|
+
dom.getThumbEl(state.context)?.focus();
|
|
289
|
+
},
|
|
290
|
+
style: dom.getLabelStyle()
|
|
291
|
+
}),
|
|
292
|
+
thumbProps: normalize.element({
|
|
293
|
+
...parts.thumb.attrs,
|
|
294
|
+
id: dom.getThumbId(state.context),
|
|
295
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
296
|
+
"data-orientation": state.context.orientation,
|
|
297
|
+
"data-focus": (0, import_dom_query2.dataAttr)(isFocused),
|
|
298
|
+
draggable: false,
|
|
299
|
+
"aria-invalid": (0, import_dom_query2.ariaAttr)(isInvalid),
|
|
300
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
301
|
+
"aria-disabled": (0, import_dom_query2.ariaAttr)(isDisabled),
|
|
302
|
+
"aria-label": ariaLabel,
|
|
303
|
+
"aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy ?? dom.getLabelId(state.context),
|
|
304
|
+
"aria-orientation": state.context.orientation,
|
|
305
|
+
"aria-valuemax": state.context.max,
|
|
306
|
+
"aria-valuemin": state.context.min,
|
|
307
|
+
"aria-valuenow": state.context.value,
|
|
308
|
+
"aria-valuetext": ariaValueText,
|
|
309
|
+
role: "slider",
|
|
310
|
+
tabIndex: isDisabled ? void 0 : 0,
|
|
311
|
+
onBlur() {
|
|
312
|
+
if (!isInteractive)
|
|
313
|
+
return;
|
|
314
|
+
send("BLUR");
|
|
315
|
+
},
|
|
316
|
+
onFocus() {
|
|
317
|
+
if (!isInteractive)
|
|
318
|
+
return;
|
|
319
|
+
send("FOCUS");
|
|
320
|
+
},
|
|
321
|
+
onKeyDown(event) {
|
|
322
|
+
if (!isInteractive)
|
|
323
|
+
return;
|
|
324
|
+
const step = (0, import_dom_event2.getEventStep)(event) * state.context.step;
|
|
325
|
+
let prevent = true;
|
|
326
|
+
const keyMap = {
|
|
327
|
+
ArrowUp() {
|
|
328
|
+
send({ type: "ARROW_UP", step });
|
|
329
|
+
prevent = state.context.isVertical;
|
|
330
|
+
},
|
|
331
|
+
ArrowDown() {
|
|
332
|
+
send({ type: "ARROW_DOWN", step });
|
|
333
|
+
prevent = state.context.isVertical;
|
|
334
|
+
},
|
|
335
|
+
ArrowLeft() {
|
|
336
|
+
send({ type: "ARROW_LEFT", step });
|
|
337
|
+
prevent = state.context.isHorizontal;
|
|
338
|
+
},
|
|
339
|
+
ArrowRight() {
|
|
340
|
+
send({ type: "ARROW_RIGHT", step });
|
|
341
|
+
prevent = state.context.isHorizontal;
|
|
342
|
+
},
|
|
343
|
+
PageUp() {
|
|
344
|
+
send({ type: "PAGE_UP", step });
|
|
345
|
+
},
|
|
346
|
+
PageDown() {
|
|
347
|
+
send({ type: "PAGE_DOWN", step });
|
|
348
|
+
},
|
|
349
|
+
Home() {
|
|
350
|
+
send("HOME");
|
|
351
|
+
},
|
|
352
|
+
End() {
|
|
353
|
+
send("END");
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
const key = (0, import_dom_event2.getEventKey)(event, state.context);
|
|
357
|
+
const exec = keyMap[key];
|
|
358
|
+
if (!exec)
|
|
359
|
+
return;
|
|
360
|
+
exec(event);
|
|
361
|
+
if (prevent) {
|
|
362
|
+
event.preventDefault();
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
style: dom.getThumbStyle(state.context)
|
|
366
|
+
}),
|
|
367
|
+
hiddenInputProps: normalize.input({
|
|
368
|
+
...parts.hiddenInput.attrs,
|
|
369
|
+
type: "text",
|
|
370
|
+
defaultValue: state.context.value,
|
|
371
|
+
name: state.context.name,
|
|
372
|
+
form: state.context.form,
|
|
373
|
+
id: dom.getHiddenInputId(state.context),
|
|
374
|
+
hidden: true
|
|
375
|
+
}),
|
|
376
|
+
outputProps: normalize.output({
|
|
377
|
+
...parts.output.attrs,
|
|
378
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
379
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
380
|
+
id: dom.getOutputId(state.context),
|
|
381
|
+
htmlFor: dom.getHiddenInputId(state.context),
|
|
382
|
+
"aria-live": "off"
|
|
383
|
+
}),
|
|
384
|
+
trackProps: normalize.element({
|
|
385
|
+
...parts.track.attrs,
|
|
386
|
+
id: dom.getTrackId(state.context),
|
|
387
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
388
|
+
"data-focus": (0, import_dom_query2.dataAttr)(isFocused),
|
|
389
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
390
|
+
"data-orientation": state.context.orientation,
|
|
391
|
+
style: dom.getTrackStyle()
|
|
392
|
+
}),
|
|
393
|
+
rangeProps: normalize.element({
|
|
394
|
+
...parts.range.attrs,
|
|
395
|
+
id: dom.getRangeId(state.context),
|
|
396
|
+
"data-focus": (0, import_dom_query2.dataAttr)(isFocused),
|
|
397
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
398
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
399
|
+
"data-orientation": state.context.orientation,
|
|
400
|
+
style: dom.getRangeStyle(state.context)
|
|
401
|
+
}),
|
|
402
|
+
controlProps: normalize.element({
|
|
403
|
+
...parts.control.attrs,
|
|
404
|
+
id: dom.getControlId(state.context),
|
|
405
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
406
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
407
|
+
"data-orientation": state.context.orientation,
|
|
408
|
+
"data-focus": (0, import_dom_query2.dataAttr)(isFocused),
|
|
409
|
+
onPointerDown(event) {
|
|
410
|
+
if (!isInteractive)
|
|
411
|
+
return;
|
|
412
|
+
const evt = (0, import_dom_event2.getNativeEvent)(event);
|
|
413
|
+
if (!(0, import_dom_event2.isLeftClick)(evt) || (0, import_dom_event2.isModifiedEvent)(evt))
|
|
414
|
+
return;
|
|
415
|
+
const point = (0, import_dom_event2.getEventPoint)(evt);
|
|
416
|
+
send({ type: "POINTER_DOWN", point });
|
|
417
|
+
event.preventDefault();
|
|
418
|
+
event.stopPropagation();
|
|
419
|
+
},
|
|
420
|
+
style: dom.getControlStyle()
|
|
421
|
+
}),
|
|
422
|
+
markerGroupProps: normalize.element({
|
|
423
|
+
...parts.markerGroup.attrs,
|
|
424
|
+
role: "presentation",
|
|
425
|
+
"aria-hidden": true,
|
|
426
|
+
"data-orientation": state.context.orientation,
|
|
427
|
+
style: dom.getMarkerGroupStyle()
|
|
428
|
+
}),
|
|
429
|
+
getMarkerProps({ value }) {
|
|
430
|
+
const percent = getValuePercentFn(value);
|
|
431
|
+
const style = dom.getMarkerStyle(state.context, percent);
|
|
432
|
+
const markerState = value > state.context.value ? "over-value" : value < state.context.value ? "under-value" : "at-value";
|
|
433
|
+
return normalize.element({
|
|
434
|
+
...parts.marker.attrs,
|
|
435
|
+
id: dom.getMarkerId(state.context, value),
|
|
436
|
+
role: "presentation",
|
|
437
|
+
"data-orientation": state.context.orientation,
|
|
438
|
+
"data-value": value,
|
|
439
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
440
|
+
"data-state": markerState,
|
|
441
|
+
style
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// src/slider.machine.ts
|
|
448
|
+
var import_core = require("@zag-js/core");
|
|
449
|
+
var import_dom_event3 = require("@zag-js/dom-event");
|
|
450
|
+
var import_dom_query3 = require("@zag-js/dom-query");
|
|
451
|
+
var import_element_size = require("@zag-js/element-size");
|
|
452
|
+
var import_form_utils2 = require("@zag-js/form-utils");
|
|
453
|
+
var import_numeric_range5 = require("@zag-js/numeric-range");
|
|
454
|
+
var import_utils = require("@zag-js/utils");
|
|
455
|
+
|
|
456
|
+
// src/slider.utils.ts
|
|
457
|
+
var import_numeric_range4 = require("@zag-js/numeric-range");
|
|
458
|
+
function constrainValue(ctx, value) {
|
|
459
|
+
const snapValue = (0, import_numeric_range4.snapValueToStep)(value, ctx.min, ctx.max, ctx.step);
|
|
460
|
+
return (0, import_numeric_range4.clampValue)(snapValue, ctx.min, ctx.max);
|
|
461
|
+
}
|
|
462
|
+
function decrement(ctx, step) {
|
|
463
|
+
const index = 0;
|
|
464
|
+
const values = (0, import_numeric_range4.getPreviousStepValue)(index, {
|
|
465
|
+
...ctx,
|
|
466
|
+
step: step ?? ctx.step,
|
|
467
|
+
values: [ctx.value]
|
|
468
|
+
});
|
|
469
|
+
return values[index];
|
|
470
|
+
}
|
|
471
|
+
function increment(ctx, step) {
|
|
472
|
+
const index = 0;
|
|
473
|
+
const values = (0, import_numeric_range4.getNextStepValue)(index, {
|
|
474
|
+
...ctx,
|
|
475
|
+
step: step ?? ctx.step,
|
|
476
|
+
values: [ctx.value]
|
|
477
|
+
});
|
|
478
|
+
return values[index];
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// src/slider.machine.ts
|
|
482
|
+
function machine(userContext) {
|
|
483
|
+
const ctx = (0, import_utils.compact)(userContext);
|
|
484
|
+
return (0, import_core.createMachine)(
|
|
485
|
+
{
|
|
486
|
+
id: "slider",
|
|
487
|
+
initial: "idle",
|
|
488
|
+
context: {
|
|
489
|
+
thumbSize: null,
|
|
490
|
+
thumbAlignment: "contain",
|
|
491
|
+
disabled: false,
|
|
492
|
+
threshold: 5,
|
|
493
|
+
dir: "ltr",
|
|
494
|
+
origin: "start",
|
|
495
|
+
orientation: "horizontal",
|
|
496
|
+
initialValue: null,
|
|
497
|
+
value: 0,
|
|
498
|
+
step: 1,
|
|
499
|
+
min: 0,
|
|
500
|
+
max: 100,
|
|
501
|
+
...ctx
|
|
502
|
+
},
|
|
503
|
+
computed: {
|
|
504
|
+
isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
|
|
505
|
+
isVertical: (ctx2) => ctx2.orientation === "vertical",
|
|
506
|
+
isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
|
|
507
|
+
isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readOnly),
|
|
508
|
+
hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null,
|
|
509
|
+
valuePercent: (ctx2) => 100 * (0, import_numeric_range5.getValuePercent)(ctx2.value, ctx2.min, ctx2.max)
|
|
510
|
+
},
|
|
511
|
+
watch: {
|
|
512
|
+
value: ["invokeOnChange", "dispatchChangeEvent"]
|
|
513
|
+
},
|
|
514
|
+
activities: ["trackFormControlState", "trackThumbSize"],
|
|
515
|
+
on: {
|
|
516
|
+
SET_VALUE: {
|
|
517
|
+
actions: "setValue"
|
|
518
|
+
},
|
|
519
|
+
INCREMENT: {
|
|
520
|
+
actions: "increment"
|
|
521
|
+
},
|
|
522
|
+
DECREMENT: {
|
|
523
|
+
actions: "decrement"
|
|
524
|
+
}
|
|
525
|
+
},
|
|
526
|
+
entry: ["checkValue"],
|
|
527
|
+
states: {
|
|
528
|
+
idle: {
|
|
529
|
+
on: {
|
|
530
|
+
POINTER_DOWN: {
|
|
531
|
+
target: "dragging",
|
|
532
|
+
actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
|
|
533
|
+
},
|
|
534
|
+
FOCUS: "focus"
|
|
535
|
+
}
|
|
536
|
+
},
|
|
537
|
+
focus: {
|
|
538
|
+
entry: "focusThumb",
|
|
539
|
+
on: {
|
|
540
|
+
POINTER_DOWN: {
|
|
541
|
+
target: "dragging",
|
|
542
|
+
actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
|
|
543
|
+
},
|
|
544
|
+
ARROW_LEFT: {
|
|
545
|
+
guard: "isHorizontal",
|
|
546
|
+
actions: "decrement"
|
|
547
|
+
},
|
|
548
|
+
ARROW_RIGHT: {
|
|
549
|
+
guard: "isHorizontal",
|
|
550
|
+
actions: "increment"
|
|
551
|
+
},
|
|
552
|
+
ARROW_UP: {
|
|
553
|
+
guard: "isVertical",
|
|
554
|
+
actions: "increment"
|
|
555
|
+
},
|
|
556
|
+
ARROW_DOWN: {
|
|
557
|
+
guard: "isVertical",
|
|
558
|
+
actions: "decrement"
|
|
559
|
+
},
|
|
560
|
+
PAGE_UP: {
|
|
561
|
+
actions: "increment"
|
|
562
|
+
},
|
|
563
|
+
PAGE_DOWN: {
|
|
564
|
+
actions: "decrement"
|
|
565
|
+
},
|
|
566
|
+
HOME: {
|
|
567
|
+
actions: "setToMin"
|
|
568
|
+
},
|
|
569
|
+
END: {
|
|
570
|
+
actions: "setToMax"
|
|
571
|
+
},
|
|
572
|
+
BLUR: "idle"
|
|
573
|
+
}
|
|
574
|
+
},
|
|
575
|
+
dragging: {
|
|
576
|
+
entry: "focusThumb",
|
|
577
|
+
activities: "trackPointerMove",
|
|
578
|
+
on: {
|
|
579
|
+
POINTER_UP: {
|
|
580
|
+
target: "focus",
|
|
581
|
+
actions: "invokeOnChangeEnd"
|
|
582
|
+
},
|
|
583
|
+
POINTER_MOVE: {
|
|
584
|
+
actions: "setPointerValue"
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
},
|
|
590
|
+
{
|
|
591
|
+
guards: {
|
|
592
|
+
isHorizontal: (ctx2) => ctx2.isHorizontal,
|
|
593
|
+
isVertical: (ctx2) => ctx2.isVertical
|
|
594
|
+
},
|
|
595
|
+
activities: {
|
|
596
|
+
trackFormControlState(ctx2) {
|
|
597
|
+
return (0, import_form_utils2.trackFormControl)(dom.getHiddenInputEl(ctx2), {
|
|
598
|
+
onFieldsetDisabled() {
|
|
599
|
+
ctx2.disabled = true;
|
|
600
|
+
},
|
|
601
|
+
onFormReset() {
|
|
602
|
+
if (ctx2.initialValue != null) {
|
|
603
|
+
ctx2.value = ctx2.initialValue;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
},
|
|
608
|
+
trackPointerMove(ctx2, _evt, { send }) {
|
|
609
|
+
return (0, import_dom_event3.trackPointerMove)(dom.getDoc(ctx2), {
|
|
610
|
+
onPointerMove(info) {
|
|
611
|
+
send({ type: "POINTER_MOVE", point: info.point });
|
|
612
|
+
},
|
|
613
|
+
onPointerUp() {
|
|
614
|
+
send("POINTER_UP");
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
},
|
|
618
|
+
trackThumbSize(ctx2, _evt) {
|
|
619
|
+
if (ctx2.thumbAlignment !== "contain")
|
|
620
|
+
return;
|
|
621
|
+
return (0, import_element_size.trackElementSize)(dom.getThumbEl(ctx2), (size) => {
|
|
622
|
+
if (size)
|
|
623
|
+
ctx2.thumbSize = size;
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
},
|
|
627
|
+
actions: {
|
|
628
|
+
checkValue(ctx2) {
|
|
629
|
+
const value = constrainValue(ctx2, ctx2.value);
|
|
630
|
+
ctx2.value = value;
|
|
631
|
+
ctx2.initialValue = value;
|
|
632
|
+
},
|
|
633
|
+
invokeOnChangeStart(ctx2) {
|
|
634
|
+
ctx2.onChangeStart?.({ value: ctx2.value });
|
|
635
|
+
},
|
|
636
|
+
invokeOnChangeEnd(ctx2) {
|
|
637
|
+
ctx2.onChangeEnd?.({ value: ctx2.value });
|
|
638
|
+
},
|
|
639
|
+
invokeOnChange(ctx2) {
|
|
640
|
+
ctx2.onChange?.({ value: ctx2.value });
|
|
641
|
+
},
|
|
642
|
+
dispatchChangeEvent(ctx2) {
|
|
643
|
+
dom.dispatchChangeEvent(ctx2);
|
|
644
|
+
},
|
|
645
|
+
setPointerValue(ctx2, evt) {
|
|
646
|
+
const value = dom.getValueFromPoint(ctx2, evt.point);
|
|
647
|
+
if (value == null)
|
|
648
|
+
return;
|
|
649
|
+
ctx2.value = (0, import_numeric_range5.clampValue)(value, ctx2.min, ctx2.max);
|
|
650
|
+
},
|
|
651
|
+
focusThumb(ctx2) {
|
|
652
|
+
(0, import_dom_query3.raf)(() => dom.getThumbEl(ctx2)?.focus());
|
|
653
|
+
},
|
|
654
|
+
decrement(ctx2, evt) {
|
|
655
|
+
ctx2.value = decrement(ctx2, evt.step);
|
|
656
|
+
},
|
|
657
|
+
increment(ctx2, evt) {
|
|
658
|
+
ctx2.value = increment(ctx2, evt.step);
|
|
659
|
+
},
|
|
660
|
+
setToMin(ctx2) {
|
|
661
|
+
ctx2.value = ctx2.min;
|
|
662
|
+
},
|
|
663
|
+
setToMax(ctx2) {
|
|
664
|
+
ctx2.value = ctx2.max;
|
|
665
|
+
},
|
|
666
|
+
setValue(ctx2, evt) {
|
|
667
|
+
ctx2.value = constrainValue(ctx2, evt.value);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
);
|
|
672
|
+
}
|
|
673
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
674
|
+
0 && (module.exports = {
|
|
675
|
+
anatomy,
|
|
676
|
+
connect,
|
|
677
|
+
machine,
|
|
678
|
+
unstable__dom
|
|
679
|
+
});
|
|
680
|
+
//# sourceMappingURL=index.js.map
|