{"version":3,"file":"ng-primitives-focus-trap.mjs","sources":["../../../../packages/ng-primitives/focus-trap/src/focus-trap/focus-trap-state.ts","../../../../packages/ng-primitives/focus-trap/src/focus-trap/focus-trap.ts","../../../../packages/ng-primitives/focus-trap/src/ng-primitives-focus-trap.ts"],"sourcesContent":["import { FocusMonitor, FocusOrigin, InteractivityChecker } from '@angular/cdk/a11y';\nimport { afterNextRender, inject, Injector, NgZone, signal, Signal } from '@angular/core';\nimport { explicitEffect, injectElementRef } from 'ng-primitives/internal';\nimport { NgpOverlay, NgpOverlayRegistry } from 'ng-primitives/portal';\nimport {\n  attrBinding,\n  createPrimitive,\n  dataBinding,\n  listener,\n  onDestroy,\n} from 'ng-primitives/state';\nimport { safeTakeUntilDestroyed } from 'ng-primitives/utils';\n\nclass FocusTrap {\n  /**\n   * Whether the focus trap is active.\n   */\n  active: boolean = false;\n\n  /**\n   * Activates the focus trap.\n   */\n  activate(): void {\n    this.active = true;\n  }\n\n  /**\n   * Deactivates the focus trap.\n   */\n  deactivate(): void {\n    this.active = false;\n  }\n}\n\nclass FocusTrapStack {\n  /**\n   * The stack of focus traps.\n   */\n  private readonly stack: FocusTrap[] = [];\n\n  /**\n   * Adds a focus trap to the stack.\n   */\n  add(focusTrap: FocusTrap): void {\n    // deactivate the previous focus trap\n    this.stack.forEach(t => t.deactivate());\n\n    // add the new focus trap and activate it\n    this.stack.push(focusTrap);\n    focusTrap.activate();\n  }\n\n  /**\n   * Removes a focus trap from the stack.\n   */\n  remove(focusTrap: FocusTrap): void {\n    // remove the focus trap\n    const index = this.stack.indexOf(focusTrap);\n\n    if (index < 0) {\n      return;\n    }\n\n    // Only reactivate the previous trap if we're removing from the top of the stack.\n    // This prevents reactivating a parent trap when closing all overlays (where the\n    // parent is removed first, leaving the child at the top).\n    const wasOnTop = index === this.stack.length - 1;\n\n    // Deactivate the removed focus trap so its event listeners don't interfere\n    focusTrap.deactivate();\n    this.stack.splice(index, 1);\n\n    // activate the previous focus trap only if removed from top\n    if (wasOnTop) {\n      const previous = this.stack[this.stack.length - 1];\n\n      if (previous) {\n        previous.activate();\n      }\n    }\n  }\n}\n\n// create a global stack of focus traps\nconst focusTrapStack = new FocusTrapStack();\n\n/**\n * The state for the FocusTrap primitive.\n */\nexport interface NgpFocusTrapState {\n  // No public API\n}\n\n/**\n * The props for the FocusTrap primitive.\n */\nexport interface NgpFocusTrapProps {\n  /**\n   * Whether the focus trap is disabled.\n   */\n  readonly disabled?: Signal<boolean>;\n\n  /**\n   * The focus origin to use when programmatically focusing elements.\n   * If not provided, falls back to the FocusMonitor's last known origin.\n   */\n  readonly focusOrigin?: Signal<FocusOrigin>;\n\n  /**\n   * The element to focus when the trap activates, if no `[autofocus]` element takes focus first.\n   * When it returns nothing, the first tabbable element is focused.\n   */\n  readonly initialFocus?: () => HTMLElement | null | undefined;\n}\n\nexport const [NgpFocusTrapStateToken, ngpFocusTrap, injectFocusTrapState, provideFocusTrapState] =\n  createPrimitive(\n    'NgpFocusTrap',\n    ({ disabled = signal(false), focusOrigin, initialFocus }: NgpFocusTrapProps) => {\n      const element = injectElementRef();\n      const overlay = inject(NgpOverlay, { optional: true });\n      const injector = inject(Injector);\n      const focusMonitor = inject(FocusMonitor);\n      const interactivityChecker = inject(InteractivityChecker);\n      const ngZone = inject(NgZone);\n      const overlayRegistry = inject(NgpOverlayRegistry);\n\n      // Create a new focus trap\n      const focusTrap = new FocusTrap();\n\n      // Store the mutation observer\n      let mutationObserver: MutationObserver | null = null;\n\n      // Store the last focused element\n      let lastFocusedElement: HTMLElement | null = null;\n\n      // Whether the trap is currently armed - on the stack, observing, and listening.\n      // Setup and teardown can each be reached more than once (an overlay closing, then\n      // being shown again with the same view), so both are idempotent.\n      let armed = false;\n\n      // Host bindings\n      attrBinding(element, 'tabindex', '-1');\n      dataBinding(element, 'data-focus-trap', () => (disabled() ? null : ''));\n\n      // Setup the focus trap\n      function setupFocusTrap(): void {\n        if (armed) {\n          return;\n        }\n\n        armed = true;\n        focusTrapStack.add(focusTrap);\n\n        mutationObserver = new MutationObserver(handleMutations);\n\n        // Setup event listeners\n        ngZone.runOutsideAngular(() => {\n          mutationObserver!.observe(element.nativeElement, {\n            childList: true,\n            subtree: true,\n          });\n          document.addEventListener('focusin', handleFocusIn);\n          document.addEventListener('focusout', handleFocusOut);\n        });\n\n        const previouslyFocusedElement = getFocusedElement();\n        const hasFocusedCandidate = element.nativeElement.contains(getFocusedElementInTrapTree());\n\n        // Only perform initial focusing if the focus trap is not disabled\n        if (!hasFocusedCandidate && !disabled?.()) {\n          // we do this to ensure the content is rendered before we try to find the first focusable element\n          // and focus it\n          afterNextRender(\n            {\n              write: () => {\n                if (!focusAutofocusElement() && !focusInitialElement()) {\n                  focusFirst();\n                }\n\n                // if the focus didn't change, focus the container\n                if (getFocusedElement() === previouslyFocusedElement) {\n                  focus(element.nativeElement);\n                }\n              },\n            },\n            { injector },\n          );\n        }\n      }\n\n      function teardownFocusTrap(): void {\n        if (!armed) {\n          return;\n        }\n\n        armed = false;\n\n        // Remove from stack (this also deactivates the trap)\n        focusTrapStack.remove(focusTrap);\n        mutationObserver?.disconnect();\n        mutationObserver = null;\n\n        // Remove event listeners\n        document.removeEventListener('focusin', handleFocusIn);\n        document.removeEventListener('focusout', handleFocusOut);\n      }\n\n      function handleFocusIn(event: FocusEvent): void {\n        if (!focusTrap.active || disabled?.()) {\n          return;\n        }\n\n        const target = event.target as HTMLElement | null;\n\n        if (element.nativeElement.contains(target)) {\n          lastFocusedElement = target;\n        } else if (isAllowedExternalTarget(target)) {\n          // Don't interfere — see `isAllowedExternalTarget` for details.\n        } else {\n          focus(lastFocusedElement);\n        }\n      }\n\n      /**\n       * Handles the `focusout` event.\n       */\n      function handleFocusOut(event: FocusEvent) {\n        if (!focusTrap.active || disabled?.() || event.relatedTarget === null) {\n          return;\n        }\n\n        const relatedTarget = event.relatedTarget as HTMLElement;\n\n        if (\n          !element.nativeElement.contains(relatedTarget) &&\n          !isAllowedExternalTarget(relatedTarget)\n        ) {\n          focus(lastFocusedElement);\n        }\n      }\n\n      /**\n       * Whether the given element belongs to another focus trap, a CDK overlay\n       * container, or an open ng-primitives overlay (e.g. a combobox/menu/popover\n       * dropdown rendered into a portal).\n       *\n       * When focus moves to these elements we must not redirect it back, because\n       * they manage their own focus or are an intentional escape hatch from the\n       * trapped region. Without this check, opening a combobox dropdown from\n       * inside a focus-trapped dialog would yank focus back into the dialog as\n       * soon as the user tried to focus the dropdown's search input, making it\n       * unusable.\n       *\n       * See https://github.com/ng-primitives/ng-primitives/issues/682\n       * and https://github.com/ng-primitives/ng-primitives/issues/687\n       */\n      function isAllowedExternalTarget(target: HTMLElement | null): boolean {\n        if (!target) {\n          return false;\n        }\n        if (target.closest?.('[data-focus-trap]') || target.closest?.('.cdk-overlay-container')) {\n          return true;\n        }\n        // toasts stay reachable from inside a trap (F6, see NgpToastManager)\n        if (target.closest?.('[data-ngp-toast-container]')) {\n          return true;\n        }\n        return overlayRegistry.findContainingOverlay(target) !== null;\n      }\n\n      /**\n       * If the focused element gets removed from the DOM, browsers move focus back to the document.body.\n       * We move focus to the container to keep focus trapped correctly.\n       */\n      function handleMutations(mutations: MutationRecord[]): void {\n        // Don't handle mutations if the focus trap is not active (e.g., during overlay close)\n        if (!focusTrap.active || disabled?.()) {\n          return;\n        }\n\n        const focusedElement = getFocusedElement();\n\n        if (focusedElement !== document.body) {\n          return;\n        }\n\n        for (const mutation of mutations) {\n          if (mutation.removedNodes.length > 0) {\n            focus(element.nativeElement);\n          }\n        }\n      }\n\n      /**\n       * Handles the `keydown` event.\n       */\n      function handleKeyDown(event: KeyboardEvent): void {\n        if (!focusTrap.active || disabled?.()) {\n          return;\n        }\n\n        const isTabKey = event.key === 'Tab' && !event.altKey && !event.ctrlKey && !event.metaKey;\n        const focusedElement = getFocusedElementInTrapTree();\n\n        if (!isTabKey || !focusedElement) {\n          return;\n        }\n\n        // The tabbable walker does not enter nested shadow roots, so from inside one the trap\n        // cannot tell where Tab should go; leave it to the browser.\n        if (focusedElement !== getFocusedElement()) {\n          return;\n        }\n\n        const container = event.currentTarget as HTMLElement;\n        const [first, last] = getTabbableEdges(container, focusedElement);\n\n        if (!first || !last) {\n          if (container.contains(focusedElement)) {\n            event.preventDefault();\n          }\n          return;\n        }\n\n        // Wrap when no tabbable lies ahead of focus in DOM order, rather than only from the\n        // edges: focus can sit on a non-tabbable element, such as a `tabindex=\"-1\"` autofocus\n        // target or the container itself. Comparing with the edges is enough, and keeps the\n        // layout reads of `isVisible()` to the two ends of the list.\n        if (!event.shiftKey && !follows(last, focusedElement)) {\n          event.preventDefault();\n          focus(first);\n        } else if (event.shiftKey && !follows(focusedElement, first)) {\n          event.preventDefault();\n          focus(last);\n        }\n      }\n\n      /**\n       * Returns the first and last tabbable elements in a container, skipping those that can't take\n       * focus.\n       */\n      function getTabbableEdges(container: HTMLElement, focusedElement: Element) {\n        const candidates = getTabbableCandidates(container);\n        // While modals are open, everything outside the topmost one is inert, so focus is inside\n        // it. Reading it from focus, unlike a document query, also finds one in a shadow root. The\n        // nearest modal around focus is taken as the topmost, which misreads a modal shown after\n        // one nested inside it.\n        const activeModal = getModalDialogAncestor(focusedElement);\n        // `isTabbable()` checks neither `disabled` nor `inert`, accepts a link without an `href`\n        // that Tab skips, and `isVisible()` misses collapsed content, such as a closed `<details>`,\n        // which `checkVisibility()` catches. The visibility checks read layout, so the scan stops\n        // at the first match from each end. Unlike `[disabled]`, `:disabled` also matches a\n        // control in a disabled `<fieldset>`.\n        const canTakeFocus = (candidate: HTMLElement) =>\n          !candidate.matches(':disabled, a:not([href]):not([tabindex])') &&\n          !isInert(candidate, activeModal) &&\n          interactivityChecker.isVisible(candidate) &&\n          candidate.checkVisibility?.() !== false;\n        const firstIndex = candidates.findIndex(canTakeFocus);\n\n        if (firstIndex === -1) {\n          return [undefined, undefined] as const;\n        }\n\n        // Scan back only down to the first edge, so each candidate is checked once at most.\n        let lastIndex = candidates.length - 1;\n        while (lastIndex > firstIndex && !canTakeFocus(candidates[lastIndex])) {\n          lastIndex--;\n        }\n\n        return [candidates[firstIndex], candidates[lastIndex]] as const;\n      }\n\n      /**\n       * Returns the focused element, looking through shadow roots: inside one,\n       * `document.activeElement` is the shadow host rather than the element itself. A closed\n       * root can't be entered from its host, so start from the trap's own root when it holds focus.\n       */\n      function getFocusedElement(): HTMLElement | null {\n        const trapRoot = element.nativeElement.getRootNode();\n        let focusedElement = (\n          trapRoot instanceof ShadowRoot && trapRoot.activeElement\n            ? trapRoot.activeElement\n            : document.activeElement\n        ) as HTMLElement | null;\n\n        while (focusedElement?.shadowRoot?.activeElement) {\n          focusedElement = focusedElement.shadowRoot.activeElement as HTMLElement;\n        }\n\n        return focusedElement;\n      }\n\n      /**\n       * Returns the focused element, or the shadow host that contains it, in the trap's own\n       * tree, so it can be compared with the trap's descendants.\n       */\n      function getFocusedElementInTrapTree(): HTMLElement | null {\n        const trapRoot = element.nativeElement.getRootNode();\n        let focusedElement: Element | null = getFocusedElement();\n\n        while (focusedElement && focusedElement.getRootNode() !== trapRoot) {\n          const root = focusedElement.getRootNode();\n          focusedElement = root instanceof ShadowRoot ? root.host : null;\n        }\n\n        return focusedElement as HTMLElement | null;\n      }\n\n      /**\n       * Whether `node` comes after `reference` in DOM order.\n       */\n      function follows(node: Node, reference: Node): boolean {\n        return (reference.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_FOLLOWING) !== 0;\n      }\n\n      /**\n       * Returns a list of potential focusable elements inside a container.\n       */\n      function getTabbableCandidates(container: HTMLElement) {\n        const nodes: HTMLElement[] = [];\n        const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {\n          acceptNode: (node: HTMLElement) =>\n            interactivityChecker.isTabbable(node)\n              ? NodeFilter.FILTER_ACCEPT\n              : NodeFilter.FILTER_SKIP,\n        });\n        while (walker.nextNode()) {\n          nodes.push(walker.currentNode as HTMLElement);\n        }\n        return nodes;\n      }\n\n      /**\n       * Whether `candidate` is inert. Walks the flat tree: the nearest `inert` ancestor wins\n       * unless the active modal `<dialog>` sits in between, and while a modal is active,\n       * everything outside it is inert. Slots inside a closed shadow root can't be seen.\n       */\n      function isInert(candidate: Element, activeModal: HTMLDialogElement | null): boolean {\n        for (let node: Element | null = candidate; node; node = getFlatTreeParent(node)) {\n          if (node instanceof HTMLElement && node.inert) {\n            return true;\n          }\n          if (node === activeModal) {\n            return false;\n          }\n        }\n        return activeModal !== null;\n      }\n\n      /**\n       * Returns the nearest modal `<dialog>` in the flat tree that holds `element` or is it.\n       */\n      function getModalDialogAncestor(element: Element): HTMLDialogElement | null {\n        for (let node: Element | null = element; node; node = getFlatTreeParent(node)) {\n          if (isModalDialog(node)) {\n            return node;\n          }\n        }\n        return null;\n      }\n\n      /**\n       * Whether `node` is a `<dialog>` opened with `showModal()`.\n       */\n      function isModalDialog(node: Element): node is HTMLDialogElement {\n        if (!(node instanceof HTMLDialogElement) || !node.open) {\n          return false;\n        }\n        try {\n          return node.matches(':modal');\n        } catch {\n          // jsdom before v27 rejects `:modal`, and has no `showModal()` either.\n          return false;\n        }\n      }\n\n      /**\n       * Returns the parent in the flat tree: the slot a node is assigned to, else its parent,\n       * else the host of the shadow root it sits in.\n       */\n      function getFlatTreeParent(node: Element): Element | null {\n        if (node.assignedSlot) {\n          return node.assignedSlot;\n        }\n        const parent = node.parentNode;\n        return parent instanceof ShadowRoot ? parent.host : node.parentElement;\n      }\n\n      function focus(element: HTMLElement | null): void {\n        if (!element) {\n          return;\n        }\n        // Use the provided focus origin if available, otherwise fall back to FocusMonitor's last origin\n        // eslint-disable-next-line @typescript-eslint/no-explicit-any\n        const origin = focusOrigin?.() ?? (focusMonitor as any)._lastFocusOrigin ?? 'program';\n        focusMonitor.focusVia(element, origin, {\n          preventScroll: true,\n        });\n      }\n\n      /**\n       * Focuses the first focusable `[autofocus]` descendant, as a native `<dialog>` does on\n       * `showModal()`. Angular does not apply `autofocus` to dynamically inserted content.\n       * Returns whether an element received focus.\n       */\n      function focusAutofocusElement(): boolean {\n        const candidates = element.nativeElement.querySelectorAll<HTMLElement>('[autofocus]');\n\n        for (const candidate of Array.from(candidates)) {\n          if (candidate.matches(':disabled')) {\n            continue;\n          }\n\n          // Let the browser decide focusability: CDK's checker rejects some natively focusable\n          // elements (e.g. `<summary>`), and the browser refuses hidden or inert ones.\n          focus(candidate);\n\n          // a host that delegates focus hands it to a control in its own shadow root\n          if (getFocusedElement() === candidate || candidate.shadowRoot?.activeElement) {\n            return true;\n          }\n        }\n\n        return false;\n      }\n\n      /** Focuses the element `initialFocus` names. Returns whether it received focus. */\n      function focusInitialElement(): boolean {\n        const target = initialFocus?.();\n        focus(target ?? null);\n        // a host that delegates focus hands it to a control in its own shadow root\n        return !!target && (getFocusedElement() === target || !!target.shadowRoot?.activeElement);\n      }\n\n      function focusFirst(): void {\n        const previouslyFocusedElement = getFocusedElement();\n\n        for (const candidate of getTabbableCandidates(element.nativeElement)) {\n          focus(candidate);\n\n          if (getFocusedElement() !== previouslyFocusedElement) {\n            return;\n          }\n        }\n      }\n\n      // Setup the focus trap\n      setupFocusTrap();\n\n      // Teardown the focus trap on destroy\n      onDestroy(teardownFocusTrap);\n\n      // Listen to keydown events\n      listener(element, 'keydown', handleKeyDown);\n\n      // if this is used within an overlay we must tear the focus trap down as soon as the\n      // overlay is closing rather than waiting for destruction - this prevents reactivation\n      // of parent focus traps during component destruction\n      overlay?.closing.pipe(safeTakeUntilDestroyed()).subscribe(() => teardownFocusTrap());\n\n      // An overlay that keeps its content mounted reuses this view when shown again, so the\n      // factory - and the `setupFocusTrap()` above - does not run a second time. Re-arm on\n      // each open instead, or a reopened overlay would neither move focus inside nor trap it.\n      if (overlay) {\n        explicitEffect([overlay.isOpen], ([isOpen]) => {\n          if (isOpen) {\n            setupFocusTrap();\n          }\n        });\n      }\n\n      return {} satisfies NgpFocusTrapState;\n    },\n  );\n","import { BooleanInput } from '@angular/cdk/coercion';\nimport { booleanAttribute, Directive, input } from '@angular/core';\nimport { ngpFocusTrap, provideFocusTrapState } from './focus-trap-state';\n\n/**\n * This implementation is based on the Radix UI FocusScope:\n * https://github.com/radix-ui/primitives/blob/main/packages/react/focus-scope/src/FocusScope.tsx#L306\n */\n\n/**\n * The `NgpFocusTrap` directive traps focus within the host element.\n */\n@Directive({\n  selector: '[ngpFocusTrap]',\n  exportAs: 'ngpFocusTrap',\n  providers: [provideFocusTrapState()],\n})\nexport class NgpFocusTrap {\n  /**\n   * Whether the focus trap is disabled.\n   */\n  readonly disabled = input<boolean, BooleanInput>(false, {\n    alias: 'ngpFocusTrapDisabled',\n    transform: booleanAttribute,\n  });\n\n  /**\n   * The focus trap state.\n   */\n  constructor() {\n    ngpFocusTrap({ disabled: this.disabled });\n  }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;AAaA,MAAM,SAAS,CAAA;AAAf,IAAA,WAAA,GAAA;AACE;;AAEG;QACH,IAAA,CAAA,MAAM,GAAY,KAAK;IAezB;AAbE;;AAEG;IACH,QAAQ,GAAA;AACN,QAAA,IAAI,CAAC,MAAM,GAAG,IAAI;IACpB;AAEA;;AAEG;IACH,UAAU,GAAA;AACR,QAAA,IAAI,CAAC,MAAM,GAAG,KAAK;IACrB;AACD;AAED,MAAM,cAAc,CAAA;AAApB,IAAA,WAAA,GAAA;AACE;;AAEG;QACc,IAAA,CAAA,KAAK,GAAgB,EAAE;IA2C1C;AAzCE;;AAEG;AACH,IAAA,GAAG,CAAC,SAAoB,EAAA;;AAEtB,QAAA,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC;;AAGvC,QAAA,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;QAC1B,SAAS,CAAC,QAAQ,EAAE;IACtB;AAEA;;AAEG;AACH,IAAA,MAAM,CAAC,SAAoB,EAAA;;QAEzB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;AAE3C,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