{
  "version": 3,
  "sources": ["/cdn/shop/t/6/assets/focus.js?cb=20260407-7"],
  "sourcesContent": ["// Store references to our event handlers so we can remove them.\n/** @type {Record<string, (event: Event) => void>} */\nconst trapFocusHandlers = {};\n\n/**\n * Get all focusable elements within a container.\n * @param {HTMLElement} container - The container to get focusable elements from.\n * @returns {HTMLElement[]} An array of focusable elements.\n */\nfunction getFocusableElements(container) {\n  return Array.from(\n    container.querySelectorAll(\n      \"summary, a[href], button:enabled, [tabindex]:not([tabindex^='-']), [draggable], area, input:not([type=hidden]):enabled, select:enabled, textarea:enabled, object, iframe\"\n    )\n  );\n}\n\n/**\n * Trap focus within the given container.\n * @param {HTMLElement} container - The container to trap focus within.\n */\nexport function trapFocus(container) {\n  // Clean up any previously set traps.\n  removeTrapFocus();\n\n  // Gather focusable elements.\n  const focusable = getFocusableElements(container);\n  if (!focusable.length) {\n    // If nothing is focusable, just abort\u2014no need to trap.\n    return;\n  }\n\n  const first = focusable[0];\n  const last = focusable[focusable.length - 1];\n\n  // Keydown handler for cycling focus with Tab and Shift+Tab\n  /** @type {(event: KeyboardEvent) => void} */\n  trapFocusHandlers.keydown = (event) => {\n    if (event.key !== 'Tab') return;\n\n    const activeEl = document.activeElement;\n\n    // If on the last focusable and tabbing forward, go to first\n    if (!event.shiftKey && activeEl === last) {\n      event.preventDefault();\n      first?.focus();\n    }\n    // If on the first (or the container) and shift-tabbing, go to last\n    else if (event.shiftKey && (activeEl === first || activeEl === container)) {\n      event.preventDefault();\n      last?.focus();\n    }\n  };\n\n  // Focusin (capturing) handler to forcibly keep focus in the container\n  /** @type {(event: FocusEvent) => void} */\n  trapFocusHandlers.focusin = (event) => {\n    // If the newly focused element isn't inside the container, redirect focus back.\n    if (event.target instanceof Node && !container.contains(event.target)) {\n      event.stopPropagation();\n      // E.g., refocus the first focusable element:\n      first?.focus();\n    }\n  };\n\n  // Attach the handlers\n  document.addEventListener('keydown', trapFocusHandlers.keydown, true);\n  // Use capture phase for focusin so we can catch it before it lands outside\n  document.addEventListener('focusin', trapFocusHandlers.focusin, true);\n\n  // Finally, put focus where you want it.\n  container.focus();\n}\n\n/**\n * Remove focus trap and optionally refocus another element.\n */\nexport function removeTrapFocus() {\n  trapFocusHandlers.keydown && document.removeEventListener('keydown', trapFocusHandlers.keydown, true);\n  trapFocusHandlers.focusin && document.removeEventListener('focusin', trapFocusHandlers.focusin, true);\n}\n\n/**\n * Cycle focus to the next or previous link\n *\n * @param {HTMLElement[]} items\n * @param {number} increment\n */\nexport function cycleFocus(items, increment) {\n  const currentIndex = items.findIndex((item) => item.matches(':focus'));\n  let targetIndex = currentIndex + increment;\n\n  if (targetIndex >= items.length) {\n    targetIndex = 0;\n  } else if (targetIndex < 0) {\n    targetIndex = items.length - 1;\n  }\n\n  const targetItem = items[targetIndex];\n\n  if (!targetItem) return;\n\n  targetItem.focus();\n}\n"],
  "mappings": "AAEA,MAAM,kBAAoB,CAAC,EAO3B,SAAS,qBAAqB,UAAW,CACvC,OAAO,MAAM,KACX,UAAU,iBACR,0KACF,CACF,CACF,CAMO,gBAAS,UAAU,UAAW,CAEnC,gBAAgB,EAGhB,MAAM,UAAY,qBAAqB,SAAS,EAChD,GAAI,CAAC,UAAU,OAEb,OAGF,MAAM,MAAQ,UAAU,CAAC,EACnB,KAAO,UAAU,UAAU,OAAS,CAAC,EAI3C,kBAAkB,QAAW,OAAU,CACrC,GAAI,MAAM,MAAQ,MAAO,OAEzB,MAAM,SAAW,SAAS,cAGtB,CAAC,MAAM,UAAY,WAAa,MAClC,MAAM,eAAe,EACrB,OAAO,MAAM,GAGN,MAAM,WAAa,WAAa,OAAS,WAAa,aAC7D,MAAM,eAAe,EACrB,MAAM,MAAM,EAEhB,EAIA,kBAAkB,QAAW,OAAU,CAEjC,MAAM,kBAAkB,MAAQ,CAAC,UAAU,SAAS,MAAM,MAAM,IAClE,MAAM,gBAAgB,EAEtB,OAAO,MAAM,EAEjB,EAGA,SAAS,iBAAiB,UAAW,kBAAkB,QAAS,EAA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