@reshaped/utilities 4.2.0 → 4.3.0-canary.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 (63) hide show
  1. package/dist/a11y/TrapFocus.d.ts +2 -2
  2. package/dist/a11y/TrapFocus.js +6 -6
  3. package/dist/a11y/focus.d.ts +1 -1
  4. package/dist/a11y/focus.js +2 -2
  5. package/dist/a11y/index.d.ts +4 -4
  6. package/dist/a11y/index.js +3 -3
  7. package/dist/a11y/tests/Chain.test.js +1 -1
  8. package/dist/a11y/tests/TrapFocus.test.js +1 -1
  9. package/dist/a11y/tests/TrapScreenReader.test.js +1 -1
  10. package/dist/a11y/tests/focus.test.js +1 -1
  11. package/dist/a11y/tests/keyboardMode.test.js +1 -1
  12. package/dist/css/StyleCache.js +3 -1
  13. package/dist/css/index.d.ts +2 -2
  14. package/dist/css/index.js +2 -2
  15. package/dist/css/tests/StyleCache.test.js +10 -1
  16. package/dist/css/tests/classNames.test.js +1 -1
  17. package/dist/dom/index.d.ts +3 -3
  18. package/dist/dom/index.js +3 -3
  19. package/dist/dom/tests/findClosestScrollableContainer.test.js +1 -1
  20. package/dist/dom/tests/findParent.test.js +1 -1
  21. package/dist/flyout/Flyout.d.ts +2 -2
  22. package/dist/flyout/Flyout.js +3 -3
  23. package/dist/flyout/index.d.ts +1 -1
  24. package/dist/flyout/index.js +1 -1
  25. package/dist/flyout/tests/Flyout.test.js +1 -1
  26. package/dist/flyout/types.d.ts +1 -1
  27. package/dist/flyout/utilities/applyPosition.d.ts +1 -1
  28. package/dist/flyout/utilities/applyPosition.js +8 -8
  29. package/dist/flyout/utilities/calculateLayoutAdjustment.d.ts +3 -3
  30. package/dist/flyout/utilities/calculateLayoutAdjustment.js +1 -1
  31. package/dist/flyout/utilities/calculatePosition.d.ts +1 -1
  32. package/dist/flyout/utilities/calculatePosition.js +2 -2
  33. package/dist/flyout/utilities/getPositionFallbacks.d.ts +1 -1
  34. package/dist/flyout/utilities/getRTLPosition.d.ts +1 -1
  35. package/dist/flyout/utilities/getRectFromCoordinates.d.ts +1 -1
  36. package/dist/flyout/utilities/isFullyVisible.js +1 -1
  37. package/dist/flyout/utilities/tests/applyPosition.test.js +1 -1
  38. package/dist/flyout/utilities/tests/calculateLayoutAdjustment.test.js +2 -2
  39. package/dist/flyout/utilities/tests/calculatePosition.test.js +1 -1
  40. package/dist/flyout/utilities/tests/centerBySize.test.js +1 -1
  41. package/dist/flyout/utilities/tests/getPositionFallbacks.test.js +1 -1
  42. package/dist/flyout/utilities/tests/getRTLPosition.test.js +1 -1
  43. package/dist/flyout/utilities/tests/isFullyVisible.test.js +1 -1
  44. package/dist/helpers/index.d.ts +1 -1
  45. package/dist/helpers/index.js +1 -1
  46. package/dist/helpers/tests/rafThrottle.test.js +1 -1
  47. package/dist/i18n/index.d.ts +1 -1
  48. package/dist/i18n/index.js +1 -1
  49. package/dist/i18n/tests/isRTL.test.js +1 -1
  50. package/dist/index.d.ts +6 -6
  51. package/dist/index.js +6 -6
  52. package/dist/internal.d.ts +6 -6
  53. package/dist/internal.js +4 -4
  54. package/dist/scroll/index.d.ts +2 -2
  55. package/dist/scroll/index.js +2 -2
  56. package/dist/scroll/lock.js +4 -4
  57. package/dist/scroll/lockSafari.d.ts +5 -0
  58. package/dist/scroll/lockSafari.js +20 -16
  59. package/dist/scroll/lockStandard.js +2 -2
  60. package/dist/scroll/tests/lock.test.js +1 -1
  61. package/dist/scroll/tests/lockSafari.test.d.ts +1 -0
  62. package/dist/scroll/tests/lockSafari.test.js +42 -0
  63. package/package.json +2 -1
@@ -1,5 +1,5 @@
1
- import Chain from "./Chain";
2
- import type { FocusableElement, TrapMode } from "./types";
1
+ import Chain from "./Chain.js";
2
+ import type { FocusableElement, TrapMode } from "./types.js";
3
3
  type ReleaseOptions = {
4
4
  withoutFocusReturn?: boolean;
5
5
  };
@@ -1,10 +1,10 @@
1
1
  var _a;
2
- import keys from "../constants/keys";
3
- import { getShadowRoot } from "../dom";
4
- import Chain from "./Chain";
5
- import { focusElement, getActiveElement, getFocusableElements, getFocusData } from "./focus";
6
- import { checkKeyboardMode } from "./keyboardMode";
7
- import TrapScreenReader from "./TrapScreenReader";
2
+ import keys from "../constants/keys.js";
3
+ import { getShadowRoot } from "../dom/index.js";
4
+ import Chain from "./Chain.js";
5
+ import { focusElement, getActiveElement, getFocusableElements, getFocusData } from "./focus.js";
6
+ import { checkKeyboardMode } from "./keyboardMode.js";
7
+ import TrapScreenReader from "./TrapScreenReader.js";
8
8
  class TrapFocus {
9
9
  static chain = new Chain();
10
10
  // Monotonic counter bumped on every trap() call. Used by the deferred
@@ -1,4 +1,4 @@
1
- import type { FocusableElement, FocusableOptions } from "./types";
1
+ import type { FocusableElement, FocusableOptions } from "./types.js";
2
2
  export declare const focusableSelector = "a,button,input:not([type=\"hidden\"]),textarea,select,details,[tabindex],[contenteditable]";
3
3
  export declare const getActiveElement: (originEl?: HTMLElement | null) => HTMLButtonElement;
4
4
  export declare const focusElement: (el: FocusableElement, options?: {
@@ -1,5 +1,5 @@
1
- import { getShadowRoot } from "../dom";
2
- import { checkKeyboardMode } from "./keyboardMode";
1
+ import { getShadowRoot } from "../dom/index.js";
2
+ import { checkKeyboardMode } from "./keyboardMode.js";
3
3
  const pseudoFocusAttribute = "data-rs-focus";
4
4
  export const focusableSelector = 'a,button,input:not([type="hidden"]),textarea,select,details,[tabindex],[contenteditable]';
5
5
  export const getActiveElement = (originEl) => {
@@ -1,4 +1,4 @@
1
- export { focusableSelector, focusFirstElement, focusLastElement, focusNextElement, focusPreviousElement, getActiveElement, getFocusableElements, } from "./focus";
2
- export { activateKeyboardMode, checkKeyboardMode, deactivateKeyboardMode } from "./keyboardMode";
3
- export { default as TrapFocus } from "./TrapFocus";
4
- export type { FocusableElement, TrapMode } from "./types";
1
+ export { focusableSelector, focusFirstElement, focusLastElement, focusNextElement, focusPreviousElement, getActiveElement, getFocusableElements, } from "./focus.js";
2
+ export { activateKeyboardMode, checkKeyboardMode, deactivateKeyboardMode } from "./keyboardMode.js";
3
+ export { default as TrapFocus } from "./TrapFocus.js";
4
+ export type { FocusableElement, TrapMode } from "./types.js";
@@ -1,3 +1,3 @@
1
- export { focusableSelector, focusFirstElement, focusLastElement, focusNextElement, focusPreviousElement, getActiveElement, getFocusableElements, } from "./focus";
2
- export { activateKeyboardMode, checkKeyboardMode, deactivateKeyboardMode } from "./keyboardMode";
3
- export { default as TrapFocus } from "./TrapFocus";
1
+ export { focusableSelector, focusFirstElement, focusLastElement, focusNextElement, focusPreviousElement, getActiveElement, getFocusableElements, } from "./focus.js";
2
+ export { activateKeyboardMode, checkKeyboardMode, deactivateKeyboardMode } from "./keyboardMode.js";
3
+ export { default as TrapFocus } from "./TrapFocus.js";
@@ -1,5 +1,5 @@
1
1
  import { beforeEach, describe, expect, test } from "vitest";
2
- import Chain from "../Chain";
2
+ import Chain from "../Chain.js";
3
3
  describe("a11y/Chain", () => {
4
4
  let chain;
5
5
  beforeEach(() => {
@@ -1,5 +1,5 @@
1
1
  import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
2
- import TrapFocus from "../TrapFocus";
2
+ import TrapFocus from "../TrapFocus.js";
3
3
  describe("a11y/TrapFocus", () => {
4
4
  let container;
5
5
  let trigger;
@@ -1,5 +1,5 @@
1
1
  import { afterEach, beforeEach, describe, expect, test } from "vitest";
2
- import TrapScreenReader from "../TrapScreenReader";
2
+ import TrapScreenReader from "../TrapScreenReader.js";
3
3
  describe("a11y/TrapScreenReader", () => {
4
4
  let container;
5
5
  beforeEach(() => {
@@ -1,5 +1,5 @@
1
1
  import { afterEach, beforeEach, describe, expect, test } from "vitest";
2
- import { focusElement, focusFirstElement, focusLastElement, focusNextElement, focusPreviousElement, getActiveElement, getFocusableElements, getFocusData, } from "../focus";
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
1
  import { afterEach, beforeEach, describe, expect, test } from "vitest";
2
- import { activateKeyboardMode, checkKeyboardMode, deactivateKeyboardMode, keyboardModeAttribute, } from "../keyboardMode";
2
+ import { activateKeyboardMode, checkKeyboardMode, deactivateKeyboardMode, keyboardModeAttribute, } from "../keyboardMode.js";
3
3
  describe("a11y/keyboardMode", () => {
4
4
  beforeEach(() => {
5
5
  document.documentElement.removeAttribute(keyboardModeAttribute);
@@ -5,9 +5,11 @@ class StyleCache {
5
5
  // don't reapply, so locking an element that's already locked is a no-op.
6
6
  if (this.cache.has(el))
7
7
  return;
8
+ // Reading through the style object supports both camelCase and kebab-case keys, same as Object.assign
9
+ const elStyles = el.style;
8
10
  const originalStyles = {};
9
11
  Object.keys(styles).forEach((key) => {
10
- originalStyles[key] = el.style.getPropertyValue(key);
12
+ originalStyles[key] = elStyles[key];
11
13
  });
12
14
  this.cache.set(el, originalStyles);
13
15
  Object.assign(el.style, styles);
@@ -1,2 +1,2 @@
1
- export { type ClassName, default as classNames } from "./classNames";
2
- export { default as StyleCache } from "./StyleCache";
1
+ export { type ClassName, default as classNames } from "./classNames.js";
2
+ export { default as StyleCache } from "./StyleCache.js";
package/dist/css/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // External
2
- export { default as classNames } from "./classNames";
2
+ export { default as classNames } from "./classNames.js";
3
3
  // Internal
4
- export { default as StyleCache } from "./StyleCache";
4
+ export { default as StyleCache } from "./StyleCache.js";
@@ -1,5 +1,5 @@
1
1
  import { beforeEach, describe, expect, test } from "vitest";
2
- import StyleCache from "../StyleCache";
2
+ import StyleCache from "../StyleCache.js";
3
3
  describe("css/StyleCache", () => {
4
4
  let styleCache;
5
5
  beforeEach(() => {
@@ -16,6 +16,15 @@ describe("css/StyleCache", () => {
16
16
  expect(el.style.color).toBe("red");
17
17
  expect(el.style.overflow).toBe("visible");
18
18
  });
19
+ test("restores camelCase properties", () => {
20
+ const el = document.createElement("div");
21
+ el.style.paddingRight = "4px";
22
+ styleCache.set(el, { paddingRight: "16px", scrollbarGutter: "stable" });
23
+ expect(el.style.paddingRight).toBe("16px");
24
+ styleCache.reset(el);
25
+ expect(el.style.paddingRight).toBe("4px");
26
+ expect(el.style.scrollbarGutter).toBe("");
27
+ });
19
28
  test("ignores repeated set calls on an already-cached element", () => {
20
29
  const el = document.createElement("div");
21
30
  el.style.color = "red";
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, test } from "vitest";
2
- import classNames from "../classNames";
2
+ import classNames from "../classNames.js";
3
3
  describe("helpers/classNames", () => {
4
4
  test("returns empty string when no arguments are provided", () => {
5
5
  expect(classNames()).toBe("");
@@ -1,3 +1,3 @@
1
- export { default as findClosestScrollableContainer } from "./findClosestScrollableContainer";
2
- export { default as findParent } from "./findParent";
3
- export { default as getShadowRoot } from "./getShadowRoot";
1
+ export { default as findClosestScrollableContainer } from "./findClosestScrollableContainer.js";
2
+ export { default as findParent } from "./findParent.js";
3
+ export { default as getShadowRoot } from "./getShadowRoot.js";
package/dist/dom/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // Internal
2
- export { default as findClosestScrollableContainer } from "./findClosestScrollableContainer";
3
- export { default as findParent } from "./findParent";
4
- export { default as getShadowRoot } from "./getShadowRoot";
2
+ export { default as findClosestScrollableContainer } from "./findClosestScrollableContainer.js";
3
+ export { default as findParent } from "./findParent.js";
4
+ export { default as getShadowRoot } from "./getShadowRoot.js";
@@ -1,5 +1,5 @@
1
1
  import { afterEach, describe, expect, test } from "vitest";
2
- import findClosestScrollableContainer from "../findClosestScrollableContainer";
2
+ import findClosestScrollableContainer from "../findClosestScrollableContainer.js";
3
3
  describe("dom/findClosestScrollableContainer", () => {
4
4
  afterEach(() => {
5
5
  document.body.innerHTML = "";
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, test } from "vitest";
2
- import findParent from "../findParent";
2
+ import findParent from "../findParent.js";
3
3
  describe("dom/findParent", () => {
4
4
  test("returns null when element has no parent", () => {
5
5
  const element = document.createElement("div");
@@ -1,5 +1,5 @@
1
- import type { Options } from "./types";
2
- import applyPosition from "./utilities/applyPosition";
1
+ import type { Options } from "./types.js";
2
+ import applyPosition from "./utilities/applyPosition.js";
3
3
  declare class Flyout {
4
4
  #private;
5
5
  constructor(options: Options);
@@ -1,6 +1,6 @@
1
- import { findClosestScrollableContainer } from "../dom";
2
- import { rafThrottle } from "../helpers";
3
- import applyPosition from "./utilities/applyPosition";
1
+ import { findClosestScrollableContainer } from "../dom/index.js";
2
+ import { rafThrottle } from "../helpers/index.js";
3
+ import applyPosition from "./utilities/applyPosition.js";
4
4
  class Flyout {
5
5
  #active = false;
6
6
  #lastUsedPosition = null;
@@ -1 +1 @@
1
- export { default as Flyout } from "./Flyout";
1
+ export { default as Flyout } from "./Flyout.js";
@@ -1 +1 @@
1
- export { default as Flyout } from "./Flyout";
1
+ export { default as Flyout } from "./Flyout.js";
@@ -1,5 +1,5 @@
1
1
  import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
2
- import Flyout from "../Flyout";
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 { Coordinates } from "../types/global";
1
+ import type { Coordinates } from "../types/global.js";
2
2
  type XSide = "start" | "end";
3
3
  type YSide = "top" | "bottom";
4
4
  export type Side = XSide | YSide;
@@ -1,4 +1,4 @@
1
- import type { Options, Position } from "../types";
1
+ import type { Options, Position } from "../types.js";
2
2
  declare const applyPosition: (args: Options & {
3
3
  lastUsedPosition: Position | null;
4
4
  }) => {
@@ -1,11 +1,11 @@
1
- import { getShadowRoot } from "../../dom";
2
- import isRTL from "../../i18n/isRTL";
3
- import { RESET_STYLES, VIEWPORT_OFFSET } from "../constants";
4
- import calculateLayoutAdjustment from "./calculateLayoutAdjustment";
5
- import calculatePosition from "./calculatePosition";
6
- import getPositionFallbacks from "./getPositionFallbacks";
7
- import getRectFromCoordinates from "./getRectFromCoordinates";
8
- import isFullyVisible from "./isFullyVisible";
1
+ import { getShadowRoot } from "../../dom/index.js";
2
+ import isRTL from "../../i18n/isRTL.js";
3
+ import { RESET_STYLES, VIEWPORT_OFFSET } from "../constants.js";
4
+ import calculateLayoutAdjustment from "./calculateLayoutAdjustment.js";
5
+ import calculatePosition from "./calculatePosition.js";
6
+ import getPositionFallbacks from "./getPositionFallbacks.js";
7
+ import getRectFromCoordinates from "./getRectFromCoordinates.js";
8
+ import isFullyVisible from "./isFullyVisible.js";
9
9
  /**
10
10
  * Get the viewport-relative rect of the element's containing block.
11
11
  * When the content is inside a positioned ancestor (e.g. a fixed overlay),
@@ -1,12 +1,12 @@
1
- import type { Options } from "../types";
2
- import type { CalculatePositionResult } from "./calculatePosition";
1
+ import type { Options } from "../types.js";
2
+ import type { CalculatePositionResult } from "./calculatePosition.js";
3
3
  type CalculateLayoutAdjustmentArgs = CalculatePositionResult & Pick<Options, "fallbackAdjustLayout" | "fallbackMinHeight" | "width"> & {
4
4
  flyoutBounds: DOMRect;
5
5
  triggerBounds: DOMRect;
6
6
  containerBounds: Pick<DOMRect, "left" | "top" | "width" | "height">;
7
7
  };
8
8
  declare const calculateLayoutAdjustment: (args: CalculateLayoutAdjustmentArgs) => {
9
- position: import("../types").Position;
9
+ position: import("../types.js").Position;
10
10
  styles: {
11
11
  left: number;
12
12
  right: number | null;
@@ -1,4 +1,4 @@
1
- import { VIEWPORT_OFFSET } from "../constants";
1
+ import { VIEWPORT_OFFSET } from "../constants.js";
2
2
  const calculateLayoutAdjustment = (args) => {
3
3
  const { position, styles, fallbackAdjustLayout, fallbackMinHeight, width: passedWidth, flyoutBounds, containerBounds, triggerBounds, } = args;
4
4
  const { width: flyoutWidth, height: flyoutHeight } = flyoutBounds;
@@ -1,4 +1,4 @@
1
- import type { Position } from "../types";
1
+ import type { Position } from "../types.js";
2
2
  type CalculatePositionArgs = {
3
3
  triggerBounds: DOMRect;
4
4
  flyoutBounds: DOMRect;
@@ -1,5 +1,5 @@
1
- import centerBySize from "./centerBySize";
2
- import getRTLPosition from "./getRTLPosition";
1
+ import centerBySize from "./centerBySize.js";
2
+ import getRTLPosition from "./getRTLPosition.js";
3
3
  const calculatePosition = (args) => {
4
4
  const { triggerBounds, flyoutBounds, position: passedPosition, rtl, contentGap = 0, contentShift = 0, } = args;
5
5
  const position = rtl ? getRTLPosition(passedPosition) : passedPosition;
@@ -1,4 +1,4 @@
1
- import type { Position } from "../types";
1
+ import type { Position } from "../types.js";
2
2
  /**
3
3
  * Get an order of positions to try to fit flyout on the screen based on its starting position
4
4
  * @param position - position being checked
@@ -1,3 +1,3 @@
1
- import { Position } from "../types";
1
+ import { Position } from "../types.js";
2
2
  declare const getRTLPosition: (position: Position) => Position;
3
3
  export default getRTLPosition;
@@ -1,4 +1,4 @@
1
- import type { Coordinates } from "../../types/global";
1
+ import type { Coordinates } from "../../types/global.js";
2
2
  /**
3
3
  * Include any missing properties to match DOMRect interface when coordinates are passed
4
4
  */
@@ -1,4 +1,4 @@
1
- import { VIEWPORT_OFFSET } from "../constants";
1
+ import { VIEWPORT_OFFSET } from "../constants.js";
2
2
  /**
3
3
  * Check if element visually fits within its render container
4
4
  * @param flyoutBounds - Bounds of the flyout content
@@ -1,5 +1,5 @@
1
1
  import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
2
- import applyPosition from "../applyPosition";
2
+ import applyPosition from "../applyPosition.js";
3
3
  describe("flyout/applyPosition", () => {
4
4
  let content;
5
5
  let trigger;
@@ -1,6 +1,6 @@
1
1
  import { beforeEach, describe, expect, test, vi } from "vitest";
2
- import { VIEWPORT_OFFSET } from "../../constants";
3
- import calculateLayoutAdjustment from "../calculateLayoutAdjustment";
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
1
  import { beforeEach, describe, expect, test, vi } from "vitest";
2
- import calculatePosition from "../calculatePosition";
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
1
  import { describe, expect, test } from "vitest";
2
- import centerBySize from "../centerBySize";
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
1
  import { describe, expect, test } from "vitest";
2
- import getPositionFallbacks from "../getPositionFallbacks";
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
1
  import { describe, expect, test } from "vitest";
2
- import getRTLPosition from "../getRTLPosition";
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,5 +1,5 @@
1
1
  import { describe, expect, test } from "vitest";
2
- import isFullyVisible from "../isFullyVisible";
2
+ import isFullyVisible from "../isFullyVisible.js";
3
3
  describe("flyout/isFullyVisible", () => {
4
4
  test("returns true when flyout is fully visible within visual container", () => {
5
5
  const result = isFullyVisible({
@@ -1 +1 @@
1
- export { default as rafThrottle } from "./rafThrottle";
1
+ export { default as rafThrottle } from "./rafThrottle.js";
@@ -1,2 +1,2 @@
1
1
  // Internal
2
- export { default as rafThrottle } from "./rafThrottle";
2
+ export { default as rafThrottle } from "./rafThrottle.js";
@@ -1,5 +1,5 @@
1
1
  import { beforeEach, describe, expect, test, vi } from "vitest";
2
- import rafThrottle from "../rafThrottle";
2
+ import rafThrottle from "../rafThrottle.js";
3
3
  const waitForNextFrame = () => {
4
4
  return new Promise((resolve) => {
5
5
  requestAnimationFrame(() => {
@@ -1 +1 @@
1
- export { default as isRTL } from "./isRTL";
1
+ export { default as isRTL } from "./isRTL.js";
@@ -1,2 +1,2 @@
1
1
  // External
2
- export { default as isRTL } from "./isRTL";
2
+ export { default as isRTL } from "./isRTL.js";
@@ -1,5 +1,5 @@
1
1
  import { afterAll, beforeEach, describe, expect, test, vi } from "vitest";
2
- import isRTL from "../isRTL";
2
+ import isRTL from "../isRTL.js";
3
3
  describe("i18n/isRTL", () => {
4
4
  beforeEach(() => {
5
5
  document.documentElement.removeAttribute("dir");
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { TrapFocus } from "./a11y";
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";
1
+ export { TrapFocus } from "./a11y/index.js";
2
+ export { default as keys } from "./constants/keys.js";
3
+ export { type ClassName, 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";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- export { TrapFocus } from "./a11y";
2
- export { default as keys } from "./constants/keys";
3
- export { classNames } from "./css";
4
- export { Flyout } from "./flyout";
5
- export { isRTL } from "./i18n";
6
- export { lockScroll } from "./scroll";
1
+ export { TrapFocus } from "./a11y/index.js";
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 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
- export { rafThrottle } from "./helpers";
11
- export { disableScroll, enableScroll } from "./scroll";
12
- export type { Coordinates } from "./types/global";
7
+ export type { FocusableElement, TrapMode } from "./a11y/index.js";
8
+ export { activateKeyboardMode, checkKeyboardMode, deactivateKeyboardMode, focusableSelector, focusFirstElement, focusLastElement, focusNextElement, focusPreviousElement, getActiveElement, getFocusableElements, } from "./a11y/index.js";
9
+ export { findParent, getShadowRoot } from "./dom/index.js";
10
+ export { rafThrottle } from "./helpers/index.js";
11
+ export { disableScroll, enableScroll } from "./scroll/index.js";
12
+ export type { Coordinates } from "./types/global.js";
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 { activateKeyboardMode, checkKeyboardMode, deactivateKeyboardMode, focusableSelector, focusFirstElement, focusLastElement, focusNextElement, focusPreviousElement, getActiveElement, getFocusableElements, } from "./a11y";
8
- export { findParent, getShadowRoot } from "./dom";
9
- export { rafThrottle } from "./helpers";
10
- export { disableScroll, enableScroll } from "./scroll";
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
+ export { rafThrottle } from "./helpers/index.js";
10
+ export { disableScroll, enableScroll } from "./scroll/index.js";
@@ -1,2 +1,2 @@
1
- export { lockScroll } from "./lock";
2
- export { disableScroll, enableScroll } from "./disable";
1
+ export { lockScroll } from "./lock.js";
2
+ export { disableScroll, enableScroll } from "./disable.js";
@@ -1,4 +1,4 @@
1
1
  // External
2
- export { lockScroll } from "./lock";
2
+ export { lockScroll } from "./lock.js";
3
3
  // Internal
4
- export { disableScroll, enableScroll } from "./disable";
4
+ export { disableScroll, enableScroll } from "./disable.js";
@@ -1,7 +1,7 @@
1
- import { findClosestScrollableContainer } from "../dom";
2
- import { isIOS } from "../platform";
3
- import lockSafariScroll from "./lockSafari";
4
- import lockStandardScroll from "./lockStandard";
1
+ import { findClosestScrollableContainer } from "../dom/index.js";
2
+ import { isIOS } from "../platform/index.js";
3
+ import lockSafariScroll from "./lockSafari.js";
4
+ import lockStandardScroll from "./lockStandard.js";
5
5
  const locks = new WeakMap();
6
6
  export const lockScroll = (args) => {
7
7
  const isIOSLock = isIOS();
@@ -1,2 +1,7 @@
1
+ /**
2
+ * iOS uses overlay scrollbars, so the document scroll is locked with overflow only.
3
+ * Body is not moved to a fixed position since that collapses the document height,
4
+ * which makes Safari lose its translucent toolbars and resets the scroll position on unlock
5
+ */
1
6
  declare const lockSafariScroll: () => () => void;
2
7
  export default lockSafariScroll;
@@ -1,20 +1,24 @@
1
- import { StyleCache } from "../css";
1
+ import { StyleCache } from "../css/index.js";
2
2
  const styleCache = new StyleCache();
3
+ /**
4
+ * Viewport overflow comes from <html> when it has its own overflow value,
5
+ * and propagates from <body> otherwise, so an overflow style on the other element doesn't lock the page.
6
+ */
7
+ const getViewportScroller = () => {
8
+ const html = document.documentElement;
9
+ const { overflowX, overflowY } = window.getComputedStyle(html);
10
+ const htmlHasOverflow = overflowX !== "visible" || overflowY !== "visible";
11
+ return htmlHasOverflow ? html : document.body;
12
+ };
13
+ /**
14
+ * iOS uses overlay scrollbars, so the document scroll is locked with overflow only.
15
+ * Body is not moved to a fixed position since that collapses the document height,
16
+ * which makes Safari lose its translucent toolbars and resets the scroll position on unlock
17
+ */
3
18
  const lockSafariScroll = () => {
4
- const viewport = window.visualViewport;
5
- const offsetLeft = viewport?.offsetLeft || 0;
6
- const offsetTop = viewport?.offsetTop || 0;
7
- const { scrollX, scrollY } = window;
8
- styleCache.set(document.body, {
9
- position: "fixed",
10
- top: `${-(scrollY - Math.floor(offsetTop))}px`,
11
- left: `${-(scrollX - Math.floor(offsetLeft))}px`,
12
- right: "0",
13
- overflow: "hidden",
14
- });
15
- return () => {
16
- styleCache.reset(document.body);
17
- window.scrollTo({ top: scrollY, left: scrollX, behavior: "instant" });
18
- };
19
+ const el = getViewportScroller();
20
+ // Longhands keep the original value of each axis when unlocking, e.g. overflow-x: hidden on body
21
+ styleCache.set(el, { overflowX: "hidden", overflowY: "hidden" });
22
+ return () => styleCache.reset(el);
19
23
  };
20
24
  export default lockSafariScroll;
@@ -1,5 +1,5 @@
1
- import { StyleCache } from "../css";
2
- import { getScrollbarWidth } from "./helpers";
1
+ import { StyleCache } from "../css/index.js";
2
+ import { getScrollbarWidth } from "./helpers.js";
3
3
  const styleCache = new StyleCache();
4
4
  const lockStandardScroll = (args) => {
5
5
  const { container } = args;
@@ -1,5 +1,5 @@
1
1
  import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
2
- import { lockScroll } from "../lock";
2
+ import { lockScroll } from "../lock.js";
3
3
  // Mock the platform module to avoid iOS path
4
4
  vi.mock("@/platform", () => ({
5
5
  isIOS: () => false,
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,42 @@
1
+ import { afterEach, describe, expect, test } from "vitest";
2
+ import lockSafariScroll from "../lockSafari.js";
3
+ describe("scroll/lockSafariScroll", () => {
4
+ afterEach(() => {
5
+ document.documentElement.style.overflow = "";
6
+ document.body.style.overflow = "";
7
+ document.body.style.overflowX = "";
8
+ document.body.innerHTML = "";
9
+ });
10
+ test("locks the body without changing its position", () => {
11
+ const unlock = lockSafariScroll();
12
+ expect(document.body.style.overflow).toBe("hidden");
13
+ expect(document.body.style.position).toBe("");
14
+ expect(document.documentElement.style.overflow).toBe("");
15
+ unlock();
16
+ expect(document.body.style.overflow).toBe("");
17
+ });
18
+ test("keeps the body overflow when it's not the viewport scroller", () => {
19
+ document.body.style.overflowX = "hidden";
20
+ const unlock = lockSafariScroll();
21
+ expect(document.body.style.overflow).toBe("hidden");
22
+ unlock();
23
+ expect(document.body.style.overflowX).toBe("hidden");
24
+ });
25
+ test("locks html when it defines the viewport overflow", () => {
26
+ document.documentElement.style.overflow = "auto";
27
+ const unlock = lockSafariScroll();
28
+ expect(document.documentElement.style.overflow).toBe("hidden");
29
+ expect(document.body.style.overflow).toBe("");
30
+ unlock();
31
+ expect(document.documentElement.style.overflow).toBe("auto");
32
+ });
33
+ test("keeps the scroll position", () => {
34
+ const content = document.createElement("div");
35
+ content.style.height = "5000px";
36
+ document.body.appendChild(content);
37
+ window.scrollTo({ top: 300, behavior: "instant" });
38
+ const unlock = lockSafariScroll();
39
+ unlock();
40
+ expect(window.scrollY).toBe(300);
41
+ });
42
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reshaped/utilities",
3
- "version": "4.2.0",
3
+ "version": "4.3.0-canary.1",
4
4
  "description": "Vanilla JS utilities for implementing common UI patterns",
5
5
  "homepage": "https://reshaped.so",
6
6
  "bugs": {
@@ -20,6 +20,7 @@
20
20
  "files": [
21
21
  "dist/**/*"
22
22
  ],
23
+ "type": "module",
23
24
  "types": "./dist/index.d.ts",
24
25
  "exports": {
25
26
  ".": {