@dnd-kit/dom 0.5.2-beta-20261029020134 → 0.5.2
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/package.json +5 -5
- package/utilities.cjs +82 -61
- package/utilities.cjs.map +1 -1
- package/utilities.d.cts +4 -0
- package/utilities.d.ts +4 -0
- package/utilities.js +82 -61
- package/utilities.js.map +1 -1
package/utilities.d.cts
CHANGED
package/utilities.d.ts
CHANGED
package/utilities.js
CHANGED
|
@@ -747,6 +747,60 @@ function hidePopover(element) {
|
|
|
747
747
|
}
|
|
748
748
|
}
|
|
749
749
|
|
|
750
|
+
// src/utilities/scheduling/scheduler.ts
|
|
751
|
+
var Scheduler = class {
|
|
752
|
+
constructor(scheduler4) {
|
|
753
|
+
this.scheduler = scheduler4;
|
|
754
|
+
this.pending = false;
|
|
755
|
+
this.tasks = /* @__PURE__ */ new Set();
|
|
756
|
+
this.resolvers = /* @__PURE__ */ new Set();
|
|
757
|
+
this.flush = () => {
|
|
758
|
+
const { tasks, resolvers } = this;
|
|
759
|
+
this.pending = false;
|
|
760
|
+
this.tasks = /* @__PURE__ */ new Set();
|
|
761
|
+
this.resolvers = /* @__PURE__ */ new Set();
|
|
762
|
+
for (const task of tasks) {
|
|
763
|
+
task();
|
|
764
|
+
}
|
|
765
|
+
for (const resolve of resolvers) {
|
|
766
|
+
resolve();
|
|
767
|
+
}
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
schedule(task) {
|
|
771
|
+
this.tasks.add(task);
|
|
772
|
+
if (!this.pending) {
|
|
773
|
+
this.pending = true;
|
|
774
|
+
this.scheduler(this.flush);
|
|
775
|
+
}
|
|
776
|
+
return new Promise((resolve) => this.resolvers.add(resolve));
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
var scheduler = new Scheduler((callback) => {
|
|
780
|
+
if (typeof requestAnimationFrame === "function") {
|
|
781
|
+
requestAnimationFrame(callback);
|
|
782
|
+
} else {
|
|
783
|
+
callback();
|
|
784
|
+
}
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
// src/utilities/styles/getComputedStyles.ts
|
|
788
|
+
var scheduler2 = new Scheduler((callback) => setTimeout(callback, 50));
|
|
789
|
+
var cachedStyles = /* @__PURE__ */ new Map();
|
|
790
|
+
var clear = cachedStyles.clear.bind(cachedStyles);
|
|
791
|
+
function getComputedStyles(element, cached = false) {
|
|
792
|
+
if (!cached) return computeStyles(element);
|
|
793
|
+
let styles = cachedStyles.get(element);
|
|
794
|
+
if (styles) return styles;
|
|
795
|
+
styles = computeStyles(element);
|
|
796
|
+
cachedStyles.set(element, styles);
|
|
797
|
+
scheduler2.schedule(clear);
|
|
798
|
+
return styles;
|
|
799
|
+
}
|
|
800
|
+
function computeStyles(element) {
|
|
801
|
+
return getWindow(element).getComputedStyle(element);
|
|
802
|
+
}
|
|
803
|
+
|
|
750
804
|
// src/utilities/scroll/documentScrollingElement.ts
|
|
751
805
|
function isDocumentScrollingElement(element) {
|
|
752
806
|
if (!canUseDOM || !element) {
|
|
@@ -759,27 +813,35 @@ function isDocumentScrollingElement(element) {
|
|
|
759
813
|
function getScrollPosition(scrollableElement) {
|
|
760
814
|
var _a, _b;
|
|
761
815
|
const window2 = getWindow(scrollableElement);
|
|
762
|
-
const
|
|
816
|
+
const isDocument2 = isDocumentScrollingElement(scrollableElement);
|
|
817
|
+
const rect = isDocument2 ? getViewportBoundingRectangle(scrollableElement) : getBoundingRectangle(scrollableElement);
|
|
763
818
|
const vv = window2.visualViewport;
|
|
764
|
-
const dimensions =
|
|
819
|
+
const dimensions = isDocument2 ? {
|
|
765
820
|
height: (_a = vv == null ? void 0 : vv.height) != null ? _a : window2.innerHeight,
|
|
766
821
|
width: (_b = vv == null ? void 0 : vv.width) != null ? _b : window2.innerWidth
|
|
767
822
|
} : {
|
|
768
823
|
height: scrollableElement.clientHeight,
|
|
769
824
|
width: scrollableElement.clientWidth
|
|
770
825
|
};
|
|
826
|
+
const rangeX = scrollableElement.scrollWidth - dimensions.width;
|
|
827
|
+
const styles = getComputedStyles(scrollableElement, true);
|
|
828
|
+
const hasNegativeScrollLeft = isDocument2 ? styles.direction === "rtl" : isHorizontalScrollReversed(styles);
|
|
771
829
|
const position = {
|
|
772
830
|
current: {
|
|
773
831
|
x: scrollableElement.scrollLeft,
|
|
774
832
|
y: scrollableElement.scrollTop
|
|
775
833
|
},
|
|
834
|
+
min: {
|
|
835
|
+
x: hasNegativeScrollLeft ? -rangeX : 0,
|
|
836
|
+
y: 0
|
|
837
|
+
},
|
|
776
838
|
max: {
|
|
777
|
-
x:
|
|
839
|
+
x: hasNegativeScrollLeft ? 0 : rangeX,
|
|
778
840
|
y: scrollableElement.scrollHeight - dimensions.height
|
|
779
841
|
}
|
|
780
842
|
};
|
|
781
|
-
const isTop = position.current.y <=
|
|
782
|
-
const isLeft = position.current.x <=
|
|
843
|
+
const isTop = position.current.y <= position.min.y;
|
|
844
|
+
const isLeft = position.current.x <= position.min.x;
|
|
783
845
|
const isBottom = position.current.y >= position.max.y;
|
|
784
846
|
const isRight = position.current.x >= position.max.x;
|
|
785
847
|
return {
|
|
@@ -791,14 +853,27 @@ function getScrollPosition(scrollableElement) {
|
|
|
791
853
|
isRight
|
|
792
854
|
};
|
|
793
855
|
}
|
|
856
|
+
function isHorizontalScrollReversed(styles) {
|
|
857
|
+
const { direction, display, writingMode } = styles;
|
|
858
|
+
const isVertical = writingMode === "vertical-lr" || writingMode === "vertical-rl" || writingMode === "sideways-lr" || writingMode === "sideways-rl";
|
|
859
|
+
const isReversed = isVertical ? writingMode === "vertical-rl" || writingMode === "sideways-rl" : direction === "rtl";
|
|
860
|
+
if (display !== "flex" && display !== "inline-flex") {
|
|
861
|
+
return isReversed;
|
|
862
|
+
}
|
|
863
|
+
const { flexDirection, flexWrap } = styles;
|
|
864
|
+
const isRow = flexDirection === "row" || flexDirection === "row-reverse";
|
|
865
|
+
const isHorizontalMainAxis = isVertical ? !isRow : isRow;
|
|
866
|
+
const isFlexReversed = isHorizontalMainAxis ? flexDirection === "row-reverse" || flexDirection === "column-reverse" : flexWrap === "wrap-reverse";
|
|
867
|
+
return isReversed !== isFlexReversed;
|
|
868
|
+
}
|
|
794
869
|
|
|
795
870
|
// src/utilities/scroll/canScroll.ts
|
|
796
871
|
function canScroll(scrollableElement, by, scrollPosition = getScrollPosition(scrollableElement)) {
|
|
797
872
|
const { isTop, isBottom, isLeft, isRight, position } = scrollPosition;
|
|
798
873
|
const { x, y } = by != null ? by : { x: 0, y: 0 };
|
|
799
|
-
const top = !isTop && position.current.y + y >
|
|
874
|
+
const top = !isTop && position.current.y + y > position.min.y;
|
|
800
875
|
const bottom = !isBottom && position.current.y + y < position.max.y;
|
|
801
|
-
const left = !isLeft && position.current.x + x >
|
|
876
|
+
const left = !isLeft && position.current.x + x > position.min.x;
|
|
802
877
|
const right = !isRight && position.current.x + x < position.max.x;
|
|
803
878
|
return {
|
|
804
879
|
top,
|
|
@@ -810,60 +885,6 @@ function canScroll(scrollableElement, by, scrollPosition = getScrollPosition(scr
|
|
|
810
885
|
};
|
|
811
886
|
}
|
|
812
887
|
|
|
813
|
-
// src/utilities/scheduling/scheduler.ts
|
|
814
|
-
var Scheduler = class {
|
|
815
|
-
constructor(scheduler4) {
|
|
816
|
-
this.scheduler = scheduler4;
|
|
817
|
-
this.pending = false;
|
|
818
|
-
this.tasks = /* @__PURE__ */ new Set();
|
|
819
|
-
this.resolvers = /* @__PURE__ */ new Set();
|
|
820
|
-
this.flush = () => {
|
|
821
|
-
const { tasks, resolvers } = this;
|
|
822
|
-
this.pending = false;
|
|
823
|
-
this.tasks = /* @__PURE__ */ new Set();
|
|
824
|
-
this.resolvers = /* @__PURE__ */ new Set();
|
|
825
|
-
for (const task of tasks) {
|
|
826
|
-
task();
|
|
827
|
-
}
|
|
828
|
-
for (const resolve of resolvers) {
|
|
829
|
-
resolve();
|
|
830
|
-
}
|
|
831
|
-
};
|
|
832
|
-
}
|
|
833
|
-
schedule(task) {
|
|
834
|
-
this.tasks.add(task);
|
|
835
|
-
if (!this.pending) {
|
|
836
|
-
this.pending = true;
|
|
837
|
-
this.scheduler(this.flush);
|
|
838
|
-
}
|
|
839
|
-
return new Promise((resolve) => this.resolvers.add(resolve));
|
|
840
|
-
}
|
|
841
|
-
};
|
|
842
|
-
var scheduler = new Scheduler((callback) => {
|
|
843
|
-
if (typeof requestAnimationFrame === "function") {
|
|
844
|
-
requestAnimationFrame(callback);
|
|
845
|
-
} else {
|
|
846
|
-
callback();
|
|
847
|
-
}
|
|
848
|
-
});
|
|
849
|
-
|
|
850
|
-
// src/utilities/styles/getComputedStyles.ts
|
|
851
|
-
var scheduler2 = new Scheduler((callback) => setTimeout(callback, 50));
|
|
852
|
-
var cachedStyles = /* @__PURE__ */ new Map();
|
|
853
|
-
var clear = cachedStyles.clear.bind(cachedStyles);
|
|
854
|
-
function getComputedStyles(element, cached = false) {
|
|
855
|
-
if (!cached) return computeStyles(element);
|
|
856
|
-
let styles = cachedStyles.get(element);
|
|
857
|
-
if (styles) return styles;
|
|
858
|
-
styles = computeStyles(element);
|
|
859
|
-
cachedStyles.set(element, styles);
|
|
860
|
-
scheduler2.schedule(clear);
|
|
861
|
-
return styles;
|
|
862
|
-
}
|
|
863
|
-
function computeStyles(element) {
|
|
864
|
-
return getWindow(element).getComputedStyle(element);
|
|
865
|
-
}
|
|
866
|
-
|
|
867
888
|
// src/utilities/scroll/isFixed.ts
|
|
868
889
|
function isFixed(node, computedStyle = getComputedStyles(node, true)) {
|
|
869
890
|
return computedStyle.position === "fixed" || computedStyle.position === "sticky";
|