{"version":3,"file":"TourRoot.mjs","names":[],"sources":["../../../../src/components/Tour/TourRoot/TourRoot.tsx"],"sourcesContent":["import { useCallback, useId, useState } from 'react';\nimport {\n  Box,\n  BoxProps,\n  createVarsResolver,\n  ElementProps,\n  factory,\n  Factory,\n  getShadow,\n  getThemeColor,\n  MantineColor,\n  StylesApiProps,\n  useProps,\n  useStyles,\n} from '../../../core';\nimport { OptionalPortal, type PortalProps } from '../../Portal';\nimport type { TransitionOverride } from '../../Transition';\nimport type { TourStylesNames, TourCssVariables } from '../Tour';\nimport { defaultLabels, TourLabels, TourProvider } from '../Tour.context';\nimport { useTourState } from '../use-tour-state';\nimport classes from '../Tour.module.css';\n\nexport interface TourRootProps\n  extends BoxProps, StylesApiProps<TourRootFactory>, ElementProps<'div'> {\n  /** Whether the tour is active @default false */\n  active?: boolean;\n\n  /** Total number of steps, used by `Tour.Navigation` and keyboard navigation to detect the last step */\n  stepsCount: number;\n\n  /** Called when the tour is closed */\n  onClose?: () => void;\n\n  /** Controlled current step index */\n  step?: number;\n\n  /** Uncontrolled default step index @default 0 */\n  defaultStep?: number;\n\n  /** Called when step changes */\n  onStepChange?: (step: number) => void;\n\n  /** Called when a step opens */\n  onStepOpen?: (step: number) => void;\n\n  /** Called when a step closes */\n  onStepClose?: (step: number) => void;\n\n  /** Whether `Tour.Overlay` is rendered @default true */\n  withOverlay?: boolean;\n\n  /** Whether pointer events pass through the spotlight cutout to the target element, the rest of the overlay keeps blocking clicks @default false */\n  withOverlayInteraction?: boolean;\n\n  /** Whether `Tour.CloseButton` is rendered @default true */\n  withCloseButton?: boolean;\n\n  /** Whether arrow keys navigate between steps @default true */\n  withKeyboardNavigation?: boolean;\n\n  /** Padding around the spotlight cutout in px @default 8 */\n  spotlightPadding?: number;\n\n  /** Border radius of the spotlight cutout in px @default 4 */\n  spotlightRadius?: number;\n\n  /** Whether pressing Escape closes the tour @default true */\n  closeOnEscape?: boolean;\n\n  /** Whether clicking the overlay closes the tour, with `withOverlayInteraction` only clicks outside the spotlight cutout close it @default false */\n  closeOnOverlayClick?: boolean;\n\n  /** Labels for tour UI elements */\n  labels?: Partial<TourLabels>;\n\n  /** Whether to render inside a portal @default true */\n  withinPortal?: boolean;\n\n  /** Props passed to the Portal component */\n  portalProps?: Omit<PortalProps, 'children'>;\n\n  /** z-index of the tour @default 10000 */\n  zIndex?: string | number;\n\n  /** Default transition props of `Tour.Tooltip` @default { duration: 200, transition: 'fade' } */\n  transitionProps?: TransitionOverride;\n\n  /** Tour step overlay color @default \"rgba(0, 0, 0, 0.5)\" */\n  overlayColor?: string;\n\n  /** Key of `theme.colors` or any valid CSS color, controls `Tour.Beacon` color and `Tour.Navigation` next button color @default theme.primaryColor */\n  color?: MantineColor;\n\n  /** Key of `theme.shadows` or any valid CSS box-shadow value, controls the tooltip shadow @default 'md' */\n  tooltipShadow?: string;\n\n  /** Tour content: `Tour.Overlay`, `Tour.Tooltip`, `Tour.Beacon` and other compound components */\n  children?: React.ReactNode;\n}\n\nexport type TourRootFactory = Factory<{\n  props: TourRootProps;\n  ref: HTMLDivElement;\n  stylesNames: TourStylesNames;\n  vars: TourCssVariables;\n}>;\n\nconst defaultProps = {\n  active: false,\n  withOverlay: true,\n  withOverlayInteraction: false,\n  withCloseButton: true,\n  withKeyboardNavigation: true,\n  spotlightPadding: 8,\n  closeOnEscape: true,\n  closeOnOverlayClick: false,\n  withinPortal: true,\n  zIndex: 10000,\n  transitionProps: { duration: 200, transition: 'fade' },\n  overlayColor: 'rgba(0, 0, 0, 0.5)',\n} satisfies Partial<TourRootProps>;\n\nconst varsResolver = createVarsResolver<TourRootFactory>(\n  (theme, { zIndex, overlayColor, tooltipShadow, color }) => ({\n    root: {\n      '--tour-color': color ? getThemeColor(color, theme) : undefined,\n      '--tour-z-index': zIndex?.toString(),\n      '--tour-overlay-color': overlayColor,\n      '--tour-tooltip-radius': undefined,\n      '--tour-tooltip-shadow': getShadow(tooltipShadow),\n      '--tour-beacon-size': undefined,\n      '--tour-beacon-color': undefined,\n    },\n  })\n);\n\nexport const TourRoot = factory<TourRootFactory>((_props) => {\n  const props = useProps('TourRoot', defaultProps, _props);\n  const {\n    classNames,\n    className,\n    style,\n    styles,\n    unstyled,\n    vars,\n    active,\n    stepsCount,\n    onClose,\n    step: stepProp,\n    defaultStep,\n    onStepChange,\n    onStepOpen,\n    onStepClose,\n    withOverlay,\n    withOverlayInteraction,\n    withCloseButton,\n    withKeyboardNavigation,\n    spotlightPadding,\n    spotlightRadius,\n    closeOnEscape,\n    closeOnOverlayClick,\n    labels: labelsProp,\n    withinPortal,\n    portalProps,\n    zIndex,\n    transitionProps,\n    overlayColor,\n    tooltipShadow,\n    color,\n    children,\n    attributes,\n    ...others\n  } = props;\n\n  const labels: TourLabels = { ...defaultLabels, ...labelsProp };\n  const id = useId();\n  const [registeredTitleId, registerTitle] = useState<string | null>(null);\n  const [registeredBodyId, registerBody] = useState<string | null>(null);\n  const titleId = registeredTitleId ?? `${id}-title`;\n  const bodyId = registeredBodyId ?? `${id}-body`;\n  const titleMounted = registeredTitleId !== null;\n  const bodyMounted = registeredBodyId !== null;\n\n  const { currentStep, setStep, close, targetRef } = useTourState({\n    active,\n    onClose,\n    step: stepProp,\n    defaultStep,\n    onStepChange,\n    onStepOpen: (index) => onStepOpen?.(index),\n    onStepClose: (index) => onStepClose?.(index),\n    mode: 'guided',\n    stepsCount,\n    closeOnEscape,\n    withKeyboardNavigation,\n  });\n\n  const setTargetElement = useCallback(\n    (element: HTMLElement | null) => {\n      targetRef.current = element;\n    },\n    [targetRef]\n  );\n\n  const getStyles = useStyles<TourRootFactory>({\n    name: 'Tour',\n    classes,\n    props,\n    className,\n    style,\n    classNames,\n    styles,\n    unstyled,\n    attributes,\n    vars,\n    varsResolver,\n  });\n\n  if (!active) {\n    return null;\n  }\n\n  return (\n    <TourProvider\n      value={{\n        getStyles,\n        step: currentStep,\n        setStep,\n        stepsCount,\n        close,\n        withOverlay: withOverlay!,\n        withOverlayInteraction: withOverlayInteraction!,\n        withCloseButton: withCloseButton!,\n        spotlightPadding: spotlightPadding!,\n        spotlightRadius: spotlightRadius ?? 4,\n        closeOnOverlayClick: closeOnOverlayClick!,\n        transitionProps,\n        color,\n        labels,\n        titleId,\n        bodyId,\n        titleMounted,\n        bodyMounted,\n        registerTitle,\n        registerBody,\n        setTargetElement,\n      }}\n    >\n      <OptionalPortal {...portalProps} withinPortal={withinPortal}>\n        <Box {...getStyles('root')} {...others}>\n          {children}\n        </Box>\n      </OptionalPortal>\n    </TourProvider>\n  );\n});\n\nTourRoot.displayName = '@mantine/core/TourRoot';\n\nexport namespace TourRoot {\n  export type Props = TourRootProps;\n}\n"],"mappings":";;;;;;;;;;;;;;;AA2GA,MAAM,eAAe;CACnB,QAAQ;CACR,aAAa;CACb,wBAAwB;CACxB,iBAAiB;CACjB,wBAAwB;CACxB,kBAAkB;CAClB,eAAe;CACf,qBAAqB;CACrB,cAAc;CACd,QAAQ;CACR,iBAAiB;EAAE,UAAU;EAAK,YAAY;CAAO;CACrD,cAAc;AAChB;AAEA,MAAM,eAAe,oBAClB,OAAO,EAAE,QAAQ,cAAc,eAAe,aAAa,EAC1D,MAAM;CACJ,gBAAgB,QAAQ,cAAc,OAAO,KAAK,IAAI,KAAA;CACtD,kBAAkB,QAAQ,SAAS;CACnC,wBAAwB;CACxB,yBAAyB,KAAA;CACzB,yBAAyB,UAAU,aAAa;CAChD,sBAAsB,KAAA;CACtB,uBAAuB,KAAA;AACzB,EACF,EACF;AAEA,MAAa,WAAW,SAA0B,WAAW;CAC3D,MAAM,QAAQ,SAAS,YAAY,cAAc,MAAM;CACvD,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,QACA,YACA,SACA,MAAM,UACN,aACA,cACA,YACA,aACA,aACA,wBACA,iBACA,wBACA,kBACA,iBACA,eACA,qBACA,QAAQ,YACR,cACA,aACA,QACA,iBACA,cACA,eACA,OACA,UACA,YACA,GAAG,WACD;CAEJ,MAAM,SAAqB;EAAE,GAAG;EAAe,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