@zag-js/splitter 0.1.0 → 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
@@ -56,6 +56,12 @@ function nextTick(fn) {
56
56
  });
57
57
  };
58
58
  }
59
+ function raf(fn) {
60
+ const id = globalThis.requestAnimationFrame(fn);
61
+ return function cleanup() {
62
+ globalThis.cancelAnimationFrame(id);
63
+ };
64
+ }
59
65
  var noop = () => {
60
66
  };
61
67
  var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
@@ -235,6 +241,30 @@ function getEventStep(event) {
235
241
  return isSkipKey ? 10 : 1;
236
242
  }
237
243
  }
244
+ function itemById(v, id) {
245
+ return v.find((node) => node.id === id);
246
+ }
247
+ function indexOfId(v, id) {
248
+ const item = itemById(v, id);
249
+ return item ? v.indexOf(item) : -1;
250
+ }
251
+ var getValueText = (item) => {
252
+ var _a, _b;
253
+ return (_b = (_a = item.dataset.valuetext) != null ? _a : item.textContent) != null ? _b : "";
254
+ };
255
+ var match = (valueText, query2) => valueText.toLowerCase().startsWith(query2.toLowerCase());
256
+ var wrap = (v, idx) => {
257
+ return v.map((_, index) => v[(Math.max(idx, 0) + index) % v.length]);
258
+ };
259
+ function findByText(v, text, currentId) {
260
+ const index = currentId ? indexOfId(v, currentId) : -1;
261
+ let items = currentId ? wrap(v, index) : v;
262
+ const isSingleKey = text.length === 1;
263
+ if (isSingleKey) {
264
+ items = items.filter((item) => item.id !== currentId);
265
+ }
266
+ return items.find((item) => match(getValueText(item), text));
267
+ }
238
268
  var state = "default";
239
269
  var savedUserSelect = "";
240
270
  var modifiedElementMap = /* @__PURE__ */ new WeakMap();
@@ -298,6 +328,34 @@ function trackPointerMove(opts) {
298
328
  };
299
329
  return pipe(addPointerEvent(doc, "pointermove", handlePointerMove, false), addPointerEvent(doc, "pointerup", onPointerUp, false), addPointerEvent(doc, "pointercancel", onPointerUp, false), addPointerEvent(doc, "contextmenu", onPointerUp, false), disableTextSelection({ doc }));
300
330
  }
331
+ function findByTypeahead(_items, options) {
332
+ const { state: state2, activeId, key, timeout = 350 } = options;
333
+ const search = state2.keysSoFar + key;
334
+ const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]);
335
+ const query2 = isRepeated ? search[0] : search;
336
+ let items = _items.slice();
337
+ const next = findByText(items, query2, activeId);
338
+ function cleanup() {
339
+ clearTimeout(state2.timer);
340
+ state2.timer = -1;
341
+ }
342
+ function update(value) {
343
+ state2.keysSoFar = value;
344
+ cleanup();
345
+ if (value !== "") {
346
+ state2.timer = +setTimeout(() => {
347
+ update("");
348
+ cleanup();
349
+ }, timeout);
350
+ }
351
+ }
352
+ update(search);
353
+ return next;
354
+ }
355
+ findByTypeahead.defaultOptions = {
356
+ keysSoFar: "",
357
+ timer: -1
358
+ };
301
359
 
302
360
  // ../../types/dist/index.mjs
303
361
  function createNormalizer(fn) {
@@ -519,7 +577,7 @@ var import_core = require("@zag-js/core");
519
577
 
520
578
  // ../../utilities/number/dist/index.mjs
521
579
  var __pow2 = Math.pow;
522
- var nf = new Intl.NumberFormat("en-US", { style: "decimal" });
580
+ var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
523
581
  function formatter(n) {
524
582
  return parseFloat(nf.format(n));
525
583
  }
@@ -532,9 +590,16 @@ function round(v, t2) {
532
590
  function clamp(v, o) {
533
591
  return Math.min(Math.max(valueOf(v), o.min), o.max);
534
592
  }
535
- function countDecimals(v) {
536
- var _a, _b;
537
- return (_b = (_a = nf.formatToParts(v).find((p) => p.type === "fraction")) == null ? void 0 : _a.value.length) != null ? _b : 0;
593
+ function countDecimals(value) {
594
+ if (!Number.isFinite(value))
595
+ return 0;
596
+ let e = 1;
597
+ let p = 0;
598
+ while (Math.round(value * e) / e !== value) {
599
+ e *= 10;
600
+ p += 1;
601
+ }
602
+ return p;
538
603
  }
539
604
  var increment = (v, s) => formatter(valueOf(v) + s);
540
605
  var decrement = (v, s) => formatter(valueOf(v) - s);
@@ -759,7 +824,7 @@ function machine(ctx = {}) {
759
824
  ctx2.value = clamp(decrement(ctx2.value, evt.step), ctx2);
760
825
  },
761
826
  focusSplitter(ctx2) {
762
- nextTick(() => {
827
+ raf(() => {
763
828
  var _a;
764
829
  return (_a = dom.getSplitterEl(ctx2)) == null ? void 0 : _a.focus();
765
830
  });