{
  "version": 3,
  "sources": ["../../src/tooltip/index.tsx"],
  "sourcesContent": ["import * as Ariakit from '@ariakit/react';\nimport clsx from 'clsx';\nimport { useInstanceId } from '@wordpress/compose';\nimport { Children, useContext, forwardRef, cloneElement } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\nimport Shortcut from '../shortcut';\nimport { positionToPlacement } from '../popover/utils';\nimport { TooltipInternalContext } from './context';\n\n/**\n * Time over anchor to wait before showing tooltip\n */\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nexport const TOOLTIP_DELAY = 700;\nconst CONTEXT_VALUE = {\n  isNestedInTooltip: true\n};\nfunction UnforwardedTooltip(props, ref) {\n  const {\n    children,\n    className,\n    delay = TOOLTIP_DELAY,\n    hideOnClick = true,\n    placement,\n    position,\n    shortcut,\n    text,\n    ...restProps\n  } = props;\n  const {\n    isNestedInTooltip\n  } = useContext(TooltipInternalContext);\n  const baseId = useInstanceId(Tooltip, 'tooltip');\n  const describedById = text || shortcut ? baseId : undefined;\n  const isOnlyChild = Children.count(children) === 1;\n  // console error if more than one child element is added\n  if (!isOnlyChild) {\n    if ('development' === process.env.NODE_ENV) {\n      // eslint-disable-next-line no-console\n      console.error('wp-components.Tooltip should be called with only a single child element.');\n    }\n  }\n\n  // Compute tooltip's placement:\n  // - give priority to `placement` prop, if defined\n  // - otherwise, compute it from the legacy `position` prop (if defined)\n  // - finally, fallback to the default placement: 'top'\n  let computedPlacement;\n  if (placement !== undefined) {\n    computedPlacement = placement;\n  } else if (position !== undefined) {\n    computedPlacement = positionToPlacement(position);\n    deprecated('`position` prop in wp.components.tooltip', {\n      since: '6.4',\n      alternative: '`placement` prop'\n    });\n  }\n  computedPlacement = computedPlacement || 'top';\n  const tooltipStore = Ariakit.useTooltipStore({\n    placement: computedPlacement,\n    showTimeout: delay\n  });\n  const mounted = Ariakit.useStoreState(tooltipStore, 'mounted');\n  if (isNestedInTooltip) {\n    return isOnlyChild ? /*#__PURE__*/_jsx(Ariakit.Role, {\n      ...restProps,\n      render: children\n    }) : children;\n  }\n\n  // TODO: this is a temporary workaround to minimize the effects of the\n  // Ariakit upgrade. Ariakit doesn't pass the `aria-describedby` prop to\n  // the tooltip anchor anymore since 0.4.0, so we need to add it manually.\n  // The `aria-describedby` attribute is added only if the anchor doesn't have\n  // one already, and if the tooltip text is not the same as the anchor's\n  // `aria-label`\n  // See: https://github.com/WordPress/gutenberg/pull/64066\n  // See: https://github.com/WordPress/gutenberg/pull/65989\n  function addDescribedById(element) {\n    return describedById && mounted && element.props['aria-describedby'] === undefined && element.props['aria-label'] !== text ? cloneElement(element, {\n      'aria-describedby': describedById\n    }) : element;\n  }\n  return /*#__PURE__*/_jsxs(TooltipInternalContext.Provider, {\n    value: CONTEXT_VALUE,\n    children: [/*#__PURE__*/_jsx(Ariakit.TooltipAnchor, {\n      onClick: hideOnClick ? tooltipStore.hide : undefined,\n      store: tooltipStore,\n      render: isOnlyChild ? addDescribedById(children) : undefined,\n      ref: ref,\n      children: isOnlyChild ? undefined : children\n    }), isOnlyChild && (text || shortcut) && /*#__PURE__*/_jsxs(Ariakit.Tooltip, {\n      ...restProps,\n      className: clsx('components-tooltip', className),\n      unmountOnHide: true,\n      gutter: 4,\n      id: describedById,\n      overflowPadding: 0.5,\n      store: tooltipStore,\n      children: [text, shortcut && /*#__PURE__*/_jsx(Shortcut, {\n        className: text ? 'components-tooltip__shortcut' : '',\n        shortcut: shortcut\n      })]\n    })]\n  });\n}\nexport const Tooltip = forwardRef(UnforwardedTooltip);\nexport default Tooltip;"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,iBAAAA;AAAA,EAAA;AAAA;AAAA;AAAA,cAAyB;AACzB,kBAAiB;AACjB,qBAA8B;AAC9B,qBAA+D;AAC/D,wBAAuB;AACvB,sBAAqB;AACrB,mBAAoC;AACpC,qBAAuC;AAKvC,yBAA2C;AACpC,IAAM,gBAAgB;AAC7B,IAAM,g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