@zag-js/slider 0.2.6 → 0.2.8
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/chunk-3Y7IIPR5.mjs +20 -0
- package/dist/chunk-6D4ETNPG.mjs +288 -0
- package/dist/chunk-A2ZK6G4F.mjs +475 -0
- package/dist/chunk-DRAPR6JV.mjs +34 -0
- package/dist/chunk-J5IGGBVE.mjs +159 -0
- package/dist/chunk-SGCWELVB.mjs +44 -0
- package/dist/chunk-YREEXXZP.mjs +117 -0
- package/dist/index.d.ts +8 -1085
- package/dist/index.js +123 -150
- package/dist/index.mjs +15 -1090
- package/dist/slider.anatomy.d.ts +6 -0
- package/dist/slider.anatomy.js +45 -0
- package/dist/slider.anatomy.mjs +8 -0
- package/dist/slider.connect.d.ts +30 -0
- package/dist/slider.connect.js +601 -0
- package/dist/slider.connect.mjs +10 -0
- package/dist/slider.dom.d.ts +48 -0
- package/dist/slider.dom.js +297 -0
- package/dist/slider.dom.mjs +7 -0
- package/dist/slider.machine.d.ts +7 -0
- package/dist/slider.machine.js +800 -0
- package/dist/slider.machine.mjs +10 -0
- package/dist/slider.style.d.ts +26 -0
- package/dist/slider.style.js +141 -0
- package/dist/slider.style.mjs +6 -0
- package/dist/slider.types.d.ts +166 -0
- package/dist/slider.types.js +18 -0
- package/dist/slider.types.mjs +0 -0
- package/dist/slider.utils.d.ts +10 -0
- package/dist/slider.utils.js +61 -0
- package/dist/slider.utils.mjs +12 -0
- package/package.json +24 -14
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
2
|
+
|
|
3
|
+
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "label" | "thumb" | "hiddenInput" | "output" | "track" | "range" | "control" | "markerGroup" | "marker">;
|
|
4
|
+
declare const parts: Record<"root" | "label" | "thumb" | "hiddenInput" | "output" | "track" | "range" | "control" | "markerGroup" | "marker", _zag_js_anatomy.AnatomyPart>;
|
|
5
|
+
|
|
6
|
+
export { anatomy, parts };
|
|
@@ -0,0 +1,45 @@
|
|
|
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);
|
|
19
|
+
|
|
20
|
+
// src/slider.anatomy.ts
|
|
21
|
+
var slider_anatomy_exports = {};
|
|
22
|
+
__export(slider_anatomy_exports, {
|
|
23
|
+
anatomy: () => anatomy,
|
|
24
|
+
parts: () => parts
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(slider_anatomy_exports);
|
|
27
|
+
var import_anatomy = require("@zag-js/anatomy");
|
|
28
|
+
var anatomy = (0, import_anatomy.createAnatomy)("slider").parts(
|
|
29
|
+
"root",
|
|
30
|
+
"label",
|
|
31
|
+
"thumb",
|
|
32
|
+
"hiddenInput",
|
|
33
|
+
"output",
|
|
34
|
+
"track",
|
|
35
|
+
"range",
|
|
36
|
+
"control",
|
|
37
|
+
"markerGroup",
|
|
38
|
+
"marker"
|
|
39
|
+
);
|
|
40
|
+
var parts = anatomy.build();
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
anatomy,
|
|
44
|
+
parts
|
|
45
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { PropTypes, NormalizeProps } from '@zag-js/types';
|
|
2
|
+
import { State, Send } from './slider.types.js';
|
|
3
|
+
import '@zag-js/core';
|
|
4
|
+
|
|
5
|
+
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
6
|
+
isFocused: boolean;
|
|
7
|
+
isDragging: boolean;
|
|
8
|
+
value: number;
|
|
9
|
+
percent: number;
|
|
10
|
+
setValue(value: number): void;
|
|
11
|
+
getPercentValue(percent: number): number;
|
|
12
|
+
getValuePercent(value: number): number;
|
|
13
|
+
focus(): void;
|
|
14
|
+
increment(): void;
|
|
15
|
+
decrement(): void;
|
|
16
|
+
rootProps: T["element"];
|
|
17
|
+
labelProps: T["label"];
|
|
18
|
+
thumbProps: T["element"];
|
|
19
|
+
hiddenInputProps: T["input"];
|
|
20
|
+
outputProps: T["output"];
|
|
21
|
+
trackProps: T["element"];
|
|
22
|
+
rangeProps: T["element"];
|
|
23
|
+
controlProps: T["element"];
|
|
24
|
+
markerGroupProps: T["element"];
|
|
25
|
+
getMarkerProps({ value }: {
|
|
26
|
+
value: number;
|
|
27
|
+
}): T["element"];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { connect };
|
|
@@ -0,0 +1,601 @@
|
|
|
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);
|
|
19
|
+
|
|
20
|
+
// src/slider.connect.ts
|
|
21
|
+
var slider_connect_exports = {};
|
|
22
|
+
__export(slider_connect_exports, {
|
|
23
|
+
connect: () => connect
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(slider_connect_exports);
|
|
26
|
+
|
|
27
|
+
// ../../utilities/dom/src/attrs.ts
|
|
28
|
+
var dataAttr = (guard) => {
|
|
29
|
+
return guard ? "" : void 0;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// ../../utilities/core/src/guard.ts
|
|
33
|
+
var isArray = (v) => Array.isArray(v);
|
|
34
|
+
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
35
|
+
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
36
|
+
|
|
37
|
+
// ../../utilities/dom/src/query.ts
|
|
38
|
+
function isDocument(el) {
|
|
39
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
40
|
+
}
|
|
41
|
+
function isWindow(value) {
|
|
42
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
43
|
+
}
|
|
44
|
+
function getDocument(el) {
|
|
45
|
+
var _a;
|
|
46
|
+
if (isWindow(el))
|
|
47
|
+
return el.document;
|
|
48
|
+
if (isDocument(el))
|
|
49
|
+
return el;
|
|
50
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
51
|
+
}
|
|
52
|
+
function getWindow(el) {
|
|
53
|
+
var _a;
|
|
54
|
+
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
55
|
+
}
|
|
56
|
+
function defineDomHelpers(helpers) {
|
|
57
|
+
const dom2 = {
|
|
58
|
+
getRootNode: (ctx) => {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
61
|
+
},
|
|
62
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
63
|
+
getWin: (ctx) => {
|
|
64
|
+
var _a;
|
|
65
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
66
|
+
},
|
|
67
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
68
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
69
|
+
};
|
|
70
|
+
return {
|
|
71
|
+
...dom2,
|
|
72
|
+
...helpers
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ../../utilities/dom/src/event.ts
|
|
77
|
+
function getNativeEvent(e) {
|
|
78
|
+
var _a;
|
|
79
|
+
return (_a = e.nativeEvent) != null ? _a : e;
|
|
80
|
+
}
|
|
81
|
+
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
82
|
+
var isLeftClick = (v) => v.button === 0;
|
|
83
|
+
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
84
|
+
|
|
85
|
+
// ../../utilities/dom/src/get-element-offset.ts
|
|
86
|
+
function getElementOffset(element) {
|
|
87
|
+
let left = 0;
|
|
88
|
+
let top = 0;
|
|
89
|
+
let el = element;
|
|
90
|
+
if (el.parentNode) {
|
|
91
|
+
do {
|
|
92
|
+
left += el.offsetLeft;
|
|
93
|
+
top += el.offsetTop;
|
|
94
|
+
} while ((el = el.offsetParent) && el.nodeType < 9);
|
|
95
|
+
el = element;
|
|
96
|
+
do {
|
|
97
|
+
left -= el.scrollLeft;
|
|
98
|
+
top -= el.scrollTop;
|
|
99
|
+
} while ((el = el.parentNode) && !/body/i.test(el.nodeName));
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
top,
|
|
103
|
+
right: innerWidth - left - element.offsetWidth,
|
|
104
|
+
bottom: innerHeight - top - element.offsetHeight,
|
|
105
|
+
left
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ../../utilities/dom/src/get-event-point.ts
|
|
110
|
+
var fallback = {
|
|
111
|
+
pageX: 0,
|
|
112
|
+
pageY: 0,
|
|
113
|
+
clientX: 0,
|
|
114
|
+
clientY: 0
|
|
115
|
+
};
|
|
116
|
+
function getEventPoint(event, type = "page") {
|
|
117
|
+
var _a, _b;
|
|
118
|
+
const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event;
|
|
119
|
+
return { x: point[`${type}X`], y: point[`${type}Y`] };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// ../../utilities/dom/src/get-point-relative-to-element.ts
|
|
123
|
+
function getPointRelativeToNode(point, element) {
|
|
124
|
+
const offset = getElementOffset(element);
|
|
125
|
+
const x = point.x - offset.left;
|
|
126
|
+
const y = point.y - offset.top;
|
|
127
|
+
return { x, y };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ../../utilities/dom/src/keyboard-event.ts
|
|
131
|
+
var rtlKeyMap = {
|
|
132
|
+
ArrowLeft: "ArrowRight",
|
|
133
|
+
ArrowRight: "ArrowLeft"
|
|
134
|
+
};
|
|
135
|
+
var sameKeyMap = {
|
|
136
|
+
Up: "ArrowUp",
|
|
137
|
+
Down: "ArrowDown",
|
|
138
|
+
Esc: "Escape",
|
|
139
|
+
" ": "Space",
|
|
140
|
+
",": "Comma",
|
|
141
|
+
Left: "ArrowLeft",
|
|
142
|
+
Right: "ArrowRight"
|
|
143
|
+
};
|
|
144
|
+
function getEventKey(event, options = {}) {
|
|
145
|
+
var _a;
|
|
146
|
+
const { dir = "ltr", orientation = "horizontal" } = options;
|
|
147
|
+
let { key } = event;
|
|
148
|
+
key = (_a = sameKeyMap[key]) != null ? _a : key;
|
|
149
|
+
const isRtl = dir === "rtl" && orientation === "horizontal";
|
|
150
|
+
if (isRtl && key in rtlKeyMap) {
|
|
151
|
+
key = rtlKeyMap[key];
|
|
152
|
+
}
|
|
153
|
+
return key;
|
|
154
|
+
}
|
|
155
|
+
var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
|
|
156
|
+
var ARROW_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
|
|
157
|
+
function getEventStep(event) {
|
|
158
|
+
if (event.ctrlKey || event.metaKey) {
|
|
159
|
+
return 0.1;
|
|
160
|
+
} else {
|
|
161
|
+
const isPageKey = PAGE_KEYS.has(event.key);
|
|
162
|
+
const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.has(event.key);
|
|
163
|
+
return isSkipKey ? 10 : 1;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// src/slider.connect.ts
|
|
168
|
+
var import_numeric_range3 = require("@zag-js/numeric-range");
|
|
169
|
+
|
|
170
|
+
// src/slider.anatomy.ts
|
|
171
|
+
var import_anatomy = require("@zag-js/anatomy");
|
|
172
|
+
var anatomy = (0, import_anatomy.createAnatomy)("slider").parts(
|
|
173
|
+
"root",
|
|
174
|
+
"label",
|
|
175
|
+
"thumb",
|
|
176
|
+
"hiddenInput",
|
|
177
|
+
"output",
|
|
178
|
+
"track",
|
|
179
|
+
"range",
|
|
180
|
+
"control",
|
|
181
|
+
"markerGroup",
|
|
182
|
+
"marker"
|
|
183
|
+
);
|
|
184
|
+
var parts = anatomy.build();
|
|
185
|
+
|
|
186
|
+
// ../../utilities/form-utils/src/input-event.ts
|
|
187
|
+
function getDescriptor(el, options) {
|
|
188
|
+
var _a;
|
|
189
|
+
const { type, property = "value" } = options;
|
|
190
|
+
const proto = getWindow(el)[type].prototype;
|
|
191
|
+
return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
|
|
192
|
+
}
|
|
193
|
+
function dispatchInputValueEvent(el, value) {
|
|
194
|
+
var _a;
|
|
195
|
+
if (!el)
|
|
196
|
+
return;
|
|
197
|
+
const win = getWindow(el);
|
|
198
|
+
if (!(el instanceof win.HTMLInputElement))
|
|
199
|
+
return;
|
|
200
|
+
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
201
|
+
(_a = desc.set) == null ? void 0 : _a.call(el, value);
|
|
202
|
+
const event = new win.Event("input", { bubbles: true });
|
|
203
|
+
el.dispatchEvent(event);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// src/slider.dom.ts
|
|
207
|
+
var import_numeric_range2 = require("@zag-js/numeric-range");
|
|
208
|
+
|
|
209
|
+
// src/slider.style.ts
|
|
210
|
+
var import_numeric_range = require("@zag-js/numeric-range");
|
|
211
|
+
function getVerticalThumbOffset(ctx) {
|
|
212
|
+
var _a;
|
|
213
|
+
const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
|
|
214
|
+
const getValue = (0, import_numeric_range.getValueTransformer)([ctx.min, ctx.max], [-height / 2, height / 2]);
|
|
215
|
+
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
216
|
+
}
|
|
217
|
+
function getHorizontalThumbOffset(ctx) {
|
|
218
|
+
var _a;
|
|
219
|
+
const { width = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
|
|
220
|
+
if (ctx.isRtl) {
|
|
221
|
+
const getValue2 = (0, import_numeric_range.getValueTransformer)([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
|
|
222
|
+
return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
|
|
223
|
+
}
|
|
224
|
+
const getValue = (0, import_numeric_range.getValueTransformer)([ctx.min, ctx.max], [-width / 2, width / 2]);
|
|
225
|
+
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
226
|
+
}
|
|
227
|
+
function getThumbOffset(ctx) {
|
|
228
|
+
const percent = (0, import_numeric_range.getValuePercent)(ctx.value, ctx.min, ctx.max) * 100;
|
|
229
|
+
if (ctx.thumbAlignment === "center") {
|
|
230
|
+
return `${percent}%`;
|
|
231
|
+
}
|
|
232
|
+
const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
|
|
233
|
+
return `calc(${percent}% - ${offset}px)`;
|
|
234
|
+
}
|
|
235
|
+
function getVisibility(ctx) {
|
|
236
|
+
let visibility = "visible";
|
|
237
|
+
if (ctx.thumbAlignment === "contain" && !ctx.hasMeasuredThumbSize) {
|
|
238
|
+
visibility = "hidden";
|
|
239
|
+
}
|
|
240
|
+
return visibility;
|
|
241
|
+
}
|
|
242
|
+
function getThumbStyle(ctx) {
|
|
243
|
+
const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
|
|
244
|
+
return {
|
|
245
|
+
visibility: getVisibility(ctx),
|
|
246
|
+
position: "absolute",
|
|
247
|
+
transform: "var(--slider-thumb-transform)",
|
|
248
|
+
[placementProp]: "var(--slider-thumb-offset)"
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
function getRangeOffsets(ctx) {
|
|
252
|
+
let start = "0%";
|
|
253
|
+
let end = `${100 - ctx.valuePercent}%`;
|
|
254
|
+
if (ctx.origin === "center") {
|
|
255
|
+
const isNegative = ctx.valuePercent < 50;
|
|
256
|
+
start = isNegative ? `${ctx.valuePercent}%` : "50%";
|
|
257
|
+
end = isNegative ? "50%" : end;
|
|
258
|
+
}
|
|
259
|
+
return { start, end };
|
|
260
|
+
}
|
|
261
|
+
function getRangeStyle(ctx) {
|
|
262
|
+
if (ctx.isVertical) {
|
|
263
|
+
return {
|
|
264
|
+
position: "absolute",
|
|
265
|
+
bottom: "var(--slider-range-start)",
|
|
266
|
+
top: "var(--slider-range-end)"
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
return {
|
|
270
|
+
position: "absolute",
|
|
271
|
+
[ctx.isRtl ? "right" : "left"]: "var(--slider-range-start)",
|
|
272
|
+
[ctx.isRtl ? "left" : "right"]: "var(--slider-range-end)"
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
function getControlStyle() {
|
|
276
|
+
return {
|
|
277
|
+
touchAction: "none",
|
|
278
|
+
userSelect: "none",
|
|
279
|
+
position: "relative"
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
function getRootStyle(ctx) {
|
|
283
|
+
const range = getRangeOffsets(ctx);
|
|
284
|
+
return {
|
|
285
|
+
"--slider-thumb-transform": ctx.isVertical ? "translateY(50%)" : "translateX(-50%)",
|
|
286
|
+
"--slider-thumb-offset": getThumbOffset(ctx),
|
|
287
|
+
"--slider-range-start": range.start,
|
|
288
|
+
"--slider-range-end": range.end
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
function getMarkerStyle(ctx, percent) {
|
|
292
|
+
return {
|
|
293
|
+
position: "absolute",
|
|
294
|
+
pointerEvents: "none",
|
|
295
|
+
[ctx.isHorizontal ? "left" : "bottom"]: `${(ctx.isRtl ? 1 - percent : percent) * 100}%`
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function getLabelStyle() {
|
|
299
|
+
return { userSelect: "none" };
|
|
300
|
+
}
|
|
301
|
+
function getTrackStyle() {
|
|
302
|
+
return { position: "relative" };
|
|
303
|
+
}
|
|
304
|
+
function getMarkerGroupStyle() {
|
|
305
|
+
return {
|
|
306
|
+
userSelect: "none",
|
|
307
|
+
pointerEvents: "none",
|
|
308
|
+
position: "relative"
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
var styles = {
|
|
312
|
+
getThumbOffset,
|
|
313
|
+
getControlStyle,
|
|
314
|
+
getThumbStyle,
|
|
315
|
+
getRangeStyle,
|
|
316
|
+
getRootStyle,
|
|
317
|
+
getMarkerStyle,
|
|
318
|
+
getLabelStyle,
|
|
319
|
+
getTrackStyle,
|
|
320
|
+
getMarkerGroupStyle
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
// src/slider.dom.ts
|
|
324
|
+
var dom = defineDomHelpers({
|
|
325
|
+
...styles,
|
|
326
|
+
getRootId: (ctx) => {
|
|
327
|
+
var _a, _b;
|
|
328
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `slider:${ctx.id}`;
|
|
329
|
+
},
|
|
330
|
+
getThumbId: (ctx) => {
|
|
331
|
+
var _a, _b;
|
|
332
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.thumb) != null ? _b : `slider:${ctx.id}:thumb`;
|
|
333
|
+
},
|
|
334
|
+
getControlId: (ctx) => {
|
|
335
|
+
var _a, _b;
|
|
336
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.control) != null ? _b : `slider:${ctx.id}:control`;
|
|
337
|
+
},
|
|
338
|
+
getHiddenInputId: (ctx) => `slider:${ctx.id}:input`,
|
|
339
|
+
getOutputId: (ctx) => {
|
|
340
|
+
var _a, _b;
|
|
341
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.output) != null ? _b : `slider:${ctx.id}:output`;
|
|
342
|
+
},
|
|
343
|
+
getTrackId: (ctx) => {
|
|
344
|
+
var _a, _b;
|
|
345
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}track`;
|
|
346
|
+
},
|
|
347
|
+
getRangeId: (ctx) => {
|
|
348
|
+
var _a, _b;
|
|
349
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}:range`;
|
|
350
|
+
},
|
|
351
|
+
getLabelId: (ctx) => {
|
|
352
|
+
var _a, _b;
|
|
353
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.id}:label`;
|
|
354
|
+
},
|
|
355
|
+
getMarkerId: (ctx, value) => `slider:${ctx.id}:marker:${value}`,
|
|
356
|
+
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
357
|
+
getThumbEl: (ctx) => dom.getById(ctx, dom.getThumbId(ctx)),
|
|
358
|
+
getControlEl: (ctx) => dom.getById(ctx, dom.getControlId(ctx)),
|
|
359
|
+
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx)),
|
|
360
|
+
getValueFromPoint(ctx, point) {
|
|
361
|
+
const el = dom.getControlEl(ctx);
|
|
362
|
+
if (!el)
|
|
363
|
+
return;
|
|
364
|
+
const relativePoint = getPointRelativeToNode(point, el);
|
|
365
|
+
const percentX = relativePoint.x / el.offsetWidth;
|
|
366
|
+
const percentY = relativePoint.y / el.offsetHeight;
|
|
367
|
+
let percent;
|
|
368
|
+
if (ctx.isHorizontal) {
|
|
369
|
+
percent = ctx.isRtl ? 1 - percentX : percentX;
|
|
370
|
+
} else {
|
|
371
|
+
percent = 1 - percentY;
|
|
372
|
+
}
|
|
373
|
+
return (0, import_numeric_range2.getPercentValue)(percent, ctx.min, ctx.max, ctx.step);
|
|
374
|
+
},
|
|
375
|
+
dispatchChangeEvent(ctx) {
|
|
376
|
+
const input = dom.getHiddenInputEl(ctx);
|
|
377
|
+
if (!input)
|
|
378
|
+
return;
|
|
379
|
+
dispatchInputValueEvent(input, ctx.value);
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// src/slider.connect.ts
|
|
384
|
+
function connect(state, send, normalize) {
|
|
385
|
+
var _a, _b;
|
|
386
|
+
const ariaLabel = state.context["aria-label"];
|
|
387
|
+
const ariaLabelledBy = state.context["aria-labelledby"];
|
|
388
|
+
const ariaValueText = (_b = (_a = state.context).getAriaValueText) == null ? void 0 : _b.call(_a, state.context.value);
|
|
389
|
+
const isFocused = state.matches("focus");
|
|
390
|
+
const isDragging = state.matches("dragging");
|
|
391
|
+
const isDisabled = state.context.disabled;
|
|
392
|
+
const isInteractive = state.context.isInteractive;
|
|
393
|
+
const isInvalid = state.context.invalid;
|
|
394
|
+
return {
|
|
395
|
+
isFocused,
|
|
396
|
+
isDragging,
|
|
397
|
+
value: state.context.value,
|
|
398
|
+
percent: (0, import_numeric_range3.getValuePercent)(state.context.value, state.context.min, state.context.max),
|
|
399
|
+
setValue(value) {
|
|
400
|
+
send({ type: "SET_VALUE", value });
|
|
401
|
+
},
|
|
402
|
+
getPercentValue(percent) {
|
|
403
|
+
return (0, import_numeric_range3.getPercentValue)(percent, state.context.min, state.context.max, state.context.step);
|
|
404
|
+
},
|
|
405
|
+
getValuePercent(value) {
|
|
406
|
+
return (0, import_numeric_range3.getValuePercent)(value, state.context.min, state.context.max);
|
|
407
|
+
},
|
|
408
|
+
focus() {
|
|
409
|
+
var _a2;
|
|
410
|
+
(_a2 = dom.getThumbEl(state.context)) == null ? void 0 : _a2.focus();
|
|
411
|
+
},
|
|
412
|
+
increment() {
|
|
413
|
+
send("INCREMENT");
|
|
414
|
+
},
|
|
415
|
+
decrement() {
|
|
416
|
+
send("DECREMENT");
|
|
417
|
+
},
|
|
418
|
+
rootProps: normalize.element({
|
|
419
|
+
...parts.root.attrs,
|
|
420
|
+
"data-disabled": dataAttr(isDisabled),
|
|
421
|
+
"data-focus": dataAttr(isFocused),
|
|
422
|
+
"data-orientation": state.context.orientation,
|
|
423
|
+
"data-invalid": dataAttr(isInvalid),
|
|
424
|
+
id: dom.getRootId(state.context),
|
|
425
|
+
dir: state.context.dir,
|
|
426
|
+
style: dom.getRootStyle(state.context)
|
|
427
|
+
}),
|
|
428
|
+
labelProps: normalize.label({
|
|
429
|
+
...parts.label.attrs,
|
|
430
|
+
"data-disabled": dataAttr(isDisabled),
|
|
431
|
+
"data-invalid": dataAttr(isInvalid),
|
|
432
|
+
"data-focus": dataAttr(isFocused),
|
|
433
|
+
id: dom.getLabelId(state.context),
|
|
434
|
+
htmlFor: dom.getHiddenInputId(state.context),
|
|
435
|
+
onClick(event) {
|
|
436
|
+
var _a2;
|
|
437
|
+
if (!isInteractive)
|
|
438
|
+
return;
|
|
439
|
+
event.preventDefault();
|
|
440
|
+
(_a2 = dom.getThumbEl(state.context)) == null ? void 0 : _a2.focus();
|
|
441
|
+
},
|
|
442
|
+
style: dom.getLabelStyle()
|
|
443
|
+
}),
|
|
444
|
+
thumbProps: normalize.element({
|
|
445
|
+
...parts.thumb.attrs,
|
|
446
|
+
id: dom.getThumbId(state.context),
|
|
447
|
+
"data-disabled": dataAttr(isDisabled),
|
|
448
|
+
"data-orientation": state.context.orientation,
|
|
449
|
+
"data-focus": dataAttr(isFocused),
|
|
450
|
+
draggable: false,
|
|
451
|
+
"aria-invalid": isInvalid || void 0,
|
|
452
|
+
"data-invalid": dataAttr(isInvalid),
|
|
453
|
+
"aria-disabled": isDisabled || void 0,
|
|
454
|
+
"aria-label": ariaLabel,
|
|
455
|
+
"aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy != null ? ariaLabelledBy : dom.getLabelId(state.context),
|
|
456
|
+
"aria-orientation": state.context.orientation,
|
|
457
|
+
"aria-valuemax": state.context.max,
|
|
458
|
+
"aria-valuemin": state.context.min,
|
|
459
|
+
"aria-valuenow": state.context.value,
|
|
460
|
+
"aria-valuetext": ariaValueText,
|
|
461
|
+
role: "slider",
|
|
462
|
+
tabIndex: isDisabled ? void 0 : 0,
|
|
463
|
+
onBlur() {
|
|
464
|
+
if (!isInteractive)
|
|
465
|
+
return;
|
|
466
|
+
send("BLUR");
|
|
467
|
+
},
|
|
468
|
+
onFocus() {
|
|
469
|
+
if (!isInteractive)
|
|
470
|
+
return;
|
|
471
|
+
send("FOCUS");
|
|
472
|
+
},
|
|
473
|
+
onKeyDown(event) {
|
|
474
|
+
if (!isInteractive)
|
|
475
|
+
return;
|
|
476
|
+
const step = getEventStep(event) * state.context.step;
|
|
477
|
+
let prevent = true;
|
|
478
|
+
const keyMap = {
|
|
479
|
+
ArrowUp() {
|
|
480
|
+
send({ type: "ARROW_UP", step });
|
|
481
|
+
prevent = state.context.isVertical;
|
|
482
|
+
},
|
|
483
|
+
ArrowDown() {
|
|
484
|
+
send({ type: "ARROW_DOWN", step });
|
|
485
|
+
prevent = state.context.isVertical;
|
|
486
|
+
},
|
|
487
|
+
ArrowLeft() {
|
|
488
|
+
send({ type: "ARROW_LEFT", step });
|
|
489
|
+
prevent = state.context.isHorizontal;
|
|
490
|
+
},
|
|
491
|
+
ArrowRight() {
|
|
492
|
+
send({ type: "ARROW_RIGHT", step });
|
|
493
|
+
prevent = state.context.isHorizontal;
|
|
494
|
+
},
|
|
495
|
+
PageUp() {
|
|
496
|
+
send({ type: "PAGE_UP", step });
|
|
497
|
+
},
|
|
498
|
+
PageDown() {
|
|
499
|
+
send({ type: "PAGE_DOWN", step });
|
|
500
|
+
},
|
|
501
|
+
Home() {
|
|
502
|
+
send("HOME");
|
|
503
|
+
},
|
|
504
|
+
End() {
|
|
505
|
+
send("END");
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
const key = getEventKey(event, state.context);
|
|
509
|
+
const exec = keyMap[key];
|
|
510
|
+
if (!exec)
|
|
511
|
+
return;
|
|
512
|
+
exec(event);
|
|
513
|
+
if (prevent) {
|
|
514
|
+
event.preventDefault();
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
style: dom.getThumbStyle(state.context)
|
|
518
|
+
}),
|
|
519
|
+
hiddenInputProps: normalize.input({
|
|
520
|
+
...parts.hiddenInput.attrs,
|
|
521
|
+
type: "text",
|
|
522
|
+
defaultValue: state.context.value,
|
|
523
|
+
name: state.context.name,
|
|
524
|
+
form: state.context.form,
|
|
525
|
+
id: dom.getHiddenInputId(state.context),
|
|
526
|
+
hidden: true
|
|
527
|
+
}),
|
|
528
|
+
outputProps: normalize.output({
|
|
529
|
+
...parts.output.attrs,
|
|
530
|
+
"data-disabled": dataAttr(isDisabled),
|
|
531
|
+
"data-invalid": dataAttr(isInvalid),
|
|
532
|
+
id: dom.getOutputId(state.context),
|
|
533
|
+
htmlFor: dom.getHiddenInputId(state.context),
|
|
534
|
+
"aria-live": "off"
|
|
535
|
+
}),
|
|
536
|
+
trackProps: normalize.element({
|
|
537
|
+
...parts.track.attrs,
|
|
538
|
+
id: dom.getTrackId(state.context),
|
|
539
|
+
"data-disabled": dataAttr(isDisabled),
|
|
540
|
+
"data-focus": dataAttr(isFocused),
|
|
541
|
+
"data-invalid": dataAttr(isInvalid),
|
|
542
|
+
"data-orientation": state.context.orientation,
|
|
543
|
+
style: dom.getTrackStyle()
|
|
544
|
+
}),
|
|
545
|
+
rangeProps: normalize.element({
|
|
546
|
+
...parts.range.attrs,
|
|
547
|
+
id: dom.getRangeId(state.context),
|
|
548
|
+
"data-focus": dataAttr(isFocused),
|
|
549
|
+
"data-invalid": dataAttr(isInvalid),
|
|
550
|
+
"data-disabled": dataAttr(isDisabled),
|
|
551
|
+
"data-orientation": state.context.orientation,
|
|
552
|
+
style: dom.getRangeStyle(state.context)
|
|
553
|
+
}),
|
|
554
|
+
controlProps: normalize.element({
|
|
555
|
+
...parts.control.attrs,
|
|
556
|
+
id: dom.getControlId(state.context),
|
|
557
|
+
"data-disabled": dataAttr(isDisabled),
|
|
558
|
+
"data-invalid": dataAttr(isInvalid),
|
|
559
|
+
"data-orientation": state.context.orientation,
|
|
560
|
+
"data-focus": dataAttr(isFocused),
|
|
561
|
+
onPointerDown(event) {
|
|
562
|
+
if (!isInteractive)
|
|
563
|
+
return;
|
|
564
|
+
const evt = getNativeEvent(event);
|
|
565
|
+
if (!isLeftClick(evt) || isModifiedEvent(evt))
|
|
566
|
+
return;
|
|
567
|
+
const point = getEventPoint(evt);
|
|
568
|
+
send({ type: "POINTER_DOWN", point });
|
|
569
|
+
event.preventDefault();
|
|
570
|
+
event.stopPropagation();
|
|
571
|
+
},
|
|
572
|
+
style: dom.getControlStyle()
|
|
573
|
+
}),
|
|
574
|
+
markerGroupProps: normalize.element({
|
|
575
|
+
...parts.markerGroup.attrs,
|
|
576
|
+
role: "presentation",
|
|
577
|
+
"aria-hidden": true,
|
|
578
|
+
"data-orientation": state.context.orientation,
|
|
579
|
+
style: dom.getMarkerGroupStyle()
|
|
580
|
+
}),
|
|
581
|
+
getMarkerProps({ value }) {
|
|
582
|
+
const percent = this.getValuePercent(value);
|
|
583
|
+
const style = dom.getMarkerStyle(state.context, percent);
|
|
584
|
+
const markerState = value > state.context.value ? "over-value" : value < state.context.value ? "under-value" : "at-value";
|
|
585
|
+
return normalize.element({
|
|
586
|
+
...parts.marker.attrs,
|
|
587
|
+
role: "presentation",
|
|
588
|
+
"data-orientation": state.context.orientation,
|
|
589
|
+
id: dom.getMarkerId(state.context, value),
|
|
590
|
+
"data-value": value,
|
|
591
|
+
"data-disabled": dataAttr(isDisabled),
|
|
592
|
+
"data-state": markerState,
|
|
593
|
+
style
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
599
|
+
0 && (module.exports = {
|
|
600
|
+
connect
|
|
601
|
+
});
|