@dnd-kit/dom 0.1.7 → 0.1.8-beta-20250504131722
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 +54 -46
- package/utilities.cjs.map +1 -1
- package/utilities.d.cts +7 -1
- package/utilities.d.ts +7 -1
- package/utilities.js +54 -46
- package/utilities.js.map +1 -1
package/utilities.js
CHANGED
|
@@ -511,18 +511,59 @@ function canScroll(scrollableElement, by) {
|
|
|
511
511
|
};
|
|
512
512
|
}
|
|
513
513
|
|
|
514
|
+
// src/utilities/scheduling/scheduler.ts
|
|
515
|
+
var Scheduler = class {
|
|
516
|
+
constructor(scheduler4) {
|
|
517
|
+
this.scheduler = scheduler4;
|
|
518
|
+
this.pending = false;
|
|
519
|
+
this.tasks = /* @__PURE__ */ new Set();
|
|
520
|
+
this.resolvers = /* @__PURE__ */ new Set();
|
|
521
|
+
this.flush = () => {
|
|
522
|
+
const { tasks, resolvers } = this;
|
|
523
|
+
this.pending = false;
|
|
524
|
+
this.tasks = /* @__PURE__ */ new Set();
|
|
525
|
+
this.resolvers = /* @__PURE__ */ new Set();
|
|
526
|
+
for (const task of tasks) {
|
|
527
|
+
task();
|
|
528
|
+
}
|
|
529
|
+
for (const resolve of resolvers) {
|
|
530
|
+
resolve();
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
schedule(task) {
|
|
535
|
+
this.tasks.add(task);
|
|
536
|
+
if (!this.pending) {
|
|
537
|
+
this.pending = true;
|
|
538
|
+
this.scheduler(this.flush);
|
|
539
|
+
}
|
|
540
|
+
return new Promise((resolve) => this.resolvers.add(resolve));
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
var scheduler = new Scheduler(
|
|
544
|
+
(callback) => requestAnimationFrame(callback)
|
|
545
|
+
);
|
|
546
|
+
|
|
514
547
|
// src/utilities/styles/getComputedStyles.ts
|
|
515
|
-
|
|
516
|
-
|
|
548
|
+
var scheduler2 = new Scheduler((callback) => setTimeout(callback, 50));
|
|
549
|
+
var cachedStyles = /* @__PURE__ */ new Map();
|
|
550
|
+
var clear = cachedStyles.clear.bind(cachedStyles);
|
|
551
|
+
function getComputedStyles(element, cached = false) {
|
|
552
|
+
let styles = cachedStyles.get(element);
|
|
553
|
+
if (cached && styles) return styles;
|
|
554
|
+
styles = getWindow(element).getComputedStyle(element);
|
|
555
|
+
cachedStyles.set(element, styles);
|
|
556
|
+
scheduler2.schedule(clear);
|
|
557
|
+
return styles;
|
|
517
558
|
}
|
|
518
559
|
|
|
519
560
|
// src/utilities/scroll/isFixed.ts
|
|
520
|
-
function isFixed(node, computedStyle = getComputedStyles(node)) {
|
|
561
|
+
function isFixed(node, computedStyle = getComputedStyles(node, true)) {
|
|
521
562
|
return computedStyle.position === "fixed" || computedStyle.position === "sticky";
|
|
522
563
|
}
|
|
523
564
|
|
|
524
565
|
// src/utilities/scroll/isScrollable.ts
|
|
525
|
-
function isScrollable(element, computedStyle = getComputedStyles(element)) {
|
|
566
|
+
function isScrollable(element, computedStyle = getComputedStyles(element, true)) {
|
|
526
567
|
const overflowRegex = /(auto|scroll|overlay)/;
|
|
527
568
|
const properties = ["overflow", "overflowX", "overflowY"];
|
|
528
569
|
return properties.some((property) => {
|
|
@@ -558,7 +599,7 @@ function getScrollableAncestors(element, options = defaultOptions) {
|
|
|
558
599
|
if (scrollParents.has(node)) {
|
|
559
600
|
return scrollParents;
|
|
560
601
|
}
|
|
561
|
-
const computedStyle = getComputedStyles(node);
|
|
602
|
+
const computedStyle = getComputedStyles(node, true);
|
|
562
603
|
if (excludeElement && node === element) ; else if (isScrollable(node, computedStyle)) {
|
|
563
604
|
scrollParents.add(node);
|
|
564
605
|
}
|
|
@@ -602,7 +643,7 @@ function getFrameTransform(el, boundary = window.frameElement) {
|
|
|
602
643
|
if (frame === boundary) {
|
|
603
644
|
return transform;
|
|
604
645
|
}
|
|
605
|
-
const rect = frame
|
|
646
|
+
const rect = getBoundingRectangle(frame);
|
|
606
647
|
const { x: scaleX, y: scaleY } = getScale(frame, rect);
|
|
607
648
|
transform.x = transform.x + rect.left;
|
|
608
649
|
transform.y = transform.y + rect.top;
|
|
@@ -612,7 +653,7 @@ function getFrameTransform(el, boundary = window.frameElement) {
|
|
|
612
653
|
}
|
|
613
654
|
return transform;
|
|
614
655
|
}
|
|
615
|
-
function getScale(element, boundingRectangle = element
|
|
656
|
+
function getScale(element, boundingRectangle = getBoundingRectangle(element)) {
|
|
616
657
|
const width = Math.round(boundingRectangle.width);
|
|
617
658
|
const height = Math.round(boundingRectangle.height);
|
|
618
659
|
if (isHTMLElement(element)) {
|
|
@@ -621,7 +662,7 @@ function getScale(element, boundingRectangle = element.getBoundingClientRect())
|
|
|
621
662
|
y: height / element.offsetHeight
|
|
622
663
|
};
|
|
623
664
|
}
|
|
624
|
-
const styles = getComputedStyles(element);
|
|
665
|
+
const styles = getComputedStyles(element, true);
|
|
625
666
|
return {
|
|
626
667
|
x: (parseFloat(styles.width) || width) / width,
|
|
627
668
|
y: (parseFloat(styles.height) || height) / height
|
|
@@ -734,7 +775,7 @@ function detectScrollIntent(scrollableElement, coordinates, intent, acceleration
|
|
|
734
775
|
const { x, y } = coordinates;
|
|
735
776
|
const { rect, isTop, isBottom, isLeft, isRight } = getScrollPosition(scrollableElement);
|
|
736
777
|
const frameTransform = getFrameTransform(scrollableElement);
|
|
737
|
-
const computedStyles = getComputedStyles(scrollableElement);
|
|
778
|
+
const computedStyles = getComputedStyles(scrollableElement, true);
|
|
738
779
|
const parsedTransform = parseTransform(computedStyles);
|
|
739
780
|
const isXAxisInverted = parsedTransform !== null ? (parsedTransform == null ? void 0 : parsedTransform.scaleX) < 0 : false;
|
|
740
781
|
const isYAxisInverted = parsedTransform !== null ? (parsedTransform == null ? void 0 : parsedTransform.scaleY) < 0 : false;
|
|
@@ -800,7 +841,7 @@ function scrollIntoViewIfNeeded(el, centerIfNeeded = false) {
|
|
|
800
841
|
if (!isHTMLElement(parent)) {
|
|
801
842
|
return;
|
|
802
843
|
}
|
|
803
|
-
const parentComputedStyle = getComputedStyles(parent), parentBorderTopWidth = parseInt(
|
|
844
|
+
const parentComputedStyle = getComputedStyles(parent, true), parentBorderTopWidth = parseInt(
|
|
804
845
|
parentComputedStyle.getPropertyValue("border-top-width")
|
|
805
846
|
), parentBorderLeftWidth = parseInt(
|
|
806
847
|
parentComputedStyle.getPropertyValue("border-left-width")
|
|
@@ -816,39 +857,6 @@ function scrollIntoViewIfNeeded(el, centerIfNeeded = false) {
|
|
|
816
857
|
}
|
|
817
858
|
}
|
|
818
859
|
|
|
819
|
-
// src/utilities/scheduling/scheduler.ts
|
|
820
|
-
var Scheduler = class {
|
|
821
|
-
constructor(scheduler3) {
|
|
822
|
-
this.scheduler = scheduler3;
|
|
823
|
-
this.pending = false;
|
|
824
|
-
this.tasks = /* @__PURE__ */ new Set();
|
|
825
|
-
this.resolvers = /* @__PURE__ */ new Set();
|
|
826
|
-
this.flush = () => {
|
|
827
|
-
const { tasks, resolvers } = this;
|
|
828
|
-
this.pending = false;
|
|
829
|
-
this.tasks = /* @__PURE__ */ new Set();
|
|
830
|
-
this.resolvers = /* @__PURE__ */ new Set();
|
|
831
|
-
for (const task of tasks) {
|
|
832
|
-
task();
|
|
833
|
-
}
|
|
834
|
-
for (const resolve of resolvers) {
|
|
835
|
-
resolve();
|
|
836
|
-
}
|
|
837
|
-
};
|
|
838
|
-
}
|
|
839
|
-
schedule(task) {
|
|
840
|
-
this.tasks.add(task);
|
|
841
|
-
if (!this.pending) {
|
|
842
|
-
this.pending = true;
|
|
843
|
-
this.scheduler(this.flush);
|
|
844
|
-
}
|
|
845
|
-
return new Promise((resolve) => this.resolvers.add(resolve));
|
|
846
|
-
}
|
|
847
|
-
};
|
|
848
|
-
var scheduler = new Scheduler(
|
|
849
|
-
(callback) => requestAnimationFrame(callback)
|
|
850
|
-
);
|
|
851
|
-
|
|
852
860
|
// src/utilities/transform/inverseTransform.ts
|
|
853
861
|
function inverseTransform(rect, parsedTransform, transformOrigin) {
|
|
854
862
|
const { scaleX, scaleY, x: translateX, y: translateY } = parsedTransform;
|
|
@@ -1009,16 +1017,16 @@ function getProjectedTransform(element) {
|
|
|
1009
1017
|
}
|
|
1010
1018
|
return projectedTransform;
|
|
1011
1019
|
}
|
|
1012
|
-
var
|
|
1020
|
+
var scheduler3 = new Scheduler((callback) => setTimeout(callback, 0));
|
|
1013
1021
|
var animations = /* @__PURE__ */ new Map();
|
|
1014
|
-
var
|
|
1022
|
+
var clear2 = animations.clear.bind(animations);
|
|
1015
1023
|
function getDocumentAnimations(element) {
|
|
1016
1024
|
const document2 = element.ownerDocument;
|
|
1017
1025
|
let documentAnimations = animations.get(document2);
|
|
1018
1026
|
if (documentAnimations) return documentAnimations;
|
|
1019
1027
|
documentAnimations = document2.getAnimations();
|
|
1020
1028
|
animations.set(document2, documentAnimations);
|
|
1021
|
-
|
|
1029
|
+
scheduler3.schedule(clear2);
|
|
1022
1030
|
const elementAnimations = documentAnimations.filter(
|
|
1023
1031
|
(animation) => isKeyframeEffect(animation.effect) && animation.effect.target === element
|
|
1024
1032
|
);
|