{"version":3,"sources":["jsdelivr-header.js","/npm/@radix-ui/react-dismissable-layer@1.1.16/src/index.ts","/npm/@radix-ui/react-dismissable-layer@1.1.16/src/dismissable-layer.tsx"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,kzBCNA,cAAA,GAAA,SAAA,cAAA,CAAA,OAAA,IAAA,OAAA,iBAAA,IAAA,iBAAA,uBAAA,IAAA,uBAAA,KAAA,IAAA,KAAA,2BAAA,IAAA,6BAAA,OAAA,QAAA,aAAA,eCAA,IAaI,0BAbJ,MAAuB,QAAA,QAAA,UACvB,iBAAqC,QAAA,uBACrC,uBAAuD,QAAA,6BACvD,0BAAgC,QAAA,gCAChC,8BAA+B,QAAA,oCA6NzB,mBAAA,QAAA,qBAxNA,eAAiB,0BACjB,qBAAuB,sCACvB,cAAgB,gCAIhB,wBAAgC,MAAA,cAAc,CAClD,OAAQ,IAAI,IACZ,uCAAwC,IAAI,IAC5C,SAAU,IAAI,IAOd,oBAAqB,IAAI,MA6CrB,iBAAyC,MAAA,WAK7C,OAAA,SAA0B,EAAO,GAC/B,MAAM,4BACJ,GAA8B,EAAA,wBAC9B,GAA0B,EAAA,gBAC1B,EAAA,qBACA,EAAA,eACA,EAAA,kBACA,EAAA,UACA,KACG,GACD,EACE,EAAgB,MAAA,WAAW,0BAC1B,EAAM,GAAiB,MAAA,SAAyC,MACjE,EAAgB,GAAM,eAAiB,YAAY,UAClD,CAAE,GAAe,MAAA,SAAS,CAAC,GAC5B,GAAA,EAAe,0BAAA,iBAAgB,EAAc,GAC7C,EAAS,MAAM,KAAK,EAAQ,SAC3B,GAAgD,IAClD,EAAQ,wCACX,OAAM,GACF,EACJ,EACI,EAAO,QAAQ,IACf,EACA,EAAQ,EAAO,EAAO,QAAQ,IAAQ,EACtC,EAA8B,EAAQ,uCAAuC,KAAO,EACpF,EAAyB,GAAS,EAClC,EAAwC,MAAA,QAAO,GAE/C,EAAqB,sBACxB,IACC,IAAuB,GACvB,IAAoB,GAC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AAA,sBAAA,yBAgMA,OAAA,gBAAA,mBA0BA,OAAA,eAAA,kBAKA,OAAA,6BAAA,gCAiBT,IAAM,KAAO,iBACP,OAAS","file":"/npm/@radix-ui/react-dismissable-layer@1.1.16/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.48.0.\n * Original file: /npm/@radix-ui/react-dismissable-layer@1.1.16/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use client';\nexport {\n  DismissableLayer,\n  DismissableLayerBranch,\n  //\n  Root,\n  Branch,\n  /** @internal */\n  useDismissableLayerSurface,\n} from './dismissable-layer';\nexport type { DismissableLayerProps } from './dismissable-layer';\n","import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { Primitive, dispatchDiscreteCustomEvent } from '@radix-ui/react-primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { useCallbackRef } from '@radix-ui/react-use-callback-ref';\n\n/* -------------------------------------------------------------------------------------------------\n * DismissableLayer\n * -----------------------------------------------------------------------------------------------*/\nconst CONTEXT_UPDATE = 'dismissableLayer.update';\nconst POINTER_DOWN_OUTSIDE = 'dismissableLayer.pointerDownOutside';\nconst FOCUS_OUTSIDE = 'dismissableLayer.focusOutside';\n\nlet originalBodyPointerEvents: string;\n\nconst DismissableLayerContext = React.createContext({\n  layers: new Set<DismissableLayerElement>(),\n  layersWithOutsidePointerEventsDisabled: new Set<DismissableLayerElement>(),\n  branches: new Set<DismissableLayerBranchElement>(),\n\n  // Outside elements that belong to a layer's own dismiss affordance (eg, a\n  // dialog overlay). Pressing them should dismiss the layer regardless of\n  // whether or not they stop propagation.\n  //\n  // See https://github.com/radix-ui/primitives/issues/3346\n  dismissableSurfaces: new Set<DismissableLayerBranchElement>(),\n});\n\ntype DismissableLayerElement = React.ComponentRef<typeof Primitive.div>;\ntype PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;\ninterface DismissableLayerProps extends PrimitiveDivProps {\n  /**\n   * When `true`, hover/focus/click interactions will be disabled on elements outside\n   * the `DismissableLayer`. Users will need to click twice on outside elements to\n   * interact with them: once to close the `DismissableLayer`, and again to trigger the element.\n   */\n  disableOutsidePointerEvents?: boolean;\n  /**\n   * When `true`, a `'pointerdown'` event outside of the layered element will\n   * wait for the interaction's click event before dispatching, allowing\n   * third-party code to stop propagation of later events and cancel dismissal.\n   */\n  deferPointerDownOutside?: boolean;\n  /**\n   * Event handler called when the escape key is down.\n   * Can be prevented.\n   */\n  onEscapeKeyDown?: (event: KeyboardEvent) => void;\n  /**\n   * Event handler called when the a `pointerdown` event happens outside of the `DismissableLayer`.\n   * Can be prevented.\n   */\n  onPointerDownOutside?: (event: PointerDownOutsideEvent) => void;\n  /**\n   * Event handler called when the focus moves outside of the `DismissableLayer`.\n   * Can be prevented.\n   */\n  onFocusOutside?: (event: FocusOutsideEvent) => void;\n  /**\n   * Event handler called when an interaction happens outside the `DismissableLayer`.\n   * Specifically, when a `pointerdown` event happens outside or focus moves outside of it.\n   * Can be prevented.\n   */\n  onInteractOutside?: (event: PointerDownOutsideEvent | FocusOutsideEvent) => void;\n  /**\n   * Handler called when the `DismissableLayer` should be dismissed\n   */\n  onDismiss?: () => void;\n}\n\nconst DismissableLayer = /* @__PURE__ */ React.forwardRef<\n  DismissableLayerElement,\n  DismissableLayerProps\n>(\n  // blank line to reduce diff noise\n  function DismissableLayer(props, forwardedRef) {\n    const {\n      disableOutsidePointerEvents = false,\n      deferPointerDownOutside = false,\n      onEscapeKeyDown,\n      onPointerDownOutside,\n      onFocusOutside,\n      onInteractOutside,\n      onDismiss,\n      ...layerProps\n    } = props;\n    const context = React.useContext(DismissableLayerContext);\n    const [node, setNode] = React.useState<DismissableLayerElement | null>(null);\n    const ownerDocument = node?.ownerDocument ?? globalThis?.document;\n    const [, force] = React.useState({});\n    const composedRefs = useComposedRefs(forwardedRef, setNode);\n    const layers = Array.from(context.layers);\n    const [highestLayerWithOutsidePointerEventsDisabled] = [\n      ...context.layersWithOutsidePointerEventsDisabled,\n    ].slice(-1);\n    const highestLayerWithOutsidePointerEventsDisabledIndex =\n      highestLayerWithOutsidePointerEventsDisabled\n        ? layers.indexOf(highestLayerWithOutsidePointerEventsDisabled)\n        : -1;\n    const index = node ? layers.indexOf(node) : -1;\n    const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0;\n    const isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex;\n    const isDeferredPointerDownOutsideRef = React.useRef(false);\n\n    const pointerDownOutside = usePointerDownOutside(\n      (event) => {\n        onPointerDownOutside?.(event);\n        onInteractOutside?.(event);\n        if (!event.defaultPrevented) onDismiss?.();\n      },\n      {\n        ownerDocument,\n        deferPointerDownOutside,\n        isDeferredPointerDownOutsideRef,\n        dismissableSurfaces: context.dismissableSurfaces,\n        shouldHandlePointerDownOutside: React.useCallback(\n          (target: EventTarget | null) => {\n            if (!(target instanceof Node)) {\n              return false;\n            }\n\n            const isPointerDownOnBranch = [...context.branches].some((branch) =>\n              branch.contains(target),\n            );\n            return isPointerEventsEnabled && !isPointerDownOnBranch;\n          },\n          [context.branches, isPointerEventsEnabled],\n        ),\n      },\n    );\n\n    const focusOutside = useFocusOutside((event) => {\n      if (deferPointerDownOutside && isDeferredPointerDownOutsideRef.current) {\n        return;\n      }\n\n      const target = event.target as HTMLElement;\n      const isFocusInBranch = [...context.branches].some((branch) => branch.contains(target));\n      if (isFocusInBranch) return;\n      onFocusOutside?.(event);\n      onInteractOutside?.(event);\n      if (!event.defaultPrevented) onDismiss?.();\n    }, ownerDocument);\n\n    const isHighestLayer = node ? index === layers.length - 1 : false;\n\n    // Stabilize via `useCallbackRef` rather than `useEffectEvent`: React's\n    // native `useEffectEvent` returns a stale closure inside `forwardRef`\n    // components on React 19.2.x, which caused escape handlers to observe\n    // mount-time props/state instead of the latest values.\n    //\n    // We should revert this to use useEffectEvent when the fix lands in React.\n    //\n    // - https://github.com/radix-ui/primitives/issues/4014\n    // - https://github.com/react/react/pull/34831\n    const handleKeyDown = useCallbackRef((event: KeyboardEvent) => {\n      if (event.key !== 'Escape') {\n        return;\n      }\n\n      onEscapeKeyDown?.(event);\n      if (!event.defaultPrevented && onDismiss) {\n        event.preventDefault();\n        onDismiss();\n      }\n    });\n\n    React.useEffect(() => {\n      if (!isHighestLayer) {\n        return;\n      }\n\n      ownerDocument.addEventListener('keydown', handleKeyDown, { capture: true });\n      return () => ownerDocument.removeEventListener('keydown', handleKeyDown, { capture: true });\n    }, [ownerDocument, isHighestLayer, handleKeyDown]);\n\n    React.useEffect(() => {\n      if (!node) return;\n      if (disableOutsidePointerEvents) {\n        if (context.layersWithOutsidePointerEventsDisabled.size === 0) {\n          originalBodyPointerEvents = ownerDocument.body.style.pointerEvents;\n          ownerDocument.body.style.pointerEvents = 'none';\n        }\n        context.layersWithOutsidePointerEventsDisabled.add(node);\n      }\n      context.layers.add(node);\n      dispatchUpdate();\n      return () => {\n        // We must remove this layer from the disabled set whenever\n        // `disableOutsidePointerEvents` becomes `false` (eg, when a modal\n        // closes but stays mounted during an exit animation) and not only on\n        // unmount. Otherwise the `body` `pointer-events` could be left as\n        // `none` when multiple layers overlap.\n        // See: https://github.com/radix-ui/primitives/issues/3645\n        if (disableOutsidePointerEvents) {\n          context.layersWithOutsidePointerEventsDisabled.delete(node);\n          if (context.layersWithOutsidePointerEventsDisabled.size === 0) {\n            ownerDocument.body.style.pointerEvents = originalBodyPointerEvents;\n          }\n        }\n      };\n    }, [node, ownerDocument, disableOutsidePointerEvents, context]);\n\n    /**\n     * We purposefully prevent combining this effect with the `disableOutsidePointerEvents` effect\n     * because a change to `disableOutsidePointerEvents` would remove this layer from the stack\n     * and add it to the end again so the layering order wouldn't be _creation order_.\n     * We only want them to be removed from context stacks when unmounted.\n     */\n    React.useEffect(() => {\n      return () => {\n        if (!node) return;\n        context.layers.delete(node);\n        context.layersWithOutsidePointerEventsDisabled.delete(node);\n        dispatchUpdate();\n      };\n    }, [node, context]);\n\n    React.useEffect(() => {\n      const handleUpdate = () => force({});\n      document.addEventListener(CONTEXT_UPDATE, handleUpdate);\n      return () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate);\n    }, []);\n\n    return (\n      <Primitive.div\n        {...layerProps}\n        ref={composedRefs}\n        style={{\n          pointerEvents: isBodyPointerEventsDisabled\n            ? isPointerEventsEnabled\n              ? 'auto'\n              : 'none'\n            : undefined,\n          ...props.style,\n        }}\n        onFocusCapture={composeEventHandlers(props.onFocusCapture, focusOutside.onFocusCapture)}\n        onBlurCapture={composeEventHandlers(props.onBlurCapture, focusOutside.onBlurCapture)}\n        onPointerDownCapture={composeEventHandlers(\n          props.onPointerDownCapture,\n          pointerDownOutside.onPointerDownCapture,\n        )}\n      />\n    );\n  },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * DismissableLayerBranch\n * -----------------------------------------------------------------------------------------------*/\n\ntype DismissableLayerBranchElement = React.ComponentRef<typeof Primitive.div>;\ninterface DismissableLayerBranchProps extends PrimitiveDivProps {}\n\nconst DismissableLayerBranch = /* @__PURE__ */ React.forwardRef<\n  DismissableLayerBranchElement,\n  DismissableLayerBranchProps\n>(function DismissableLayerBranch(props, forwardedRef) {\n  const context = React.useContext(DismissableLayerContext);\n  const ref = React.useRef<DismissableLayerBranchElement>(null);\n  const composedRefs = useComposedRefs(forwardedRef, ref);\n\n  React.useEffect(() => {\n    const node = ref.current;\n    if (node) {\n      context.branches.add(node);\n      return () => {\n        context.branches.delete(node);\n      };\n    }\n  }, [context.branches]);\n\n  return <Primitive.div {...props} ref={composedRefs} />;\n});\n\n/* -----------------------------------------------------------------------------------------------*/\n\n/**\n * Registers a node as a \"dismiss surface\" for the enclosing DismissableLayer\n */\nfunction useDismissableLayerSurface(): React.RefCallback<DismissableLayerBranchElement> {\n  const context = React.useContext(DismissableLayerContext);\n  const [node, setNode] = React.useState<DismissableLayerBranchElement | null>(null);\n\n  React.useEffect(() => {\n    if (!node) {\n      return;\n    }\n    context.dismissableSurfaces.add(node);\n    return () => {\n      context.dismissableSurfaces.delete(node);\n    };\n  }, [node, context.dismissableSurfaces]);\n\n  return setNode;\n}\n\ntype PointerDownOutsideEvent = CustomEvent<{ originalEvent: PointerEvent }>;\ntype FocusOutsideEvent = CustomEvent<{ originalEvent: FocusEvent }>;\n\nconst IS_TRUE = () => true;\n\n/**\n * Listens for `pointerdown` outside a react subtree. We detect the start of the interaction on\n * `pointerdown`, then wait for `click` so external code can intercept later mouse events.\n * Returns props to pass to the node we want to check for outside events.\n */\nfunction usePointerDownOutside(\n  onPointerDownOutside: ((event: PointerDownOutsideEvent) => void) | undefined,\n  args: {\n    ownerDocument: Document | undefined;\n    deferPointerDownOutside: boolean;\n    isDeferredPointerDownOutsideRef: React.RefObject<boolean>;\n    dismissableSurfaces: Set<DismissableLayerBranchElement>;\n    shouldHandlePointerDownOutside?: (target: EventTarget | null) => boolean;\n  },\n) {\n  const {\n    ownerDocument = globalThis?.document,\n    deferPointerDownOutside = false,\n    isDeferredPointerDownOutsideRef,\n    dismissableSurfaces,\n    shouldHandlePointerDownOutside = IS_TRUE,\n  } = args;\n  const handlePointerDownOutside = useCallbackRef(onPointerDownOutside) as EventListener;\n  const isPointerInsideReactTreeRef = React.useRef(false);\n  const isPointerDownOutsideRef = React.useRef(false);\n  const interceptedOutsideInteractionEventsRef = React.useRef<Map<string, boolean>>(new Map());\n  const handleClickRef = React.useRef(() => {});\n\n  React.useEffect(() => {\n    function resetOutsideInteraction() {\n      isPointerDownOutsideRef.current = false;\n      isDeferredPointerDownOutsideRef.current = false;\n      interceptedOutsideInteractionEventsRef.current.clear();\n    }\n\n    function isOutsideInteractionIntercepted() {\n      return Array.from(interceptedOutsideInteractionEventsRef.current.values()).some(Boolean);\n    }\n\n    function handleInteractionCapture(event: Event) {\n      if (!isPointerDownOutsideRef.current) {\n        return;\n      }\n\n      const target = event.target;\n      const isDismissableSurface =\n        target instanceof Node &&\n        [...dismissableSurfaces].some((surface) => surface.contains(target as Node));\n\n      if (!isDismissableSurface) {\n        interceptedOutsideInteractionEventsRef.current.set(event.type, true);\n      }\n\n      if (event.type === 'click') {\n        window.setTimeout(() => {\n          if (isPointerDownOutsideRef.current) {\n            handleClickRef.current();\n          }\n        }, 0);\n      }\n    }\n\n    function handleInteractionBubble(event: Event) {\n      if (isPointerDownOutsideRef.current) {\n        interceptedOutsideInteractionEventsRef.current.set(event.type, false);\n      }\n    }\n\n    const handlePointerDown = (event: PointerEvent) => {\n      if (event.target && !isPointerInsideReactTreeRef.current) {\n        if (!shouldHandlePointerDownOutside(event.target)) {\n          ownerDocument.removeEventListener('click', handleClickRef.current);\n          resetOutsideInteraction();\n          isPointerInsideReactTreeRef.current = false;\n          return;\n        }\n\n        const eventDetail = { originalEvent: event };\n        isPointerDownOutsideRef.current = true;\n        isDeferredPointerDownOutsideRef.current = deferPointerDownOutside && event.button === 0;\n        interceptedOutsideInteractionEventsRef.current.clear();\n\n        function handleAndDispatchPointerDownOutsideEvent() {\n          ownerDocument.removeEventListener('click', handleClickRef.current);\n          const wasOutsideInteractionIntercepted = isOutsideInteractionIntercepted();\n          resetOutsideInteraction();\n\n          if (!wasOutsideInteractionIntercepted) {\n            handleAndDispatchCustomEvent(\n              POINTER_DOWN_OUTSIDE,\n              handlePointerDownOutside,\n              eventDetail,\n              { discrete: true },\n            );\n          }\n        }\n\n        /**\n         * When deferring, we need to wait for a click event because:\n         *\n         * 1. On touch devices, browsers implement a ~350ms delay between the\n         *    time the user stops touching the display and when the browser\n         *    executes events. We need to ensure we don't reactivate\n         *    pointer-events within this timeframe otherwise the browser may\n         *    execute events that should have been prevented.\n         *\n         * 2. Browser extensions and other third-party code may call\n         *    `stopPropagation` on later mouse events like `mousedown`,\n         *    `mouseup`, or `click`. Waiting lets those intercepted events\n         *    cancel the outside interaction before we dismiss the layer. See\n         *    https://github.com/radix-ui/primitives/issues/2055\n         *\n         * Additionally, this also lets us deal automatically with cancellations\n         * when a click event isn't raised because the page was considered\n         * scrolled/drag-scrolled, long-pressed, etc.\n         *\n         * This is why we also continuously remove the previous listener,\n         * because we cannot be certain that it was raised, and therefore\n         * cleaned-up.\n         *\n         * For non-primary buttons, we dispatch the event immediately because we\n         * cannot be certain that the event was canceled.\n         */\n        if (!deferPointerDownOutside || event.button !== 0) {\n          handleAndDispatchPointerDownOutsideEvent();\n        } else {\n          ownerDocument.removeEventListener('click', handleClickRef.current);\n          handleClickRef.current = handleAndDispatchPointerDownOutsideEvent;\n          ownerDocument.addEventListener('click', handleClickRef.current, { once: true });\n        }\n      } else {\n        // We need to remove the event listener in case the outside click has been canceled.\n        // See: https://github.com/radix-ui/primitives/issues/2171\n        ownerDocument.removeEventListener('click', handleClickRef.current);\n        resetOutsideInteraction();\n      }\n      isPointerInsideReactTreeRef.current = false;\n    };\n\n    const outsideInteractionEvents = [\n      'pointerup',\n      'mousedown',\n      'mouseup',\n      'touchstart',\n      'touchend',\n      'click',\n    ];\n\n    for (const eventName of outsideInteractionEvents) {\n      ownerDocument.addEventListener(eventName, handleInteractionCapture, true);\n      ownerDocument.addEventListener(eventName, handleInteractionBubble);\n    }\n\n    /**\n     * if this hook executes in a component that mounts via a `pointerdown` event, the event\n     * would bubble up to the document and trigger a `pointerDownOutside` event. We avoid\n     * this by delaying the event listener registration on the document.\n     * This is not React specific, but rather how the DOM works, ie:\n     * ```\n     * button.addEventListener('pointerdown', () => {\n     *   console.log('I will log');\n     *   document.addEventListener('pointerdown', () => {\n     *     console.log('I will also log');\n     *   })\n     * });\n     */\n    const timerId = window.setTimeout(() => {\n      ownerDocument.addEventListener('pointerdown', handlePointerDown);\n    }, 0);\n    return () => {\n      window.clearTimeout(timerId);\n      ownerDocument.removeEventListener('pointerdown', handlePointerDown);\n      ownerDocument.removeEventListener('click', handleClickRef.current);\n      for (const eventName of outsideInteractionEvents) {\n        ownerDocument.removeEventListener(eventName, handleInteractionCapture, true);\n        ownerDocument.removeEventListener(eventName, handleInteractionBubble);\n      }\n    };\n  }, [\n    ownerDocument,\n    handlePointerDownOutside,\n    deferPointerDownOutside,\n    isDeferredPointerDownOutsideRef,\n    dismissableSurfaces,\n    shouldHandlePointerDownOutside,\n  ]);\n\n  return {\n    // ensures we check React component tree (not just DOM tree)\n    onPointerDownCapture: () => (isPointerInsideReactTreeRef.current = true),\n  };\n}\n\n/**\n * Listens for when focus happens outside a react subtree.\n * Returns props to pass to the root (node) of the subtree we want to check.\n */\nfunction useFocusOutside(\n  onFocusOutside?: (event: FocusOutsideEvent) => void,\n  ownerDocument: Document = globalThis?.document,\n) {\n  const handleFocusOutside = useCallbackRef(onFocusOutside) as EventListener;\n  const isFocusInsideReactTreeRef = React.useRef(false);\n\n  React.useEffect(() => {\n    const handleFocus = (event: FocusEvent) => {\n      if (event.target && !isFocusInsideReactTreeRef.current) {\n        const eventDetail = { originalEvent: event };\n        handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, eventDetail, {\n          discrete: false,\n        });\n      }\n    };\n    ownerDocument.addEventListener('focusin', handleFocus);\n    return () => ownerDocument.removeEventListener('focusin', handleFocus);\n  }, [ownerDocument, handleFocusOutside]);\n\n  return {\n    onFocusCapture: () => (isFocusInsideReactTreeRef.current = true),\n    onBlurCapture: () => (isFocusInsideReactTreeRef.current = false),\n  };\n}\n\nfunction dispatchUpdate() {\n  const event = new CustomEvent(CONTEXT_UPDATE);\n  document.dispatchEvent(event);\n}\n\nfunction handleAndDispatchCustomEvent<E extends CustomEvent, OriginalEvent extends Event>(\n  name: string,\n  handler: ((event: E) => void) | undefined,\n  detail: { originalEvent: OriginalEvent } & (E extends CustomEvent<infer D> ? D : never),\n  { discrete }: { discrete: boolean },\n) {\n  const target = detail.originalEvent.target;\n  const event = new CustomEvent(name, { bubbles: false, cancelable: true, detail });\n  if (handler) target.addEventListener(name, handler as EventListener, { once: true });\n\n  if (discrete) {\n    dispatchDiscreteCustomEvent(target, event);\n  } else {\n    target.dispatchEvent(event);\n  }\n}\n\nconst Root = DismissableLayer;\nconst Branch = DismissableLayerBranch;\n\nexport {\n  DismissableLayer,\n  DismissableLayerBranch,\n  useDismissableLayerSurface,\n  //\n  Root,\n  Branch,\n};\nexport type { DismissableLayerProps };\n"]}