diff --git a/packages/utils/package.json b/packages/utils/package.json index f857df71..4599fe83 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -37,9 +37,6 @@ "test": "echo \"No tests yet\"", "clean": "rm -rf dist" }, - "dependencies": { - "tabbable": "^6.2.0" - }, "devDependencies": { "tsdown": "^0.15.9", "typescript": "^5.9.2" diff --git a/packages/utils/src/dom/index.ts b/packages/utils/src/dom/index.ts index 25c20af9..5f1a1442 100644 --- a/packages/utils/src/dom/index.ts +++ b/packages/utils/src/dom/index.ts @@ -1,6 +1,5 @@ export * from './attributes'; export * from './element'; export * from './event'; -export * from './keyboard'; export * from './safe-polygon'; export * from './shadow-dom'; diff --git a/packages/utils/src/dom/keyboard.ts b/packages/utils/src/dom/keyboard.ts deleted file mode 100644 index fe040842..00000000 --- a/packages/utils/src/dom/keyboard.ts +++ /dev/null @@ -1,46 +0,0 @@ -import type { FocusableElement } from 'tabbable'; -import { tabbable } from 'tabbable'; -import { activeElement, getDocument } from './element'; - -export function getTabbableOptions(): Readonly<{ - getShadowRoot: boolean; - displayCheck: 'full' | 'none'; -}> { - // JSDOM does not support the `tabbable` library. To solve this we can - // check if `ResizeObserver` is a real function (not polyfilled), which - // determines if the current environment is JSDOM-like. - const isNativeResizeObserver: boolean = typeof ResizeObserver === 'function' && ResizeObserver.toString().includes('[native code]'); - const displayCheck: 'full' | 'none' = isNativeResizeObserver ? 'full' : 'none'; - - return ({ - getShadowRoot: true, - displayCheck: displayCheck as 'full' | 'none', - }) as const; -} - -function getTabbableIn(container: HTMLElement, dir: 1 | -1): FocusableElement | undefined { - const list = tabbable(container, getTabbableOptions()); - const len = list.length; - if (len === 0) { - return undefined; - } - - const active = activeElement(getDocument(container)) as FocusableElement; - const index = list.indexOf(active); - - const nextIndex = index === -1 ? (dir === 1 ? 0 : len - 1) : index + dir; - - return list[nextIndex]; -} - -export function getNextTabbable(referenceElement: Element | null): FocusableElement | null { - return ( - getTabbableIn(getDocument(referenceElement).body, 1) || (referenceElement as FocusableElement) - ); -} - -export function getPreviousTabbable(referenceElement: Element | null): FocusableElement | null { - return ( - getTabbableIn(getDocument(referenceElement).body, -1) || (referenceElement as FocusableElement) - ); -} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e40355c5..a8f440f9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -243,10 +243,6 @@ importers: version: 5.9.3 packages/utils: - dependencies: - tabbable: - specifier: ^6.2.0 - version: 6.2.0 devDependencies: tsdown: specifier: ^0.15.9 @@ -4876,6 +4872,7 @@ packages: sitemap@8.0.0: resolution: {integrity: sha512-+AbdxhM9kJsHtruUF39bwS/B0Fytw6Fr1o4ZAIAEqA6cke2xcoO2GleBw9Zw7nRzILVEgz7zBM5GiTJjie1G9A==} engines: {node: '>=14.0.0', npm: '>=6.0.0'} + deprecated: 'SECURITY: Multiple vulnerabilities fixed in 8.0.1 (XML injection, path traversal, command injection, protocol injection). Upgrade immediately: npm install sitemap@8.0.1' hasBin: true slice-ansi@7.1.2: