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AAA,GAAA,yCAAa,EAAE;IACjC,IAAI,CAAE,CAAA,gBAAgB,YAAY,QAAQ,IAAI,gBAAgB,YAAY,UAAU,AAAD,GACjF,OAAO;IAET,IAAI,gBAAgB,KAAK,aAAa;IAEtC,gGAAgG;IAChG,OAAO,iBAAiB,QAAQ,KAAK,QAAQ,CAAC;AAChD","sources":["packages/react-aria/src/utils/shadowdom/DOMFunctions.ts"],"sourcesContent":["// Source: https://github.com/microsoft/tabster/blob/a89fc5d7e332d48f68d03b1ca6e344489d1c3898/src/Shadowdomize/DOMFunctions.ts#L16\n/* eslint-disable rsp-rules/no-non-shadow-contains, rsp-rules/safe-event-target */\n\nimport {getOwnerWindow, isShadowRoot} from '../domHelpers';\nimport {shadowDOM} from 'react-stately/private/flags/flags';\nimport type {SyntheticEvent} from 'react';\n\n/**\n * ShadowDOM safe version of Node.contains.\n */\nexport function nodeContains(\n  node: Node | Element | null | undefined,\n  otherNode: Node | Element | null | undefined\n): boolean {\n  if (!shadowDOM()) {\n    return otherNode && node ? node.contains(otherNode) : false;\n  }\n\n  if (!node || !otherNode) {\n    return false;\n  }\n\n  let currentNode: HTMLElement | Node | null | undefined = otherNode;\n\n  while (currentNode !== null) {\n    if (currentNode === node) {\n      return true;\n    }\n\n    if ((currentNode as HTMLSlotElement).tagName === 'SLOT' &&\n      (currentNode as HTMLSlotElement).assignedSlot) {\n      // Element is slotted\n      currentNode = (currentNode as HTMLSlotElement).assignedSlot!.parentNode;\n    } else if (isShadowRoot(currentNode)) {\n      // Element is in shadow root\n      currentNode = currentNode.host;\n    } else {\n      currentNode = currentNode.parentNode;\n    }\n  }\n\n  return false;\n}\n\n/**\n * ShadowDOM safe version of document.activeElement.\n */\nexport const getActiveElement = (doc: Document = document): Element | null => {\n  if (!shadowDOM()) {\n    return doc.activeElement;\n  }\n  let activeElement: Element | null = doc.activeElement;\n\n  while (activeElement && 'shadowRoot' in activeElement &&\n  activeElement.shadowRoot?.activeElement) {\n    activeElement = activeElement.shadowRoot.activeElement;\n  }\n\n  return activeElement;\n};\n\n// Type helper to extract the target element type from an event\ntype EventTargetType<T> = T extends SyntheticEvent<infer E, any> ? E : EventTarget;\n\n// Possibly we can improve the types for this using https://github.com/adobe/react-spectrum/pull/8991/changes#diff-2d491c0c91701d28d08e1cf9fcadbdb21a030b67ab681460c9934140f29127b8R68 but it was more changes than I\n// wanted to make to fix the function.\n/**\n * ShadowDOM safe version of event.target.\n */\nexport function getEventTarget<T extends Event | SyntheticEvent>(event: T): EventTargetType<T> {\n  if (shadowDOM() && (event.target instanceof Element) && event.target.shadowRoot) {\n    if ('composedPath' in event) {\n      return (event.composedPath()[0] ?? null) as EventTargetType<T>;\n    } else if ('composedPath' in event.nativeEvent) {\n      return (event.nativeEvent.composedPath()[0] ?? null) as EventTargetType<T>;\n    }\n  }\n  return event.target as EventTargetType<T>;\n}\n\n/**\n * ShadowDOM safe fast version of node.contains(document.activeElement).\n * @param node\n * @returns\n */\nexport function isFocusWithin(node: Element | null | undefined): boolean {\n  if (!node) {\n    return false;\n  }\n  // Get the active element within the node's parent shadow root (or the document). Can return null.\n  let root = node.getRootNode();\n  let ownerWindow = getOwnerWindow(node);\n  if (!(root instanceof ownerWindow.Document || root instanceof ownerWindow.ShadowRoot)) {\n    return false;\n  }\n  let activeElement = root.activeElement;\n\n  // Check if the active element is within this node. These nodes are within the same shadow root.\n  return activeElement != null && node.contains(activeElement);\n}\n"],"names":[],"version":3,"file":"DOMFunctions.mjs.map"}