@zag-js/slider 0.2.7 → 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-YCRSV2RE.mjs → chunk-6D4ETNPG.mjs} +8 -8
- package/dist/{chunk-3JMGYHB3.mjs → chunk-A2ZK6G4F.mjs} +16 -10
- package/dist/chunk-DRAPR6JV.mjs +34 -0
- package/dist/{chunk-MR2MUD77.mjs → chunk-J5IGGBVE.mjs} +4 -24
- package/dist/{chunk-MXJ3RGFD.mjs → chunk-YREEXXZP.mjs} +19 -27
- package/dist/index.js +67 -121
- package/dist/index.mjs +5 -6
- package/dist/slider.connect.d.ts +1 -0
- package/dist/slider.connect.js +32 -115
- package/dist/slider.connect.mjs +3 -5
- package/dist/slider.dom.d.ts +0 -4
- package/dist/slider.dom.js +23 -112
- package/dist/slider.dom.mjs +2 -4
- package/dist/slider.machine.js +59 -119
- package/dist/slider.machine.mjs +4 -5
- package/dist/slider.style.js +19 -34
- package/dist/slider.style.mjs +1 -2
- package/dist/slider.types.d.ts +5 -0
- package/dist/slider.utils.d.ts +5 -8
- package/dist/slider.utils.js +30 -67
- package/dist/slider.utils.mjs +9 -4
- package/package.json +6 -6
- package/dist/chunk-FUTBDWTA.mjs +0 -33
- package/dist/chunk-GBYBRQZL.mjs +0 -56
package/dist/slider.connect.js
CHANGED
|
@@ -65,25 +65,7 @@ function defineDomHelpers(helpers) {
|
|
|
65
65
|
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
66
66
|
},
|
|
67
67
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
68
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
69
|
-
createEmitter: (ctx, target) => {
|
|
70
|
-
const win = dom2.getWin(ctx);
|
|
71
|
-
return function emit(evt, detail, options) {
|
|
72
|
-
const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
|
|
73
|
-
const eventName = `zag:${evt}`;
|
|
74
|
-
const init = { bubbles, cancelable, composed, detail };
|
|
75
|
-
const event = new win.CustomEvent(eventName, init);
|
|
76
|
-
target.dispatchEvent(event);
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
|
-
createListener: (target) => {
|
|
80
|
-
return function listen(evt, handler) {
|
|
81
|
-
const eventName = `zag:${evt}`;
|
|
82
|
-
const listener = (e) => handler(e);
|
|
83
|
-
target.addEventListener(eventName, listener);
|
|
84
|
-
return () => target.removeEventListener(eventName, listener);
|
|
85
|
-
};
|
|
86
|
-
}
|
|
68
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
87
69
|
};
|
|
88
70
|
return {
|
|
89
71
|
...dom2,
|
|
@@ -182,65 +164,8 @@ function getEventStep(event) {
|
|
|
182
164
|
}
|
|
183
165
|
}
|
|
184
166
|
|
|
185
|
-
//
|
|
186
|
-
|
|
187
|
-
let num = valueOf(v);
|
|
188
|
-
const p = 10 ** (t != null ? t : 10);
|
|
189
|
-
num = Math.round(num * p) / p;
|
|
190
|
-
return t ? num.toFixed(t) : v.toString();
|
|
191
|
-
}
|
|
192
|
-
var valueToPercent = (v, r) => (valueOf(v) - r.min) * 100 / (r.max - r.min);
|
|
193
|
-
var percentToValue = (v, r) => r.min + (r.max - r.min) * valueOf(v);
|
|
194
|
-
function clamp(v, o) {
|
|
195
|
-
return Math.min(Math.max(valueOf(v), o.min), o.max);
|
|
196
|
-
}
|
|
197
|
-
function countDecimals(value) {
|
|
198
|
-
if (!Number.isFinite(value))
|
|
199
|
-
return 0;
|
|
200
|
-
let e = 1, p = 0;
|
|
201
|
-
while (Math.round(value * e) / e !== value) {
|
|
202
|
-
e *= 10;
|
|
203
|
-
p += 1;
|
|
204
|
-
}
|
|
205
|
-
return p;
|
|
206
|
-
}
|
|
207
|
-
var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
|
|
208
|
-
var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
|
|
209
|
-
function snapToStep(value, step) {
|
|
210
|
-
const num = valueOf(value);
|
|
211
|
-
const p = countDecimals(step);
|
|
212
|
-
const v = Math.round(num / step) * step;
|
|
213
|
-
return round(v, p);
|
|
214
|
-
}
|
|
215
|
-
function valueOf(v) {
|
|
216
|
-
if (typeof v === "number")
|
|
217
|
-
return v;
|
|
218
|
-
const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
|
|
219
|
-
return !Number.isNaN(num) ? num : 0;
|
|
220
|
-
}
|
|
221
|
-
function decimalOperation(a, op, b) {
|
|
222
|
-
let result = op === "+" ? a + b : a - b;
|
|
223
|
-
if (a % 1 !== 0 || b % 1 !== 0) {
|
|
224
|
-
const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
|
|
225
|
-
a = Math.round(a * multiplier);
|
|
226
|
-
b = Math.round(b * multiplier);
|
|
227
|
-
result = op === "+" ? a + b : a - b;
|
|
228
|
-
result /= multiplier;
|
|
229
|
-
}
|
|
230
|
-
return result;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// ../../utilities/number/src/transform.ts
|
|
234
|
-
var transform = (a, b) => {
|
|
235
|
-
const i = { min: a[0], max: a[1] };
|
|
236
|
-
const o = { min: b[0], max: b[1] };
|
|
237
|
-
return (v) => {
|
|
238
|
-
if (i.min === i.max || o.min === o.max)
|
|
239
|
-
return o.min;
|
|
240
|
-
const ratio = (o.max - o.min) / (i.max - i.min);
|
|
241
|
-
return o.min + ratio * (v - i.min);
|
|
242
|
-
};
|
|
243
|
-
};
|
|
167
|
+
// src/slider.connect.ts
|
|
168
|
+
var import_numeric_range3 = require("@zag-js/numeric-range");
|
|
244
169
|
|
|
245
170
|
// src/slider.anatomy.ts
|
|
246
171
|
var import_anatomy = require("@zag-js/anatomy");
|
|
@@ -278,46 +203,57 @@ function dispatchInputValueEvent(el, value) {
|
|
|
278
203
|
el.dispatchEvent(event);
|
|
279
204
|
}
|
|
280
205
|
|
|
206
|
+
// src/slider.dom.ts
|
|
207
|
+
var import_numeric_range2 = require("@zag-js/numeric-range");
|
|
208
|
+
|
|
281
209
|
// src/slider.style.ts
|
|
210
|
+
var import_numeric_range = require("@zag-js/numeric-range");
|
|
282
211
|
function getVerticalThumbOffset(ctx) {
|
|
283
212
|
var _a;
|
|
284
213
|
const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
|
|
285
|
-
const getValue =
|
|
214
|
+
const getValue = (0, import_numeric_range.getValueTransformer)([ctx.min, ctx.max], [-height / 2, height / 2]);
|
|
286
215
|
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
287
216
|
}
|
|
288
217
|
function getHorizontalThumbOffset(ctx) {
|
|
289
218
|
var _a;
|
|
290
219
|
const { width = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
|
|
291
220
|
if (ctx.isRtl) {
|
|
292
|
-
const getValue2 =
|
|
221
|
+
const getValue2 = (0, import_numeric_range.getValueTransformer)([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
|
|
293
222
|
return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
|
|
294
223
|
}
|
|
295
|
-
const getValue =
|
|
224
|
+
const getValue = (0, import_numeric_range.getValueTransformer)([ctx.min, ctx.max], [-width / 2, width / 2]);
|
|
296
225
|
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
297
226
|
}
|
|
298
227
|
function getThumbOffset(ctx) {
|
|
299
|
-
const percent =
|
|
300
|
-
if (ctx.thumbAlignment === "center")
|
|
228
|
+
const percent = (0, import_numeric_range.getValuePercent)(ctx.value, ctx.min, ctx.max) * 100;
|
|
229
|
+
if (ctx.thumbAlignment === "center") {
|
|
301
230
|
return `${percent}%`;
|
|
231
|
+
}
|
|
302
232
|
const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
|
|
303
233
|
return `calc(${percent}% - ${offset}px)`;
|
|
304
234
|
}
|
|
235
|
+
function getVisibility(ctx) {
|
|
236
|
+
let visibility = "visible";
|
|
237
|
+
if (ctx.thumbAlignment === "contain" && !ctx.hasMeasuredThumbSize) {
|
|
238
|
+
visibility = "hidden";
|
|
239
|
+
}
|
|
240
|
+
return visibility;
|
|
241
|
+
}
|
|
305
242
|
function getThumbStyle(ctx) {
|
|
306
243
|
const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
|
|
307
244
|
return {
|
|
308
|
-
visibility: ctx
|
|
245
|
+
visibility: getVisibility(ctx),
|
|
309
246
|
position: "absolute",
|
|
310
247
|
transform: "var(--slider-thumb-transform)",
|
|
311
248
|
[placementProp]: "var(--slider-thumb-offset)"
|
|
312
249
|
};
|
|
313
250
|
}
|
|
314
251
|
function getRangeOffsets(ctx) {
|
|
315
|
-
const percent = valueToPercent(ctx.value, ctx);
|
|
316
252
|
let start = "0%";
|
|
317
|
-
let end = `${100 -
|
|
253
|
+
let end = `${100 - ctx.valuePercent}%`;
|
|
318
254
|
if (ctx.origin === "center") {
|
|
319
|
-
const isNegative =
|
|
320
|
-
start = isNegative ? `${
|
|
255
|
+
const isNegative = ctx.valuePercent < 50;
|
|
256
|
+
start = isNegative ? `${ctx.valuePercent}%` : "50%";
|
|
321
257
|
end = isNegative ? "50%" : end;
|
|
322
258
|
}
|
|
323
259
|
return { start, end };
|
|
@@ -356,7 +292,7 @@ function getMarkerStyle(ctx, percent) {
|
|
|
356
292
|
return {
|
|
357
293
|
position: "absolute",
|
|
358
294
|
pointerEvents: "none",
|
|
359
|
-
[ctx.isHorizontal ? "left" : "bottom"]: `${ctx.isRtl ?
|
|
295
|
+
[ctx.isHorizontal ? "left" : "bottom"]: `${(ctx.isRtl ? 1 - percent : percent) * 100}%`
|
|
360
296
|
};
|
|
361
297
|
}
|
|
362
298
|
function getLabelStyle() {
|
|
@@ -384,28 +320,6 @@ var styles = {
|
|
|
384
320
|
getMarkerGroupStyle
|
|
385
321
|
};
|
|
386
322
|
|
|
387
|
-
// src/slider.utils.ts
|
|
388
|
-
var utils = {
|
|
389
|
-
fromPercent(ctx, percent) {
|
|
390
|
-
percent = clamp(percent, { min: 0, max: 1 });
|
|
391
|
-
return parseFloat(snapToStep(percentToValue(percent, ctx), ctx.step));
|
|
392
|
-
},
|
|
393
|
-
clamp(ctx, value) {
|
|
394
|
-
return clamp(value, ctx);
|
|
395
|
-
},
|
|
396
|
-
convert(ctx, value) {
|
|
397
|
-
return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
|
|
398
|
-
},
|
|
399
|
-
decrement(ctx, step) {
|
|
400
|
-
let value = decrement(ctx.value, step != null ? step : ctx.step);
|
|
401
|
-
return utils.convert(ctx, value);
|
|
402
|
-
},
|
|
403
|
-
increment(ctx, step) {
|
|
404
|
-
let value = increment(ctx.value, step != null ? step : ctx.step);
|
|
405
|
-
return utils.convert(ctx, value);
|
|
406
|
-
}
|
|
407
|
-
};
|
|
408
|
-
|
|
409
323
|
// src/slider.dom.ts
|
|
410
324
|
var dom = defineDomHelpers({
|
|
411
325
|
...styles,
|
|
@@ -456,7 +370,7 @@ var dom = defineDomHelpers({
|
|
|
456
370
|
} else {
|
|
457
371
|
percent = 1 - percentY;
|
|
458
372
|
}
|
|
459
|
-
return
|
|
373
|
+
return (0, import_numeric_range2.getPercentValue)(percent, ctx.min, ctx.max, ctx.step);
|
|
460
374
|
},
|
|
461
375
|
dispatchChangeEvent(ctx) {
|
|
462
376
|
const input = dom.getHiddenInputEl(ctx);
|
|
@@ -481,12 +395,15 @@ function connect(state, send, normalize) {
|
|
|
481
395
|
isFocused,
|
|
482
396
|
isDragging,
|
|
483
397
|
value: state.context.value,
|
|
484
|
-
percent:
|
|
398
|
+
percent: (0, import_numeric_range3.getValuePercent)(state.context.value, state.context.min, state.context.max),
|
|
485
399
|
setValue(value) {
|
|
486
400
|
send({ type: "SET_VALUE", value });
|
|
487
401
|
},
|
|
488
402
|
getPercentValue(percent) {
|
|
489
|
-
return
|
|
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);
|
|
490
407
|
},
|
|
491
408
|
focus() {
|
|
492
409
|
var _a2;
|
|
@@ -662,7 +579,7 @@ function connect(state, send, normalize) {
|
|
|
662
579
|
style: dom.getMarkerGroupStyle()
|
|
663
580
|
}),
|
|
664
581
|
getMarkerProps({ value }) {
|
|
665
|
-
const percent =
|
|
582
|
+
const percent = this.getValuePercent(value);
|
|
666
583
|
const style = dom.getMarkerStyle(state.context, percent);
|
|
667
584
|
const markerState = value > state.context.value ? "over-value" : value < state.context.value ? "under-value" : "at-value";
|
|
668
585
|
return normalize.element({
|
package/dist/slider.connect.mjs
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
connect
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6D4ETNPG.mjs";
|
|
4
4
|
import "./chunk-3Y7IIPR5.mjs";
|
|
5
5
|
import "./chunk-SGCWELVB.mjs";
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-FUTBDWTA.mjs";
|
|
9
|
-
import "./chunk-GBYBRQZL.mjs";
|
|
6
|
+
import "./chunk-J5IGGBVE.mjs";
|
|
7
|
+
import "./chunk-YREEXXZP.mjs";
|
|
10
8
|
export {
|
|
11
9
|
connect
|
|
12
10
|
};
|
package/dist/slider.dom.d.ts
CHANGED
|
@@ -18,10 +18,6 @@ declare const dom: {
|
|
|
18
18
|
getById: <T = HTMLElement>(ctx: {
|
|
19
19
|
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
20
20
|
}, id: string) => T | null;
|
|
21
|
-
createEmitter: (ctx: {
|
|
22
|
-
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
23
|
-
}, target: HTMLElement) => (evt: string, detail: Record<string, any>, options?: EventInit | undefined) => void;
|
|
24
|
-
createListener: (target: HTMLElement) => <T_1 = any>(evt: string, handler: (e: CustomEvent<T_1>) => void) => () => void;
|
|
25
21
|
} & {
|
|
26
22
|
getRootId: (ctx: MachineContext) => string;
|
|
27
23
|
getThumbId: (ctx: MachineContext) => string;
|
package/dist/slider.dom.js
CHANGED
|
@@ -55,25 +55,7 @@ function defineDomHelpers(helpers) {
|
|
|
55
55
|
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
56
56
|
},
|
|
57
57
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
58
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
59
|
-
createEmitter: (ctx, target) => {
|
|
60
|
-
const win = dom2.getWin(ctx);
|
|
61
|
-
return function emit(evt, detail, options) {
|
|
62
|
-
const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
|
|
63
|
-
const eventName = `zag:${evt}`;
|
|
64
|
-
const init = { bubbles, cancelable, composed, detail };
|
|
65
|
-
const event = new win.CustomEvent(eventName, init);
|
|
66
|
-
target.dispatchEvent(event);
|
|
67
|
-
};
|
|
68
|
-
},
|
|
69
|
-
createListener: (target) => {
|
|
70
|
-
return function listen(evt, handler) {
|
|
71
|
-
const eventName = `zag:${evt}`;
|
|
72
|
-
const listener = (e) => handler(e);
|
|
73
|
-
target.addEventListener(eventName, listener);
|
|
74
|
-
return () => target.removeEventListener(eventName, listener);
|
|
75
|
-
};
|
|
76
|
-
}
|
|
58
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
77
59
|
};
|
|
78
60
|
return {
|
|
79
61
|
...dom2,
|
|
@@ -133,106 +115,57 @@ function dispatchInputValueEvent(el, value) {
|
|
|
133
115
|
el.dispatchEvent(event);
|
|
134
116
|
}
|
|
135
117
|
|
|
136
|
-
//
|
|
137
|
-
|
|
138
|
-
let num = valueOf(v);
|
|
139
|
-
const p = 10 ** (t != null ? t : 10);
|
|
140
|
-
num = Math.round(num * p) / p;
|
|
141
|
-
return t ? num.toFixed(t) : v.toString();
|
|
142
|
-
}
|
|
143
|
-
var valueToPercent = (v, r) => (valueOf(v) - r.min) * 100 / (r.max - r.min);
|
|
144
|
-
var percentToValue = (v, r) => r.min + (r.max - r.min) * valueOf(v);
|
|
145
|
-
function clamp(v, o) {
|
|
146
|
-
return Math.min(Math.max(valueOf(v), o.min), o.max);
|
|
147
|
-
}
|
|
148
|
-
function countDecimals(value) {
|
|
149
|
-
if (!Number.isFinite(value))
|
|
150
|
-
return 0;
|
|
151
|
-
let e = 1, p = 0;
|
|
152
|
-
while (Math.round(value * e) / e !== value) {
|
|
153
|
-
e *= 10;
|
|
154
|
-
p += 1;
|
|
155
|
-
}
|
|
156
|
-
return p;
|
|
157
|
-
}
|
|
158
|
-
var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
|
|
159
|
-
var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
|
|
160
|
-
function snapToStep(value, step) {
|
|
161
|
-
const num = valueOf(value);
|
|
162
|
-
const p = countDecimals(step);
|
|
163
|
-
const v = Math.round(num / step) * step;
|
|
164
|
-
return round(v, p);
|
|
165
|
-
}
|
|
166
|
-
function valueOf(v) {
|
|
167
|
-
if (typeof v === "number")
|
|
168
|
-
return v;
|
|
169
|
-
const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
|
|
170
|
-
return !Number.isNaN(num) ? num : 0;
|
|
171
|
-
}
|
|
172
|
-
function decimalOperation(a, op, b) {
|
|
173
|
-
let result = op === "+" ? a + b : a - b;
|
|
174
|
-
if (a % 1 !== 0 || b % 1 !== 0) {
|
|
175
|
-
const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
|
|
176
|
-
a = Math.round(a * multiplier);
|
|
177
|
-
b = Math.round(b * multiplier);
|
|
178
|
-
result = op === "+" ? a + b : a - b;
|
|
179
|
-
result /= multiplier;
|
|
180
|
-
}
|
|
181
|
-
return result;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// ../../utilities/number/src/transform.ts
|
|
185
|
-
var transform = (a, b) => {
|
|
186
|
-
const i = { min: a[0], max: a[1] };
|
|
187
|
-
const o = { min: b[0], max: b[1] };
|
|
188
|
-
return (v) => {
|
|
189
|
-
if (i.min === i.max || o.min === o.max)
|
|
190
|
-
return o.min;
|
|
191
|
-
const ratio = (o.max - o.min) / (i.max - i.min);
|
|
192
|
-
return o.min + ratio * (v - i.min);
|
|
193
|
-
};
|
|
194
|
-
};
|
|
118
|
+
// src/slider.dom.ts
|
|
119
|
+
var import_numeric_range2 = require("@zag-js/numeric-range");
|
|
195
120
|
|
|
196
121
|
// src/slider.style.ts
|
|
122
|
+
var import_numeric_range = require("@zag-js/numeric-range");
|
|
197
123
|
function getVerticalThumbOffset(ctx) {
|
|
198
124
|
var _a;
|
|
199
125
|
const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
|
|
200
|
-
const getValue =
|
|
126
|
+
const getValue = (0, import_numeric_range.getValueTransformer)([ctx.min, ctx.max], [-height / 2, height / 2]);
|
|
201
127
|
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
202
128
|
}
|
|
203
129
|
function getHorizontalThumbOffset(ctx) {
|
|
204
130
|
var _a;
|
|
205
131
|
const { width = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
|
|
206
132
|
if (ctx.isRtl) {
|
|
207
|
-
const getValue2 =
|
|
133
|
+
const getValue2 = (0, import_numeric_range.getValueTransformer)([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
|
|
208
134
|
return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
|
|
209
135
|
}
|
|
210
|
-
const getValue =
|
|
136
|
+
const getValue = (0, import_numeric_range.getValueTransformer)([ctx.min, ctx.max], [-width / 2, width / 2]);
|
|
211
137
|
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
212
138
|
}
|
|
213
139
|
function getThumbOffset(ctx) {
|
|
214
|
-
const percent =
|
|
215
|
-
if (ctx.thumbAlignment === "center")
|
|
140
|
+
const percent = (0, import_numeric_range.getValuePercent)(ctx.value, ctx.min, ctx.max) * 100;
|
|
141
|
+
if (ctx.thumbAlignment === "center") {
|
|
216
142
|
return `${percent}%`;
|
|
143
|
+
}
|
|
217
144
|
const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
|
|
218
145
|
return `calc(${percent}% - ${offset}px)`;
|
|
219
146
|
}
|
|
147
|
+
function getVisibility(ctx) {
|
|
148
|
+
let visibility = "visible";
|
|
149
|
+
if (ctx.thumbAlignment === "contain" && !ctx.hasMeasuredThumbSize) {
|
|
150
|
+
visibility = "hidden";
|
|
151
|
+
}
|
|
152
|
+
return visibility;
|
|
153
|
+
}
|
|
220
154
|
function getThumbStyle(ctx) {
|
|
221
155
|
const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
|
|
222
156
|
return {
|
|
223
|
-
visibility: ctx
|
|
157
|
+
visibility: getVisibility(ctx),
|
|
224
158
|
position: "absolute",
|
|
225
159
|
transform: "var(--slider-thumb-transform)",
|
|
226
160
|
[placementProp]: "var(--slider-thumb-offset)"
|
|
227
161
|
};
|
|
228
162
|
}
|
|
229
163
|
function getRangeOffsets(ctx) {
|
|
230
|
-
const percent = valueToPercent(ctx.value, ctx);
|
|
231
164
|
let start = "0%";
|
|
232
|
-
let end = `${100 -
|
|
165
|
+
let end = `${100 - ctx.valuePercent}%`;
|
|
233
166
|
if (ctx.origin === "center") {
|
|
234
|
-
const isNegative =
|
|
235
|
-
start = isNegative ? `${
|
|
167
|
+
const isNegative = ctx.valuePercent < 50;
|
|
168
|
+
start = isNegative ? `${ctx.valuePercent}%` : "50%";
|
|
236
169
|
end = isNegative ? "50%" : end;
|
|
237
170
|
}
|
|
238
171
|
return { start, end };
|
|
@@ -271,7 +204,7 @@ function getMarkerStyle(ctx, percent) {
|
|
|
271
204
|
return {
|
|
272
205
|
position: "absolute",
|
|
273
206
|
pointerEvents: "none",
|
|
274
|
-
[ctx.isHorizontal ? "left" : "bottom"]: `${ctx.isRtl ?
|
|
207
|
+
[ctx.isHorizontal ? "left" : "bottom"]: `${(ctx.isRtl ? 1 - percent : percent) * 100}%`
|
|
275
208
|
};
|
|
276
209
|
}
|
|
277
210
|
function getLabelStyle() {
|
|
@@ -299,28 +232,6 @@ var styles = {
|
|
|
299
232
|
getMarkerGroupStyle
|
|
300
233
|
};
|
|
301
234
|
|
|
302
|
-
// src/slider.utils.ts
|
|
303
|
-
var utils = {
|
|
304
|
-
fromPercent(ctx, percent) {
|
|
305
|
-
percent = clamp(percent, { min: 0, max: 1 });
|
|
306
|
-
return parseFloat(snapToStep(percentToValue(percent, ctx), ctx.step));
|
|
307
|
-
},
|
|
308
|
-
clamp(ctx, value) {
|
|
309
|
-
return clamp(value, ctx);
|
|
310
|
-
},
|
|
311
|
-
convert(ctx, value) {
|
|
312
|
-
return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
|
|
313
|
-
},
|
|
314
|
-
decrement(ctx, step) {
|
|
315
|
-
let value = decrement(ctx.value, step != null ? step : ctx.step);
|
|
316
|
-
return utils.convert(ctx, value);
|
|
317
|
-
},
|
|
318
|
-
increment(ctx, step) {
|
|
319
|
-
let value = increment(ctx.value, step != null ? step : ctx.step);
|
|
320
|
-
return utils.convert(ctx, value);
|
|
321
|
-
}
|
|
322
|
-
};
|
|
323
|
-
|
|
324
235
|
// src/slider.dom.ts
|
|
325
236
|
var dom = defineDomHelpers({
|
|
326
237
|
...styles,
|
|
@@ -371,7 +282,7 @@ var dom = defineDomHelpers({
|
|
|
371
282
|
} else {
|
|
372
283
|
percent = 1 - percentY;
|
|
373
284
|
}
|
|
374
|
-
return
|
|
285
|
+
return (0, import_numeric_range2.getPercentValue)(percent, ctx.min, ctx.max, ctx.step);
|
|
375
286
|
},
|
|
376
287
|
dispatchChangeEvent(ctx) {
|
|
377
288
|
const input = dom.getHiddenInputEl(ctx);
|
package/dist/slider.dom.mjs
CHANGED