@zag-js/splitter 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.mjs CHANGED
@@ -33,6 +33,12 @@ function nextTick(fn) {
33
33
  });
34
34
  };
35
35
  }
36
+ function raf(fn) {
37
+ const id = globalThis.requestAnimationFrame(fn);
38
+ return function cleanup() {
39
+ globalThis.cancelAnimationFrame(id);
40
+ };
41
+ }
36
42
  var noop = () => {
37
43
  };
38
44
  var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
@@ -212,6 +218,30 @@ function getEventStep(event) {
212
218
  return isSkipKey ? 10 : 1;
213
219
  }
214
220
  }
221
+ function itemById(v, id) {
222
+ return v.find((node) => node.id === id);
223
+ }
224
+ function indexOfId(v, id) {
225
+ const item = itemById(v, id);
226
+ return item ? v.indexOf(item) : -1;
227
+ }
228
+ var getValueText = (item) => {
229
+ var _a, _b;
230
+ return (_b = (_a = item.dataset.valuetext) != null ? _a : item.textContent) != null ? _b : "";
231
+ };
232
+ var match = (valueText, query2) => valueText.toLowerCase().startsWith(query2.toLowerCase());
233
+ var wrap = (v, idx) => {
234
+ return v.map((_, index) => v[(Math.max(idx, 0) + index) % v.length]);
235
+ };
236
+ function findByText(v, text, currentId) {
237
+ const index = currentId ? indexOfId(v, currentId) : -1;
238
+ let items = currentId ? wrap(v, index) : v;
239
+ const isSingleKey = text.length === 1;
240
+ if (isSingleKey) {
241
+ items = items.filter((item) => item.id !== currentId);
242
+ }
243
+ return items.find((item) => match(getValueText(item), text));
244
+ }
215
245
  var state = "default";
216
246
  var savedUserSelect = "";
217
247
  var modifiedElementMap = /* @__PURE__ */ new WeakMap();
@@ -275,6 +305,34 @@ function trackPointerMove(opts) {
275
305
  };
276
306
  return pipe(addPointerEvent(doc, "pointermove", handlePointerMove, false), addPointerEvent(doc, "pointerup", onPointerUp, false), addPointerEvent(doc, "pointercancel", onPointerUp, false), addPointerEvent(doc, "contextmenu", onPointerUp, false), disableTextSelection({ doc }));
277
307
  }
308
+ function findByTypeahead(_items, options) {
309
+ const { state: state2, activeId, key, timeout = 350 } = options;
310
+ const search = state2.keysSoFar + key;
311
+ const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]);
312
+ const query2 = isRepeated ? search[0] : search;
313
+ let items = _items.slice();
314
+ const next = findByText(items, query2, activeId);
315
+ function cleanup() {
316
+ clearTimeout(state2.timer);
317
+ state2.timer = -1;
318
+ }
319
+ function update(value) {
320
+ state2.keysSoFar = value;
321
+ cleanup();
322
+ if (value !== "") {
323
+ state2.timer = +setTimeout(() => {
324
+ update("");
325
+ cleanup();
326
+ }, timeout);
327
+ }
328
+ }
329
+ update(search);
330
+ return next;
331
+ }
332
+ findByTypeahead.defaultOptions = {
333
+ keysSoFar: "",
334
+ timer: -1
335
+ };
278
336
 
279
337
  // ../../types/dist/index.mjs
280
338
  function createNormalizer(fn) {
@@ -496,7 +554,7 @@ import { createMachine, guards, ref } from "@zag-js/core";
496
554
 
497
555
  // ../../utilities/number/dist/index.mjs
498
556
  var __pow2 = Math.pow;
499
- var nf = new Intl.NumberFormat("en-US", { style: "decimal" });
557
+ var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
500
558
  function formatter(n) {
501
559
  return parseFloat(nf.format(n));
502
560
  }
@@ -509,9 +567,16 @@ function round(v, t2) {
509
567
  function clamp(v, o) {
510
568
  return Math.min(Math.max(valueOf(v), o.min), o.max);
511
569
  }
512
- function countDecimals(v) {
513
- var _a, _b;
514
- return (_b = (_a = nf.formatToParts(v).find((p) => p.type === "fraction")) == null ? void 0 : _a.value.length) != null ? _b : 0;
570
+ function countDecimals(value) {
571
+ if (!Number.isFinite(value))
572
+ return 0;
573
+ let e = 1;
574
+ let p = 0;
575
+ while (Math.round(value * e) / e !== value) {
576
+ e *= 10;
577
+ p += 1;
578
+ }
579
+ return p;
515
580
  }
516
581
  var increment = (v, s) => formatter(valueOf(v) + s);
517
582
  var decrement = (v, s) => formatter(valueOf(v) - s);
@@ -736,7 +801,7 @@ function machine(ctx = {}) {
736
801
  ctx2.value = clamp(decrement(ctx2.value, evt.step), ctx2);
737
802
  },
738
803
  focusSplitter(ctx2) {
739
- nextTick(() => {
804
+ raf(() => {
740
805
  var _a;
741
806
  return (_a = dom.getSplitterEl(ctx2)) == null ? void 0 : _a.focus();
742
807
  });