@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnd-kit/dom",
3
- "version": "0.1.7",
3
+ "version": "0.1.8-beta-20250504134846",
4
4
  "type": "module",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.js",
@@ -74,10 +74,10 @@
74
74
  "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
75
75
  },
76
76
  "dependencies": {
77
- "@dnd-kit/abstract": "^0.1.7",
78
- "@dnd-kit/collision": "^0.1.7",
79
- "@dnd-kit/geometry": "^0.1.7",
80
- "@dnd-kit/state": "^0.1.7",
77
+ "@dnd-kit/abstract": "0.1.8-beta-20250504134846",
78
+ "@dnd-kit/collision": "0.1.8-beta-20250504134846",
79
+ "@dnd-kit/geometry": "0.1.8-beta-20250504134846",
80
+ "@dnd-kit/state": "0.1.8-beta-20250504134846",
81
81
  "tslib": "^2.6.2"
82
82
  },
83
83
  "devDependencies": {
package/utilities.cjs CHANGED
@@ -513,18 +513,63 @@ function canScroll(scrollableElement, by) {
513
513
  };
514
514
  }
515
515
 
516
+ // src/utilities/scheduling/scheduler.ts
517
+ var Scheduler = class {
518
+ constructor(scheduler4) {
519
+ this.scheduler = scheduler4;
520
+ this.pending = false;
521
+ this.tasks = /* @__PURE__ */ new Set();
522
+ this.resolvers = /* @__PURE__ */ new Set();
523
+ this.flush = () => {
524
+ const { tasks, resolvers } = this;
525
+ this.pending = false;
526
+ this.tasks = /* @__PURE__ */ new Set();
527
+ this.resolvers = /* @__PURE__ */ new Set();
528
+ for (const task of tasks) {
529
+ task();
530
+ }
531
+ for (const resolve of resolvers) {
532
+ resolve();
533
+ }
534
+ };
535
+ }
536
+ schedule(task) {
537
+ this.tasks.add(task);
538
+ if (!this.pending) {
539
+ this.pending = true;
540
+ this.scheduler(this.flush);
541
+ }
542
+ return new Promise((resolve) => this.resolvers.add(resolve));
543
+ }
544
+ };
545
+ var scheduler = new Scheduler(
546
+ (callback) => requestAnimationFrame(callback)
547
+ );
548
+
516
549
  // src/utilities/styles/getComputedStyles.ts
517
- function getComputedStyles(element) {
550
+ var scheduler2 = new Scheduler((callback) => setTimeout(callback, 50));
551
+ var cachedStyles = /* @__PURE__ */ new Map();
552
+ var clear = cachedStyles.clear.bind(cachedStyles);
553
+ function getComputedStyles(element, cached = false) {
554
+ if (!cached) return computeStyles(element);
555
+ let styles = cachedStyles.get(element);
556
+ if (styles) return styles;
557
+ styles = computeStyles(element);
558
+ cachedStyles.set(element, styles);
559
+ scheduler2.schedule(clear);
560
+ return styles;
561
+ }
562
+ function computeStyles(element) {
518
563
  return getWindow(element).getComputedStyle(element);
519
564
  }
520
565
 
521
566
  // src/utilities/scroll/isFixed.ts
522
- function isFixed(node, computedStyle = getComputedStyles(node)) {
567
+ function isFixed(node, computedStyle = getComputedStyles(node, true)) {
523
568
  return computedStyle.position === "fixed" || computedStyle.position === "sticky";
524
569
  }
525
570
 
526
571
  // src/utilities/scroll/isScrollable.ts
527
- function isScrollable(element, computedStyle = getComputedStyles(element)) {
572
+ function isScrollable(element, computedStyle = getComputedStyles(element, true)) {
528
573
  const overflowRegex = /(auto|scroll|overlay)/;
529
574
  const properties = ["overflow", "overflowX", "overflowY"];
530
575
  return properties.some((property) => {
@@ -560,7 +605,7 @@ function getScrollableAncestors(element, options = defaultOptions) {
560
605
  if (scrollParents.has(node)) {
561
606
  return scrollParents;
562
607
  }
563
- const computedStyle = getComputedStyles(node);
608
+ const computedStyle = getComputedStyles(node, true);
564
609
  if (excludeElement && node === element) ; else if (isScrollable(node, computedStyle)) {
565
610
  scrollParents.add(node);
566
611
  }
@@ -604,7 +649,7 @@ function getFrameTransform(el, boundary = window.frameElement) {
604
649
  if (frame === boundary) {
605
650
  return transform;
606
651
  }
607
- const rect = frame.getBoundingClientRect();
652
+ const rect = getBoundingRectangle(frame);
608
653
  const { x: scaleX, y: scaleY } = getScale(frame, rect);
609
654
  transform.x = transform.x + rect.left;
610
655
  transform.y = transform.y + rect.top;
@@ -614,7 +659,7 @@ function getFrameTransform(el, boundary = window.frameElement) {
614
659
  }
615
660
  return transform;
616
661
  }
617
- function getScale(element, boundingRectangle = element.getBoundingClientRect()) {
662
+ function getScale(element, boundingRectangle = getBoundingRectangle(element)) {
618
663
  const width = Math.round(boundingRectangle.width);
619
664
  const height = Math.round(boundingRectangle.height);
620
665
  if (isHTMLElement(element)) {
@@ -623,7 +668,7 @@ function getScale(element, boundingRectangle = element.getBoundingClientRect())
623
668
  y: height / element.offsetHeight
624
669
  };
625
670
  }
626
- const styles = getComputedStyles(element);
671
+ const styles = getComputedStyles(element, true);
627
672
  return {
628
673
  x: (parseFloat(styles.width) || width) / width,
629
674
  y: (parseFloat(styles.height) || height) / height
@@ -736,7 +781,7 @@ function detectScrollIntent(scrollableElement, coordinates, intent, acceleration
736
781
  const { x, y } = coordinates;
737
782
  const { rect, isTop, isBottom, isLeft, isRight } = getScrollPosition(scrollableElement);
738
783
  const frameTransform = getFrameTransform(scrollableElement);
739
- const computedStyles = getComputedStyles(scrollableElement);
784
+ const computedStyles = getComputedStyles(scrollableElement, true);
740
785
  const parsedTransform = parseTransform(computedStyles);
741
786
  const isXAxisInverted = parsedTransform !== null ? (parsedTransform == null ? void 0 : parsedTransform.scaleX) < 0 : false;
742
787
  const isYAxisInverted = parsedTransform !== null ? (parsedTransform == null ? void 0 : parsedTransform.scaleY) < 0 : false;
@@ -802,7 +847,7 @@ function scrollIntoViewIfNeeded(el, centerIfNeeded = false) {
802
847
  if (!isHTMLElement(parent)) {
803
848
  return;
804
849
  }
805
- const parentComputedStyle = getComputedStyles(parent), parentBorderTopWidth = parseInt(
850
+ const parentComputedStyle = getComputedStyles(parent, true), parentBorderTopWidth = parseInt(
806
851
  parentComputedStyle.getPropertyValue("border-top-width")
807
852
  ), parentBorderLeftWidth = parseInt(
808
853
  parentComputedStyle.getPropertyValue("border-left-width")
@@ -818,39 +863,6 @@ function scrollIntoViewIfNeeded(el, centerIfNeeded = false) {
818
863
  }
819
864
  }
820
865
 
821
- // src/utilities/scheduling/scheduler.ts
822
- var Scheduler = class {
823
- constructor(scheduler3) {
824
- this.scheduler = scheduler3;
825
- this.pending = false;
826
- this.tasks = /* @__PURE__ */ new Set();
827
- this.resolvers = /* @__PURE__ */ new Set();
828
- this.flush = () => {
829
- const { tasks, resolvers } = this;
830
- this.pending = false;
831
- this.tasks = /* @__PURE__ */ new Set();
832
- this.resolvers = /* @__PURE__ */ new Set();
833
- for (const task of tasks) {
834
- task();
835
- }
836
- for (const resolve of resolvers) {
837
- resolve();
838
- }
839
- };
840
- }
841
- schedule(task) {
842
- this.tasks.add(task);
843
- if (!this.pending) {
844
- this.pending = true;
845
- this.scheduler(this.flush);
846
- }
847
- return new Promise((resolve) => this.resolvers.add(resolve));
848
- }
849
- };
850
- var scheduler = new Scheduler(
851
- (callback) => requestAnimationFrame(callback)
852
- );
853
-
854
866
  // src/utilities/transform/inverseTransform.ts
855
867
  function inverseTransform(rect, parsedTransform, transformOrigin) {
856
868
  const { scaleX, scaleY, x: translateX, y: translateY } = parsedTransform;
@@ -1011,16 +1023,16 @@ function getProjectedTransform(element) {
1011
1023
  }
1012
1024
  return projectedTransform;
1013
1025
  }
1014
- var scheduler2 = new Scheduler((callback) => setTimeout(callback, 0));
1026
+ var scheduler3 = new Scheduler((callback) => setTimeout(callback, 0));
1015
1027
  var animations = /* @__PURE__ */ new Map();
1016
- var clear = animations.clear.bind(animations);
1028
+ var clear2 = animations.clear.bind(animations);
1017
1029
  function getDocumentAnimations(element) {
1018
1030
  const document2 = element.ownerDocument;
1019
1031
  let documentAnimations = animations.get(document2);
1020
1032
  if (documentAnimations) return documentAnimations;
1021
1033
  documentAnimations = document2.getAnimations();
1022
1034
  animations.set(document2, documentAnimations);
1023
- scheduler2.schedule(clear);
1035
+ scheduler3.schedule(clear2);
1024
1036
  const elementAnimations = documentAnimations.filter(
1025
1037
  (animation) => isKeyframeEffect(animation.effect) && animation.effect.target === element
1026
1038
  );