@zag-js/slider 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +25 -13
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +25 -13
- package/dist/index.mjs.map +3 -3
- package/dist/slider.dom.d.ts +1 -0
- package/dist/slider.dom.d.ts.map +1 -1
- package/dist/slider.machine.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -427,10 +427,6 @@ findByTypeahead.defaultOptions = {
|
|
|
427
427
|
|
|
428
428
|
// ../../utilities/number/dist/index.mjs
|
|
429
429
|
var __pow2 = Math.pow;
|
|
430
|
-
var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
|
|
431
|
-
function formatter(n) {
|
|
432
|
-
return parseFloat(nf.format(n));
|
|
433
|
-
}
|
|
434
430
|
function round(v, t2) {
|
|
435
431
|
let num = valueOf(v);
|
|
436
432
|
const p = __pow2(10, t2 != null ? t2 : 10);
|
|
@@ -445,17 +441,15 @@ function clamp(v, o) {
|
|
|
445
441
|
function countDecimals(value) {
|
|
446
442
|
if (!Number.isFinite(value))
|
|
447
443
|
return 0;
|
|
448
|
-
let e = 1;
|
|
449
|
-
let p = 0;
|
|
444
|
+
let e = 1, p = 0;
|
|
450
445
|
while (Math.round(value * e) / e !== value) {
|
|
451
446
|
e *= 10;
|
|
452
447
|
p += 1;
|
|
453
448
|
}
|
|
454
449
|
return p;
|
|
455
450
|
}
|
|
456
|
-
var increment = (v, s) =>
|
|
457
|
-
var decrement = (v, s) =>
|
|
458
|
-
var multiply = (v, s) => formatter(valueOf(v) * s);
|
|
451
|
+
var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
|
|
452
|
+
var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
|
|
459
453
|
function snapToStep(value, step) {
|
|
460
454
|
const num = valueOf(value);
|
|
461
455
|
const p = countDecimals(step);
|
|
@@ -468,6 +462,18 @@ function valueOf(v) {
|
|
|
468
462
|
const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
|
|
469
463
|
return !Number.isNaN(num) ? num : 0;
|
|
470
464
|
}
|
|
465
|
+
function decimalOperation(a, op, b) {
|
|
466
|
+
let result = op === "+" ? a + b : a - b;
|
|
467
|
+
if (a % 1 !== 0 || b % 1 !== 0) {
|
|
468
|
+
const multiplier = __pow2(10, Math.max(countDecimals(a), countDecimals(b)));
|
|
469
|
+
a = Math.round(a * multiplier);
|
|
470
|
+
b = Math.round(b * multiplier);
|
|
471
|
+
result = op === "+" ? a + b : a - b;
|
|
472
|
+
result /= multiplier;
|
|
473
|
+
}
|
|
474
|
+
return result;
|
|
475
|
+
}
|
|
476
|
+
var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
|
|
471
477
|
var transform = (a, b) => {
|
|
472
478
|
const i = { min: a[0], max: a[1] };
|
|
473
479
|
const o = { min: b[0], max: b[1] };
|
|
@@ -588,6 +594,10 @@ var dom = {
|
|
|
588
594
|
var _a;
|
|
589
595
|
return (_a = ctx.doc) != null ? _a : document;
|
|
590
596
|
},
|
|
597
|
+
getRootNode: (ctx) => {
|
|
598
|
+
var _a;
|
|
599
|
+
return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
|
|
600
|
+
},
|
|
591
601
|
getRootId: (ctx) => {
|
|
592
602
|
var _a, _b;
|
|
593
603
|
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `slider:${ctx.uid}`;
|
|
@@ -618,9 +628,9 @@ var dom = {
|
|
|
618
628
|
return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.uid}:label`;
|
|
619
629
|
},
|
|
620
630
|
getMarkerId: (ctx, value) => `slider:${ctx.uid}:marker:${value}`,
|
|
621
|
-
getThumbEl: (ctx) => dom.
|
|
622
|
-
getControlEl: (ctx) => dom.
|
|
623
|
-
getInputEl: (ctx) => dom.
|
|
631
|
+
getThumbEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getThumbId(ctx)),
|
|
632
|
+
getControlEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getControlId(ctx)),
|
|
633
|
+
getInputEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getInputId(ctx)),
|
|
624
634
|
getControlStyle,
|
|
625
635
|
getThumbStyle,
|
|
626
636
|
getRangeStyle,
|
|
@@ -756,7 +766,7 @@ function connect(state2, send, normalize = normalizeProp) {
|
|
|
756
766
|
onKeyDown(event) {
|
|
757
767
|
if (!isInteractive)
|
|
758
768
|
return;
|
|
759
|
-
const step =
|
|
769
|
+
const step = getEventStep(event) * state2.context.step;
|
|
760
770
|
let prevent = true;
|
|
761
771
|
const keyMap = {
|
|
762
772
|
ArrowUp() {
|
|
@@ -1043,6 +1053,8 @@ function machine(ctx = {}) {
|
|
|
1043
1053
|
setupDocument(ctx2, evt) {
|
|
1044
1054
|
if (evt.doc)
|
|
1045
1055
|
ctx2.doc = (0, import_core.ref)(evt.doc);
|
|
1056
|
+
if (evt.root)
|
|
1057
|
+
ctx2.rootNode = (0, import_core.ref)(evt.root);
|
|
1046
1058
|
ctx2.uid = evt.id;
|
|
1047
1059
|
},
|
|
1048
1060
|
checkValue(ctx2) {
|