@zag-js/slider 0.1.2 → 0.1.3
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 +64 -5
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +64 -5
- package/dist/index.mjs.map +3 -3
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
|
@@ -285,6 +285,30 @@ function getEventStep(event) {
|
|
|
285
285
|
return isSkipKey ? 10 : 1;
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
|
+
function itemById(v, id) {
|
|
289
|
+
return v.find((node) => node.id === id);
|
|
290
|
+
}
|
|
291
|
+
function indexOfId(v, id) {
|
|
292
|
+
const item = itemById(v, id);
|
|
293
|
+
return item ? v.indexOf(item) : -1;
|
|
294
|
+
}
|
|
295
|
+
var getValueText = (item) => {
|
|
296
|
+
var _a, _b;
|
|
297
|
+
return (_b = (_a = item.dataset.valuetext) != null ? _a : item.textContent) != null ? _b : "";
|
|
298
|
+
};
|
|
299
|
+
var match = (valueText, query2) => valueText.toLowerCase().startsWith(query2.toLowerCase());
|
|
300
|
+
var wrap = (v, idx) => {
|
|
301
|
+
return v.map((_, index) => v[(Math.max(idx, 0) + index) % v.length]);
|
|
302
|
+
};
|
|
303
|
+
function findByText(v, text, currentId) {
|
|
304
|
+
const index = currentId ? indexOfId(v, currentId) : -1;
|
|
305
|
+
let items = currentId ? wrap(v, index) : v;
|
|
306
|
+
const isSingleKey = text.length === 1;
|
|
307
|
+
if (isSingleKey) {
|
|
308
|
+
items = items.filter((item) => item.id !== currentId);
|
|
309
|
+
}
|
|
310
|
+
return items.find((item) => match(getValueText(item), text));
|
|
311
|
+
}
|
|
288
312
|
var state = "default";
|
|
289
313
|
var savedUserSelect = "";
|
|
290
314
|
var modifiedElementMap = /* @__PURE__ */ new WeakMap();
|
|
@@ -348,10 +372,38 @@ function trackPointerMove(opts) {
|
|
|
348
372
|
};
|
|
349
373
|
return pipe(addPointerEvent(doc, "pointermove", handlePointerMove, false), addPointerEvent(doc, "pointerup", onPointerUp, false), addPointerEvent(doc, "pointercancel", onPointerUp, false), addPointerEvent(doc, "contextmenu", onPointerUp, false), disableTextSelection({ doc }));
|
|
350
374
|
}
|
|
375
|
+
function findByTypeahead(_items, options) {
|
|
376
|
+
const { state: state2, activeId, key, timeout = 350 } = options;
|
|
377
|
+
const search = state2.keysSoFar + key;
|
|
378
|
+
const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]);
|
|
379
|
+
const query2 = isRepeated ? search[0] : search;
|
|
380
|
+
let items = _items.slice();
|
|
381
|
+
const next = findByText(items, query2, activeId);
|
|
382
|
+
function cleanup() {
|
|
383
|
+
clearTimeout(state2.timer);
|
|
384
|
+
state2.timer = -1;
|
|
385
|
+
}
|
|
386
|
+
function update(value) {
|
|
387
|
+
state2.keysSoFar = value;
|
|
388
|
+
cleanup();
|
|
389
|
+
if (value !== "") {
|
|
390
|
+
state2.timer = +setTimeout(() => {
|
|
391
|
+
update("");
|
|
392
|
+
cleanup();
|
|
393
|
+
}, timeout);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
update(search);
|
|
397
|
+
return next;
|
|
398
|
+
}
|
|
399
|
+
findByTypeahead.defaultOptions = {
|
|
400
|
+
keysSoFar: "",
|
|
401
|
+
timer: -1
|
|
402
|
+
};
|
|
351
403
|
|
|
352
404
|
// ../../utilities/number/dist/index.mjs
|
|
353
405
|
var __pow2 = Math.pow;
|
|
354
|
-
var nf = new Intl.NumberFormat("en-US", { style: "decimal" });
|
|
406
|
+
var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
|
|
355
407
|
function formatter(n) {
|
|
356
408
|
return parseFloat(nf.format(n));
|
|
357
409
|
}
|
|
@@ -366,9 +418,16 @@ var percentToValue = (v, r) => r.min + (r.max - r.min) * valueOf(v);
|
|
|
366
418
|
function clamp(v, o) {
|
|
367
419
|
return Math.min(Math.max(valueOf(v), o.min), o.max);
|
|
368
420
|
}
|
|
369
|
-
function countDecimals(
|
|
370
|
-
|
|
371
|
-
|
|
421
|
+
function countDecimals(value) {
|
|
422
|
+
if (!Number.isFinite(value))
|
|
423
|
+
return 0;
|
|
424
|
+
let e = 1;
|
|
425
|
+
let p = 0;
|
|
426
|
+
while (Math.round(value * e) / e !== value) {
|
|
427
|
+
e *= 10;
|
|
428
|
+
p += 1;
|
|
429
|
+
}
|
|
430
|
+
return p;
|
|
372
431
|
}
|
|
373
432
|
var increment = (v, s) => formatter(valueOf(v) + s);
|
|
374
433
|
var decrement = (v, s) => formatter(valueOf(v) - s);
|
|
@@ -583,7 +642,7 @@ var normalizeProp = createNormalizer((v) => v);
|
|
|
583
642
|
|
|
584
643
|
// ../../utilities/core/dist/index.mjs
|
|
585
644
|
var isLeftClick2 = (v) => v.button === 0;
|
|
586
|
-
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey
|
|
645
|
+
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
587
646
|
|
|
588
647
|
// src/slider.connect.ts
|
|
589
648
|
function connect(state2, send, normalize = normalizeProp) {
|