@dnd-kit/dom 0.1.7 → 0.1.8-beta-20250504134846

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/utilities.js CHANGED
@@ -511,18 +511,63 @@ 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
- function getComputedStyles(element) {
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
+ if (!cached) return computeStyles(element);
553
+ let styles = cachedStyles.get(element);
554
+ if (styles) return styles;
555
+ styles = computeStyles(element);
556
+ cachedStyles.set(element, styles);
557
+ scheduler2.schedule(clear);
558
+ return styles;
559
+ }
560
+ function computeStyles(element) {
516
561
  return getWindow(element).getComputedStyle(element);
517
562
  }
518
563
 
519
564
  // src/utilities/scroll/isFixed.ts
520
- function isFixed(node, computedStyle = getComputedStyles(node)) {
565
+ function isFixed(node, computedStyle = getComputedStyles(node, true)) {
521
566
  return computedStyle.position === "fixed" || computedStyle.position === "sticky";
522
567
  }
523
568
 
524
569
  // src/utilities/scroll/isScrollable.ts
525
- function isScrollable(element, computedStyle = getComputedStyles(element)) {
570
+ function isScrollable(element, computedStyle = getComputedStyles(element, true)) {
526
571
  const overflowRegex = /(auto|scroll|overlay)/;
527
572
  const properties = ["overflow", "overflowX", "overflowY"];
528
573
  return properties.some((property) => {
@@ -558,7 +603,7 @@ function getScrollableAncestors(element, options = defaultOptions) {
558
603
  if (scrollParents.has(node)) {
559
604
  return scrollParents;
560
605
  }
561
- const computedStyle = getComputedStyles(node);
606
+ const computedStyle = getComputedStyles(node, true);
562
607
  if (excludeElement && node === element) ; else if (isScrollable(node, computedStyle)) {
563
608
  scrollParents.add(node);
564
609
  }
@@ -602,7 +647,7 @@ function getFrameTransform(el, boundary = window.frameElement) {
602
647
  if (frame === boundary) {
603
648
  return transform;
604
649
  }
605
- const rect = frame.getBoundingClientRect();
650
+ const rect = getBoundingRectangle(frame);
606
651
  const { x: scaleX, y: scaleY } = getScale(frame, rect);
607
652
  transform.x = transform.x + rect.left;
608
653
  transform.y = transform.y + rect.top;
@@ -612,7 +657,7 @@ function getFrameTransform(el, boundary = window.frameElement) {
612
657
  }
613
658
  return transform;
614
659
  }
615
- function getScale(element, boundingRectangle = element.getBoundingClientRect()) {
660
+ function getScale(element, boundingRectangle = getBoundingRectangle(element)) {
616
661
  const width = Math.round(boundingRectangle.width);
617
662
  const height = Math.round(boundingRectangle.height);
618
663
  if (isHTMLElement(element)) {
@@ -621,7 +666,7 @@ function getScale(element, boundingRectangle = element.getBoundingClientRect())
621
666
  y: height / element.offsetHeight
622
667
  };
623
668
  }
624
- const styles = getComputedStyles(element);
669
+ const styles = getComputedStyles(element, true);
625
670
  return {
626
671
  x: (parseFloat(styles.width) || width) / width,
627
672
  y: (parseFloat(styles.height) || height) / height
@@ -734,7 +779,7 @@ function detectScrollIntent(scrollableElement, coordinates, intent, acceleration
734
779
  const { x, y } = coordinates;
735
780
  const { rect, isTop, isBottom, isLeft, isRight } = getScrollPosition(scrollableElement);
736
781
  const frameTransform = getFrameTransform(scrollableElement);
737
- const computedStyles = getComputedStyles(scrollableElement);
782
+ const computedStyles = getComputedStyles(scrollableElement, true);
738
783
  const parsedTransform = parseTransform(computedStyles);
739
784
  const isXAxisInverted = parsedTransform !== null ? (parsedTransform == null ? void 0 : parsedTransform.scaleX) < 0 : false;
740
785
  const isYAxisInverted = parsedTransform !== null ? (parsedTransform == null ? void 0 : parsedTransform.scaleY) < 0 : false;
@@ -800,7 +845,7 @@ function scrollIntoViewIfNeeded(el, centerIfNeeded = false) {
800
845
  if (!isHTMLElement(parent)) {
801
846
  return;
802
847
  }
803
- const parentComputedStyle = getComputedStyles(parent), parentBorderTopWidth = parseInt(
848
+ const parentComputedStyle = getComputedStyles(parent, true), parentBorderTopWidth = parseInt(
804
849
  parentComputedStyle.getPropertyValue("border-top-width")
805
850
  ), parentBorderLeftWidth = parseInt(
806
851
  parentComputedStyle.getPropertyValue("border-left-width")
@@ -816,39 +861,6 @@ function scrollIntoViewIfNeeded(el, centerIfNeeded = false) {
816
861
  }
817
862
  }
818
863
 
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
864
  // src/utilities/transform/inverseTransform.ts
853
865
  function inverseTransform(rect, parsedTransform, transformOrigin) {
854
866
  const { scaleX, scaleY, x: translateX, y: translateY } = parsedTransform;
@@ -1009,16 +1021,16 @@ function getProjectedTransform(element) {
1009
1021
  }
1010
1022
  return projectedTransform;
1011
1023
  }
1012
- var scheduler2 = new Scheduler((callback) => setTimeout(callback, 0));
1024
+ var scheduler3 = new Scheduler((callback) => setTimeout(callback, 0));
1013
1025
  var animations = /* @__PURE__ */ new Map();
1014
- var clear = animations.clear.bind(animations);
1026
+ var clear2 = animations.clear.bind(animations);
1015
1027
  function getDocumentAnimations(element) {
1016
1028
  const document2 = element.ownerDocument;
1017
1029
  let documentAnimations = animations.get(document2);
1018
1030
  if (documentAnimations) return documentAnimations;
1019
1031
  documentAnimations = document2.getAnimations();
1020
1032
  animations.set(document2, documentAnimations);
1021
- scheduler2.schedule(clear);
1033
+ scheduler3.schedule(clear2);
1022
1034
  const elementAnimations = documentAnimations.filter(
1023
1035
  (animation) => isKeyframeEffect(animation.effect) && animation.effect.target === element
1024
1036
  );