@zag-js/slider 0.1.2 → 0.1.5
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 +90 -19
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +90 -19
- 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 +7 -7
package/dist/index.js
CHANGED
|
@@ -212,10 +212,6 @@ function getOwnerWindow(el) {
|
|
|
212
212
|
var _a;
|
|
213
213
|
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
214
214
|
}
|
|
215
|
-
function getNativeEvent(event) {
|
|
216
|
-
var _a;
|
|
217
|
-
return (_a = event.nativeEvent) != null ? _a : event;
|
|
218
|
-
}
|
|
219
215
|
function getDescriptor(el, options) {
|
|
220
216
|
var _a;
|
|
221
217
|
const { type, property } = options;
|
|
@@ -254,6 +250,10 @@ function trackInputPropertyMutation(el, options) {
|
|
|
254
250
|
run = false;
|
|
255
251
|
};
|
|
256
252
|
}
|
|
253
|
+
function getNativeEvent(event) {
|
|
254
|
+
var _a;
|
|
255
|
+
return (_a = event.nativeEvent) != null ? _a : event;
|
|
256
|
+
}
|
|
257
257
|
function getClosestFormElement(el) {
|
|
258
258
|
if (isFormElement(el))
|
|
259
259
|
return el.form;
|
|
@@ -309,6 +309,30 @@ function getEventStep(event) {
|
|
|
309
309
|
return isSkipKey ? 10 : 1;
|
|
310
310
|
}
|
|
311
311
|
}
|
|
312
|
+
function itemById(v, id) {
|
|
313
|
+
return v.find((node) => node.id === id);
|
|
314
|
+
}
|
|
315
|
+
function indexOfId(v, id) {
|
|
316
|
+
const item = itemById(v, id);
|
|
317
|
+
return item ? v.indexOf(item) : -1;
|
|
318
|
+
}
|
|
319
|
+
var getValueText = (item) => {
|
|
320
|
+
var _a, _b;
|
|
321
|
+
return (_b = (_a = item.dataset.valuetext) != null ? _a : item.textContent) != null ? _b : "";
|
|
322
|
+
};
|
|
323
|
+
var match = (valueText, query2) => valueText.toLowerCase().startsWith(query2.toLowerCase());
|
|
324
|
+
var wrap = (v, idx) => {
|
|
325
|
+
return v.map((_, index) => v[(Math.max(idx, 0) + index) % v.length]);
|
|
326
|
+
};
|
|
327
|
+
function findByText(v, text, currentId) {
|
|
328
|
+
const index = currentId ? indexOfId(v, currentId) : -1;
|
|
329
|
+
let items = currentId ? wrap(v, index) : v;
|
|
330
|
+
const isSingleKey = text.length === 1;
|
|
331
|
+
if (isSingleKey) {
|
|
332
|
+
items = items.filter((item) => item.id !== currentId);
|
|
333
|
+
}
|
|
334
|
+
return items.find((item) => match(getValueText(item), text));
|
|
335
|
+
}
|
|
312
336
|
var state = "default";
|
|
313
337
|
var savedUserSelect = "";
|
|
314
338
|
var modifiedElementMap = /* @__PURE__ */ new WeakMap();
|
|
@@ -372,13 +396,37 @@ function trackPointerMove(opts) {
|
|
|
372
396
|
};
|
|
373
397
|
return pipe(addPointerEvent(doc, "pointermove", handlePointerMove, false), addPointerEvent(doc, "pointerup", onPointerUp, false), addPointerEvent(doc, "pointercancel", onPointerUp, false), addPointerEvent(doc, "contextmenu", onPointerUp, false), disableTextSelection({ doc }));
|
|
374
398
|
}
|
|
399
|
+
function findByTypeahead(_items, options) {
|
|
400
|
+
const { state: state2, activeId, key, timeout = 350 } = options;
|
|
401
|
+
const search = state2.keysSoFar + key;
|
|
402
|
+
const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]);
|
|
403
|
+
const query2 = isRepeated ? search[0] : search;
|
|
404
|
+
let items = _items.slice();
|
|
405
|
+
const next = findByText(items, query2, activeId);
|
|
406
|
+
function cleanup() {
|
|
407
|
+
clearTimeout(state2.timer);
|
|
408
|
+
state2.timer = -1;
|
|
409
|
+
}
|
|
410
|
+
function update(value) {
|
|
411
|
+
state2.keysSoFar = value;
|
|
412
|
+
cleanup();
|
|
413
|
+
if (value !== "") {
|
|
414
|
+
state2.timer = +setTimeout(() => {
|
|
415
|
+
update("");
|
|
416
|
+
cleanup();
|
|
417
|
+
}, timeout);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
update(search);
|
|
421
|
+
return next;
|
|
422
|
+
}
|
|
423
|
+
findByTypeahead.defaultOptions = {
|
|
424
|
+
keysSoFar: "",
|
|
425
|
+
timer: -1
|
|
426
|
+
};
|
|
375
427
|
|
|
376
428
|
// ../../utilities/number/dist/index.mjs
|
|
377
429
|
var __pow2 = Math.pow;
|
|
378
|
-
var nf = new Intl.NumberFormat("en-US", { style: "decimal" });
|
|
379
|
-
function formatter(n) {
|
|
380
|
-
return parseFloat(nf.format(n));
|
|
381
|
-
}
|
|
382
430
|
function round(v, t2) {
|
|
383
431
|
let num = valueOf(v);
|
|
384
432
|
const p = __pow2(10, t2 != null ? t2 : 10);
|
|
@@ -390,13 +438,18 @@ var percentToValue = (v, r) => r.min + (r.max - r.min) * valueOf(v);
|
|
|
390
438
|
function clamp(v, o) {
|
|
391
439
|
return Math.min(Math.max(valueOf(v), o.min), o.max);
|
|
392
440
|
}
|
|
393
|
-
function countDecimals(
|
|
394
|
-
|
|
395
|
-
|
|
441
|
+
function countDecimals(value) {
|
|
442
|
+
if (!Number.isFinite(value))
|
|
443
|
+
return 0;
|
|
444
|
+
let e = 1, p = 0;
|
|
445
|
+
while (Math.round(value * e) / e !== value) {
|
|
446
|
+
e *= 10;
|
|
447
|
+
p += 1;
|
|
448
|
+
}
|
|
449
|
+
return p;
|
|
396
450
|
}
|
|
397
|
-
var increment = (v, s) =>
|
|
398
|
-
var decrement = (v, s) =>
|
|
399
|
-
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);
|
|
400
453
|
function snapToStep(value, step) {
|
|
401
454
|
const num = valueOf(value);
|
|
402
455
|
const p = countDecimals(step);
|
|
@@ -409,6 +462,18 @@ function valueOf(v) {
|
|
|
409
462
|
const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
|
|
410
463
|
return !Number.isNaN(num) ? num : 0;
|
|
411
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 });
|
|
412
477
|
var transform = (a, b) => {
|
|
413
478
|
const i = { min: a[0], max: a[1] };
|
|
414
479
|
const o = { min: b[0], max: b[1] };
|
|
@@ -529,6 +594,10 @@ var dom = {
|
|
|
529
594
|
var _a;
|
|
530
595
|
return (_a = ctx.doc) != null ? _a : document;
|
|
531
596
|
},
|
|
597
|
+
getRootNode: (ctx) => {
|
|
598
|
+
var _a;
|
|
599
|
+
return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
|
|
600
|
+
},
|
|
532
601
|
getRootId: (ctx) => {
|
|
533
602
|
var _a, _b;
|
|
534
603
|
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `slider:${ctx.uid}`;
|
|
@@ -559,9 +628,9 @@ var dom = {
|
|
|
559
628
|
return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.uid}:label`;
|
|
560
629
|
},
|
|
561
630
|
getMarkerId: (ctx, value) => `slider:${ctx.uid}:marker:${value}`,
|
|
562
|
-
getThumbEl: (ctx) => dom.
|
|
563
|
-
getControlEl: (ctx) => dom.
|
|
564
|
-
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)),
|
|
565
634
|
getControlStyle,
|
|
566
635
|
getThumbStyle,
|
|
567
636
|
getRangeStyle,
|
|
@@ -607,7 +676,7 @@ var normalizeProp = createNormalizer((v) => v);
|
|
|
607
676
|
|
|
608
677
|
// ../../utilities/core/dist/index.mjs
|
|
609
678
|
var isLeftClick2 = (v) => v.button === 0;
|
|
610
|
-
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey
|
|
679
|
+
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
611
680
|
|
|
612
681
|
// src/slider.connect.ts
|
|
613
682
|
function connect(state2, send, normalize = normalizeProp) {
|
|
@@ -697,7 +766,7 @@ function connect(state2, send, normalize = normalizeProp) {
|
|
|
697
766
|
onKeyDown(event) {
|
|
698
767
|
if (!isInteractive)
|
|
699
768
|
return;
|
|
700
|
-
const step =
|
|
769
|
+
const step = getEventStep(event) * state2.context.step;
|
|
701
770
|
let prevent = true;
|
|
702
771
|
const keyMap = {
|
|
703
772
|
ArrowUp() {
|
|
@@ -984,6 +1053,8 @@ function machine(ctx = {}) {
|
|
|
984
1053
|
setupDocument(ctx2, evt) {
|
|
985
1054
|
if (evt.doc)
|
|
986
1055
|
ctx2.doc = (0, import_core.ref)(evt.doc);
|
|
1056
|
+
if (evt.root)
|
|
1057
|
+
ctx2.rootNode = (0, import_core.ref)(evt.root);
|
|
987
1058
|
ctx2.uid = evt.id;
|
|
988
1059
|
},
|
|
989
1060
|
checkValue(ctx2) {
|