@vuu-ui/vuu-utils 4.0.1 → 4.1.1

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.
Files changed (45) hide show
  1. package/package.json +7 -8
  2. package/src/column-utils.js +6 -1
  3. package/src/tree-utils.js +2 -2
  4. package/src/vendor/@dnd-kit/abstract/index.d.ts +114 -32
  5. package/src/vendor/@dnd-kit/abstract/index.js +430 -280
  6. package/src/vendor/@dnd-kit/abstract/index.js.map +1 -1
  7. package/src/vendor/@dnd-kit/abstract/modifiers.d.ts +7 -7
  8. package/src/vendor/@dnd-kit/abstract/modifiers.js.map +1 -1
  9. package/src/vendor/@dnd-kit/abstract/package.json +8 -3
  10. package/src/vendor/@dnd-kit/collision/dist/index.js +10 -3
  11. package/src/vendor/@dnd-kit/collision/package.json +8 -3
  12. package/src/vendor/@dnd-kit/dom/index.d.ts +225 -126
  13. package/src/vendor/@dnd-kit/dom/index.js +998 -484
  14. package/src/vendor/@dnd-kit/dom/index.js.map +1 -1
  15. package/src/vendor/@dnd-kit/dom/modifiers.d.ts +1 -1
  16. package/src/vendor/@dnd-kit/dom/package.json +11 -5
  17. package/src/vendor/@dnd-kit/dom/plugins/debug.js +10 -7
  18. package/src/vendor/@dnd-kit/dom/plugins/debug.js.map +1 -1
  19. package/src/vendor/@dnd-kit/dom/sortable.d.ts +45 -11
  20. package/src/vendor/@dnd-kit/dom/sortable.js +203 -54
  21. package/src/vendor/@dnd-kit/dom/sortable.js.map +1 -1
  22. package/src/vendor/@dnd-kit/dom/utilities.d.ts +82 -10
  23. package/src/vendor/@dnd-kit/dom/utilities.js +249 -95
  24. package/src/vendor/@dnd-kit/dom/utilities.js.map +1 -1
  25. package/src/vendor/@dnd-kit/geometry/package.json +7 -2
  26. package/src/vendor/@dnd-kit/react/hooks.js +61 -38
  27. package/src/vendor/@dnd-kit/react/hooks.js.map +1 -0
  28. package/src/vendor/@dnd-kit/react/index.d.ts +18 -9
  29. package/src/vendor/@dnd-kit/react/index.js +100 -59
  30. package/src/vendor/@dnd-kit/react/index.js.map +1 -0
  31. package/src/vendor/@dnd-kit/react/package.json +17 -5
  32. package/src/vendor/@dnd-kit/react/sortable.d.ts +1 -1
  33. package/src/vendor/@dnd-kit/react/sortable.js +24 -10
  34. package/src/vendor/@dnd-kit/react/sortable.js.map +1 -0
  35. package/src/vendor/@dnd-kit/react/utilities.js.map +1 -0
  36. package/src/vendor/@dnd-kit/state/dist/index.js +1 -1
  37. package/src/vendor/@dnd-kit/state/package.json +6 -1
  38. package/src/vendor/@preact/signals-core/dist/signals-core.js +1 -1
  39. package/src/vendor/@preact/signals-core/dist/signals-core.js.map +1 -1
  40. package/types/ThemeProvider.d.ts +1 -1
  41. package/types/column-utils.d.ts +2 -1
  42. package/types/context-definitions/DataProvider.d.ts +1 -1
  43. package/types/context-definitions/DataSourceProvider.d.ts +1 -1
  44. package/types/filters/filter-utils.d.ts +1 -0
  45. package/types/tree-types.d.ts +5 -0
@@ -19,18 +19,17 @@ function isKeyframeEffect(effect) {
19
19
  // src/utilities/animations/getFinalKeyframe.ts
20
20
  function getFinalKeyframe(element, match) {
21
21
  const animations2 = element.getAnimations();
22
- if (animations2.length > 0) {
23
- for (const animation of animations2) {
24
- if (animation.playState !== "running") continue;
25
- const { effect } = animation;
26
- const keyframes = isKeyframeEffect(effect) ? effect.getKeyframes() : [];
27
- const matchedKeyframes = keyframes.filter(match);
28
- if (matchedKeyframes.length > 0) {
29
- return [matchedKeyframes[matchedKeyframes.length - 1], animation];
30
- }
22
+ let result = null;
23
+ for (const animation of animations2) {
24
+ if (animation.playState !== "running") continue;
25
+ const { effect } = animation;
26
+ const keyframes = isKeyframeEffect(effect) ? effect.getKeyframes() : [];
27
+ const matchedKeyframes = keyframes.filter(match);
28
+ if (matchedKeyframes.length > 0) {
29
+ result = [matchedKeyframes[matchedKeyframes.length - 1], animation];
31
30
  }
32
31
  }
33
- return null;
32
+ return result;
34
33
  }
35
34
 
36
35
  // src/utilities/bounding-rectangle/getBoundingRectangle.ts
@@ -39,9 +38,6 @@ function getBoundingRectangle(element) {
39
38
  return { width, height, top, left, bottom, right };
40
39
  }
41
40
 
42
- // src/utilities/execution-context/canUseDOM.ts
43
- var canUseDOM = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
44
-
45
41
  // src/utilities/type-guards/isWindow.ts
46
42
  function isWindow(element) {
47
43
  const elementString = Object.prototype.toString.call(element);
@@ -74,8 +70,8 @@ function getWindow(target) {
74
70
 
75
71
  // src/utilities/type-guards/isDocument.ts
76
72
  function isDocument(node) {
77
- const { Document } = getWindow(node);
78
- return node instanceof Document || "nodeType" in node && node.nodeType === Node.DOCUMENT_NODE;
73
+ const { Document: Document2 } = getWindow(node);
74
+ return node instanceof Document2 || "nodeType" in node && node.nodeType === Node.DOCUMENT_NODE;
79
75
  }
80
76
 
81
77
  // src/utilities/type-guards/isHTMLElement.ts
@@ -111,14 +107,18 @@ function getDocument(target) {
111
107
 
112
108
  // src/utilities/bounding-rectangle/getViewportBoundingRectangle.ts
113
109
  function getViewportBoundingRectangle(element) {
110
+ var _a, _b, _c, _d;
114
111
  const { documentElement } = getDocument(element);
115
- const width = documentElement.clientWidth;
116
- const height = documentElement.clientHeight;
112
+ const vv = getWindow(element).visualViewport;
113
+ const width = (_a = vv == null ? void 0 : vv.width) != null ? _a : documentElement.clientWidth;
114
+ const height = (_b = vv == null ? void 0 : vv.height) != null ? _b : documentElement.clientHeight;
115
+ const top = (_c = vv == null ? void 0 : vv.offsetTop) != null ? _c : 0;
116
+ const left = (_d = vv == null ? void 0 : vv.offsetLeft) != null ? _d : 0;
117
117
  return {
118
- top: 0,
119
- left: 0,
120
- right: width,
121
- bottom: height,
118
+ top,
119
+ left,
120
+ right: left + width,
121
+ bottom: top + height,
122
122
  width,
123
123
  height
124
124
  };
@@ -138,7 +138,7 @@ function isDetailsElement(element) {
138
138
 
139
139
  // src/utilities/bounding-rectangle/getVisibleBoundingRectangle.ts
140
140
  function getVisibleBoundingRectangle(element, boundingClientRect = element.getBoundingClientRect(), margin = 0) {
141
- var _a;
141
+ var _a, _b, _c, _d, _e;
142
142
  let rect = boundingClientRect;
143
143
  const { ownerDocument } = element;
144
144
  const ownerWindow = (_a = ownerDocument.defaultView) != null ? _a : window;
@@ -165,15 +165,24 @@ function getVisibleBoundingRectangle(element, boundingClientRect = element.getBo
165
165
  }
166
166
  ancestor = ancestor.parentElement;
167
167
  }
168
- const viewportWidth = ownerWindow.innerWidth;
169
- const viewportHeight = ownerWindow.innerHeight;
168
+ const vv = ownerWindow.visualViewport;
169
+ const viewportTop = (_b = vv == null ? void 0 : vv.offsetTop) != null ? _b : 0;
170
+ const viewportLeft = (_c = vv == null ? void 0 : vv.offsetLeft) != null ? _c : 0;
171
+ const viewportWidth = (_d = vv == null ? void 0 : vv.width) != null ? _d : ownerWindow.innerWidth;
172
+ const viewportHeight = (_e = vv == null ? void 0 : vv.height) != null ? _e : ownerWindow.innerHeight;
170
173
  const viewportMarginY = margin * viewportHeight;
171
174
  const viewportMarginX = margin * viewportWidth;
172
175
  rect = {
173
- top: Math.max(rect.top, 0 - viewportMarginY),
174
- right: Math.min(rect.right, viewportWidth + viewportMarginX),
175
- bottom: Math.min(rect.bottom, viewportHeight + viewportMarginY),
176
- left: Math.max(rect.left, 0 - viewportMarginX),
176
+ top: Math.max(rect.top, viewportTop - viewportMarginY),
177
+ right: Math.min(
178
+ rect.right,
179
+ viewportLeft + viewportWidth + viewportMarginX
180
+ ),
181
+ bottom: Math.min(
182
+ rect.bottom,
183
+ viewportTop + viewportHeight + viewportMarginY
184
+ ),
185
+ left: Math.max(rect.left, viewportLeft - viewportMarginX),
177
186
  width: 0,
178
187
  // Will be calculated next
179
188
  height: 0
@@ -190,11 +199,85 @@ function getVisibleBoundingRectangle(element, boundingClientRect = element.getBo
190
199
  return rect;
191
200
  }
192
201
 
202
+ // src/utilities/coordinates/getEventCoordinates.ts
203
+ function getEventCoordinates(event) {
204
+ return {
205
+ x: event.clientX,
206
+ y: event.clientY
207
+ };
208
+ }
209
+
210
+ // src/utilities/execution-context/canUseDOM.ts
211
+ var canUseDOM = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
212
+
213
+ // src/utilities/execution-context/getDocuments.ts
214
+ function getDocuments(rootDoc = document, seen = /* @__PURE__ */ new Set()) {
215
+ if (seen.has(rootDoc)) return [];
216
+ seen.add(rootDoc);
217
+ const docs = [rootDoc];
218
+ for (const frame of Array.from(
219
+ rootDoc.querySelectorAll("iframe, frame")
220
+ )) {
221
+ try {
222
+ const childDoc = frame.contentDocument;
223
+ if (childDoc && !seen.has(childDoc)) {
224
+ docs.push(...getDocuments(childDoc, seen));
225
+ }
226
+ } catch (e) {
227
+ }
228
+ }
229
+ try {
230
+ const win = rootDoc.defaultView;
231
+ if (win && win !== window.top) {
232
+ const parentWin = win.parent;
233
+ if (parentWin && parentWin.document && parentWin.document !== rootDoc) {
234
+ docs.push(...getDocuments(parentWin.document, seen));
235
+ }
236
+ }
237
+ } catch (e) {
238
+ }
239
+ return docs;
240
+ }
241
+
193
242
  // src/utilities/execution-context/isSafari.ts
194
243
  function isSafari() {
195
244
  return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
196
245
  }
197
246
 
247
+ // src/utilities/execution-context/getFixedPositionOffset.ts
248
+ function getFixedPositionOffset() {
249
+ var _a, _b;
250
+ const vv = isSafari() ? window.visualViewport : null;
251
+ return {
252
+ x: (_a = vv == null ? void 0 : vv.offsetLeft) != null ? _a : 0,
253
+ y: (_b = vv == null ? void 0 : vv.offsetTop) != null ? _b : 0
254
+ };
255
+ }
256
+
257
+ // src/utilities/type-guards/isShadowRoot.ts
258
+ function isShadowRoot(target) {
259
+ if (!target || !isNode(target)) return false;
260
+ return target instanceof getWindow(target).ShadowRoot;
261
+ }
262
+
263
+ // src/utilities/execution-context/getRoot.ts
264
+ function getRoot(target) {
265
+ if (target && isNode(target)) {
266
+ let root = target.getRootNode();
267
+ if (isShadowRoot(root)) {
268
+ return root;
269
+ } else if (root instanceof Document) {
270
+ return root;
271
+ }
272
+ }
273
+ return getDocument(target);
274
+ }
275
+
276
+ // src/utilities/execution-context/prefersReducedMotion.ts
277
+ function prefersReducedMotion(window2) {
278
+ return window2.matchMedia("(prefers-reduced-motion: reduce)").matches;
279
+ }
280
+
198
281
  // src/utilities/element/cloneElement.ts
199
282
  function cloneElement(element) {
200
283
  const selector = "input, textarea, select, canvas, [contenteditable]";
@@ -226,8 +309,8 @@ function isCanvasElement(element) {
226
309
  }
227
310
 
228
311
  // src/utilities/element/getElementFromPoint.ts
229
- function getElementFromPoint(document2, { x, y }) {
230
- const element = document2.elementFromPoint(x, y);
312
+ function getElementFromPoint(root, { x, y }) {
313
+ const element = root.elementFromPoint(x, y);
231
314
  if (isIFrameElement(element)) {
232
315
  const { contentDocument } = element;
233
316
  if (contentDocument) {
@@ -247,6 +330,21 @@ function isIFrameElement(element) {
247
330
  // src/utilities/element/proxiedElements.ts
248
331
  var ProxiedElements = /* @__PURE__ */ new WeakMap();
249
332
 
333
+ // src/utilities/element/isInteractiveElement.ts
334
+ function isInteractiveElement(element) {
335
+ return Boolean(getInteractiveElement(element));
336
+ }
337
+ function getInteractiveElement(element) {
338
+ return element.closest(`
339
+ input:not([disabled]),
340
+ select:not([disabled]),
341
+ textarea:not([disabled]),
342
+ button:not([disabled]),
343
+ a[href],
344
+ [contenteditable]:not([contenteditable="false"])
345
+ `);
346
+ }
347
+
250
348
  // src/utilities/event-listeners/Listeners.ts
251
349
  var Listeners = class {
252
350
  constructor() {
@@ -260,18 +358,24 @@ var Listeners = class {
260
358
  };
261
359
  }
262
360
  bind(target, input) {
361
+ const eventTargets = Array.isArray(target) ? target : [target];
263
362
  const listeners = Array.isArray(input) ? input : [input];
264
363
  const entries = [];
265
- for (const descriptor of listeners) {
266
- const { type, listener, options } = descriptor;
267
- const entry = [target, descriptor];
268
- target.addEventListener(type, listener, options);
269
- this.entries.add(entry);
270
- entries.push(entry);
364
+ for (const target2 of eventTargets) {
365
+ for (const descriptor of listeners) {
366
+ const { type, listener, options } = descriptor;
367
+ const entry = [target2, descriptor];
368
+ target2.addEventListener(type, listener, options);
369
+ this.entries.add(entry);
370
+ entries.push(entry);
371
+ }
271
372
  }
373
+ const allEntries = this.entries;
272
374
  return function cleanup() {
273
- for (const [target2, { type, listener, options }] of entries) {
375
+ for (const entry of entries) {
376
+ const [target2, { type, listener, options }] = entry;
274
377
  target2.removeEventListener(type, listener, options);
378
+ allEntries.delete(entry);
275
379
  }
276
380
  };
277
381
  }
@@ -342,7 +446,7 @@ function isVisible(element, boundingClientRect = element.getBoundingClientRect()
342
446
  }
343
447
 
344
448
  // src/utilities/observers/ResizeNotifier.ts
345
- var Observer = canUseDOM ? ResizeObserver : class MockResizeObserver {
449
+ var Observer = typeof ResizeObserver !== "undefined" ? ResizeObserver : class MockResizeObserver {
346
450
  observe() {
347
451
  }
348
452
  unobserve() {
@@ -653,11 +757,13 @@ function isDocumentScrollingElement(element) {
653
757
 
654
758
  // src/utilities/scroll/getScrollPosition.ts
655
759
  function getScrollPosition(scrollableElement) {
760
+ var _a, _b;
656
761
  const window2 = getWindow(scrollableElement);
657
762
  const rect = isDocumentScrollingElement(scrollableElement) ? getViewportBoundingRectangle(scrollableElement) : getBoundingRectangle(scrollableElement);
763
+ const vv = window2.visualViewport;
658
764
  const dimensions = isDocumentScrollingElement(scrollableElement) ? {
659
- height: window2.innerHeight,
660
- width: window2.innerWidth
765
+ height: (_a = vv == null ? void 0 : vv.height) != null ? _a : window2.innerHeight,
766
+ width: (_b = vv == null ? void 0 : vv.width) != null ? _b : window2.innerWidth
661
767
  } : {
662
768
  height: scrollableElement.clientHeight,
663
769
  width: scrollableElement.clientWidth
@@ -687,8 +793,8 @@ function getScrollPosition(scrollableElement) {
687
793
  }
688
794
 
689
795
  // src/utilities/scroll/canScroll.ts
690
- function canScroll(scrollableElement, by) {
691
- const { isTop, isBottom, isLeft, isRight, position } = getScrollPosition(scrollableElement);
796
+ function canScroll(scrollableElement, by, scrollPosition = getScrollPosition(scrollableElement)) {
797
+ const { isTop, isBottom, isLeft, isRight, position } = scrollPosition;
692
798
  const { x, y } = by != null ? by : { x: 0, y: 0 };
693
799
  const top = !isTop && position.current.y + y > 0;
694
800
  const bottom = !isBottom && position.current.y + y < position.max.y;
@@ -775,10 +881,11 @@ function isScrollable(element, computedStyle = getComputedStyles(element, true))
775
881
 
776
882
  // src/utilities/scroll/getScrollableAncestors.ts
777
883
  var defaultOptions = {
778
- excludeElement: true
884
+ excludeElement: true,
885
+ escapeShadowDOM: true
779
886
  };
780
887
  function getScrollableAncestors(element, options = defaultOptions) {
781
- const { limit, excludeElement } = options;
888
+ const { limit, excludeElement, escapeShadowDOM } = options;
782
889
  const scrollParents = /* @__PURE__ */ new Set();
783
890
  function findScrollableAncestors(node) {
784
891
  if (limit != null && scrollParents.size >= limit) {
@@ -791,6 +898,9 @@ function getScrollableAncestors(element, options = defaultOptions) {
791
898
  scrollParents.add(node.scrollingElement);
792
899
  return scrollParents;
793
900
  }
901
+ if (escapeShadowDOM && isShadowRoot(node)) {
902
+ return findScrollableAncestors(node.host);
903
+ }
794
904
  if (!isHTMLElement(node)) {
795
905
  if (isSVGElement(node)) {
796
906
  return findScrollableAncestors(node.parentElement);
@@ -863,7 +973,7 @@ function getScale(element, boundingRectangle = getBoundingRectangle(element)) {
863
973
 
864
974
  // src/utilities/transform/parseScale.ts
865
975
  function parseScale(scale) {
866
- if (scale === "none") {
976
+ if (!scale || scale === "none") {
867
977
  return null;
868
978
  }
869
979
  const values = scale.split(" ");
@@ -880,7 +990,7 @@ function parseScale(scale) {
880
990
 
881
991
  // src/utilities/transform/parseTranslate.ts
882
992
  function parseTranslate(translate) {
883
- if (translate === "none") {
993
+ if (!translate || translate === "none") {
884
994
  return null;
885
995
  }
886
996
  const [x, y, z = "0"] = translate.split(" ");
@@ -963,9 +1073,9 @@ var defaultTolerance = {
963
1073
  x: 10,
964
1074
  y: 10
965
1075
  };
966
- function detectScrollIntent(scrollableElement, coordinates, intent, acceleration = 25, thresholdPercentage = defaultThreshold, tolerance = defaultTolerance) {
1076
+ function detectScrollIntent(scrollableElement, coordinates, intent, acceleration = 25, thresholdPercentage = defaultThreshold, tolerance = defaultTolerance, scrollPosition = getScrollPosition(scrollableElement)) {
967
1077
  const { x, y } = coordinates;
968
- const { rect, isTop, isBottom, isLeft, isRight } = getScrollPosition(scrollableElement);
1078
+ const { rect, isTop, isBottom, isLeft, isRight } = scrollPosition;
969
1079
  const frameTransform = getFrameTransform(scrollableElement);
970
1080
  const computedStyles = getComputedStyles(scrollableElement, true);
971
1081
  const parsedTransform = parseTransform(computedStyles);
@@ -989,23 +1099,23 @@ function detectScrollIntent(scrollableElement, coordinates, intent, acceleration
989
1099
  height: scrollContainerRect.height * thresholdPercentage.y,
990
1100
  width: scrollContainerRect.width * thresholdPercentage.x
991
1101
  };
992
- if ((!isTop || isYAxisInverted && !isBottom) && y <= scrollContainerRect.top + threshold2.height && (intent == null ? void 0 : intent.y) !== 1 /* Forward */ && x >= scrollContainerRect.left - tolerance.x && x <= scrollContainerRect.right + tolerance.x) {
1102
+ if (threshold2.height > 0 && (!isTop || isYAxisInverted && !isBottom) && y <= scrollContainerRect.top + threshold2.height && (intent == null ? void 0 : intent.y) !== 1 /* Forward */ && x >= scrollContainerRect.left - tolerance.x && x <= scrollContainerRect.right + tolerance.x) {
993
1103
  direction.y = isYAxisInverted ? 1 /* Forward */ : -1 /* Reverse */;
994
1104
  speed.y = acceleration * Math.abs(
995
1105
  (scrollContainerRect.top + threshold2.height - y) / threshold2.height
996
1106
  );
997
- } else if ((!isBottom || isYAxisInverted && !isTop) && y >= scrollContainerRect.bottom - threshold2.height && (intent == null ? void 0 : intent.y) !== -1 /* Reverse */ && x >= scrollContainerRect.left - tolerance.x && x <= scrollContainerRect.right + tolerance.x) {
1107
+ } else if (threshold2.height > 0 && (!isBottom || isYAxisInverted && !isTop) && y >= scrollContainerRect.bottom - threshold2.height && (intent == null ? void 0 : intent.y) !== -1 /* Reverse */ && x >= scrollContainerRect.left - tolerance.x && x <= scrollContainerRect.right + tolerance.x) {
998
1108
  direction.y = isYAxisInverted ? -1 /* Reverse */ : 1 /* Forward */;
999
1109
  speed.y = acceleration * Math.abs(
1000
1110
  (scrollContainerRect.bottom - threshold2.height - y) / threshold2.height
1001
1111
  );
1002
1112
  }
1003
- if ((!isRight || isXAxisInverted && !isLeft) && x >= scrollContainerRect.right - threshold2.width && (intent == null ? void 0 : intent.x) !== -1 /* Reverse */ && y >= scrollContainerRect.top - tolerance.y && y <= scrollContainerRect.bottom + tolerance.y) {
1113
+ if (threshold2.width > 0 && (!isRight || isXAxisInverted && !isLeft) && x >= scrollContainerRect.right - threshold2.width && (intent == null ? void 0 : intent.x) !== -1 /* Reverse */ && y >= scrollContainerRect.top - tolerance.y && y <= scrollContainerRect.bottom + tolerance.y) {
1004
1114
  direction.x = isXAxisInverted ? -1 /* Reverse */ : 1 /* Forward */;
1005
1115
  speed.x = acceleration * Math.abs(
1006
1116
  (scrollContainerRect.right - threshold2.width - x) / threshold2.width
1007
1117
  );
1008
- } else if ((!isLeft || isXAxisInverted && !isRight) && x <= scrollContainerRect.left + threshold2.width && (intent == null ? void 0 : intent.x) !== 1 /* Forward */ && y >= scrollContainerRect.top - tolerance.y && y <= scrollContainerRect.bottom + tolerance.y) {
1118
+ } else if (threshold2.width > 0 && (!isLeft || isXAxisInverted && !isRight) && x <= scrollContainerRect.left + threshold2.width && (intent == null ? void 0 : intent.x) !== 1 /* Forward */ && y >= scrollContainerRect.top - tolerance.y && y <= scrollContainerRect.bottom + tolerance.y) {
1009
1119
  direction.x = isXAxisInverted ? 1 /* Forward */ : -1 /* Reverse */;
1010
1120
  speed.x = acceleration * Math.abs(
1011
1121
  (scrollContainerRect.left + threshold2.width - x) / threshold2.width
@@ -1018,35 +1128,76 @@ function detectScrollIntent(scrollableElement, coordinates, intent, acceleration
1018
1128
  }
1019
1129
 
1020
1130
  // src/utilities/scroll/scrollIntoViewIfNeeded.ts
1021
- function supportsScrollIntoViewIfNeeded(element) {
1022
- return "scrollIntoViewIfNeeded" in element && typeof element.scrollIntoViewIfNeeded === "function";
1023
- }
1024
- function scrollIntoViewIfNeeded(el, centerIfNeeded = false) {
1025
- if (supportsScrollIntoViewIfNeeded(el)) {
1026
- el.scrollIntoViewIfNeeded(centerIfNeeded);
1027
- return;
1028
- }
1131
+ function scrollIntoViewIfNeeded(el, { block = "nearest", inline = "nearest" } = {}) {
1029
1132
  if (!isHTMLElement(el)) {
1030
- return el.scrollIntoView();
1031
- }
1032
- var parent = getFirstScrollableAncestor(el);
1033
- if (!isHTMLElement(parent)) {
1034
1133
  return;
1035
1134
  }
1036
- const parentComputedStyle = getComputedStyles(parent, true), parentBorderTopWidth = parseInt(
1037
- parentComputedStyle.getPropertyValue("border-top-width")
1038
- ), parentBorderLeftWidth = parseInt(
1039
- parentComputedStyle.getPropertyValue("border-left-width")
1040
- ), overTop = el.offsetTop - parent.offsetTop < parent.scrollTop, overBottom = el.offsetTop - parent.offsetTop + el.clientHeight - parentBorderTopWidth > parent.scrollTop + parent.clientHeight, overLeft = el.offsetLeft - parent.offsetLeft < parent.scrollLeft, overRight = el.offsetLeft - parent.offsetLeft + el.clientWidth - parentBorderLeftWidth > parent.scrollLeft + parent.clientWidth, alignWithTop = overTop && !overBottom;
1041
- if ((overTop || overBottom) && centerIfNeeded) {
1042
- parent.scrollTop = el.offsetTop - parent.offsetTop - parent.clientHeight / 2 - parentBorderTopWidth + el.clientHeight / 2;
1043
- }
1044
- if ((overLeft || overRight) && centerIfNeeded) {
1045
- parent.scrollLeft = el.offsetLeft - parent.offsetLeft - parent.clientWidth / 2 - parentBorderLeftWidth + el.clientWidth / 2;
1135
+ const scrollableAncestors = getScrollableAncestors(el);
1136
+ const processedAncestors = [];
1137
+ for (const ancestor of scrollableAncestors) {
1138
+ if (!isHTMLElement(ancestor)) {
1139
+ continue;
1140
+ }
1141
+ const { top, left } = getOffsetRelativeTo(el, ancestor);
1142
+ let adjustedTop = top;
1143
+ let adjustedLeft = left;
1144
+ for (const inner of processedAncestors) {
1145
+ adjustedTop -= inner.scrollTop;
1146
+ adjustedLeft -= inner.scrollLeft;
1147
+ }
1148
+ if (block !== "none") {
1149
+ const overTop = adjustedTop < ancestor.scrollTop;
1150
+ const overBottom = adjustedTop + el.offsetHeight > ancestor.scrollTop + ancestor.clientHeight;
1151
+ if (overTop !== overBottom) {
1152
+ if (block === "center") {
1153
+ ancestor.scrollTop = adjustedTop - ancestor.clientHeight / 2 + el.offsetHeight / 2;
1154
+ } else if (overTop) {
1155
+ ancestor.scrollTop = adjustedTop;
1156
+ } else {
1157
+ ancestor.scrollTop = adjustedTop + el.offsetHeight - ancestor.clientHeight;
1158
+ }
1159
+ }
1160
+ }
1161
+ if (inline !== "none") {
1162
+ const overLeft = adjustedLeft < ancestor.scrollLeft;
1163
+ const overRight = adjustedLeft + el.offsetWidth > ancestor.scrollLeft + ancestor.clientWidth;
1164
+ if (overLeft !== overRight) {
1165
+ if (inline === "center") {
1166
+ ancestor.scrollLeft = adjustedLeft - ancestor.clientWidth / 2 + el.offsetWidth / 2;
1167
+ } else if (overLeft) {
1168
+ ancestor.scrollLeft = adjustedLeft;
1169
+ } else {
1170
+ ancestor.scrollLeft = adjustedLeft + el.offsetWidth - ancestor.clientWidth;
1171
+ }
1172
+ }
1173
+ }
1174
+ processedAncestors.push(ancestor);
1046
1175
  }
1047
- if ((overTop || overBottom || overLeft || overRight) && !centerIfNeeded) {
1048
- el.scrollIntoView(alignWithTop);
1176
+ }
1177
+ function getDocumentOffset(element) {
1178
+ let top = 0;
1179
+ let left = 0;
1180
+ let current = element;
1181
+ while (current) {
1182
+ top += current.offsetTop;
1183
+ left += current.offsetLeft;
1184
+ const offsetParent = current.offsetParent;
1185
+ if (!isHTMLElement(offsetParent)) {
1186
+ break;
1187
+ }
1188
+ top += offsetParent.clientTop;
1189
+ left += offsetParent.clientLeft;
1190
+ current = offsetParent;
1049
1191
  }
1192
+ return { top, left };
1193
+ }
1194
+ function getOffsetRelativeTo(element, ancestor) {
1195
+ const elOffset = getDocumentOffset(element);
1196
+ const ancestorOffset = getDocumentOffset(ancestor);
1197
+ return {
1198
+ top: elOffset.top - ancestorOffset.top - ancestor.clientTop,
1199
+ left: elOffset.left - ancestorOffset.left - ancestor.clientLeft
1200
+ };
1050
1201
  }
1051
1202
 
1052
1203
  // src/utilities/transform/applyTransform.ts
@@ -1232,34 +1383,37 @@ var DOMRectangle = class extends Rectangle {
1232
1383
  }
1233
1384
  };
1234
1385
  function getProjectedTransform(element, computedStyles) {
1235
- var _a;
1236
1386
  const animations2 = element.getAnimations();
1237
- let projectedTransform = null;
1238
1387
  if (!animations2.length) return null;
1388
+ let latestTransform;
1389
+ let latestTranslate;
1390
+ let latestScale;
1391
+ let hasAnimatedProperty = false;
1239
1392
  for (const animation of animations2) {
1240
1393
  if (animation.playState !== "running") continue;
1241
1394
  const keyframes = isKeyframeEffect(animation.effect) ? animation.effect.getKeyframes() : [];
1242
1395
  const keyframe = keyframes[keyframes.length - 1];
1243
1396
  if (!keyframe) continue;
1244
1397
  const { transform, translate, scale } = keyframe;
1245
- if (transform || translate || scale) {
1246
- const parsedTransform = parseTransform({
1247
- transform: typeof transform === "string" && transform ? transform : computedStyles.transform,
1248
- translate: typeof translate === "string" && translate ? translate : computedStyles.translate,
1249
- scale: typeof scale === "string" && scale ? scale : computedStyles.scale
1250
- });
1251
- if (parsedTransform) {
1252
- projectedTransform = projectedTransform ? {
1253
- x: projectedTransform.x + parsedTransform.x,
1254
- y: projectedTransform.y + parsedTransform.y,
1255
- z: (_a = projectedTransform.z) != null ? _a : parsedTransform.z,
1256
- scaleX: projectedTransform.scaleX * parsedTransform.scaleX,
1257
- scaleY: projectedTransform.scaleY * parsedTransform.scaleY
1258
- } : parsedTransform;
1259
- }
1398
+ if (typeof transform === "string" && transform) {
1399
+ latestTransform = transform;
1400
+ hasAnimatedProperty = true;
1401
+ }
1402
+ if (typeof translate === "string" && translate) {
1403
+ latestTranslate = translate;
1404
+ hasAnimatedProperty = true;
1405
+ }
1406
+ if (typeof scale === "string" && scale) {
1407
+ latestScale = scale;
1408
+ hasAnimatedProperty = true;
1260
1409
  }
1261
1410
  }
1262
- return projectedTransform;
1411
+ if (!hasAnimatedProperty) return null;
1412
+ return parseTransform({
1413
+ transform: latestTransform != null ? latestTransform : computedStyles.transform,
1414
+ translate: latestTranslate != null ? latestTranslate : computedStyles.translate,
1415
+ scale: latestScale != null ? latestScale : computedStyles.scale
1416
+ });
1263
1417
  }
1264
1418
 
1265
1419
  // src/utilities/type-guards/supportsStyle.ts
@@ -1356,6 +1510,6 @@ function generateUniqueId(prefix) {
1356
1510
  return `${prefix}-${id}`;
1357
1511
  }
1358
1512
 
1359
- export { DOMRectangle, Listeners, FrameObserver as PositionObserver, ProxiedElements, ResizeNotifier, Scheduler, ScrollDirection, Styles, animateTransform, canScroll, canUseDOM, cloneElement, computeTranslate, detectScrollIntent, generateUniqueId, getBoundingRectangle, getComputedStyles, getDocument, getElementFromPoint, getFinalKeyframe, getFirstScrollableAncestor, getFrameElement, getFrameTransform, getScrollableAncestors, getViewportBoundingRectangle, getVisibleBoundingRectangle, getWindow, hidePopover, inverseTransform, isDocumentScrollingElement, isElement, isHTMLElement, isKeyboardEvent, isKeyframeEffect, isPointerEvent, isSafari, isTextInput, parseTransform, parseTranslate, scheduler, scrollIntoViewIfNeeded, showPopover, supportsPopover, supportsStyle, supportsViewTransition, timeout };
1513
+ export { DOMRectangle, Listeners, FrameObserver as PositionObserver, ProxiedElements, ResizeNotifier, Scheduler, ScrollDirection, Styles, animateTransform, canScroll, canUseDOM, cloneElement, computeTranslate, detectScrollIntent, generateUniqueId, getBoundingRectangle, getComputedStyles, getDocument, getDocuments, getElementFromPoint, getEventCoordinates, getFinalKeyframe, getFirstScrollableAncestor, getFixedPositionOffset, getFrameElement, getFrameTransform, getInteractiveElement, getRoot, getScrollPosition, getScrollableAncestors, getViewportBoundingRectangle, getVisibleBoundingRectangle, getWindow, hidePopover, inverseTransform, isDocument, isDocumentScrollingElement, isElement, isHTMLElement, isInteractiveElement, isKeyboardEvent, isKeyframeEffect, isPointerEvent, isSafari, isShadowRoot, isTextInput, parseTransform, parseTranslate, prefersReducedMotion, scheduler, scrollIntoViewIfNeeded, showPopover, supportsPopover, supportsStyle, supportsViewTransition, timeout };
1360
1514
  //# sourceMappingURL=utilities.js.map
1361
1515
  //# sourceMappingURL=utilities.js.map