@zag-js/slider 0.2.5 → 0.2.7
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-3JMGYHB3.mjs +469 -0
- package/dist/chunk-3Y7IIPR5.mjs +20 -0
- package/dist/chunk-FUTBDWTA.mjs +33 -0
- package/dist/chunk-GBYBRQZL.mjs +56 -0
- package/dist/chunk-MR2MUD77.mjs +179 -0
- package/dist/chunk-MXJ3RGFD.mjs +125 -0
- package/dist/chunk-SGCWELVB.mjs +44 -0
- package/dist/chunk-YCRSV2RE.mjs +288 -0
- package/dist/index.d.ts +8 -1085
- package/dist/index.js +63 -36
- package/dist/index.mjs +16 -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 +29 -0
- package/dist/slider.connect.js +684 -0
- package/dist/slider.connect.mjs +12 -0
- package/dist/slider.dom.d.ts +52 -0
- package/dist/slider.dom.js +386 -0
- package/dist/slider.dom.mjs +9 -0
- package/dist/slider.machine.d.ts +7 -0
- package/dist/slider.machine.js +860 -0
- package/dist/slider.machine.mjs +11 -0
- package/dist/slider.style.d.ts +26 -0
- package/dist/slider.style.js +156 -0
- package/dist/slider.style.mjs +7 -0
- package/dist/slider.types.d.ts +161 -0
- package/dist/slider.types.js +18 -0
- package/dist/slider.types.mjs +0 -0
- package/dist/slider.utils.d.ts +13 -0
- package/dist/slider.utils.js +98 -0
- package/dist/slider.utils.mjs +7 -0
- package/package.json +24 -14
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import {
|
|
2
|
+
styles
|
|
3
|
+
} from "./chunk-MXJ3RGFD.mjs";
|
|
4
|
+
import {
|
|
5
|
+
utils
|
|
6
|
+
} from "./chunk-FUTBDWTA.mjs";
|
|
7
|
+
|
|
8
|
+
// ../../utilities/dom/src/query.ts
|
|
9
|
+
function isDocument(el) {
|
|
10
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
11
|
+
}
|
|
12
|
+
function isWindow(value) {
|
|
13
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
14
|
+
}
|
|
15
|
+
function getDocument(el) {
|
|
16
|
+
var _a;
|
|
17
|
+
if (isWindow(el))
|
|
18
|
+
return el.document;
|
|
19
|
+
if (isDocument(el))
|
|
20
|
+
return el;
|
|
21
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
22
|
+
}
|
|
23
|
+
function getWindow(el) {
|
|
24
|
+
var _a;
|
|
25
|
+
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
26
|
+
}
|
|
27
|
+
function defineDomHelpers(helpers) {
|
|
28
|
+
const dom2 = {
|
|
29
|
+
getRootNode: (ctx) => {
|
|
30
|
+
var _a, _b;
|
|
31
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
32
|
+
},
|
|
33
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
34
|
+
getWin: (ctx) => {
|
|
35
|
+
var _a;
|
|
36
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
37
|
+
},
|
|
38
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
39
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
|
|
40
|
+
createEmitter: (ctx, target) => {
|
|
41
|
+
const win = dom2.getWin(ctx);
|
|
42
|
+
return function emit(evt, detail, options) {
|
|
43
|
+
const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
|
|
44
|
+
const eventName = `zag:${evt}`;
|
|
45
|
+
const init = { bubbles, cancelable, composed, detail };
|
|
46
|
+
const event = new win.CustomEvent(eventName, init);
|
|
47
|
+
target.dispatchEvent(event);
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
createListener: (target) => {
|
|
51
|
+
return function listen(evt, handler) {
|
|
52
|
+
const eventName = `zag:${evt}`;
|
|
53
|
+
const listener = (e) => handler(e);
|
|
54
|
+
target.addEventListener(eventName, listener);
|
|
55
|
+
return () => target.removeEventListener(eventName, listener);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
...dom2,
|
|
61
|
+
...helpers
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ../../utilities/dom/src/get-element-offset.ts
|
|
66
|
+
function getElementOffset(element) {
|
|
67
|
+
let left = 0;
|
|
68
|
+
let top = 0;
|
|
69
|
+
let el = element;
|
|
70
|
+
if (el.parentNode) {
|
|
71
|
+
do {
|
|
72
|
+
left += el.offsetLeft;
|
|
73
|
+
top += el.offsetTop;
|
|
74
|
+
} while ((el = el.offsetParent) && el.nodeType < 9);
|
|
75
|
+
el = element;
|
|
76
|
+
do {
|
|
77
|
+
left -= el.scrollLeft;
|
|
78
|
+
top -= el.scrollTop;
|
|
79
|
+
} while ((el = el.parentNode) && !/body/i.test(el.nodeName));
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
top,
|
|
83
|
+
right: innerWidth - left - element.offsetWidth,
|
|
84
|
+
bottom: innerHeight - top - element.offsetHeight,
|
|
85
|
+
left
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// ../../utilities/dom/src/get-point-relative-to-element.ts
|
|
90
|
+
function getPointRelativeToNode(point, element) {
|
|
91
|
+
const offset = getElementOffset(element);
|
|
92
|
+
const x = point.x - offset.left;
|
|
93
|
+
const y = point.y - offset.top;
|
|
94
|
+
return { x, y };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ../../utilities/form-utils/src/input-event.ts
|
|
98
|
+
function getDescriptor(el, options) {
|
|
99
|
+
var _a;
|
|
100
|
+
const { type, property = "value" } = options;
|
|
101
|
+
const proto = getWindow(el)[type].prototype;
|
|
102
|
+
return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
|
|
103
|
+
}
|
|
104
|
+
function dispatchInputValueEvent(el, value) {
|
|
105
|
+
var _a;
|
|
106
|
+
if (!el)
|
|
107
|
+
return;
|
|
108
|
+
const win = getWindow(el);
|
|
109
|
+
if (!(el instanceof win.HTMLInputElement))
|
|
110
|
+
return;
|
|
111
|
+
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
112
|
+
(_a = desc.set) == null ? void 0 : _a.call(el, value);
|
|
113
|
+
const event = new win.Event("input", { bubbles: true });
|
|
114
|
+
el.dispatchEvent(event);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/slider.dom.ts
|
|
118
|
+
var dom = defineDomHelpers({
|
|
119
|
+
...styles,
|
|
120
|
+
getRootId: (ctx) => {
|
|
121
|
+
var _a, _b;
|
|
122
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `slider:${ctx.id}`;
|
|
123
|
+
},
|
|
124
|
+
getThumbId: (ctx) => {
|
|
125
|
+
var _a, _b;
|
|
126
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.thumb) != null ? _b : `slider:${ctx.id}:thumb`;
|
|
127
|
+
},
|
|
128
|
+
getControlId: (ctx) => {
|
|
129
|
+
var _a, _b;
|
|
130
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.control) != null ? _b : `slider:${ctx.id}:control`;
|
|
131
|
+
},
|
|
132
|
+
getHiddenInputId: (ctx) => `slider:${ctx.id}:input`,
|
|
133
|
+
getOutputId: (ctx) => {
|
|
134
|
+
var _a, _b;
|
|
135
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.output) != null ? _b : `slider:${ctx.id}:output`;
|
|
136
|
+
},
|
|
137
|
+
getTrackId: (ctx) => {
|
|
138
|
+
var _a, _b;
|
|
139
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}track`;
|
|
140
|
+
},
|
|
141
|
+
getRangeId: (ctx) => {
|
|
142
|
+
var _a, _b;
|
|
143
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}:range`;
|
|
144
|
+
},
|
|
145
|
+
getLabelId: (ctx) => {
|
|
146
|
+
var _a, _b;
|
|
147
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.id}:label`;
|
|
148
|
+
},
|
|
149
|
+
getMarkerId: (ctx, value) => `slider:${ctx.id}:marker:${value}`,
|
|
150
|
+
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
151
|
+
getThumbEl: (ctx) => dom.getById(ctx, dom.getThumbId(ctx)),
|
|
152
|
+
getControlEl: (ctx) => dom.getById(ctx, dom.getControlId(ctx)),
|
|
153
|
+
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx)),
|
|
154
|
+
getValueFromPoint(ctx, point) {
|
|
155
|
+
const el = dom.getControlEl(ctx);
|
|
156
|
+
if (!el)
|
|
157
|
+
return;
|
|
158
|
+
const relativePoint = getPointRelativeToNode(point, el);
|
|
159
|
+
const percentX = relativePoint.x / el.offsetWidth;
|
|
160
|
+
const percentY = relativePoint.y / el.offsetHeight;
|
|
161
|
+
let percent;
|
|
162
|
+
if (ctx.isHorizontal) {
|
|
163
|
+
percent = ctx.isRtl ? 1 - percentX : percentX;
|
|
164
|
+
} else {
|
|
165
|
+
percent = 1 - percentY;
|
|
166
|
+
}
|
|
167
|
+
return utils.fromPercent(ctx, percent);
|
|
168
|
+
},
|
|
169
|
+
dispatchChangeEvent(ctx) {
|
|
170
|
+
const input = dom.getHiddenInputEl(ctx);
|
|
171
|
+
if (!input)
|
|
172
|
+
return;
|
|
173
|
+
dispatchInputValueEvent(input, ctx.value);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
export {
|
|
178
|
+
dom
|
|
179
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import {
|
|
2
|
+
valueToPercent
|
|
3
|
+
} from "./chunk-GBYBRQZL.mjs";
|
|
4
|
+
|
|
5
|
+
// ../../utilities/number/src/transform.ts
|
|
6
|
+
var transform = (a, b) => {
|
|
7
|
+
const i = { min: a[0], max: a[1] };
|
|
8
|
+
const o = { min: b[0], max: b[1] };
|
|
9
|
+
return (v) => {
|
|
10
|
+
if (i.min === i.max || o.min === o.max)
|
|
11
|
+
return o.min;
|
|
12
|
+
const ratio = (o.max - o.min) / (i.max - i.min);
|
|
13
|
+
return o.min + ratio * (v - i.min);
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// src/slider.style.ts
|
|
18
|
+
function getVerticalThumbOffset(ctx) {
|
|
19
|
+
var _a;
|
|
20
|
+
const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
|
|
21
|
+
const getValue = transform([ctx.min, ctx.max], [-height / 2, height / 2]);
|
|
22
|
+
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
23
|
+
}
|
|
24
|
+
function getHorizontalThumbOffset(ctx) {
|
|
25
|
+
var _a;
|
|
26
|
+
const { width = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
|
|
27
|
+
if (ctx.isRtl) {
|
|
28
|
+
const getValue2 = transform([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
|
|
29
|
+
return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
|
|
30
|
+
}
|
|
31
|
+
const getValue = transform([ctx.min, ctx.max], [-width / 2, width / 2]);
|
|
32
|
+
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
33
|
+
}
|
|
34
|
+
function getThumbOffset(ctx) {
|
|
35
|
+
const percent = valueToPercent(ctx.value, ctx);
|
|
36
|
+
if (ctx.thumbAlignment === "center")
|
|
37
|
+
return `${percent}%`;
|
|
38
|
+
const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
|
|
39
|
+
return `calc(${percent}% - ${offset}px)`;
|
|
40
|
+
}
|
|
41
|
+
function getThumbStyle(ctx) {
|
|
42
|
+
const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
|
|
43
|
+
return {
|
|
44
|
+
visibility: ctx.hasMeasuredThumbSize ? "visible" : "hidden",
|
|
45
|
+
position: "absolute",
|
|
46
|
+
transform: "var(--slider-thumb-transform)",
|
|
47
|
+
[placementProp]: "var(--slider-thumb-offset)"
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function getRangeOffsets(ctx) {
|
|
51
|
+
const percent = valueToPercent(ctx.value, ctx);
|
|
52
|
+
let start = "0%";
|
|
53
|
+
let end = `${100 - percent}%`;
|
|
54
|
+
if (ctx.origin === "center") {
|
|
55
|
+
const isNegative = percent < 50;
|
|
56
|
+
start = isNegative ? `${percent}%` : "50%";
|
|
57
|
+
end = isNegative ? "50%" : end;
|
|
58
|
+
}
|
|
59
|
+
return { start, end };
|
|
60
|
+
}
|
|
61
|
+
function getRangeStyle(ctx) {
|
|
62
|
+
if (ctx.isVertical) {
|
|
63
|
+
return {
|
|
64
|
+
position: "absolute",
|
|
65
|
+
bottom: "var(--slider-range-start)",
|
|
66
|
+
top: "var(--slider-range-end)"
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
position: "absolute",
|
|
71
|
+
[ctx.isRtl ? "right" : "left"]: "var(--slider-range-start)",
|
|
72
|
+
[ctx.isRtl ? "left" : "right"]: "var(--slider-range-end)"
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function getControlStyle() {
|
|
76
|
+
return {
|
|
77
|
+
touchAction: "none",
|
|
78
|
+
userSelect: "none",
|
|
79
|
+
position: "relative"
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function getRootStyle(ctx) {
|
|
83
|
+
const range = getRangeOffsets(ctx);
|
|
84
|
+
return {
|
|
85
|
+
"--slider-thumb-transform": ctx.isVertical ? "translateY(50%)" : "translateX(-50%)",
|
|
86
|
+
"--slider-thumb-offset": getThumbOffset(ctx),
|
|
87
|
+
"--slider-range-start": range.start,
|
|
88
|
+
"--slider-range-end": range.end
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function getMarkerStyle(ctx, percent) {
|
|
92
|
+
return {
|
|
93
|
+
position: "absolute",
|
|
94
|
+
pointerEvents: "none",
|
|
95
|
+
[ctx.isHorizontal ? "left" : "bottom"]: `${ctx.isRtl ? 100 - percent : percent}%`
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function getLabelStyle() {
|
|
99
|
+
return { userSelect: "none" };
|
|
100
|
+
}
|
|
101
|
+
function getTrackStyle() {
|
|
102
|
+
return { position: "relative" };
|
|
103
|
+
}
|
|
104
|
+
function getMarkerGroupStyle() {
|
|
105
|
+
return {
|
|
106
|
+
userSelect: "none",
|
|
107
|
+
pointerEvents: "none",
|
|
108
|
+
position: "relative"
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
var styles = {
|
|
112
|
+
getThumbOffset,
|
|
113
|
+
getControlStyle,
|
|
114
|
+
getThumbStyle,
|
|
115
|
+
getRangeStyle,
|
|
116
|
+
getRootStyle,
|
|
117
|
+
getMarkerStyle,
|
|
118
|
+
getLabelStyle,
|
|
119
|
+
getTrackStyle,
|
|
120
|
+
getMarkerGroupStyle
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export {
|
|
124
|
+
styles
|
|
125
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// ../../utilities/core/src/guard.ts
|
|
2
|
+
var isArray = (v) => Array.isArray(v);
|
|
3
|
+
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
4
|
+
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
5
|
+
|
|
6
|
+
// ../../utilities/dom/src/platform.ts
|
|
7
|
+
var isDom = () => typeof window !== "undefined";
|
|
8
|
+
function getPlatform() {
|
|
9
|
+
var _a;
|
|
10
|
+
const agent = navigator.userAgentData;
|
|
11
|
+
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
12
|
+
}
|
|
13
|
+
var pt = (v) => isDom() && v.test(getPlatform());
|
|
14
|
+
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
15
|
+
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
16
|
+
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
17
|
+
var isIos = () => isApple() && !isMac();
|
|
18
|
+
|
|
19
|
+
// ../../utilities/dom/src/event.ts
|
|
20
|
+
function getNativeEvent(e) {
|
|
21
|
+
var _a;
|
|
22
|
+
return (_a = e.nativeEvent) != null ? _a : e;
|
|
23
|
+
}
|
|
24
|
+
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
25
|
+
var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
|
|
26
|
+
var supportsMouseEvent = () => isDom() && window.onmousedown === null;
|
|
27
|
+
var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
|
|
28
|
+
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
29
|
+
var isLeftClick = (v) => v.button === 0;
|
|
30
|
+
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
31
|
+
|
|
32
|
+
export {
|
|
33
|
+
isObject,
|
|
34
|
+
hasProp,
|
|
35
|
+
isIos,
|
|
36
|
+
getNativeEvent,
|
|
37
|
+
supportsPointerEvent,
|
|
38
|
+
supportsTouchEvent,
|
|
39
|
+
supportsMouseEvent,
|
|
40
|
+
isMouseEvent,
|
|
41
|
+
isTouchEvent,
|
|
42
|
+
isLeftClick,
|
|
43
|
+
isModifiedEvent
|
|
44
|
+
};
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parts
|
|
3
|
+
} from "./chunk-3Y7IIPR5.mjs";
|
|
4
|
+
import {
|
|
5
|
+
getNativeEvent,
|
|
6
|
+
isLeftClick,
|
|
7
|
+
isModifiedEvent,
|
|
8
|
+
isTouchEvent
|
|
9
|
+
} from "./chunk-SGCWELVB.mjs";
|
|
10
|
+
import {
|
|
11
|
+
dom
|
|
12
|
+
} from "./chunk-MR2MUD77.mjs";
|
|
13
|
+
import {
|
|
14
|
+
percentToValue,
|
|
15
|
+
valueToPercent
|
|
16
|
+
} from "./chunk-GBYBRQZL.mjs";
|
|
17
|
+
|
|
18
|
+
// ../../utilities/dom/src/attrs.ts
|
|
19
|
+
var dataAttr = (guard) => {
|
|
20
|
+
return guard ? "" : void 0;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// ../../utilities/dom/src/get-event-point.ts
|
|
24
|
+
var fallback = {
|
|
25
|
+
pageX: 0,
|
|
26
|
+
pageY: 0,
|
|
27
|
+
clientX: 0,
|
|
28
|
+
clientY: 0
|
|
29
|
+
};
|
|
30
|
+
function getEventPoint(event, type = "page") {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event;
|
|
33
|
+
return { x: point[`${type}X`], y: point[`${type}Y`] };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ../../utilities/dom/src/keyboard-event.ts
|
|
37
|
+
var rtlKeyMap = {
|
|
38
|
+
ArrowLeft: "ArrowRight",
|
|
39
|
+
ArrowRight: "ArrowLeft"
|
|
40
|
+
};
|
|
41
|
+
var sameKeyMap = {
|
|
42
|
+
Up: "ArrowUp",
|
|
43
|
+
Down: "ArrowDown",
|
|
44
|
+
Esc: "Escape",
|
|
45
|
+
" ": "Space",
|
|
46
|
+
",": "Comma",
|
|
47
|
+
Left: "ArrowLeft",
|
|
48
|
+
Right: "ArrowRight"
|
|
49
|
+
};
|
|
50
|
+
function getEventKey(event, options = {}) {
|
|
51
|
+
var _a;
|
|
52
|
+
const { dir = "ltr", orientation = "horizontal" } = options;
|
|
53
|
+
let { key } = event;
|
|
54
|
+
key = (_a = sameKeyMap[key]) != null ? _a : key;
|
|
55
|
+
const isRtl = dir === "rtl" && orientation === "horizontal";
|
|
56
|
+
if (isRtl && key in rtlKeyMap) {
|
|
57
|
+
key = rtlKeyMap[key];
|
|
58
|
+
}
|
|
59
|
+
return key;
|
|
60
|
+
}
|
|
61
|
+
var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
|
|
62
|
+
var ARROW_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
|
|
63
|
+
function getEventStep(event) {
|
|
64
|
+
if (event.ctrlKey || event.metaKey) {
|
|
65
|
+
return 0.1;
|
|
66
|
+
} else {
|
|
67
|
+
const isPageKey = PAGE_KEYS.has(event.key);
|
|
68
|
+
const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.has(event.key);
|
|
69
|
+
return isSkipKey ? 10 : 1;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/slider.connect.ts
|
|
74
|
+
function connect(state, send, normalize) {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
const ariaLabel = state.context["aria-label"];
|
|
77
|
+
const ariaLabelledBy = state.context["aria-labelledby"];
|
|
78
|
+
const ariaValueText = (_b = (_a = state.context).getAriaValueText) == null ? void 0 : _b.call(_a, state.context.value);
|
|
79
|
+
const isFocused = state.matches("focus");
|
|
80
|
+
const isDragging = state.matches("dragging");
|
|
81
|
+
const isDisabled = state.context.disabled;
|
|
82
|
+
const isInteractive = state.context.isInteractive;
|
|
83
|
+
const isInvalid = state.context.invalid;
|
|
84
|
+
return {
|
|
85
|
+
isFocused,
|
|
86
|
+
isDragging,
|
|
87
|
+
value: state.context.value,
|
|
88
|
+
percent: valueToPercent(state.context.value, state.context),
|
|
89
|
+
setValue(value) {
|
|
90
|
+
send({ type: "SET_VALUE", value });
|
|
91
|
+
},
|
|
92
|
+
getPercentValue(percent) {
|
|
93
|
+
return percentToValue(percent, state.context);
|
|
94
|
+
},
|
|
95
|
+
focus() {
|
|
96
|
+
var _a2;
|
|
97
|
+
(_a2 = dom.getThumbEl(state.context)) == null ? void 0 : _a2.focus();
|
|
98
|
+
},
|
|
99
|
+
increment() {
|
|
100
|
+
send("INCREMENT");
|
|
101
|
+
},
|
|
102
|
+
decrement() {
|
|
103
|
+
send("DECREMENT");
|
|
104
|
+
},
|
|
105
|
+
rootProps: normalize.element({
|
|
106
|
+
...parts.root.attrs,
|
|
107
|
+
"data-disabled": dataAttr(isDisabled),
|
|
108
|
+
"data-focus": dataAttr(isFocused),
|
|
109
|
+
"data-orientation": state.context.orientation,
|
|
110
|
+
"data-invalid": dataAttr(isInvalid),
|
|
111
|
+
id: dom.getRootId(state.context),
|
|
112
|
+
dir: state.context.dir,
|
|
113
|
+
style: dom.getRootStyle(state.context)
|
|
114
|
+
}),
|
|
115
|
+
labelProps: normalize.label({
|
|
116
|
+
...parts.label.attrs,
|
|
117
|
+
"data-disabled": dataAttr(isDisabled),
|
|
118
|
+
"data-invalid": dataAttr(isInvalid),
|
|
119
|
+
"data-focus": dataAttr(isFocused),
|
|
120
|
+
id: dom.getLabelId(state.context),
|
|
121
|
+
htmlFor: dom.getHiddenInputId(state.context),
|
|
122
|
+
onClick(event) {
|
|
123
|
+
var _a2;
|
|
124
|
+
if (!isInteractive)
|
|
125
|
+
return;
|
|
126
|
+
event.preventDefault();
|
|
127
|
+
(_a2 = dom.getThumbEl(state.context)) == null ? void 0 : _a2.focus();
|
|
128
|
+
},
|
|
129
|
+
style: dom.getLabelStyle()
|
|
130
|
+
}),
|
|
131
|
+
thumbProps: normalize.element({
|
|
132
|
+
...parts.thumb.attrs,
|
|
133
|
+
id: dom.getThumbId(state.context),
|
|
134
|
+
"data-disabled": dataAttr(isDisabled),
|
|
135
|
+
"data-orientation": state.context.orientation,
|
|
136
|
+
"data-focus": dataAttr(isFocused),
|
|
137
|
+
draggable: false,
|
|
138
|
+
"aria-invalid": isInvalid || void 0,
|
|
139
|
+
"data-invalid": dataAttr(isInvalid),
|
|
140
|
+
"aria-disabled": isDisabled || void 0,
|
|
141
|
+
"aria-label": ariaLabel,
|
|
142
|
+
"aria-labelledby": ariaLabel ? void 0 : ariaLabelledBy != null ? ariaLabelledBy : dom.getLabelId(state.context),
|
|
143
|
+
"aria-orientation": state.context.orientation,
|
|
144
|
+
"aria-valuemax": state.context.max,
|
|
145
|
+
"aria-valuemin": state.context.min,
|
|
146
|
+
"aria-valuenow": state.context.value,
|
|
147
|
+
"aria-valuetext": ariaValueText,
|
|
148
|
+
role: "slider",
|
|
149
|
+
tabIndex: isDisabled ? void 0 : 0,
|
|
150
|
+
onBlur() {
|
|
151
|
+
if (!isInteractive)
|
|
152
|
+
return;
|
|
153
|
+
send("BLUR");
|
|
154
|
+
},
|
|
155
|
+
onFocus() {
|
|
156
|
+
if (!isInteractive)
|
|
157
|
+
return;
|
|
158
|
+
send("FOCUS");
|
|
159
|
+
},
|
|
160
|
+
onKeyDown(event) {
|
|
161
|
+
if (!isInteractive)
|
|
162
|
+
return;
|
|
163
|
+
const step = getEventStep(event) * state.context.step;
|
|
164
|
+
let prevent = true;
|
|
165
|
+
const keyMap = {
|
|
166
|
+
ArrowUp() {
|
|
167
|
+
send({ type: "ARROW_UP", step });
|
|
168
|
+
prevent = state.context.isVertical;
|
|
169
|
+
},
|
|
170
|
+
ArrowDown() {
|
|
171
|
+
send({ type: "ARROW_DOWN", step });
|
|
172
|
+
prevent = state.context.isVertical;
|
|
173
|
+
},
|
|
174
|
+
ArrowLeft() {
|
|
175
|
+
send({ type: "ARROW_LEFT", step });
|
|
176
|
+
prevent = state.context.isHorizontal;
|
|
177
|
+
},
|
|
178
|
+
ArrowRight() {
|
|
179
|
+
send({ type: "ARROW_RIGHT", step });
|
|
180
|
+
prevent = state.context.isHorizontal;
|
|
181
|
+
},
|
|
182
|
+
PageUp() {
|
|
183
|
+
send({ type: "PAGE_UP", step });
|
|
184
|
+
},
|
|
185
|
+
PageDown() {
|
|
186
|
+
send({ type: "PAGE_DOWN", step });
|
|
187
|
+
},
|
|
188
|
+
Home() {
|
|
189
|
+
send("HOME");
|
|
190
|
+
},
|
|
191
|
+
End() {
|
|
192
|
+
send("END");
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
const key = getEventKey(event, state.context);
|
|
196
|
+
const exec = keyMap[key];
|
|
197
|
+
if (!exec)
|
|
198
|
+
return;
|
|
199
|
+
exec(event);
|
|
200
|
+
if (prevent) {
|
|
201
|
+
event.preventDefault();
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
style: dom.getThumbStyle(state.context)
|
|
205
|
+
}),
|
|
206
|
+
hiddenInputProps: normalize.input({
|
|
207
|
+
...parts.hiddenInput.attrs,
|
|
208
|
+
type: "text",
|
|
209
|
+
defaultValue: state.context.value,
|
|
210
|
+
name: state.context.name,
|
|
211
|
+
form: state.context.form,
|
|
212
|
+
id: dom.getHiddenInputId(state.context),
|
|
213
|
+
hidden: true
|
|
214
|
+
}),
|
|
215
|
+
outputProps: normalize.output({
|
|
216
|
+
...parts.output.attrs,
|
|
217
|
+
"data-disabled": dataAttr(isDisabled),
|
|
218
|
+
"data-invalid": dataAttr(isInvalid),
|
|
219
|
+
id: dom.getOutputId(state.context),
|
|
220
|
+
htmlFor: dom.getHiddenInputId(state.context),
|
|
221
|
+
"aria-live": "off"
|
|
222
|
+
}),
|
|
223
|
+
trackProps: normalize.element({
|
|
224
|
+
...parts.track.attrs,
|
|
225
|
+
id: dom.getTrackId(state.context),
|
|
226
|
+
"data-disabled": dataAttr(isDisabled),
|
|
227
|
+
"data-focus": dataAttr(isFocused),
|
|
228
|
+
"data-invalid": dataAttr(isInvalid),
|
|
229
|
+
"data-orientation": state.context.orientation,
|
|
230
|
+
style: dom.getTrackStyle()
|
|
231
|
+
}),
|
|
232
|
+
rangeProps: normalize.element({
|
|
233
|
+
...parts.range.attrs,
|
|
234
|
+
id: dom.getRangeId(state.context),
|
|
235
|
+
"data-focus": dataAttr(isFocused),
|
|
236
|
+
"data-invalid": dataAttr(isInvalid),
|
|
237
|
+
"data-disabled": dataAttr(isDisabled),
|
|
238
|
+
"data-orientation": state.context.orientation,
|
|
239
|
+
style: dom.getRangeStyle(state.context)
|
|
240
|
+
}),
|
|
241
|
+
controlProps: normalize.element({
|
|
242
|
+
...parts.control.attrs,
|
|
243
|
+
id: dom.getControlId(state.context),
|
|
244
|
+
"data-disabled": dataAttr(isDisabled),
|
|
245
|
+
"data-invalid": dataAttr(isInvalid),
|
|
246
|
+
"data-orientation": state.context.orientation,
|
|
247
|
+
"data-focus": dataAttr(isFocused),
|
|
248
|
+
onPointerDown(event) {
|
|
249
|
+
if (!isInteractive)
|
|
250
|
+
return;
|
|
251
|
+
const evt = getNativeEvent(event);
|
|
252
|
+
if (!isLeftClick(evt) || isModifiedEvent(evt))
|
|
253
|
+
return;
|
|
254
|
+
const point = getEventPoint(evt);
|
|
255
|
+
send({ type: "POINTER_DOWN", point });
|
|
256
|
+
event.preventDefault();
|
|
257
|
+
event.stopPropagation();
|
|
258
|
+
},
|
|
259
|
+
style: dom.getControlStyle()
|
|
260
|
+
}),
|
|
261
|
+
markerGroupProps: normalize.element({
|
|
262
|
+
...parts.markerGroup.attrs,
|
|
263
|
+
role: "presentation",
|
|
264
|
+
"aria-hidden": true,
|
|
265
|
+
"data-orientation": state.context.orientation,
|
|
266
|
+
style: dom.getMarkerGroupStyle()
|
|
267
|
+
}),
|
|
268
|
+
getMarkerProps({ value }) {
|
|
269
|
+
const percent = valueToPercent(value, state.context);
|
|
270
|
+
const style = dom.getMarkerStyle(state.context, percent);
|
|
271
|
+
const markerState = value > state.context.value ? "over-value" : value < state.context.value ? "under-value" : "at-value";
|
|
272
|
+
return normalize.element({
|
|
273
|
+
...parts.marker.attrs,
|
|
274
|
+
role: "presentation",
|
|
275
|
+
"data-orientation": state.context.orientation,
|
|
276
|
+
id: dom.getMarkerId(state.context, value),
|
|
277
|
+
"data-value": value,
|
|
278
|
+
"data-disabled": dataAttr(isDisabled),
|
|
279
|
+
"data-state": markerState,
|
|
280
|
+
style
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export {
|
|
287
|
+
connect
|
|
288
|
+
};
|