@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.js +23 -10
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +23 -10
- package/dist/index.mjs.map +3 -3
- package/dist/splitter.dom.d.ts +1 -0
- package/dist/splitter.dom.d.ts.map +1 -1
- package/dist/splitter.machine.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -369,6 +369,10 @@ var dom = {
|
|
|
369
369
|
var _a;
|
|
370
370
|
return (_a = ctx.doc) != null ? _a : document;
|
|
371
371
|
},
|
|
372
|
+
getRootNode: (ctx) => {
|
|
373
|
+
var _a;
|
|
374
|
+
return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
|
|
375
|
+
},
|
|
372
376
|
getRootId: (ctx) => {
|
|
373
377
|
var _a, _b;
|
|
374
378
|
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `splitter:${ctx.uid}`;
|
|
@@ -393,8 +397,8 @@ var dom = {
|
|
|
393
397
|
var _a, _b;
|
|
394
398
|
return (_b = (_a = ctx.ids) == null ? void 0 : _a.secondaryPane) != null ? _b : `splitter:${ctx.uid}:secondary`;
|
|
395
399
|
},
|
|
396
|
-
getSplitterEl: (ctx) => dom.
|
|
397
|
-
getPrimaryPaneEl: (ctx) => dom.
|
|
400
|
+
getSplitterEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getSplitterId(ctx)),
|
|
401
|
+
getPrimaryPaneEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getPrimaryPaneId(ctx)),
|
|
398
402
|
getCursor(ctx) {
|
|
399
403
|
if (ctx.disabled || ctx.fixed)
|
|
400
404
|
return "default";
|
|
@@ -577,10 +581,6 @@ var import_core = require("@zag-js/core");
|
|
|
577
581
|
|
|
578
582
|
// ../../utilities/number/dist/index.mjs
|
|
579
583
|
var __pow2 = Math.pow;
|
|
580
|
-
var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
|
|
581
|
-
function formatter(n) {
|
|
582
|
-
return parseFloat(nf.format(n));
|
|
583
|
-
}
|
|
584
584
|
function round(v, t2) {
|
|
585
585
|
let num = valueOf(v);
|
|
586
586
|
const p = __pow2(10, t2 != null ? t2 : 10);
|
|
@@ -593,16 +593,15 @@ function clamp(v, o) {
|
|
|
593
593
|
function countDecimals(value) {
|
|
594
594
|
if (!Number.isFinite(value))
|
|
595
595
|
return 0;
|
|
596
|
-
let e = 1;
|
|
597
|
-
let p = 0;
|
|
596
|
+
let e = 1, p = 0;
|
|
598
597
|
while (Math.round(value * e) / e !== value) {
|
|
599
598
|
e *= 10;
|
|
600
599
|
p += 1;
|
|
601
600
|
}
|
|
602
601
|
return p;
|
|
603
602
|
}
|
|
604
|
-
var increment = (v, s) =>
|
|
605
|
-
var decrement = (v, s) =>
|
|
603
|
+
var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
|
|
604
|
+
var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
|
|
606
605
|
function snapToStep(value, step) {
|
|
607
606
|
const num = valueOf(value);
|
|
608
607
|
const p = countDecimals(step);
|
|
@@ -615,6 +614,18 @@ function valueOf(v) {
|
|
|
615
614
|
const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
|
|
616
615
|
return !Number.isNaN(num) ? num : 0;
|
|
617
616
|
}
|
|
617
|
+
function decimalOperation(a, op, b) {
|
|
618
|
+
let result = op === "+" ? a + b : a - b;
|
|
619
|
+
if (a % 1 !== 0 || b % 1 !== 0) {
|
|
620
|
+
const multiplier = __pow2(10, Math.max(countDecimals(a), countDecimals(b)));
|
|
621
|
+
a = Math.round(a * multiplier);
|
|
622
|
+
b = Math.round(b * multiplier);
|
|
623
|
+
result = op === "+" ? a + b : a - b;
|
|
624
|
+
result /= multiplier;
|
|
625
|
+
}
|
|
626
|
+
return result;
|
|
627
|
+
}
|
|
628
|
+
var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
|
|
618
629
|
|
|
619
630
|
// ../../utilities/rect/dist/index.mjs
|
|
620
631
|
function relativeToNode(p, el) {
|
|
@@ -809,6 +820,8 @@ function machine(ctx = {}) {
|
|
|
809
820
|
setupDocument(ctx2, evt) {
|
|
810
821
|
if (evt.doc)
|
|
811
822
|
ctx2.doc = (0, import_core.ref)(evt.doc);
|
|
823
|
+
if (evt.root)
|
|
824
|
+
ctx2.rootNode = (0, import_core.ref)(evt.root);
|
|
812
825
|
ctx2.uid = evt.id;
|
|
813
826
|
},
|
|
814
827
|
setToMin(ctx2) {
|