@zag-js/splitter 0.1.3 → 0.1.4

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
@@ -346,6 +346,10 @@ var dom = {
346
346
  var _a;
347
347
  return (_a = ctx.doc) != null ? _a : document;
348
348
  },
349
+ getRootNode: (ctx) => {
350
+ var _a;
351
+ return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
352
+ },
349
353
  getRootId: (ctx) => {
350
354
  var _a, _b;
351
355
  return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `splitter:${ctx.uid}`;
@@ -370,8 +374,8 @@ var dom = {
370
374
  var _a, _b;
371
375
  return (_b = (_a = ctx.ids) == null ? void 0 : _a.secondaryPane) != null ? _b : `splitter:${ctx.uid}:secondary`;
372
376
  },
373
- getSplitterEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getSplitterId(ctx)),
374
- getPrimaryPaneEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getPrimaryPaneId(ctx)),
377
+ getSplitterEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getSplitterId(ctx)),
378
+ getPrimaryPaneEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getPrimaryPaneId(ctx)),
375
379
  getCursor(ctx) {
376
380
  if (ctx.disabled || ctx.fixed)
377
381
  return "default";
@@ -554,10 +558,6 @@ import { createMachine, guards, ref } from "@zag-js/core";
554
558
 
555
559
  // ../../utilities/number/dist/index.mjs
556
560
  var __pow2 = Math.pow;
557
- var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
558
- function formatter(n) {
559
- return parseFloat(nf.format(n));
560
- }
561
561
  function round(v, t2) {
562
562
  let num = valueOf(v);
563
563
  const p = __pow2(10, t2 != null ? t2 : 10);
@@ -570,16 +570,15 @@ function clamp(v, o) {
570
570
  function countDecimals(value) {
571
571
  if (!Number.isFinite(value))
572
572
  return 0;
573
- let e = 1;
574
- let p = 0;
573
+ let e = 1, p = 0;
575
574
  while (Math.round(value * e) / e !== value) {
576
575
  e *= 10;
577
576
  p += 1;
578
577
  }
579
578
  return p;
580
579
  }
581
- var increment = (v, s) => formatter(valueOf(v) + s);
582
- var decrement = (v, s) => formatter(valueOf(v) - s);
580
+ var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
581
+ var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
583
582
  function snapToStep(value, step) {
584
583
  const num = valueOf(value);
585
584
  const p = countDecimals(step);
@@ -592,6 +591,18 @@ function valueOf(v) {
592
591
  const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
593
592
  return !Number.isNaN(num) ? num : 0;
594
593
  }
594
+ function decimalOperation(a, op, b) {
595
+ let result = op === "+" ? a + b : a - b;
596
+ if (a % 1 !== 0 || b % 1 !== 0) {
597
+ const multiplier = __pow2(10, Math.max(countDecimals(a), countDecimals(b)));
598
+ a = Math.round(a * multiplier);
599
+ b = Math.round(b * multiplier);
600
+ result = op === "+" ? a + b : a - b;
601
+ result /= multiplier;
602
+ }
603
+ return result;
604
+ }
605
+ var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
595
606
 
596
607
  // ../../utilities/rect/dist/index.mjs
597
608
  function relativeToNode(p, el) {
@@ -786,6 +797,8 @@ function machine(ctx = {}) {
786
797
  setupDocument(ctx2, evt) {
787
798
  if (evt.doc)
788
799
  ctx2.doc = ref(evt.doc);
800
+ if (evt.root)
801
+ ctx2.rootNode = ref(evt.root);
789
802
  ctx2.uid = evt.id;
790
803
  },
791
804
  setToMin(ctx2) {