@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/slider.machine.js
CHANGED
|
@@ -1,216 +1,20 @@
|
|
|
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 slider_machine_exports = {};
|
|
22
|
-
__export(slider_machine_exports, {
|
|
23
|
-
machine: () => machine
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(slider_machine_exports);
|
|
26
|
-
var import_core = require("@zag-js/core");
|
|
27
|
-
var import_dom_event2 = require("@zag-js/dom-event");
|
|
28
|
-
var import_dom_query2 = require("@zag-js/dom-query");
|
|
29
|
-
var import_element_size = require("@zag-js/element-size");
|
|
30
|
-
var import_form_utils2 = require("@zag-js/form-utils");
|
|
31
|
-
var import_numeric_range4 = require("@zag-js/numeric-range");
|
|
32
|
-
var import_utils = require("@zag-js/utils");
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
33
4
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
5
|
+
const core = require('@zag-js/core');
|
|
6
|
+
const domEvent = require('@zag-js/dom-event');
|
|
7
|
+
const domQuery = require('@zag-js/dom-query');
|
|
8
|
+
const elementSize = require('@zag-js/element-size');
|
|
9
|
+
const formUtils = require('@zag-js/form-utils');
|
|
10
|
+
const numericRange = require('@zag-js/numeric-range');
|
|
11
|
+
const utils = require('@zag-js/utils');
|
|
12
|
+
const slider_dom = require('./slider.dom.js');
|
|
13
|
+
const slider_utils = require('./slider.utils.js');
|
|
39
14
|
|
|
40
|
-
// src/slider.style.ts
|
|
41
|
-
var import_numeric_range = require("@zag-js/numeric-range");
|
|
42
|
-
function getVerticalThumbOffset(ctx) {
|
|
43
|
-
const { height = 0 } = ctx.thumbSize ?? {};
|
|
44
|
-
const getValue = (0, import_numeric_range.getValueTransformer)([ctx.min, ctx.max], [-height / 2, height / 2]);
|
|
45
|
-
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
46
|
-
}
|
|
47
|
-
function getHorizontalThumbOffset(ctx) {
|
|
48
|
-
const { width = 0 } = ctx.thumbSize ?? {};
|
|
49
|
-
if (ctx.isRtl) {
|
|
50
|
-
const getValue2 = (0, import_numeric_range.getValueTransformer)([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
|
|
51
|
-
return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
|
|
52
|
-
}
|
|
53
|
-
const getValue = (0, import_numeric_range.getValueTransformer)([ctx.min, ctx.max], [-width / 2, width / 2]);
|
|
54
|
-
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
55
|
-
}
|
|
56
|
-
function getThumbOffset(ctx) {
|
|
57
|
-
const percent = (0, import_numeric_range.getValuePercent)(ctx.value, ctx.min, ctx.max) * 100;
|
|
58
|
-
if (ctx.thumbAlignment === "center") {
|
|
59
|
-
return `${percent}%`;
|
|
60
|
-
}
|
|
61
|
-
const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
|
|
62
|
-
return `calc(${percent}% - ${offset}px)`;
|
|
63
|
-
}
|
|
64
|
-
function getVisibility(ctx) {
|
|
65
|
-
let visibility = "visible";
|
|
66
|
-
if (ctx.thumbAlignment === "contain" && !ctx.hasMeasuredThumbSize) {
|
|
67
|
-
visibility = "hidden";
|
|
68
|
-
}
|
|
69
|
-
return visibility;
|
|
70
|
-
}
|
|
71
|
-
function getThumbStyle(ctx) {
|
|
72
|
-
const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
|
|
73
|
-
return {
|
|
74
|
-
visibility: getVisibility(ctx),
|
|
75
|
-
position: "absolute",
|
|
76
|
-
transform: "var(--slider-thumb-transform)",
|
|
77
|
-
[placementProp]: "var(--slider-thumb-offset)"
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
function getRangeOffsets(ctx) {
|
|
81
|
-
let start = "0%";
|
|
82
|
-
let end = `${100 - ctx.valuePercent}%`;
|
|
83
|
-
if (ctx.origin === "center") {
|
|
84
|
-
const isNegative = ctx.valuePercent < 50;
|
|
85
|
-
start = isNegative ? `${ctx.valuePercent}%` : "50%";
|
|
86
|
-
end = isNegative ? "50%" : end;
|
|
87
|
-
}
|
|
88
|
-
return { start, end };
|
|
89
|
-
}
|
|
90
|
-
function getRangeStyle(ctx) {
|
|
91
|
-
if (ctx.isVertical) {
|
|
92
|
-
return {
|
|
93
|
-
position: "absolute",
|
|
94
|
-
bottom: "var(--slider-range-start)",
|
|
95
|
-
top: "var(--slider-range-end)"
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
return {
|
|
99
|
-
position: "absolute",
|
|
100
|
-
[ctx.isRtl ? "right" : "left"]: "var(--slider-range-start)",
|
|
101
|
-
[ctx.isRtl ? "left" : "right"]: "var(--slider-range-end)"
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
function getControlStyle() {
|
|
105
|
-
return {
|
|
106
|
-
touchAction: "none",
|
|
107
|
-
userSelect: "none",
|
|
108
|
-
position: "relative"
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
function getRootStyle(ctx) {
|
|
112
|
-
const range = getRangeOffsets(ctx);
|
|
113
|
-
return {
|
|
114
|
-
"--slider-thumb-transform": ctx.isVertical ? "translateY(50%)" : "translateX(-50%)",
|
|
115
|
-
"--slider-thumb-offset": getThumbOffset(ctx),
|
|
116
|
-
"--slider-range-start": range.start,
|
|
117
|
-
"--slider-range-end": range.end
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
function getMarkerStyle(ctx, percent) {
|
|
121
|
-
return {
|
|
122
|
-
position: "absolute",
|
|
123
|
-
pointerEvents: "none",
|
|
124
|
-
[ctx.isHorizontal ? "left" : "bottom"]: `${(ctx.isRtl ? 1 - percent : percent) * 100}%`
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
function getLabelStyle() {
|
|
128
|
-
return { userSelect: "none" };
|
|
129
|
-
}
|
|
130
|
-
function getTrackStyle() {
|
|
131
|
-
return { position: "relative" };
|
|
132
|
-
}
|
|
133
|
-
function getMarkerGroupStyle() {
|
|
134
|
-
return {
|
|
135
|
-
userSelect: "none",
|
|
136
|
-
pointerEvents: "none",
|
|
137
|
-
position: "relative"
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
var styles = {
|
|
141
|
-
getThumbOffset,
|
|
142
|
-
getControlStyle,
|
|
143
|
-
getThumbStyle,
|
|
144
|
-
getRangeStyle,
|
|
145
|
-
getRootStyle,
|
|
146
|
-
getMarkerStyle,
|
|
147
|
-
getLabelStyle,
|
|
148
|
-
getTrackStyle,
|
|
149
|
-
getMarkerGroupStyle
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
// src/slider.dom.ts
|
|
153
|
-
var dom = (0, import_dom_query.createScope)({
|
|
154
|
-
...styles,
|
|
155
|
-
getRootId: (ctx) => ctx.ids?.root ?? `slider:${ctx.id}`,
|
|
156
|
-
getThumbId: (ctx) => ctx.ids?.thumb ?? `slider:${ctx.id}:thumb`,
|
|
157
|
-
getControlId: (ctx) => ctx.ids?.control ?? `slider:${ctx.id}:control`,
|
|
158
|
-
getHiddenInputId: (ctx) => ctx.ids?.hiddenInput ?? `slider:${ctx.id}:input`,
|
|
159
|
-
getOutputId: (ctx) => ctx.ids?.output ?? `slider:${ctx.id}:output`,
|
|
160
|
-
getTrackId: (ctx) => ctx.ids?.track ?? `slider:${ctx.id}track`,
|
|
161
|
-
getRangeId: (ctx) => ctx.ids?.track ?? `slider:${ctx.id}:range`,
|
|
162
|
-
getLabelId: (ctx) => ctx.ids?.label ?? `slider:${ctx.id}:label`,
|
|
163
|
-
getMarkerId: (ctx, value) => `slider:${ctx.id}:marker:${value}`,
|
|
164
|
-
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
165
|
-
getThumbEl: (ctx) => dom.getById(ctx, dom.getThumbId(ctx)),
|
|
166
|
-
getControlEl: (ctx) => dom.queryById(ctx, dom.getControlId(ctx)),
|
|
167
|
-
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx)),
|
|
168
|
-
getValueFromPoint(ctx, point) {
|
|
169
|
-
const relativePoint = (0, import_dom_event.getRelativePoint)(point, dom.getControlEl(ctx));
|
|
170
|
-
const percent = relativePoint.getPercentValue({
|
|
171
|
-
orientation: ctx.orientation,
|
|
172
|
-
dir: ctx.dir,
|
|
173
|
-
inverted: { y: true }
|
|
174
|
-
});
|
|
175
|
-
return (0, import_numeric_range2.getPercentValue)(percent, ctx.min, ctx.max, ctx.step);
|
|
176
|
-
},
|
|
177
|
-
dispatchChangeEvent(ctx) {
|
|
178
|
-
const input = dom.getHiddenInputEl(ctx);
|
|
179
|
-
if (!input)
|
|
180
|
-
return;
|
|
181
|
-
(0, import_form_utils.dispatchInputValueEvent)(input, { value: ctx.value });
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
// src/slider.utils.ts
|
|
186
|
-
var import_numeric_range3 = require("@zag-js/numeric-range");
|
|
187
|
-
function constrainValue(ctx, value) {
|
|
188
|
-
const snapValue = (0, import_numeric_range3.snapValueToStep)(value, ctx.min, ctx.max, ctx.step);
|
|
189
|
-
return (0, import_numeric_range3.clampValue)(snapValue, ctx.min, ctx.max);
|
|
190
|
-
}
|
|
191
|
-
function decrement(ctx, step) {
|
|
192
|
-
const index = 0;
|
|
193
|
-
const values = (0, import_numeric_range3.getPreviousStepValue)(index, {
|
|
194
|
-
...ctx,
|
|
195
|
-
step: step ?? ctx.step,
|
|
196
|
-
values: [ctx.value]
|
|
197
|
-
});
|
|
198
|
-
return values[index];
|
|
199
|
-
}
|
|
200
|
-
function increment(ctx, step) {
|
|
201
|
-
const index = 0;
|
|
202
|
-
const values = (0, import_numeric_range3.getNextStepValue)(index, {
|
|
203
|
-
...ctx,
|
|
204
|
-
step: step ?? ctx.step,
|
|
205
|
-
values: [ctx.value]
|
|
206
|
-
});
|
|
207
|
-
return values[index];
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// src/slider.machine.ts
|
|
211
15
|
function machine(userContext) {
|
|
212
|
-
const ctx =
|
|
213
|
-
return
|
|
16
|
+
const ctx = utils.compact(userContext);
|
|
17
|
+
return core.createMachine(
|
|
214
18
|
{
|
|
215
19
|
id: "slider",
|
|
216
20
|
initial: "idle",
|
|
@@ -235,7 +39,7 @@ function machine(userContext) {
|
|
|
235
39
|
isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
|
|
236
40
|
isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readOnly),
|
|
237
41
|
hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null,
|
|
238
|
-
valuePercent: (ctx2) => 100 *
|
|
42
|
+
valuePercent: (ctx2) => 100 * numericRange.getValuePercent(ctx2.value, ctx2.min, ctx2.max)
|
|
239
43
|
},
|
|
240
44
|
watch: {
|
|
241
45
|
value: ["invokeOnChange", "dispatchChangeEvent"]
|
|
@@ -323,7 +127,7 @@ function machine(userContext) {
|
|
|
323
127
|
},
|
|
324
128
|
activities: {
|
|
325
129
|
trackFormControlState(ctx2) {
|
|
326
|
-
return
|
|
130
|
+
return formUtils.trackFormControl(slider_dom.dom.getHiddenInputEl(ctx2), {
|
|
327
131
|
onFieldsetDisabled() {
|
|
328
132
|
ctx2.disabled = true;
|
|
329
133
|
},
|
|
@@ -335,7 +139,7 @@ function machine(userContext) {
|
|
|
335
139
|
});
|
|
336
140
|
},
|
|
337
141
|
trackPointerMove(ctx2, _evt, { send }) {
|
|
338
|
-
return
|
|
142
|
+
return domEvent.trackPointerMove(slider_dom.dom.getDoc(ctx2), {
|
|
339
143
|
onPointerMove(info) {
|
|
340
144
|
send({ type: "POINTER_MOVE", point: info.point });
|
|
341
145
|
},
|
|
@@ -347,7 +151,7 @@ function machine(userContext) {
|
|
|
347
151
|
trackThumbSize(ctx2, _evt) {
|
|
348
152
|
if (ctx2.thumbAlignment !== "contain")
|
|
349
153
|
return;
|
|
350
|
-
return
|
|
154
|
+
return elementSize.trackElementSize(slider_dom.dom.getThumbEl(ctx2), (size) => {
|
|
351
155
|
if (size)
|
|
352
156
|
ctx2.thumbSize = size;
|
|
353
157
|
});
|
|
@@ -355,7 +159,7 @@ function machine(userContext) {
|
|
|
355
159
|
},
|
|
356
160
|
actions: {
|
|
357
161
|
checkValue(ctx2) {
|
|
358
|
-
const value = constrainValue(ctx2, ctx2.value);
|
|
162
|
+
const value = slider_utils.constrainValue(ctx2, ctx2.value);
|
|
359
163
|
ctx2.value = value;
|
|
360
164
|
ctx2.initialValue = value;
|
|
361
165
|
},
|
|
@@ -369,22 +173,22 @@ function machine(userContext) {
|
|
|
369
173
|
ctx2.onChange?.({ value: ctx2.value });
|
|
370
174
|
},
|
|
371
175
|
dispatchChangeEvent(ctx2) {
|
|
372
|
-
dom.dispatchChangeEvent(ctx2);
|
|
176
|
+
slider_dom.dom.dispatchChangeEvent(ctx2);
|
|
373
177
|
},
|
|
374
178
|
setPointerValue(ctx2, evt) {
|
|
375
|
-
const value = dom.getValueFromPoint(ctx2, evt.point);
|
|
179
|
+
const value = slider_dom.dom.getValueFromPoint(ctx2, evt.point);
|
|
376
180
|
if (value == null)
|
|
377
181
|
return;
|
|
378
|
-
ctx2.value =
|
|
182
|
+
ctx2.value = numericRange.clampValue(value, ctx2.min, ctx2.max);
|
|
379
183
|
},
|
|
380
184
|
focusThumb(ctx2) {
|
|
381
|
-
|
|
185
|
+
domQuery.raf(() => slider_dom.dom.getThumbEl(ctx2)?.focus());
|
|
382
186
|
},
|
|
383
187
|
decrement(ctx2, evt) {
|
|
384
|
-
ctx2.value = decrement(ctx2, evt.step);
|
|
188
|
+
ctx2.value = slider_utils.decrement(ctx2, evt.step);
|
|
385
189
|
},
|
|
386
190
|
increment(ctx2, evt) {
|
|
387
|
-
ctx2.value = increment(ctx2, evt.step);
|
|
191
|
+
ctx2.value = slider_utils.increment(ctx2, evt.step);
|
|
388
192
|
},
|
|
389
193
|
setToMin(ctx2) {
|
|
390
194
|
ctx2.value = ctx2.min;
|
|
@@ -393,13 +197,11 @@ function machine(userContext) {
|
|
|
393
197
|
ctx2.value = ctx2.max;
|
|
394
198
|
},
|
|
395
199
|
setValue(ctx2, evt) {
|
|
396
|
-
ctx2.value = constrainValue(ctx2, evt.value);
|
|
200
|
+
ctx2.value = slider_utils.constrainValue(ctx2, evt.value);
|
|
397
201
|
}
|
|
398
202
|
}
|
|
399
203
|
}
|
|
400
204
|
);
|
|
401
205
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
machine
|
|
405
|
-
});
|
|
206
|
+
|
|
207
|
+
exports.machine = machine;
|
package/dist/slider.machine.mjs
CHANGED
|
@@ -1,9 +1,203 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
1
|
+
import { createMachine } from '@zag-js/core';
|
|
2
|
+
import { trackPointerMove } from '@zag-js/dom-event';
|
|
3
|
+
import { raf } from '@zag-js/dom-query';
|
|
4
|
+
import { trackElementSize } from '@zag-js/element-size';
|
|
5
|
+
import { trackFormControl } from '@zag-js/form-utils';
|
|
6
|
+
import { getValuePercent, clampValue } from '@zag-js/numeric-range';
|
|
7
|
+
import { compact } from '@zag-js/utils';
|
|
8
|
+
import { dom } from './slider.dom.mjs';
|
|
9
|
+
import { constrainValue, decrement, increment } from './slider.utils.mjs';
|
|
10
|
+
|
|
11
|
+
function machine(userContext) {
|
|
12
|
+
const ctx = compact(userContext);
|
|
13
|
+
return createMachine(
|
|
14
|
+
{
|
|
15
|
+
id: "slider",
|
|
16
|
+
initial: "idle",
|
|
17
|
+
context: {
|
|
18
|
+
thumbSize: null,
|
|
19
|
+
thumbAlignment: "contain",
|
|
20
|
+
disabled: false,
|
|
21
|
+
threshold: 5,
|
|
22
|
+
dir: "ltr",
|
|
23
|
+
origin: "start",
|
|
24
|
+
orientation: "horizontal",
|
|
25
|
+
initialValue: null,
|
|
26
|
+
value: 0,
|
|
27
|
+
step: 1,
|
|
28
|
+
min: 0,
|
|
29
|
+
max: 100,
|
|
30
|
+
...ctx
|
|
31
|
+
},
|
|
32
|
+
computed: {
|
|
33
|
+
isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
|
|
34
|
+
isVertical: (ctx2) => ctx2.orientation === "vertical",
|
|
35
|
+
isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
|
|
36
|
+
isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readOnly),
|
|
37
|
+
hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null,
|
|
38
|
+
valuePercent: (ctx2) => 100 * getValuePercent(ctx2.value, ctx2.min, ctx2.max)
|
|
39
|
+
},
|
|
40
|
+
watch: {
|
|
41
|
+
value: ["invokeOnChange", "dispatchChangeEvent"]
|
|
42
|
+
},
|
|
43
|
+
activities: ["trackFormControlState", "trackThumbSize"],
|
|
44
|
+
on: {
|
|
45
|
+
SET_VALUE: {
|
|
46
|
+
actions: "setValue"
|
|
47
|
+
},
|
|
48
|
+
INCREMENT: {
|
|
49
|
+
actions: "increment"
|
|
50
|
+
},
|
|
51
|
+
DECREMENT: {
|
|
52
|
+
actions: "decrement"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
entry: ["checkValue"],
|
|
56
|
+
states: {
|
|
57
|
+
idle: {
|
|
58
|
+
on: {
|
|
59
|
+
POINTER_DOWN: {
|
|
60
|
+
target: "dragging",
|
|
61
|
+
actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
|
|
62
|
+
},
|
|
63
|
+
FOCUS: "focus"
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
focus: {
|
|
67
|
+
entry: "focusThumb",
|
|
68
|
+
on: {
|
|
69
|
+
POINTER_DOWN: {
|
|
70
|
+
target: "dragging",
|
|
71
|
+
actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
|
|
72
|
+
},
|
|
73
|
+
ARROW_LEFT: {
|
|
74
|
+
guard: "isHorizontal",
|
|
75
|
+
actions: "decrement"
|
|
76
|
+
},
|
|
77
|
+
ARROW_RIGHT: {
|
|
78
|
+
guard: "isHorizontal",
|
|
79
|
+
actions: "increment"
|
|
80
|
+
},
|
|
81
|
+
ARROW_UP: {
|
|
82
|
+
guard: "isVertical",
|
|
83
|
+
actions: "increment"
|
|
84
|
+
},
|
|
85
|
+
ARROW_DOWN: {
|
|
86
|
+
guard: "isVertical",
|
|
87
|
+
actions: "decrement"
|
|
88
|
+
},
|
|
89
|
+
PAGE_UP: {
|
|
90
|
+
actions: "increment"
|
|
91
|
+
},
|
|
92
|
+
PAGE_DOWN: {
|
|
93
|
+
actions: "decrement"
|
|
94
|
+
},
|
|
95
|
+
HOME: {
|
|
96
|
+
actions: "setToMin"
|
|
97
|
+
},
|
|
98
|
+
END: {
|
|
99
|
+
actions: "setToMax"
|
|
100
|
+
},
|
|
101
|
+
BLUR: "idle"
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
dragging: {
|
|
105
|
+
entry: "focusThumb",
|
|
106
|
+
activities: "trackPointerMove",
|
|
107
|
+
on: {
|
|
108
|
+
POINTER_UP: {
|
|
109
|
+
target: "focus",
|
|
110
|
+
actions: "invokeOnChangeEnd"
|
|
111
|
+
},
|
|
112
|
+
POINTER_MOVE: {
|
|
113
|
+
actions: "setPointerValue"
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
guards: {
|
|
121
|
+
isHorizontal: (ctx2) => ctx2.isHorizontal,
|
|
122
|
+
isVertical: (ctx2) => ctx2.isVertical
|
|
123
|
+
},
|
|
124
|
+
activities: {
|
|
125
|
+
trackFormControlState(ctx2) {
|
|
126
|
+
return trackFormControl(dom.getHiddenInputEl(ctx2), {
|
|
127
|
+
onFieldsetDisabled() {
|
|
128
|
+
ctx2.disabled = true;
|
|
129
|
+
},
|
|
130
|
+
onFormReset() {
|
|
131
|
+
if (ctx2.initialValue != null) {
|
|
132
|
+
ctx2.value = ctx2.initialValue;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
trackPointerMove(ctx2, _evt, { send }) {
|
|
138
|
+
return trackPointerMove(dom.getDoc(ctx2), {
|
|
139
|
+
onPointerMove(info) {
|
|
140
|
+
send({ type: "POINTER_MOVE", point: info.point });
|
|
141
|
+
},
|
|
142
|
+
onPointerUp() {
|
|
143
|
+
send("POINTER_UP");
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
trackThumbSize(ctx2, _evt) {
|
|
148
|
+
if (ctx2.thumbAlignment !== "contain")
|
|
149
|
+
return;
|
|
150
|
+
return trackElementSize(dom.getThumbEl(ctx2), (size) => {
|
|
151
|
+
if (size)
|
|
152
|
+
ctx2.thumbSize = size;
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
actions: {
|
|
157
|
+
checkValue(ctx2) {
|
|
158
|
+
const value = constrainValue(ctx2, ctx2.value);
|
|
159
|
+
ctx2.value = value;
|
|
160
|
+
ctx2.initialValue = value;
|
|
161
|
+
},
|
|
162
|
+
invokeOnChangeStart(ctx2) {
|
|
163
|
+
ctx2.onChangeStart?.({ value: ctx2.value });
|
|
164
|
+
},
|
|
165
|
+
invokeOnChangeEnd(ctx2) {
|
|
166
|
+
ctx2.onChangeEnd?.({ value: ctx2.value });
|
|
167
|
+
},
|
|
168
|
+
invokeOnChange(ctx2) {
|
|
169
|
+
ctx2.onChange?.({ value: ctx2.value });
|
|
170
|
+
},
|
|
171
|
+
dispatchChangeEvent(ctx2) {
|
|
172
|
+
dom.dispatchChangeEvent(ctx2);
|
|
173
|
+
},
|
|
174
|
+
setPointerValue(ctx2, evt) {
|
|
175
|
+
const value = dom.getValueFromPoint(ctx2, evt.point);
|
|
176
|
+
if (value == null)
|
|
177
|
+
return;
|
|
178
|
+
ctx2.value = clampValue(value, ctx2.min, ctx2.max);
|
|
179
|
+
},
|
|
180
|
+
focusThumb(ctx2) {
|
|
181
|
+
raf(() => dom.getThumbEl(ctx2)?.focus());
|
|
182
|
+
},
|
|
183
|
+
decrement(ctx2, evt) {
|
|
184
|
+
ctx2.value = decrement(ctx2, evt.step);
|
|
185
|
+
},
|
|
186
|
+
increment(ctx2, evt) {
|
|
187
|
+
ctx2.value = increment(ctx2, evt.step);
|
|
188
|
+
},
|
|
189
|
+
setToMin(ctx2) {
|
|
190
|
+
ctx2.value = ctx2.min;
|
|
191
|
+
},
|
|
192
|
+
setToMax(ctx2) {
|
|
193
|
+
ctx2.value = ctx2.max;
|
|
194
|
+
},
|
|
195
|
+
setValue(ctx2, evt) {
|
|
196
|
+
ctx2.value = constrainValue(ctx2, evt.value);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export { machine };
|
package/dist/slider.style.d.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import { Style } from
|
|
2
|
-
import {
|
|
3
|
-
import '@zag-js/core';
|
|
4
|
-
|
|
1
|
+
import type { Style } from "@zag-js/types";
|
|
2
|
+
import type { MachineContext as Ctx, SharedContext } from "./slider.types";
|
|
5
3
|
declare function getThumbOffset(ctx: SharedContext): string;
|
|
6
4
|
declare function getThumbStyle(ctx: SharedContext): Style;
|
|
7
5
|
declare function getRangeStyle(ctx: Pick<SharedContext, "isVertical" | "isRtl">): Style;
|
|
8
6
|
declare function getControlStyle(): Style;
|
|
9
|
-
declare function getRootStyle(ctx:
|
|
7
|
+
declare function getRootStyle(ctx: Ctx): Style;
|
|
10
8
|
declare function getMarkerStyle(ctx: Pick<SharedContext, "isHorizontal" | "isRtl">, percent: number): Style;
|
|
11
9
|
declare function getLabelStyle(): Style;
|
|
12
10
|
declare function getTrackStyle(): Style;
|
|
13
11
|
declare function getMarkerGroupStyle(): Style;
|
|
14
|
-
declare const styles: {
|
|
12
|
+
export declare const styles: {
|
|
15
13
|
getThumbOffset: typeof getThumbOffset;
|
|
16
14
|
getControlStyle: typeof getControlStyle;
|
|
17
15
|
getThumbStyle: typeof getThumbStyle;
|
|
@@ -22,5 +20,4 @@ declare const styles: {
|
|
|
22
20
|
getTrackStyle: typeof getTrackStyle;
|
|
23
21
|
getMarkerGroupStyle: typeof getMarkerGroupStyle;
|
|
24
22
|
};
|
|
25
|
-
|
|
26
|
-
export { styles };
|
|
23
|
+
export {};
|
package/dist/slider.style.js
CHANGED
|
@@ -1,45 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const numericRange = require('@zag-js/numeric-range');
|
|
19
6
|
|
|
20
|
-
// src/slider.style.ts
|
|
21
|
-
var slider_style_exports = {};
|
|
22
|
-
__export(slider_style_exports, {
|
|
23
|
-
styles: () => styles
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(slider_style_exports);
|
|
26
|
-
var import_numeric_range = require("@zag-js/numeric-range");
|
|
27
7
|
function getVerticalThumbOffset(ctx) {
|
|
28
8
|
const { height = 0 } = ctx.thumbSize ?? {};
|
|
29
|
-
const getValue =
|
|
9
|
+
const getValue = numericRange.getValueTransformer([ctx.min, ctx.max], [-height / 2, height / 2]);
|
|
30
10
|
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
31
11
|
}
|
|
32
12
|
function getHorizontalThumbOffset(ctx) {
|
|
33
13
|
const { width = 0 } = ctx.thumbSize ?? {};
|
|
34
14
|
if (ctx.isRtl) {
|
|
35
|
-
const getValue2 =
|
|
15
|
+
const getValue2 = numericRange.getValueTransformer([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
|
|
36
16
|
return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
|
|
37
17
|
}
|
|
38
|
-
const getValue =
|
|
18
|
+
const getValue = numericRange.getValueTransformer([ctx.min, ctx.max], [-width / 2, width / 2]);
|
|
39
19
|
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
40
20
|
}
|
|
41
21
|
function getThumbOffset(ctx) {
|
|
42
|
-
const percent =
|
|
22
|
+
const percent = numericRange.getValuePercent(ctx.value, ctx.min, ctx.max) * 100;
|
|
43
23
|
if (ctx.thumbAlignment === "center") {
|
|
44
24
|
return `${percent}%`;
|
|
45
25
|
}
|
|
@@ -122,7 +102,7 @@ function getMarkerGroupStyle() {
|
|
|
122
102
|
position: "relative"
|
|
123
103
|
};
|
|
124
104
|
}
|
|
125
|
-
|
|
105
|
+
const styles = {
|
|
126
106
|
getThumbOffset,
|
|
127
107
|
getControlStyle,
|
|
128
108
|
getThumbStyle,
|
|
@@ -133,7 +113,5 @@ var styles = {
|
|
|
133
113
|
getTrackStyle,
|
|
134
114
|
getMarkerGroupStyle
|
|
135
115
|
};
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
styles
|
|
139
|
-
});
|
|
116
|
+
|
|
117
|
+
exports.styles = styles;
|