@radix-ui/react-slider 0.1.5-rc.5 → 0.1.5-rc.6
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.map +1 -1
- package/dist/index.js +604 -1
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +585 -1
- package/dist/index.module.js.map +1 -1
- package/package.json +10 -10
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;AAeA,iBAAiB,KAAK,GAAG,KAAK,CAAC;AAoB/B,OAAA,wFAEE,CAAC;AAeH,4BACE,SAAQ,IAAI,CACV,qBAAqB,GAAG,mBAAmB,EAC3C,MAAM,6BAA6B,GAAG,cAAc,CACrD;IACD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,cAAc,CAAC,kBAAkB,CAAC,CAAC;IACvD,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,aAAa,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;CACvC;AAED,OAAA,MAAM,2FA4GL,CAAC;AAoBF,qCAAqC;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,WAAW,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,aAAa,CAAC,KAAK,EAAE,MAAM,aAAa,GAAG,IAAI,CAAC;IAChD,YAAY,CAAC,KAAK,EAAE,MAAM,aAAa,GAAG,IAAI,CAAC;IAC/C,aAAa,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,aAAa,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CAC9E,CAAC;AACF,gCACE,SAAQ,IAAI,CAAC,eAAe,EAAE,MAAM,sBAAsB,CAAC,EACzD,6BAA6B;CAAG;AAGpC,+BAAgC,SAAQ,sBAAsB;IAC5D,GAAG,CAAC,EAAE,SAAS,CAAC;CACjB;AA8DD,6BAA8B,SAAQ,sBAAsB;CAAG;AA2D/D,yBAAyB,MAAM,wBAAwB,CAAC,OAAO,UAAU,GAAG,CAAC,CAAC;AAC9E,8BAA8B;IAC5B,YAAY,CAAC,KAAK,EAAE,MAAM,YAAY,GAAG,IAAI,CAAC;IAC9C,WAAW,CAAC,KAAK,EAAE,MAAM,YAAY,GAAG,IAAI,CAAC;IAC7C,UAAU,CAAC,KAAK,EAAE,MAAM,YAAY,GAAG,IAAI,CAAC;IAC5C,aAAa,CAAC,KAAK,EAAE,MAAM,aAAa,GAAG,IAAI,CAAC;IAChD,YAAY,CAAC,KAAK,EAAE,MAAM,aAAa,GAAG,IAAI,CAAC;IAC/C,aAAa,CAAC,KAAK,EAAE,MAAM,aAAa,GAAG,IAAI,CAAC;CACjD,CAAC;AACF,yBAA0B,SAAQ,iBAAiB,EAAE,sBAAsB;CAAG;AAuE9E,0BAA0B,MAAM,wBAAwB,CAAC,OAAO,UAAU,IAAI,CAAC,CAAC;AAChF,iCAA2B,SAAQ,kBAAkB;CAAG;AAExD,OAAA,MAAM,qGAaL,CAAC;AAWF,iCAA2B,SAAQ,kBAAkB;CAAG;AAExD,OAAA,MAAM,qGA4BL,CAAC;AAWF,iCAA2B,SAAQ,IAAI,CAAC,oBAAoB,EAAE,OAAO,CAAC;CAAG;AAEzE,OAAA,MAAM,qGAWL,CAAC;AAGF,8BAA+B,SAAQ,kBAAkB;IACvD,KAAK,EAAE,MAAM,CAAC;CACf;AA0MD,OAAA,MAAM,yFAAa,CAAC;AACpB,OAAA,MAAM,+FAAmB,CAAC;AAC1B,OAAA,MAAM,+FAAmB,CAAC;AAC1B,OAAA,MAAM,+FAAmB,CAAC","sources":["packages/react/slider/src/packages/react/slider/src/Slider.tsx","packages/react/slider/src/packages/react/slider/src/index.ts","packages/react/slider/src/index.ts"],"sourcesContent":[null,null,"export * from './Slider';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,605 @@
|
|
|
1
|
-
var
|
|
1
|
+
var $inrcs$babelruntimehelpersextends = require("@babel/runtime/helpers/extends");
|
|
2
|
+
var $inrcs$react = require("react");
|
|
3
|
+
var $inrcs$radixuinumber = require("@radix-ui/number");
|
|
4
|
+
var $inrcs$radixuiprimitive = require("@radix-ui/primitive");
|
|
5
|
+
var $inrcs$radixuireactcomposerefs = require("@radix-ui/react-compose-refs");
|
|
6
|
+
var $inrcs$radixuireactcontext = require("@radix-ui/react-context");
|
|
7
|
+
var $inrcs$radixuireactusecontrollablestate = require("@radix-ui/react-use-controllable-state");
|
|
8
|
+
var $inrcs$radixuireactdirection = require("@radix-ui/react-direction");
|
|
9
|
+
var $inrcs$radixuireactuseprevious = require("@radix-ui/react-use-previous");
|
|
10
|
+
var $inrcs$radixuireactusesize = require("@radix-ui/react-use-size");
|
|
11
|
+
var $inrcs$radixuireactprimitive = require("@radix-ui/react-primitive");
|
|
12
|
+
var $inrcs$radixuireactcollection = require("@radix-ui/react-collection");
|
|
13
|
+
|
|
14
|
+
function $parcel$exportWildcard(dest, source) {
|
|
15
|
+
Object.keys(source).forEach(function(key) {
|
|
16
|
+
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
Object.defineProperty(dest, key, {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function get() {
|
|
23
|
+
return source[key];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return dest;
|
|
29
|
+
}
|
|
30
|
+
function $parcel$interopDefault(a) {
|
|
31
|
+
return a && a.__esModule ? a.default : a;
|
|
32
|
+
}
|
|
33
|
+
function $parcel$export(e, n, v, s) {
|
|
34
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
35
|
+
}
|
|
36
|
+
var $1791bb30e2e418d5$exports = {};
|
|
37
|
+
|
|
38
|
+
$parcel$export($1791bb30e2e418d5$exports, "createSliderScope", () => $1791bb30e2e418d5$export$ef72632d7b901f97);
|
|
39
|
+
$parcel$export($1791bb30e2e418d5$exports, "Slider", () => $1791bb30e2e418d5$export$472062a354075cee);
|
|
40
|
+
$parcel$export($1791bb30e2e418d5$exports, "SliderTrack", () => $1791bb30e2e418d5$export$105594979f116971);
|
|
41
|
+
$parcel$export($1791bb30e2e418d5$exports, "SliderRange", () => $1791bb30e2e418d5$export$a5cf38a7a000fe77);
|
|
42
|
+
$parcel$export($1791bb30e2e418d5$exports, "SliderThumb", () => $1791bb30e2e418d5$export$2c1b491743890dec);
|
|
43
|
+
$parcel$export($1791bb30e2e418d5$exports, "Root", () => $1791bb30e2e418d5$export$be92b6f5f03c0fe9);
|
|
44
|
+
$parcel$export($1791bb30e2e418d5$exports, "Track", () => $1791bb30e2e418d5$export$13921ac0cc260818);
|
|
45
|
+
$parcel$export($1791bb30e2e418d5$exports, "Range", () => $1791bb30e2e418d5$export$9a58ef0d7ad3278c);
|
|
46
|
+
$parcel$export($1791bb30e2e418d5$exports, "Thumb", () => $1791bb30e2e418d5$export$6521433ed15a34db);
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
const $1791bb30e2e418d5$var$PAGE_KEYS = [
|
|
60
|
+
'PageUp',
|
|
61
|
+
'PageDown'
|
|
62
|
+
];
|
|
63
|
+
const $1791bb30e2e418d5$var$ARROW_KEYS = [
|
|
64
|
+
'ArrowUp',
|
|
65
|
+
'ArrowDown',
|
|
66
|
+
'ArrowLeft',
|
|
67
|
+
'ArrowRight'
|
|
68
|
+
];
|
|
69
|
+
const $1791bb30e2e418d5$var$BACK_KEYS = {
|
|
70
|
+
ltr: [
|
|
71
|
+
'ArrowDown',
|
|
72
|
+
'Home',
|
|
73
|
+
'ArrowLeft',
|
|
74
|
+
'PageDown'
|
|
75
|
+
],
|
|
76
|
+
rtl: [
|
|
77
|
+
'ArrowDown',
|
|
78
|
+
'Home',
|
|
79
|
+
'ArrowRight',
|
|
80
|
+
'PageDown'
|
|
81
|
+
]
|
|
82
|
+
};
|
|
83
|
+
/* -------------------------------------------------------------------------------------------------
|
|
84
|
+
* Slider
|
|
85
|
+
* -----------------------------------------------------------------------------------------------*/ const $1791bb30e2e418d5$var$SLIDER_NAME = 'Slider';
|
|
86
|
+
const [$1791bb30e2e418d5$var$Collection, $1791bb30e2e418d5$var$useCollection, $1791bb30e2e418d5$var$createCollectionScope] = $inrcs$radixuireactcollection.createCollection($1791bb30e2e418d5$var$SLIDER_NAME);
|
|
87
|
+
const [$1791bb30e2e418d5$var$createSliderContext, $1791bb30e2e418d5$export$ef72632d7b901f97] = $inrcs$radixuireactcontext.createContextScope($1791bb30e2e418d5$var$SLIDER_NAME, [
|
|
88
|
+
$1791bb30e2e418d5$var$createCollectionScope
|
|
89
|
+
]);
|
|
90
|
+
const [$1791bb30e2e418d5$var$SliderProvider, $1791bb30e2e418d5$var$useSliderContext] = $1791bb30e2e418d5$var$createSliderContext($1791bb30e2e418d5$var$SLIDER_NAME);
|
|
91
|
+
const $1791bb30e2e418d5$export$472062a354075cee = /*#__PURE__*/ $inrcs$react.forwardRef((props, forwardedRef)=>{
|
|
92
|
+
const { name: name , min: min = 0 , max: max = 100 , step: step = 1 , orientation: orientation = 'horizontal' , disabled: disabled = false , minStepsBetweenThumbs: minStepsBetweenThumbs = 0 , defaultValue: defaultValue = [
|
|
93
|
+
min
|
|
94
|
+
] , value: value1 , onValueChange: onValueChange = ()=>{} , ...sliderProps } = props;
|
|
95
|
+
const [slider, setSlider] = $inrcs$react.useState(null);
|
|
96
|
+
const composedRefs = $inrcs$radixuireactcomposerefs.useComposedRefs(forwardedRef, (node)=>setSlider(node)
|
|
97
|
+
);
|
|
98
|
+
const thumbRefs = $inrcs$react.useRef(new Set());
|
|
99
|
+
const valueIndexToChangeRef = $inrcs$react.useRef(0);
|
|
100
|
+
const isHorizontal = orientation === 'horizontal'; // We set this to true by default so that events bubble to forms without JS (SSR)
|
|
101
|
+
const isFormControl = slider ? Boolean(slider.closest('form')) : true;
|
|
102
|
+
const SliderOrientation = isHorizontal ? $1791bb30e2e418d5$var$SliderHorizontal : $1791bb30e2e418d5$var$SliderVertical;
|
|
103
|
+
const [values = [], setValues] = $inrcs$radixuireactusecontrollablestate.useControllableState({
|
|
104
|
+
prop: value1,
|
|
105
|
+
defaultProp: defaultValue,
|
|
106
|
+
onChange: (value)=>{
|
|
107
|
+
var _thumbs$valueIndexToC;
|
|
108
|
+
const thumbs = [
|
|
109
|
+
...thumbRefs.current
|
|
110
|
+
];
|
|
111
|
+
(_thumbs$valueIndexToC = thumbs[valueIndexToChangeRef.current]) === null || _thumbs$valueIndexToC === void 0 || _thumbs$valueIndexToC.focus();
|
|
112
|
+
onValueChange(value);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
function handleSlideStart(value) {
|
|
116
|
+
const closestIndex = $1791bb30e2e418d5$var$getClosestValueIndex(values, value);
|
|
117
|
+
updateValues(value, closestIndex);
|
|
118
|
+
}
|
|
119
|
+
function handleSlideMove(value) {
|
|
120
|
+
updateValues(value, valueIndexToChangeRef.current);
|
|
121
|
+
}
|
|
122
|
+
function updateValues(value, atIndex) {
|
|
123
|
+
const decimalCount = $1791bb30e2e418d5$var$getDecimalCount(step);
|
|
124
|
+
const snapToStep = $1791bb30e2e418d5$var$roundValue(Math.round((value - min) / step) * step + min, decimalCount);
|
|
125
|
+
const nextValue = $inrcs$radixuinumber.clamp(snapToStep, [
|
|
126
|
+
min,
|
|
127
|
+
max
|
|
128
|
+
]);
|
|
129
|
+
setValues((prevValues = [])=>{
|
|
130
|
+
const nextValues = $1791bb30e2e418d5$var$getNextSortedValues(prevValues, nextValue, atIndex);
|
|
131
|
+
if ($1791bb30e2e418d5$var$hasMinStepsBetweenValues(nextValues, minStepsBetweenThumbs * step)) {
|
|
132
|
+
valueIndexToChangeRef.current = nextValues.indexOf(nextValue);
|
|
133
|
+
return String(nextValues) === String(prevValues) ? prevValues : nextValues;
|
|
134
|
+
} else return prevValues;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return /*#__PURE__*/ $inrcs$react.createElement($1791bb30e2e418d5$var$SliderProvider, {
|
|
138
|
+
scope: props.__scopeSlider,
|
|
139
|
+
disabled: disabled,
|
|
140
|
+
min: min,
|
|
141
|
+
max: max,
|
|
142
|
+
valueIndexToChangeRef: valueIndexToChangeRef,
|
|
143
|
+
thumbs: thumbRefs.current,
|
|
144
|
+
values: values,
|
|
145
|
+
orientation: orientation
|
|
146
|
+
}, /*#__PURE__*/ $inrcs$react.createElement($1791bb30e2e418d5$var$Collection.Provider, {
|
|
147
|
+
scope: props.__scopeSlider
|
|
148
|
+
}, /*#__PURE__*/ $inrcs$react.createElement($1791bb30e2e418d5$var$Collection.Slot, {
|
|
149
|
+
scope: props.__scopeSlider
|
|
150
|
+
}, /*#__PURE__*/ $inrcs$react.createElement(SliderOrientation, ($parcel$interopDefault($inrcs$babelruntimehelpersextends))({
|
|
151
|
+
"aria-disabled": disabled,
|
|
152
|
+
"data-disabled": disabled ? '' : undefined
|
|
153
|
+
}, sliderProps, {
|
|
154
|
+
ref: composedRefs,
|
|
155
|
+
min: min,
|
|
156
|
+
max: max,
|
|
157
|
+
onSlideStart: disabled ? undefined : handleSlideStart,
|
|
158
|
+
onSlideMove: disabled ? undefined : handleSlideMove,
|
|
159
|
+
onHomeKeyDown: ()=>!disabled && updateValues(min, 0)
|
|
160
|
+
,
|
|
161
|
+
onEndKeyDown: ()=>!disabled && updateValues(max, values.length - 1)
|
|
162
|
+
,
|
|
163
|
+
onStepKeyDown: ({ event: event , direction: stepDirection })=>{
|
|
164
|
+
if (!disabled) {
|
|
165
|
+
const isPageKey = $1791bb30e2e418d5$var$PAGE_KEYS.includes(event.key);
|
|
166
|
+
const isSkipKey = isPageKey || event.shiftKey && $1791bb30e2e418d5$var$ARROW_KEYS.includes(event.key);
|
|
167
|
+
const multiplier = isSkipKey ? 10 : 1;
|
|
168
|
+
const atIndex = valueIndexToChangeRef.current;
|
|
169
|
+
const value = values[atIndex];
|
|
170
|
+
const stepInDirection = step * multiplier * stepDirection;
|
|
171
|
+
updateValues(value + stepInDirection, atIndex);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
})))), isFormControl && values.map((value, index)=>/*#__PURE__*/ $inrcs$react.createElement($1791bb30e2e418d5$var$BubbleInput, {
|
|
175
|
+
key: index,
|
|
176
|
+
name: name ? name + (values.length > 1 ? '[]' : '') : undefined,
|
|
177
|
+
value: value
|
|
178
|
+
})
|
|
179
|
+
));
|
|
180
|
+
});
|
|
181
|
+
/*#__PURE__*/ Object.assign($1791bb30e2e418d5$export$472062a354075cee, {
|
|
182
|
+
displayName: $1791bb30e2e418d5$var$SLIDER_NAME
|
|
183
|
+
});
|
|
184
|
+
/* -------------------------------------------------------------------------------------------------
|
|
185
|
+
* SliderHorizontal
|
|
186
|
+
* -----------------------------------------------------------------------------------------------*/ const [$1791bb30e2e418d5$var$SliderOrientationProvider, $1791bb30e2e418d5$var$useSliderOrientationContext] = $1791bb30e2e418d5$var$createSliderContext($1791bb30e2e418d5$var$SLIDER_NAME, {
|
|
187
|
+
startEdge: 'left',
|
|
188
|
+
endEdge: 'right',
|
|
189
|
+
size: 'width',
|
|
190
|
+
direction: 1
|
|
191
|
+
});
|
|
192
|
+
const $1791bb30e2e418d5$var$SliderHorizontal = /*#__PURE__*/ $inrcs$react.forwardRef((props, forwardedRef)=>{
|
|
193
|
+
const { min: min , max: max , dir: dir , onSlideStart: onSlideStart , onSlideMove: onSlideMove , onStepKeyDown: onStepKeyDown , ...sliderProps } = props;
|
|
194
|
+
const [slider, setSlider] = $inrcs$react.useState(null);
|
|
195
|
+
const composedRefs = $inrcs$radixuireactcomposerefs.useComposedRefs(forwardedRef, (node)=>setSlider(node)
|
|
196
|
+
);
|
|
197
|
+
const rectRef = $inrcs$react.useRef();
|
|
198
|
+
const direction = $inrcs$radixuireactdirection.useDirection(dir);
|
|
199
|
+
const isDirectionLTR = direction === 'ltr';
|
|
200
|
+
function getValueFromPointer(pointerPosition) {
|
|
201
|
+
const rect = rectRef.current || slider.getBoundingClientRect();
|
|
202
|
+
const input = [
|
|
203
|
+
0,
|
|
204
|
+
rect.width
|
|
205
|
+
];
|
|
206
|
+
const output = isDirectionLTR ? [
|
|
207
|
+
min,
|
|
208
|
+
max
|
|
209
|
+
] : [
|
|
210
|
+
max,
|
|
211
|
+
min
|
|
212
|
+
];
|
|
213
|
+
const value = $1791bb30e2e418d5$var$linearScale(input, output);
|
|
214
|
+
rectRef.current = rect;
|
|
215
|
+
return value(pointerPosition - rect.left);
|
|
216
|
+
}
|
|
217
|
+
return /*#__PURE__*/ $inrcs$react.createElement($1791bb30e2e418d5$var$SliderOrientationProvider, {
|
|
218
|
+
scope: props.__scopeSlider,
|
|
219
|
+
startEdge: isDirectionLTR ? 'left' : 'right',
|
|
220
|
+
endEdge: isDirectionLTR ? 'right' : 'left',
|
|
221
|
+
direction: isDirectionLTR ? 1 : -1,
|
|
222
|
+
size: "width"
|
|
223
|
+
}, /*#__PURE__*/ $inrcs$react.createElement($1791bb30e2e418d5$var$SliderImpl, ($parcel$interopDefault($inrcs$babelruntimehelpersextends))({
|
|
224
|
+
dir: direction,
|
|
225
|
+
"data-orientation": "horizontal"
|
|
226
|
+
}, sliderProps, {
|
|
227
|
+
ref: composedRefs,
|
|
228
|
+
style: {
|
|
229
|
+
...sliderProps.style,
|
|
230
|
+
['--radix-slider-thumb-transform']: 'translateX(-50%)'
|
|
231
|
+
},
|
|
232
|
+
onSlideStart: (event)=>{
|
|
233
|
+
const value = getValueFromPointer(event.clientX);
|
|
234
|
+
onSlideStart === null || onSlideStart === void 0 || onSlideStart(value);
|
|
235
|
+
},
|
|
236
|
+
onSlideMove: (event)=>{
|
|
237
|
+
const value = getValueFromPointer(event.clientX);
|
|
238
|
+
onSlideMove === null || onSlideMove === void 0 || onSlideMove(value);
|
|
239
|
+
},
|
|
240
|
+
onSlideEnd: ()=>rectRef.current = undefined
|
|
241
|
+
,
|
|
242
|
+
onStepKeyDown: (event)=>{
|
|
243
|
+
const isBackKey = $1791bb30e2e418d5$var$BACK_KEYS[direction].includes(event.key);
|
|
244
|
+
onStepKeyDown === null || onStepKeyDown === void 0 || onStepKeyDown({
|
|
245
|
+
event: event,
|
|
246
|
+
direction: isBackKey ? -1 : 1
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
})));
|
|
250
|
+
});
|
|
251
|
+
/* -------------------------------------------------------------------------------------------------
|
|
252
|
+
* SliderVertical
|
|
253
|
+
* -----------------------------------------------------------------------------------------------*/ const $1791bb30e2e418d5$var$SliderVertical = /*#__PURE__*/ $inrcs$react.forwardRef((props, forwardedRef)=>{
|
|
254
|
+
const { min: min , max: max , onSlideStart: onSlideStart , onSlideMove: onSlideMove , onStepKeyDown: onStepKeyDown , ...sliderProps } = props;
|
|
255
|
+
const sliderRef = $inrcs$react.useRef(null);
|
|
256
|
+
const ref = $inrcs$radixuireactcomposerefs.useComposedRefs(forwardedRef, sliderRef);
|
|
257
|
+
const rectRef = $inrcs$react.useRef();
|
|
258
|
+
function getValueFromPointer(pointerPosition) {
|
|
259
|
+
const rect = rectRef.current || sliderRef.current.getBoundingClientRect();
|
|
260
|
+
const input = [
|
|
261
|
+
0,
|
|
262
|
+
rect.height
|
|
263
|
+
];
|
|
264
|
+
const output = [
|
|
265
|
+
max,
|
|
266
|
+
min
|
|
267
|
+
];
|
|
268
|
+
const value = $1791bb30e2e418d5$var$linearScale(input, output);
|
|
269
|
+
rectRef.current = rect;
|
|
270
|
+
return value(pointerPosition - rect.top);
|
|
271
|
+
}
|
|
272
|
+
return /*#__PURE__*/ $inrcs$react.createElement($1791bb30e2e418d5$var$SliderOrientationProvider, {
|
|
273
|
+
scope: props.__scopeSlider,
|
|
274
|
+
startEdge: "bottom",
|
|
275
|
+
endEdge: "top",
|
|
276
|
+
size: "height",
|
|
277
|
+
direction: 1
|
|
278
|
+
}, /*#__PURE__*/ $inrcs$react.createElement($1791bb30e2e418d5$var$SliderImpl, ($parcel$interopDefault($inrcs$babelruntimehelpersextends))({
|
|
279
|
+
"data-orientation": "vertical"
|
|
280
|
+
}, sliderProps, {
|
|
281
|
+
ref: ref,
|
|
282
|
+
style: {
|
|
283
|
+
...sliderProps.style,
|
|
284
|
+
['--radix-slider-thumb-transform']: 'translateY(50%)'
|
|
285
|
+
},
|
|
286
|
+
onSlideStart: (event)=>{
|
|
287
|
+
const value = getValueFromPointer(event.clientY);
|
|
288
|
+
onSlideStart === null || onSlideStart === void 0 || onSlideStart(value);
|
|
289
|
+
},
|
|
290
|
+
onSlideMove: (event)=>{
|
|
291
|
+
const value = getValueFromPointer(event.clientY);
|
|
292
|
+
onSlideMove === null || onSlideMove === void 0 || onSlideMove(value);
|
|
293
|
+
},
|
|
294
|
+
onSlideEnd: ()=>rectRef.current = undefined
|
|
295
|
+
,
|
|
296
|
+
onStepKeyDown: (event)=>{
|
|
297
|
+
const isBackKey = $1791bb30e2e418d5$var$BACK_KEYS.ltr.includes(event.key);
|
|
298
|
+
onStepKeyDown === null || onStepKeyDown === void 0 || onStepKeyDown({
|
|
299
|
+
event: event,
|
|
300
|
+
direction: isBackKey ? -1 : 1
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
})));
|
|
304
|
+
});
|
|
305
|
+
/* -------------------------------------------------------------------------------------------------
|
|
306
|
+
* SliderImpl
|
|
307
|
+
* -----------------------------------------------------------------------------------------------*/ const $1791bb30e2e418d5$var$SliderImpl = /*#__PURE__*/ $inrcs$react.forwardRef((props, forwardedRef)=>{
|
|
308
|
+
const { __scopeSlider: __scopeSlider , onSlideStart: onSlideStart , onSlideMove: onSlideMove , onSlideEnd: onSlideEnd , onHomeKeyDown: onHomeKeyDown , onEndKeyDown: onEndKeyDown , onStepKeyDown: onStepKeyDown , ...sliderProps } = props;
|
|
309
|
+
const context = $1791bb30e2e418d5$var$useSliderContext($1791bb30e2e418d5$var$SLIDER_NAME, __scopeSlider);
|
|
310
|
+
return /*#__PURE__*/ $inrcs$react.createElement($inrcs$radixuireactprimitive.Primitive.span, ($parcel$interopDefault($inrcs$babelruntimehelpersextends))({}, sliderProps, {
|
|
311
|
+
ref: forwardedRef,
|
|
312
|
+
onKeyDown: $inrcs$radixuiprimitive.composeEventHandlers(props.onKeyDown, (event)=>{
|
|
313
|
+
if (event.key === 'Home') {
|
|
314
|
+
onHomeKeyDown(event); // Prevent scrolling to page start
|
|
315
|
+
event.preventDefault();
|
|
316
|
+
} else if (event.key === 'End') {
|
|
317
|
+
onEndKeyDown(event); // Prevent scrolling to page end
|
|
318
|
+
event.preventDefault();
|
|
319
|
+
} else if ($1791bb30e2e418d5$var$PAGE_KEYS.concat($1791bb30e2e418d5$var$ARROW_KEYS).includes(event.key)) {
|
|
320
|
+
onStepKeyDown(event); // Prevent scrolling for directional key presses
|
|
321
|
+
event.preventDefault();
|
|
322
|
+
}
|
|
323
|
+
}),
|
|
324
|
+
onPointerDown: $inrcs$radixuiprimitive.composeEventHandlers(props.onPointerDown, (event)=>{
|
|
325
|
+
const target = event.target;
|
|
326
|
+
target.setPointerCapture(event.pointerId); // Prevent browser focus behaviour because we focus a thumb manually when values change.
|
|
327
|
+
event.preventDefault(); // Touch devices have a delay before focusing so won't focus if touch immediately moves
|
|
328
|
+
// away from target (sliding). We want thumb to focus regardless.
|
|
329
|
+
if (context.thumbs.has(target)) target.focus();
|
|
330
|
+
else onSlideStart(event);
|
|
331
|
+
}),
|
|
332
|
+
onPointerMove: $inrcs$radixuiprimitive.composeEventHandlers(props.onPointerMove, (event)=>{
|
|
333
|
+
const target = event.target;
|
|
334
|
+
if (target.hasPointerCapture(event.pointerId)) onSlideMove(event);
|
|
335
|
+
}),
|
|
336
|
+
onPointerUp: $inrcs$radixuiprimitive.composeEventHandlers(props.onPointerUp, (event)=>{
|
|
337
|
+
const target = event.target;
|
|
338
|
+
if (target.hasPointerCapture(event.pointerId)) {
|
|
339
|
+
target.releasePointerCapture(event.pointerId);
|
|
340
|
+
onSlideEnd(event);
|
|
341
|
+
}
|
|
342
|
+
})
|
|
343
|
+
}));
|
|
344
|
+
});
|
|
345
|
+
/* -------------------------------------------------------------------------------------------------
|
|
346
|
+
* SliderTrack
|
|
347
|
+
* -----------------------------------------------------------------------------------------------*/ const $1791bb30e2e418d5$var$TRACK_NAME = 'SliderTrack';
|
|
348
|
+
const $1791bb30e2e418d5$export$105594979f116971 = /*#__PURE__*/ $inrcs$react.forwardRef((props, forwardedRef)=>{
|
|
349
|
+
const { __scopeSlider: __scopeSlider , ...trackProps } = props;
|
|
350
|
+
const context = $1791bb30e2e418d5$var$useSliderContext($1791bb30e2e418d5$var$TRACK_NAME, __scopeSlider);
|
|
351
|
+
return /*#__PURE__*/ $inrcs$react.createElement($inrcs$radixuireactprimitive.Primitive.span, ($parcel$interopDefault($inrcs$babelruntimehelpersextends))({
|
|
352
|
+
"data-disabled": context.disabled ? '' : undefined,
|
|
353
|
+
"data-orientation": context.orientation
|
|
354
|
+
}, trackProps, {
|
|
355
|
+
ref: forwardedRef
|
|
356
|
+
}));
|
|
357
|
+
});
|
|
358
|
+
/*#__PURE__*/ Object.assign($1791bb30e2e418d5$export$105594979f116971, {
|
|
359
|
+
displayName: $1791bb30e2e418d5$var$TRACK_NAME
|
|
360
|
+
});
|
|
361
|
+
/* -------------------------------------------------------------------------------------------------
|
|
362
|
+
* SliderRange
|
|
363
|
+
* -----------------------------------------------------------------------------------------------*/ const $1791bb30e2e418d5$var$RANGE_NAME = 'SliderRange';
|
|
364
|
+
const $1791bb30e2e418d5$export$a5cf38a7a000fe77 = /*#__PURE__*/ $inrcs$react.forwardRef((props, forwardedRef)=>{
|
|
365
|
+
const { __scopeSlider: __scopeSlider , ...rangeProps } = props;
|
|
366
|
+
const context = $1791bb30e2e418d5$var$useSliderContext($1791bb30e2e418d5$var$RANGE_NAME, __scopeSlider);
|
|
367
|
+
const orientation = $1791bb30e2e418d5$var$useSliderOrientationContext($1791bb30e2e418d5$var$RANGE_NAME, __scopeSlider);
|
|
368
|
+
const ref = $inrcs$react.useRef(null);
|
|
369
|
+
const composedRefs = $inrcs$radixuireactcomposerefs.useComposedRefs(forwardedRef, ref);
|
|
370
|
+
const valuesCount = context.values.length;
|
|
371
|
+
const percentages = context.values.map((value)=>$1791bb30e2e418d5$var$convertValueToPercentage(value, context.min, context.max)
|
|
372
|
+
);
|
|
373
|
+
const offsetStart = valuesCount > 1 ? Math.min(...percentages) : 0;
|
|
374
|
+
const offsetEnd = 100 - Math.max(...percentages);
|
|
375
|
+
return /*#__PURE__*/ $inrcs$react.createElement($inrcs$radixuireactprimitive.Primitive.span, ($parcel$interopDefault($inrcs$babelruntimehelpersextends))({
|
|
376
|
+
"data-orientation": context.orientation,
|
|
377
|
+
"data-disabled": context.disabled ? '' : undefined
|
|
378
|
+
}, rangeProps, {
|
|
379
|
+
ref: composedRefs,
|
|
380
|
+
style: {
|
|
381
|
+
...props.style,
|
|
382
|
+
[orientation.startEdge]: offsetStart + '%',
|
|
383
|
+
[orientation.endEdge]: offsetEnd + '%'
|
|
384
|
+
}
|
|
385
|
+
}));
|
|
386
|
+
});
|
|
387
|
+
/*#__PURE__*/ Object.assign($1791bb30e2e418d5$export$a5cf38a7a000fe77, {
|
|
388
|
+
displayName: $1791bb30e2e418d5$var$RANGE_NAME
|
|
389
|
+
});
|
|
390
|
+
/* -------------------------------------------------------------------------------------------------
|
|
391
|
+
* SliderThumb
|
|
392
|
+
* -----------------------------------------------------------------------------------------------*/ const $1791bb30e2e418d5$var$THUMB_NAME = 'SliderThumb';
|
|
393
|
+
const $1791bb30e2e418d5$export$2c1b491743890dec = /*#__PURE__*/ $inrcs$react.forwardRef((props, forwardedRef)=>{
|
|
394
|
+
const getItems = $1791bb30e2e418d5$var$useCollection(props.__scopeSlider);
|
|
395
|
+
const [thumb, setThumb] = $inrcs$react.useState(null);
|
|
396
|
+
const composedRefs = $inrcs$radixuireactcomposerefs.useComposedRefs(forwardedRef, (node)=>setThumb(node)
|
|
397
|
+
);
|
|
398
|
+
const index = $inrcs$react.useMemo(()=>thumb ? getItems().findIndex((item)=>item.ref.current === thumb
|
|
399
|
+
) : -1
|
|
400
|
+
, [
|
|
401
|
+
getItems,
|
|
402
|
+
thumb
|
|
403
|
+
]);
|
|
404
|
+
return /*#__PURE__*/ $inrcs$react.createElement($1791bb30e2e418d5$var$SliderThumbImpl, ($parcel$interopDefault($inrcs$babelruntimehelpersextends))({}, props, {
|
|
405
|
+
ref: composedRefs,
|
|
406
|
+
index: index
|
|
407
|
+
}));
|
|
408
|
+
});
|
|
409
|
+
const $1791bb30e2e418d5$var$SliderThumbImpl = /*#__PURE__*/ $inrcs$react.forwardRef((props, forwardedRef)=>{
|
|
410
|
+
const { __scopeSlider: __scopeSlider , index: index , ...thumbProps } = props;
|
|
411
|
+
const context = $1791bb30e2e418d5$var$useSliderContext($1791bb30e2e418d5$var$THUMB_NAME, __scopeSlider);
|
|
412
|
+
const orientation = $1791bb30e2e418d5$var$useSliderOrientationContext($1791bb30e2e418d5$var$THUMB_NAME, __scopeSlider);
|
|
413
|
+
const [thumb, setThumb] = $inrcs$react.useState(null);
|
|
414
|
+
const composedRefs = $inrcs$radixuireactcomposerefs.useComposedRefs(forwardedRef, (node)=>setThumb(node)
|
|
415
|
+
);
|
|
416
|
+
const size = $inrcs$radixuireactusesize.useSize(thumb); // We cast because index could be `-1` which would return undefined
|
|
417
|
+
const value = context.values[index];
|
|
418
|
+
const percent = value === undefined ? 0 : $1791bb30e2e418d5$var$convertValueToPercentage(value, context.min, context.max);
|
|
419
|
+
const label = $1791bb30e2e418d5$var$getLabel(index, context.values.length);
|
|
420
|
+
const orientationSize = size === null || size === void 0 ? void 0 : size[orientation.size];
|
|
421
|
+
const thumbInBoundsOffset = orientationSize ? $1791bb30e2e418d5$var$getThumbInBoundsOffset(orientationSize, percent, orientation.direction) : 0;
|
|
422
|
+
$inrcs$react.useEffect(()=>{
|
|
423
|
+
if (thumb) {
|
|
424
|
+
context.thumbs.add(thumb);
|
|
425
|
+
return ()=>{
|
|
426
|
+
context.thumbs.delete(thumb);
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
}, [
|
|
430
|
+
thumb,
|
|
431
|
+
context.thumbs
|
|
432
|
+
]);
|
|
433
|
+
return /*#__PURE__*/ $inrcs$react.createElement("span", {
|
|
434
|
+
style: {
|
|
435
|
+
transform: 'var(--radix-slider-thumb-transform)',
|
|
436
|
+
position: 'absolute',
|
|
437
|
+
[orientation.startEdge]: `calc(${percent}% + ${thumbInBoundsOffset}px)`
|
|
438
|
+
}
|
|
439
|
+
}, /*#__PURE__*/ $inrcs$react.createElement($1791bb30e2e418d5$var$Collection.ItemSlot, {
|
|
440
|
+
scope: props.__scopeSlider
|
|
441
|
+
}, /*#__PURE__*/ $inrcs$react.createElement($inrcs$radixuireactprimitive.Primitive.span, ($parcel$interopDefault($inrcs$babelruntimehelpersextends))({
|
|
442
|
+
role: "slider",
|
|
443
|
+
"aria-label": props['aria-label'] || label,
|
|
444
|
+
"aria-valuemin": context.min,
|
|
445
|
+
"aria-valuenow": value,
|
|
446
|
+
"aria-valuemax": context.max,
|
|
447
|
+
"aria-orientation": context.orientation,
|
|
448
|
+
"data-orientation": context.orientation,
|
|
449
|
+
"data-disabled": context.disabled ? '' : undefined,
|
|
450
|
+
tabIndex: context.disabled ? undefined : 0
|
|
451
|
+
}, thumbProps, {
|
|
452
|
+
ref: composedRefs,
|
|
453
|
+
style: value === undefined ? {
|
|
454
|
+
display: 'none'
|
|
455
|
+
} : props.style,
|
|
456
|
+
onFocus: $inrcs$radixuiprimitive.composeEventHandlers(props.onFocus, ()=>{
|
|
457
|
+
context.valueIndexToChangeRef.current = index;
|
|
458
|
+
})
|
|
459
|
+
}))));
|
|
460
|
+
});
|
|
461
|
+
/*#__PURE__*/ Object.assign($1791bb30e2e418d5$export$2c1b491743890dec, {
|
|
462
|
+
displayName: $1791bb30e2e418d5$var$THUMB_NAME
|
|
463
|
+
});
|
|
464
|
+
/* -----------------------------------------------------------------------------------------------*/ const $1791bb30e2e418d5$var$BubbleInput = (props)=>{
|
|
465
|
+
const { value: value , ...inputProps } = props;
|
|
466
|
+
const ref = $inrcs$react.useRef(null);
|
|
467
|
+
const prevValue = $inrcs$radixuireactuseprevious.usePrevious(value); // Bubble value change to parents (e.g form change event)
|
|
468
|
+
$inrcs$react.useEffect(()=>{
|
|
469
|
+
const input = ref.current;
|
|
470
|
+
const inputProto = window.HTMLInputElement.prototype;
|
|
471
|
+
const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'value');
|
|
472
|
+
const setValue = descriptor.set;
|
|
473
|
+
if (prevValue !== value && setValue) {
|
|
474
|
+
const event = new Event('input', {
|
|
475
|
+
bubbles: true
|
|
476
|
+
});
|
|
477
|
+
setValue.call(input, value);
|
|
478
|
+
input.dispatchEvent(event);
|
|
479
|
+
}
|
|
480
|
+
}, [
|
|
481
|
+
prevValue,
|
|
482
|
+
value
|
|
483
|
+
]);
|
|
484
|
+
/**
|
|
485
|
+
* We purposefully do not use `type="hidden"` here otherwise forms that
|
|
486
|
+
* wrap it will not be able to access its value via the FormData API.
|
|
487
|
+
*
|
|
488
|
+
* We purposefully do not add the `value` attribute here to allow the value
|
|
489
|
+
* to be set programatically and bubble to any parent form `onChange` event.
|
|
490
|
+
* Adding the `value` will cause React to consider the programatic
|
|
491
|
+
* dispatch a duplicate and it will get swallowed.
|
|
492
|
+
*/ return /*#__PURE__*/ $inrcs$react.createElement("input", ($parcel$interopDefault($inrcs$babelruntimehelpersextends))({
|
|
493
|
+
style: {
|
|
494
|
+
display: 'none'
|
|
495
|
+
}
|
|
496
|
+
}, inputProps, {
|
|
497
|
+
ref: ref,
|
|
498
|
+
defaultValue: value
|
|
499
|
+
}));
|
|
500
|
+
};
|
|
501
|
+
function $1791bb30e2e418d5$var$getNextSortedValues(prevValues = [], nextValue, atIndex) {
|
|
502
|
+
const nextValues = [
|
|
503
|
+
...prevValues
|
|
504
|
+
];
|
|
505
|
+
nextValues[atIndex] = nextValue;
|
|
506
|
+
return nextValues.sort((a, b)=>a - b
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
function $1791bb30e2e418d5$var$convertValueToPercentage(value, min, max) {
|
|
510
|
+
const maxSteps = max - min;
|
|
511
|
+
const percentPerStep = 100 / maxSteps;
|
|
512
|
+
return percentPerStep * (value - min);
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Returns a label for each thumb when there are two or more thumbs
|
|
516
|
+
*/ function $1791bb30e2e418d5$var$getLabel(index, totalValues) {
|
|
517
|
+
if (totalValues > 2) return `Value ${index + 1} of ${totalValues}`;
|
|
518
|
+
else if (totalValues === 2) return [
|
|
519
|
+
'Minimum',
|
|
520
|
+
'Maximum'
|
|
521
|
+
][index];
|
|
522
|
+
else return undefined;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Given a `values` array and a `nextValue`, determine which value in
|
|
526
|
+
* the array is closest to `nextValue` and return its index.
|
|
527
|
+
*
|
|
528
|
+
* @example
|
|
529
|
+
* // returns 1
|
|
530
|
+
* getClosestValueIndex([10, 30], 25);
|
|
531
|
+
*/ function $1791bb30e2e418d5$var$getClosestValueIndex(values, nextValue) {
|
|
532
|
+
if (values.length === 1) return 0;
|
|
533
|
+
const distances = values.map((value)=>Math.abs(value - nextValue)
|
|
534
|
+
);
|
|
535
|
+
const closestDistance = Math.min(...distances);
|
|
536
|
+
return distances.indexOf(closestDistance);
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Offsets the thumb centre point while sliding to ensure it remains
|
|
540
|
+
* within the bounds of the slider when reaching the edges
|
|
541
|
+
*/ function $1791bb30e2e418d5$var$getThumbInBoundsOffset(width, left, direction) {
|
|
542
|
+
const halfWidth = width / 2;
|
|
543
|
+
const halfPercent = 50;
|
|
544
|
+
const offset = $1791bb30e2e418d5$var$linearScale([
|
|
545
|
+
0,
|
|
546
|
+
halfPercent
|
|
547
|
+
], [
|
|
548
|
+
0,
|
|
549
|
+
halfWidth
|
|
550
|
+
]);
|
|
551
|
+
return (halfWidth - offset(left) * direction) * direction;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Gets an array of steps between each value.
|
|
555
|
+
*
|
|
556
|
+
* @example
|
|
557
|
+
* // returns [1, 9]
|
|
558
|
+
* getStepsBetweenValues([10, 11, 20]);
|
|
559
|
+
*/ function $1791bb30e2e418d5$var$getStepsBetweenValues(values) {
|
|
560
|
+
return values.slice(0, -1).map((value, index)=>values[index + 1] - value
|
|
561
|
+
);
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Verifies the minimum steps between all values is greater than or equal
|
|
565
|
+
* to the expected minimum steps.
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
* // returns false
|
|
569
|
+
* hasMinStepsBetweenValues([1,2,3], 2);
|
|
570
|
+
*
|
|
571
|
+
* @example
|
|
572
|
+
* // returns true
|
|
573
|
+
* hasMinStepsBetweenValues([1,2,3], 1);
|
|
574
|
+
*/ function $1791bb30e2e418d5$var$hasMinStepsBetweenValues(values, minStepsBetweenValues) {
|
|
575
|
+
if (minStepsBetweenValues > 0) {
|
|
576
|
+
const stepsBetweenValues = $1791bb30e2e418d5$var$getStepsBetweenValues(values);
|
|
577
|
+
const actualMinStepsBetweenValues = Math.min(...stepsBetweenValues);
|
|
578
|
+
return actualMinStepsBetweenValues >= minStepsBetweenValues;
|
|
579
|
+
}
|
|
580
|
+
return true;
|
|
581
|
+
} // https://github.com/tmcw-up-for-adoption/simple-linear-scale/blob/master/index.js
|
|
582
|
+
function $1791bb30e2e418d5$var$linearScale(input, output) {
|
|
583
|
+
return (value)=>{
|
|
584
|
+
if (input[0] === input[1] || output[0] === output[1]) return output[0];
|
|
585
|
+
const ratio = (output[1] - output[0]) / (input[1] - input[0]);
|
|
586
|
+
return output[0] + ratio * (value - input[0]);
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
function $1791bb30e2e418d5$var$getDecimalCount(value) {
|
|
590
|
+
return (String(value).split('.')[1] || '').length;
|
|
591
|
+
}
|
|
592
|
+
function $1791bb30e2e418d5$var$roundValue(value, decimalCount) {
|
|
593
|
+
const rounder = Math.pow(10, decimalCount);
|
|
594
|
+
return Math.round(value * rounder) / rounder;
|
|
595
|
+
}
|
|
596
|
+
const $1791bb30e2e418d5$export$be92b6f5f03c0fe9 = $1791bb30e2e418d5$export$472062a354075cee;
|
|
597
|
+
const $1791bb30e2e418d5$export$13921ac0cc260818 = $1791bb30e2e418d5$export$105594979f116971;
|
|
598
|
+
const $1791bb30e2e418d5$export$9a58ef0d7ad3278c = $1791bb30e2e418d5$export$a5cf38a7a000fe77;
|
|
599
|
+
const $1791bb30e2e418d5$export$6521433ed15a34db = $1791bb30e2e418d5$export$2c1b491743890dec;
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
$parcel$exportWildcard(module.exports, $1791bb30e2e418d5$exports);
|
|
603
|
+
|
|
604
|
+
|
|
2
605
|
//# sourceMappingURL=index.js.map
|