@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 CHANGED
@@ -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,10 +396,38 @@ 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" });
430
+ var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
379
431
  function formatter(n) {
380
432
  return parseFloat(nf.format(n));
381
433
  }
@@ -390,9 +442,16 @@ var percentToValue = (v, r) => r.min + (r.max - r.min) * valueOf(v);
390
442
  function clamp(v, o) {
391
443
  return Math.min(Math.max(valueOf(v), o.min), o.max);
392
444
  }
393
- function countDecimals(v) {
394
- var _a, _b;
395
- return (_b = (_a = nf.formatToParts(v).find((p) => p.type === "fraction")) == null ? void 0 : _a.value.length) != null ? _b : 0;
445
+ function countDecimals(value) {
446
+ if (!Number.isFinite(value))
447
+ return 0;
448
+ let e = 1;
449
+ let p = 0;
450
+ while (Math.round(value * e) / e !== value) {
451
+ e *= 10;
452
+ p += 1;
453
+ }
454
+ return p;
396
455
  }
397
456
  var increment = (v, s) => formatter(valueOf(v) + s);
398
457
  var decrement = (v, s) => formatter(valueOf(v) - s);
@@ -607,7 +666,7 @@ var normalizeProp = createNormalizer((v) => v);
607
666
 
608
667
  // ../../utilities/core/dist/index.mjs
609
668
  var isLeftClick2 = (v) => v.button === 0;
610
- var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey || v.shiftKey;
669
+ var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
611
670
 
612
671
  // src/slider.connect.ts
613
672
  function connect(state2, send, normalize = normalizeProp) {