@zag-js/slider 0.10.2 → 0.10.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.
- package/dist/index.d.ts +5 -8
- package/dist/index.js +10 -674
- package/dist/index.mjs +4 -20
- package/dist/slider.anatomy.d.ts +3 -6
- package/dist/slider.anatomy.js +10 -33
- package/dist/slider.anatomy.mjs +17 -8
- package/dist/slider.connect.d.ts +3 -7
- package/dist/slider.connect.js +72 -261
- package/dist/slider.connect.mjs +251 -9
- package/dist/slider.dom.d.ts +26 -30
- package/dist/slider.dom.js +14 -149
- package/dist/slider.dom.mjs +39 -7
- package/dist/slider.machine.d.ts +3 -7
- package/dist/slider.machine.js +27 -225
- package/dist/slider.machine.mjs +203 -9
- package/dist/slider.style.d.ts +5 -8
- package/dist/slider.style.js +12 -34
- package/dist/slider.style.mjs +112 -5
- package/dist/slider.types.d.ts +10 -12
- package/dist/slider.utils.d.ts +5 -10
- package/dist/slider.utils.js +13 -42
- package/dist/slider.utils.mjs +26 -12
- package/package.json +11 -16
- package/dist/chunk-3Y7IIPR5.mjs +0 -20
- package/dist/chunk-IJAAAKZQ.mjs +0 -115
- package/dist/chunk-NYN3VIY4.mjs +0 -44
- package/dist/chunk-OCT2YBMN.mjs +0 -212
- package/dist/chunk-T6GXNUP7.mjs +0 -265
- package/dist/chunk-YGFSMEUO.mjs +0 -34
- package/dist/slider.types.js +0 -18
- package/dist/slider.types.mjs +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
export { anatomy } from
|
|
2
|
-
export { connect } from
|
|
3
|
-
export { dom as unstable__dom } from
|
|
4
|
-
export { machine } from
|
|
5
|
-
export { UserDefinedContext as Context } from
|
|
6
|
-
import '@zag-js/anatomy';
|
|
7
|
-
import '@zag-js/types';
|
|
8
|
-
import '@zag-js/core';
|
|
1
|
+
export { anatomy } from "./slider.anatomy";
|
|
2
|
+
export { connect } from "./slider.connect";
|
|
3
|
+
export { dom as unstable__dom } from "./slider.dom";
|
|
4
|
+
export { machine } from "./slider.machine";
|
|
5
|
+
export type { UserDefinedContext as Context } from "./slider.types";
|
package/dist/index.js
CHANGED
|
@@ -1,679 +1,15 @@
|
|
|
1
|
-
|
|
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);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
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);
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
29
4
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"label",
|
|
35
|
-
"thumb",
|
|
36
|
-
"hiddenInput",
|
|
37
|
-
"output",
|
|
38
|
-
"track",
|
|
39
|
-
"range",
|
|
40
|
-
"control",
|
|
41
|
-
"markerGroup",
|
|
42
|
-
"marker"
|
|
43
|
-
);
|
|
44
|
-
var parts = anatomy.build();
|
|
5
|
+
const slider_anatomy = require('./slider.anatomy.js');
|
|
6
|
+
const slider_connect = require('./slider.connect.js');
|
|
7
|
+
const slider_dom = require('./slider.dom.js');
|
|
8
|
+
const slider_machine = require('./slider.machine.js');
|
|
45
9
|
|
|
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");
|
|
50
10
|
|
|
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");
|
|
56
11
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
});
|
|
12
|
+
exports.anatomy = slider_anatomy.anatomy;
|
|
13
|
+
exports.connect = slider_connect.connect;
|
|
14
|
+
exports.unstable__dom = slider_dom.dom;
|
|
15
|
+
exports.machine = slider_machine.machine;
|