@reshaped/utilities 3.11.0-canary.4 → 4.0.0-canary.5

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 (46) hide show
  1. package/dist/a11y/TrapFocus.js +1 -1
  2. package/dist/a11y/index.d.ts +3 -3
  3. package/dist/a11y/index.js +2 -2
  4. package/dist/a11y/tests/Chain.test.js +1 -1
  5. package/dist/a11y/tests/TrapFocus.test.js +1 -1
  6. package/dist/a11y/tests/TrapScreenReader.test.js +1 -1
  7. package/dist/a11y/tests/focus.test.js +2 -2
  8. package/dist/a11y/tests/keyboardMode.test.js +2 -2
  9. package/dist/css/index.d.ts +1 -1
  10. package/dist/css/tests/StyleCache.test.js +1 -1
  11. package/dist/css/tests/classNames.test.js +1 -1
  12. package/dist/dom/tests/findClosestScrollableContainer.test.js +1 -1
  13. package/dist/dom/tests/findParent.test.js +1 -1
  14. package/dist/flyout/Flyout.d.ts +1 -1
  15. package/dist/flyout/Flyout.js +13 -7
  16. package/dist/flyout/tests/Flyout.test.js +2 -2
  17. package/dist/flyout/utilities/applyPosition.d.ts +1 -1
  18. package/dist/flyout/utilities/applyPosition.js +1 -1
  19. package/dist/flyout/utilities/calculateLayoutAdjustment.d.ts +1 -1
  20. package/dist/flyout/utilities/tests/applyPosition.test.js +2 -2
  21. package/dist/flyout/utilities/tests/calculateLayoutAdjustment.test.js +3 -3
  22. package/dist/flyout/utilities/tests/calculatePosition.test.js +2 -2
  23. package/dist/flyout/utilities/tests/centerBySize.test.js +2 -2
  24. package/dist/flyout/utilities/tests/getPositionFallbacks.test.js +2 -2
  25. package/dist/flyout/utilities/tests/getRTLPosition.test.js +2 -2
  26. package/dist/flyout/utilities/tests/isFullyVisible.test.js +1 -1
  27. package/dist/helpers/rafThrottle.js +0 -1
  28. package/dist/helpers/tests/rafThrottle.test.js +1 -2
  29. package/dist/i18n/tests/isRTL.test.js +1 -1
  30. package/dist/index.d.ts +4 -4
  31. package/dist/index.js +4 -4
  32. package/dist/internal.d.ts +4 -4
  33. package/dist/internal.js +3 -3
  34. package/dist/platform/index.js +0 -1
  35. package/dist/scroll/tests/lock.test.js +1 -1
  36. package/package.json +7 -7
  37. package/dist/flyout/utilities/createSafeArea.d.ts +0 -15
  38. package/dist/flyout/utilities/createSafeArea.js +0 -62
  39. package/dist/flyout/utilities/findClosestFixedContainer.d.ts +0 -5
  40. package/dist/flyout/utilities/findClosestFixedContainer.js +0 -18
  41. package/dist/flyout/utilities/findClosestScrollableContainer.d.ts +0 -5
  42. package/dist/flyout/utilities/findClosestScrollableContainer.js +0 -12
  43. package/dist/flyout/utilities/tests/findClosestFixedContainer.test.d.ts +0 -1
  44. package/dist/flyout/utilities/tests/findClosestFixedContainer.test.js +0 -46
  45. package/dist/flyout/utilities/tests/findClosestScrollableContainer.test.d.ts +0 -1
  46. package/dist/flyout/utilities/tests/findClosestScrollableContainer.test.js +0 -66
@@ -2,7 +2,7 @@ var _a;
2
2
  import keys from "../constants/keys.js";
3
3
  import { getShadowRoot } from "../dom/index.js";
4
4
  import Chain from "./Chain.js";
5
- import { getActiveElement, getFocusableElements, focusElement, getFocusData } from "./focus.js";
5
+ import { focusElement, getActiveElement, getFocusableElements, getFocusData } from "./focus.js";
6
6
  import { checkKeyboardMode } from "./keyboardMode.js";
7
7
  import TrapScreenReader from "./TrapScreenReader.js";
8
8
  class TrapFocus {
@@ -1,4 +1,4 @@
1
- export { focusableSelector, getActiveElement, getFocusableElements, focusNextElement, focusPreviousElement, focusFirstElement, focusLastElement, } from "./focus";
2
- export { activateKeyboardMode, deactivateKeyboardMode, checkKeyboardMode } from "./keyboardMode";
1
+ export { focusableSelector, focusFirstElement, focusLastElement, focusNextElement, focusPreviousElement, getActiveElement, getFocusableElements, } from "./focus";
2
+ export { activateKeyboardMode, checkKeyboardMode, deactivateKeyboardMode } from "./keyboardMode";
3
3
  export { default as TrapFocus } from "./TrapFocus";
4
- export type { TrapMode, FocusableElement } from "./types";
4
+ export type { FocusableElement, TrapMode } from "./types";
@@ -1,3 +1,3 @@
1
- export { focusableSelector, getActiveElement, getFocusableElements, focusNextElement, focusPreviousElement, focusFirstElement, focusLastElement, } from "./focus.js";
2
- export { activateKeyboardMode, deactivateKeyboardMode, checkKeyboardMode } from "./keyboardMode.js";
1
+ export { focusableSelector, focusFirstElement, focusLastElement, focusNextElement, focusPreviousElement, getActiveElement, getFocusableElements, } from "./focus.js";
2
+ export { activateKeyboardMode, checkKeyboardMode, deactivateKeyboardMode } from "./keyboardMode.js";
3
3
  export { default as TrapFocus } from "./TrapFocus.js";
@@ -1,4 +1,4 @@
1
- import { expect, test, describe, beforeEach } from "vitest";
1
+ import { beforeEach, describe, expect, test } from "vitest";
2
2
  import Chain from "../Chain.js";
3
3
  describe("a11y/Chain", () => {
4
4
  let chain;
@@ -1,4 +1,4 @@
1
- import { expect, test, describe, beforeEach, afterEach, vi } from "vitest";
1
+ import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
2
2
  import TrapFocus from "../TrapFocus.js";
3
3
  describe("a11y/TrapFocus", () => {
4
4
  let container;
@@ -1,4 +1,4 @@
1
- import { expect, test, describe, beforeEach, afterEach } from "vitest";
1
+ import { afterEach, beforeEach, describe, expect, test } from "vitest";
2
2
  import TrapScreenReader from "../TrapScreenReader.js";
3
3
  describe("a11y/TrapScreenReader", () => {
4
4
  let container;
@@ -1,5 +1,5 @@
1
- import { expect, test, describe, beforeEach, afterEach } from "vitest";
2
- import { getActiveElement, focusElement, getFocusableElements, getFocusData, focusNextElement, focusPreviousElement, focusFirstElement, focusLastElement, } from "../focus.js";
1
+ import { afterEach, beforeEach, describe, expect, test } from "vitest";
2
+ import { focusElement, focusFirstElement, focusLastElement, focusNextElement, focusPreviousElement, getActiveElement, getFocusableElements, getFocusData, } from "../focus.js";
3
3
  describe("a11y/focus", () => {
4
4
  let container;
5
5
  beforeEach(() => {
@@ -1,5 +1,5 @@
1
- import { expect, test, describe, beforeEach, afterEach } from "vitest";
2
- import { activateKeyboardMode, deactivateKeyboardMode, checkKeyboardMode, keyboardModeAttribute, } from "../keyboardMode.js";
1
+ import { afterEach, beforeEach, describe, expect, test } from "vitest";
2
+ import { activateKeyboardMode, checkKeyboardMode, deactivateKeyboardMode, keyboardModeAttribute, } from "../keyboardMode.js";
3
3
  describe("a11y/keyboardMode", () => {
4
4
  beforeEach(() => {
5
5
  document.documentElement.removeAttribute(keyboardModeAttribute);
@@ -1,2 +1,2 @@
1
- export { default as classNames, type ClassName } from "./classNames";
1
+ export { type ClassName, default as classNames } from "./classNames";
2
2
  export { default as StyleCache } from "./StyleCache";
@@ -1,4 +1,4 @@
1
- import { expect, test, describe, beforeEach } from "vitest";
1
+ import { beforeEach, describe, expect, test } from "vitest";
2
2
  import StyleCache from "../StyleCache.js";
3
3
  describe("css/StyleCache", () => {
4
4
  let styleCache;
@@ -1,4 +1,4 @@
1
- import { expect, test, describe } from "vitest";
1
+ import { describe, expect, test } from "vitest";
2
2
  import classNames from "../classNames.js";
3
3
  describe("helpers/classNames", () => {
4
4
  test("returns empty string when no arguments are provided", () => {
@@ -1,4 +1,4 @@
1
- import { expect, test, describe, afterEach } from "vitest";
1
+ import { afterEach, describe, expect, test } from "vitest";
2
2
  import findClosestScrollableContainer from "../findClosestScrollableContainer.js";
3
3
  describe("dom/findClosestScrollableContainer", () => {
4
4
  afterEach(() => {
@@ -1,4 +1,4 @@
1
- import { expect, test, describe } from "vitest";
1
+ import { describe, expect, test } from "vitest";
2
2
  import findParent from "../findParent.js";
3
3
  describe("dom/findParent", () => {
4
4
  test("returns null when element has no parent", () => {
@@ -1,5 +1,5 @@
1
- import applyPosition from "./utilities/applyPosition";
2
1
  import type { Options } from "./types";
2
+ import applyPosition from "./utilities/applyPosition";
3
3
  declare class Flyout {
4
4
  #private;
5
5
  constructor(options: Options);
@@ -18,7 +18,7 @@ class Flyout {
18
18
  return result;
19
19
  };
20
20
  #addParentScrollHandler = () => {
21
- const { trigger, onDeactivate } = this.#options;
21
+ const { trigger, onDeactivate, fallbackAdjustLayout } = this.#options;
22
22
  if (!trigger)
23
23
  return;
24
24
  const container = findClosestScrollableContainer({ el: trigger });
@@ -26,16 +26,22 @@ class Flyout {
26
26
  const handleScroll = rafThrottle(() => {
27
27
  if (!this.#active)
28
28
  return;
29
- if (!container) {
29
+ if (!container && !fallbackAdjustLayout) {
30
30
  this.#update();
31
31
  return;
32
32
  }
33
33
  const triggerBounds = trigger.getBoundingClientRect();
34
- const containerBounds = container.getBoundingClientRect();
35
- if (triggerBounds.top < containerBounds.top ||
36
- triggerBounds.left < containerBounds.left ||
37
- triggerBounds.right > containerBounds.right ||
38
- triggerBounds.bottom > containerBounds.bottom) {
34
+ const containerBounds = container?.getBoundingClientRect();
35
+ const visibilityBounds = {
36
+ top: containerBounds?.top ?? 0,
37
+ left: containerBounds?.left ?? 0,
38
+ right: containerBounds?.right ?? window.innerWidth,
39
+ bottom: containerBounds?.bottom ?? window.innerHeight,
40
+ };
41
+ if (triggerBounds.top < visibilityBounds.top ||
42
+ triggerBounds.left < visibilityBounds.left ||
43
+ triggerBounds.right > visibilityBounds.right ||
44
+ triggerBounds.bottom > visibilityBounds.bottom) {
39
45
  onDeactivate();
40
46
  }
41
47
  else {
@@ -1,5 +1,5 @@
1
- import { expect, test, describe, beforeEach, afterEach, vi } from "vitest";
2
- import Flyout from "flyout/Flyout";
1
+ import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
2
+ import Flyout from "../Flyout.js";
3
3
  describe("flyout/Flyout", () => {
4
4
  let content;
5
5
  let trigger;
@@ -1,4 +1,4 @@
1
- import type { Position, Options } from "../types";
1
+ import type { Options, Position } from "../types";
2
2
  declare const applyPosition: (args: Options & {
3
3
  lastUsedPosition: Position | null;
4
4
  }) => {
@@ -1,6 +1,6 @@
1
1
  import { getShadowRoot } from "../../dom/index.js";
2
2
  import isRTL from "../../i18n/isRTL.js";
3
- import { VIEWPORT_OFFSET, RESET_STYLES } from "../constants.js";
3
+ import { RESET_STYLES, VIEWPORT_OFFSET } from "../constants.js";
4
4
  import calculateLayoutAdjustment from "./calculateLayoutAdjustment.js";
5
5
  import calculatePosition from "./calculatePosition.js";
6
6
  import getPositionFallbacks from "./getPositionFallbacks.js";
@@ -1,5 +1,5 @@
1
- import type { CalculatePositionResult } from "./calculatePosition";
2
1
  import type { Options } from "../types";
2
+ import type { CalculatePositionResult } from "./calculatePosition";
3
3
  type CalculateLayoutAdjustmentArgs = CalculatePositionResult & Pick<Options, "fallbackAdjustLayout" | "fallbackMinHeight" | "width"> & {
4
4
  flyoutBounds: DOMRect;
5
5
  triggerBounds: DOMRect;
@@ -1,5 +1,5 @@
1
- import { expect, test, describe, beforeEach, afterEach, vi } from "vitest";
2
- import applyPosition from "flyout/utilities/applyPosition";
1
+ import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
2
+ import applyPosition from "../applyPosition.js";
3
3
  describe("flyout/applyPosition", () => {
4
4
  let content;
5
5
  let trigger;
@@ -1,6 +1,6 @@
1
- import { expect, test, describe, vi, beforeEach } from "vitest";
2
- import { VIEWPORT_OFFSET } from "flyout/constants";
3
- import calculateLayoutAdjustment from "flyout/utilities/calculateLayoutAdjustment";
1
+ import { beforeEach, describe, expect, test, vi } from "vitest";
2
+ import { VIEWPORT_OFFSET } from "../../constants.js";
3
+ import calculateLayoutAdjustment from "../calculateLayoutAdjustment.js";
4
4
  describe("flyout/calculateLayoutAdjustment", () => {
5
5
  const createBounds = (left, top, width, height) => {
6
6
  return {
@@ -1,5 +1,5 @@
1
- import { expect, test, describe, vi, beforeEach } from "vitest";
2
- import calculatePosition from "flyout/utilities/calculatePosition";
1
+ import { beforeEach, describe, expect, test, vi } from "vitest";
2
+ import calculatePosition from "../calculatePosition.js";
3
3
  describe("flyout/calculatePosition", () => {
4
4
  const createBounds = (left, top, width, height) => {
5
5
  return {
@@ -1,5 +1,5 @@
1
- import { expect, test, describe } from "vitest";
2
- import centerBySize from "flyout/utilities/centerBySize";
1
+ import { describe, expect, test } from "vitest";
2
+ import centerBySize from "../centerBySize.js";
3
3
  describe("flyout/centerBySize", () => {
4
4
  test("centers even value", () => {
5
5
  expect(centerBySize(100, 50)).toEqual(25);
@@ -1,5 +1,5 @@
1
- import { expect, test, describe } from "vitest";
2
- import getPositionFallbacks from "flyout/utilities/getPositionFallbacks";
1
+ import { describe, expect, test } from "vitest";
2
+ import getPositionFallbacks from "../getPositionFallbacks.js";
3
3
  describe("flyout/getPositionFallbacks", () => {
4
4
  test("returns original position first for top-start", () => {
5
5
  const result = getPositionFallbacks("top-start");
@@ -1,5 +1,5 @@
1
- import { expect, test, describe } from "vitest";
2
- import getRTLPosition from "flyout/utilities/getRTLPosition";
1
+ import { describe, expect, test } from "vitest";
2
+ import getRTLPosition from "../getRTLPosition.js";
3
3
  describe("flyout/getRTLPosition", () => {
4
4
  test("keeps top position", () => {
5
5
  expect(getRTLPosition("top")).toEqual("top");
@@ -1,4 +1,4 @@
1
- import { expect, test, describe } from "vitest";
1
+ import { describe, expect, test } from "vitest";
2
2
  import isFullyVisible from "../isFullyVisible.js";
3
3
  describe("flyout/isFullyVisible", () => {
4
4
  test("returns true when flyout is fully visible within visual container", () => {
@@ -1,4 +1,3 @@
1
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
1
  const rafThrottle = (fn) => {
3
2
  let rafId = null;
4
3
  let args = null;
@@ -1,4 +1,4 @@
1
- import { expect, test, describe, beforeEach, vi } from "vitest";
1
+ import { beforeEach, describe, expect, test, vi } from "vitest";
2
2
  import rafThrottle from "../rafThrottle.js";
3
3
  const waitForNextFrame = () => {
4
4
  return new Promise((resolve) => {
@@ -8,7 +8,6 @@ const waitForNextFrame = () => {
8
8
  });
9
9
  };
10
10
  describe("helpers/rafThrottle", () => {
11
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
11
  let mockFn;
13
12
  beforeEach(() => {
14
13
  mockFn = vi.fn();
@@ -1,4 +1,4 @@
1
- import { expect, test, describe, beforeEach, vi, afterAll } from "vitest";
1
+ import { afterAll, beforeEach, describe, expect, test, vi } from "vitest";
2
2
  import isRTL from "../isRTL.js";
3
3
  describe("i18n/isRTL", () => {
4
4
  beforeEach(() => {
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { Flyout } from "./flyout";
2
1
  export { TrapFocus } from "./a11y";
3
- export { lockScroll } from "./scroll";
4
- export { isRTL } from "./i18n";
5
- export { classNames, type ClassName } from "./css";
6
2
  export { default as keys } from "./constants/keys";
3
+ export { type ClassName, classNames } from "./css";
4
+ export { Flyout } from "./flyout";
5
+ export { isRTL } from "./i18n";
6
+ export { lockScroll } from "./scroll";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- export { Flyout } from "./flyout/index.js";
2
1
  export { TrapFocus } from "./a11y/index.js";
3
- export { lockScroll } from "./scroll/index.js";
4
- export { isRTL } from "./i18n/index.js";
5
- export { classNames } from "./css/index.js";
6
2
  export { default as keys } from "./constants/keys.js";
3
+ export { classNames } from "./css/index.js";
4
+ export { Flyout } from "./flyout/index.js";
5
+ export { isRTL } from "./i18n/index.js";
6
+ export { lockScroll } from "./scroll/index.js";
@@ -4,9 +4,9 @@
4
4
  *
5
5
  * If you want to use one of these utilities, open an issue or a PR about moving it to the public API file
6
6
  */
7
- export { focusableSelector, getActiveElement, getFocusableElements, focusNextElement, focusPreviousElement, focusFirstElement, focusLastElement, activateKeyboardMode, deactivateKeyboardMode, checkKeyboardMode, } from "./a11y";
8
- export type { TrapMode, FocusableElement } from "./a11y";
9
- export { disableScroll, enableScroll } from "./scroll";
7
+ export type { FocusableElement, TrapMode } from "./a11y";
8
+ export { activateKeyboardMode, checkKeyboardMode, deactivateKeyboardMode, focusableSelector, focusFirstElement, focusLastElement, focusNextElement, focusPreviousElement, getActiveElement, getFocusableElements, } from "./a11y";
9
+ export { findParent, getShadowRoot } from "./dom";
10
10
  export { rafThrottle } from "./helpers";
11
- export { getShadowRoot, findParent } from "./dom";
11
+ export { disableScroll, enableScroll } from "./scroll";
12
12
  export type { Coordinates } from "./types/global";
package/dist/internal.js CHANGED
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * If you want to use one of these utilities, open an issue or a PR about moving it to the public API file
6
6
  */
7
- export { focusableSelector, getActiveElement, getFocusableElements, focusNextElement, focusPreviousElement, focusFirstElement, focusLastElement, activateKeyboardMode, deactivateKeyboardMode, checkKeyboardMode, } from "./a11y/index.js";
8
- export { disableScroll, enableScroll } from "./scroll/index.js";
7
+ export { activateKeyboardMode, checkKeyboardMode, deactivateKeyboardMode, focusableSelector, focusFirstElement, focusLastElement, focusNextElement, focusPreviousElement, getActiveElement, getFocusableElements, } from "./a11y/index.js";
8
+ export { findParent, getShadowRoot } from "./dom/index.js";
9
9
  export { rafThrottle } from "./helpers/index.js";
10
- export { getShadowRoot, findParent } from "./dom/index.js";
10
+ export { disableScroll, enableScroll } from "./scroll/index.js";
@@ -1,7 +1,6 @@
1
1
  const testPlatform = (re) => {
2
2
  // Using experimental and deprecated features here since that's the only way to detect platform consistently
3
3
  const platform =
4
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
5
4
  // @ts-ignore
6
5
  window.navigator.userAgentData?.platform || window.navigator.platform;
7
6
  return typeof window !== "undefined" ? re.test(platform) : false;
@@ -1,4 +1,4 @@
1
- import { expect, test, describe, beforeEach, vi, afterEach } from "vitest";
1
+ import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
2
2
  import { lockScroll } from "../lock.js";
3
3
  // Mock the platform module to avoid iOS path
4
4
  vi.mock("@/platform", () => ({
package/package.json CHANGED
@@ -1,22 +1,22 @@
1
1
  {
2
2
  "name": "@reshaped/utilities",
3
+ "version": "4.0.0-canary.5",
3
4
  "description": "Vanilla JS utilities for implementing common UI patterns",
4
- "version": "3.11.0-canary.4",
5
- "license": "MIT",
6
5
  "homepage": "https://reshaped.so",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://github.com/reshaped-ui/reshaped.git",
10
- "directory": "packages/core"
11
- },
12
6
  "bugs": {
13
7
  "url": "https://github.com/reshaped-ui/reshaped/issues"
14
8
  },
9
+ "license": "MIT",
15
10
  "author": {
16
11
  "name": "Dmitry Belyaev",
17
12
  "email": "blv.dmitry@gmail.com",
18
13
  "url": "https://reshaped.so"
19
14
  },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/reshaped-ui/reshaped.git",
18
+ "directory": "packages/core"
19
+ },
20
20
  "files": [
21
21
  "dist/**/*"
22
22
  ],
@@ -1,15 +0,0 @@
1
- import type { Position, Coordinates } from "../types";
2
- type CreateSafeAreaArgs = {
3
- coordinates: Coordinates;
4
- content: HTMLElement;
5
- trigger: HTMLElement;
6
- position: Position;
7
- existingSafeArea: HTMLElement | null;
8
- };
9
- /**
10
- * Creates an SVG element representing the safe area triangle
11
- * from the mouse coordinates to the closest side of the content.
12
- * The safe area is limited by the trigger's boundaries.
13
- */
14
- declare const createSafeArea: (args: CreateSafeAreaArgs) => HTMLElement;
15
- export default createSafeArea;
@@ -1,62 +0,0 @@
1
- /**
2
- * Creates an SVG element representing the safe area triangle
3
- * from the mouse coordinates to the closest side of the content.
4
- * The safe area is limited by the trigger's boundaries.
5
- */
6
- const createSafeArea = (args) => {
7
- const { coordinates, content, trigger, position, existingSafeArea } = args;
8
- const contentBounds = content.getBoundingClientRect();
9
- const isHorizontal = position.startsWith("start") || position.startsWith("end");
10
- const isLogicalStart = position.startsWith("start") || position.startsWith("top");
11
- const BUFFER = 10;
12
- let points;
13
- if (isHorizontal) {
14
- const originX = isLogicalStart ? coordinates.x + BUFFER : coordinates.x - BUFFER;
15
- const x = isLogicalStart ? contentBounds.left + contentBounds.width : contentBounds.left;
16
- const topCoordinates = { x, y: contentBounds.top };
17
- const bottomCoordinates = { x, y: contentBounds.top + contentBounds.height };
18
- points = `${originX},${coordinates.y} ${topCoordinates.x},${topCoordinates.y} ${bottomCoordinates.x},${bottomCoordinates.y}`;
19
- }
20
- else {
21
- const originY = isLogicalStart ? coordinates.y + BUFFER : coordinates.y - BUFFER;
22
- const y = isLogicalStart ? contentBounds.top + contentBounds.height : contentBounds.top;
23
- const leftCoordinates = { x: contentBounds.left, y };
24
- const rightCoordinates = { x: contentBounds.left + contentBounds.width, y };
25
- points = `${coordinates.x},${originY} ${leftCoordinates.x},${leftCoordinates.y} ${rightCoordinates.x},${rightCoordinates.y}`;
26
- }
27
- // Calculate SVG viewBox to cover the triangle area
28
- const pointCoords = points.split(" ").map((p) => p.split(",").map(Number));
29
- const minX = Math.min(...pointCoords.map((p) => p[0]));
30
- const maxX = Math.max(...pointCoords.map((p) => p[0]));
31
- const minY = Math.min(...pointCoords.map((p) => p[1]));
32
- const maxY = Math.max(...pointCoords.map((p) => p[1]));
33
- const svgWidth = maxX - minX;
34
- const svgHeight = maxY - minY;
35
- // Adjust points relative to SVG origin
36
- const adjustedPoints = pointCoords.map((p) => `${p[0] - minX},${p[1] - minY}`).join(" ");
37
- const styles = `
38
- position: fixed;
39
- left: ${minX}px;
40
- top: ${minY}px;
41
- width: ${svgWidth}px;
42
- height: ${svgHeight}px;
43
- pointer-events: none;
44
- z-index: 9999;
45
- `;
46
- const svgContent = `
47
- <svg width="${svgWidth}" height="${svgHeight}" viewBox="0 0 ${svgWidth} ${svgHeight}">
48
- <polygon points="${adjustedPoints}" fill="red" opacity="0.5" style="pointer-events: auto;" />
49
- </svg>
50
- `;
51
- if (existingSafeArea) {
52
- existingSafeArea.style.cssText = styles;
53
- existingSafeArea.innerHTML = svgContent;
54
- return existingSafeArea;
55
- }
56
- const container = document.createElement("div");
57
- container.style.cssText = styles;
58
- container.innerHTML = svgContent;
59
- trigger.appendChild(container);
60
- return container;
61
- };
62
- export default createSafeArea;
@@ -1,5 +0,0 @@
1
- type Args = {
2
- el: HTMLElement | null;
3
- };
4
- declare const _default: (args: Args) => HTMLElement;
5
- export default _default;
@@ -1,18 +0,0 @@
1
- import getShadowRoot from "../../dom/getShadowRoot.js";
2
- const findClosestPositionContainer = (args) => {
3
- const { el, iteration = 0 } = args;
4
- const style = el && window.getComputedStyle(el);
5
- const position = style?.position;
6
- const isFixed = position === "fixed" || position === "sticky";
7
- if (iteration === 0) {
8
- const shadowRoot = getShadowRoot(el);
9
- if (shadowRoot?.firstElementChild)
10
- return shadowRoot.firstElementChild;
11
- }
12
- if (el === document.body || !el)
13
- return document.body;
14
- if (isFixed)
15
- return el;
16
- return findClosestPositionContainer({ el: el.parentElement, iteration: iteration + 1 });
17
- };
18
- export default (args) => findClosestPositionContainer({ ...args, iteration: 0 });
@@ -1,5 +0,0 @@
1
- type Args = {
2
- el: HTMLElement;
3
- };
4
- declare const _default: (args: Args) => HTMLElement | null;
5
- export default _default;
@@ -1,12 +0,0 @@
1
- const findClosestScrollableContainer = (args) => {
2
- const { el, iteration } = args;
3
- const style = el && window.getComputedStyle(el);
4
- const overflowY = style.overflowY;
5
- const isScrollable = overflowY.includes("scroll") || overflowY.includes("auto");
6
- if (!el.parentElement)
7
- return null;
8
- if (isScrollable && el.scrollHeight > el.clientHeight)
9
- return el;
10
- return findClosestScrollableContainer({ el: el.parentElement, iteration: iteration + 1 });
11
- };
12
- export default (args) => findClosestScrollableContainer({ ...args, iteration: 0 });
@@ -1,46 +0,0 @@
1
- import { expect, test, describe } from "vitest";
2
- import findClosestFixedContainer from "../findClosestFixedContainer.js";
3
- describe("flyout/findClosestFixedContainer", () => {
4
- test("returns document.body when element is null", () => {
5
- const result = findClosestFixedContainer({ el: null });
6
- expect(result).toBe(document.body);
7
- });
8
- test("returns document.body when element is document.body", () => {
9
- const result = findClosestFixedContainer({ el: document.body });
10
- expect(result).toBe(document.body);
11
- });
12
- test("returns the element itself when it has position fixed", () => {
13
- const fixedEl = document.createElement("div");
14
- fixedEl.style.position = "fixed";
15
- document.body.appendChild(fixedEl);
16
- const result = findClosestFixedContainer({ el: fixedEl });
17
- expect(result).toBe(fixedEl);
18
- });
19
- test("returns the element itself when it has position sticky", () => {
20
- const stickyEl = document.createElement("div");
21
- stickyEl.style.position = "sticky";
22
- document.body.appendChild(stickyEl);
23
- const result = findClosestFixedContainer({ el: stickyEl });
24
- expect(result).toBe(stickyEl);
25
- });
26
- test("returns grandparent when it has position fixed", () => {
27
- const fixedEl = document.createElement("div");
28
- fixedEl.style.position = "fixed";
29
- const childEl = document.createElement("div");
30
- const grandChildEl = document.createElement("div");
31
- childEl.appendChild(grandChildEl);
32
- fixedEl.appendChild(childEl);
33
- document.body.appendChild(fixedEl);
34
- const result = findClosestFixedContainer({ el: grandChildEl });
35
- expect(result).toBe(fixedEl);
36
- });
37
- test("returns document.body when no fixed container is found", () => {
38
- const staticEl = document.createElement("div");
39
- staticEl.style.position = "static";
40
- const childEl = document.createElement("div");
41
- staticEl.appendChild(childEl);
42
- document.body.appendChild(staticEl);
43
- const result = findClosestFixedContainer({ el: childEl });
44
- expect(result).toBe(document.body);
45
- });
46
- });
@@ -1,66 +0,0 @@
1
- import { expect, test, describe } from "vitest";
2
- import findClosestScrollableContainer from "../findClosestScrollableContainer.js";
3
- describe("flyout/findClosestScrollableContainer", () => {
4
- test("returns null when element has no parent", () => {
5
- const result = findClosestScrollableContainer({ el: document.documentElement });
6
- expect(result).toBe(null);
7
- });
8
- test("returns the element itself has overflow auto", () => {
9
- const scrollableEl = document.createElement("div");
10
- scrollableEl.style.overflowY = "auto";
11
- scrollableEl.style.height = "100px";
12
- const childEl = document.createElement("div");
13
- childEl.style.height = "200px";
14
- scrollableEl.appendChild(childEl);
15
- document.body.appendChild(scrollableEl);
16
- const result = findClosestScrollableContainer({ el: scrollableEl });
17
- expect(result).toBe(scrollableEl);
18
- });
19
- test("returns the element itself has overflow scroll", () => {
20
- const scrollableEl = document.createElement("div");
21
- scrollableEl.style.overflowY = "scroll";
22
- scrollableEl.style.height = "100px";
23
- const childEl = document.createElement("div");
24
- childEl.style.height = "200px";
25
- scrollableEl.appendChild(childEl);
26
- document.body.appendChild(scrollableEl);
27
- const result = findClosestScrollableContainer({ el: scrollableEl });
28
- expect(result).toBe(scrollableEl);
29
- });
30
- test("returns grandparent when it is scrollable", () => {
31
- const scrollableEl = document.createElement("div");
32
- scrollableEl.style.overflowY = "auto";
33
- scrollableEl.style.height = "100px";
34
- const childEl = document.createElement("div");
35
- childEl.style.height = "200px";
36
- const grandChildEl = document.createElement("div");
37
- grandChildEl.style.height = "100px";
38
- childEl.appendChild(grandChildEl);
39
- scrollableEl.appendChild(childEl);
40
- document.body.appendChild(scrollableEl);
41
- const result = findClosestScrollableContainer({ el: grandChildEl });
42
- expect(result).toBe(scrollableEl);
43
- });
44
- test("returns null when no scrollable container is found", () => {
45
- const scrollableEl = document.createElement("div");
46
- scrollableEl.style.overflowY = "visible";
47
- scrollableEl.style.height = "100px";
48
- const childEl = document.createElement("div");
49
- childEl.style.height = "200px";
50
- scrollableEl.appendChild(childEl);
51
- document.body.appendChild(scrollableEl);
52
- const result = findClosestScrollableContainer({ el: childEl });
53
- expect(result).toBe(null);
54
- });
55
- test("does not return element with overflow auto but scrollHeight <= clientHeight", () => {
56
- const scrollableEl = document.createElement("div");
57
- scrollableEl.style.overflowY = "auto";
58
- scrollableEl.style.height = "100px";
59
- const childEl = document.createElement("div");
60
- childEl.style.height = "100px";
61
- scrollableEl.appendChild(childEl);
62
- document.body.appendChild(scrollableEl);
63
- const result = findClosestScrollableContainer({ el: childEl });
64
- expect(result).toBe(null);
65
- });
66
- });