{"version":3,"file":"react-responsive.cjs","names":["React","React","React","React"],"sources":["../src/sanitize.ts","../src/BreakpointsContext.tsx","../src/fromBreakpointToMedia.ts","../src/mediaQueryBuilder.ts","../src/useMediaQuery.ts","../src/useBreakpoint.ts","../src/Only.tsx"],"sourcesContent":["export type Units =\n  | \"em\"\n  | \"ex\"\n  | \"%\"\n  | \"px\"\n  | \"cm\"\n  | \"mm\"\n  | \"in\"\n  | \"pt\"\n  | \"pc\"\n  | \"ch\"\n  | \"rem\"\n  | \"vh\"\n  | \"vw\"\n  | \"vmin\"\n  | \"vmax\";\n\nconst listOfSupportedUnits: Units[] = [\n  \"em\",\n  \"ex\",\n  \"%\",\n  \"px\",\n  \"cm\",\n  \"mm\",\n  \"in\",\n  \"pt\",\n  \"pc\",\n  \"ch\",\n  \"rem\",\n  \"vh\",\n  \"vw\",\n  \"vmin\",\n  \"vmax\",\n];\n\ntype Directions = \"width\" | \"height\";\n\nconst listOfSupportedDirections: Directions[] = [\"width\", \"height\"];\n\nexport type ExposedBreakpoint =\n  | [number, number]\n  | [number, number, Units]\n  | [number, number, { unit?: Units; direction?: Directions }];\n\nexport interface ExposedBreakpoints {\n  [key: string]: ExposedBreakpoint;\n}\n\nexport type Breakpoint = [number, number, Units, Directions];\n\nexport interface Breakpoints {\n  [breakpoint: string]: Breakpoint;\n}\n\nexport function sanitize(inBreakpoints: ExposedBreakpoints): Breakpoints {\n  return Object.keys(inBreakpoints).reduce<Breakpoints>((breakpoints, breakpointName) => {\n    const breakpoint = inBreakpoints[breakpointName];\n\n    if (!Array.isArray(breakpoint) || breakpoint.length <= 1) {\n      return breakpoints;\n    }\n\n    const [supposedMin, supposedMax, options, ...rest] = breakpoint;\n    if (rest.length > 0) {\n      const error = new Error(`The following fields \"${rest}\" have been ignored`);\n      console.error(error);\n    }\n\n    if (typeof supposedMin !== \"number\" || typeof supposedMax !== \"number\") {\n      return breakpoints;\n    }\n\n    let supposedUnit: Units | undefined;\n    let supposedDirection: Directions | undefined;\n    if (typeof options === \"string\") {\n      supposedUnit = options;\n    } else if (typeof options === \"object\") {\n      supposedDirection = options.direction;\n      supposedUnit = options.unit;\n    }\n\n    const min = Math.min(supposedMin, supposedMax);\n    const max = Math.max(supposedMin, supposedMax);\n    const unit = supposedUnit && listOfSupportedUnits.includes(supposedUnit) ? supposedUnit : \"px\";\n    const direction =\n      supposedDirection && listOfSupportedDirections.includes(supposedDirection) ? supposedDirection : \"width\";\n\n    breakpoints[breakpointName] = [min, max, unit, direction];\n    breakpoints[`${breakpointName}Up`] = [min, Infinity, unit, direction];\n    breakpoints[`${breakpointName}Down`] = [0, max, unit, direction];\n\n    return breakpoints;\n  }, {});\n}\n","import * as React from \"react\";\n\nimport { sanitize, ExposedBreakpoints, Breakpoints } from \"./sanitize\";\n\nconst defaultBreakpoints: ExposedBreakpoints = {\n  xs: [0, 575, \"px\"], // Extra small devices (portrait phones)\n  sm: [576, 767, \"px\"], // Small devices (landscape phones)\n  md: [768, 991, \"px\"], // Medium devices (tablets)\n  lg: [992, 1199, \"px\"], // Large devices (desktops)\n  xl: [1200, Infinity, \"px\"], // Extra large devices (large desktops)\n};\n\nexport const BreakpointsContext: React.Context<Breakpoints> = React.createContext<Breakpoints>(\n  sanitize(defaultBreakpoints),\n);\n\ninterface BreakpointsProviderProps {\n  breakpoints?: ExposedBreakpoints;\n  additionalBreakpoints?: ExposedBreakpoints;\n}\n\nexport function BreakpointsProvider({\n  breakpoints = defaultBreakpoints,\n  additionalBreakpoints,\n  children,\n}: React.PropsWithChildren<BreakpointsProviderProps>): React.ReactElement {\n  return (\n    <BreakpointsContext.Provider\n      value={sanitize({\n        ...breakpoints,\n        ...additionalBreakpoints,\n      })}\n    >\n      {children}\n    </BreakpointsContext.Provider>\n  );\n}\n","import { Breakpoint } from \"./sanitize\";\n\nexport function fromBreakpointToMedia(breakpoint: Breakpoint): string {\n  const mediaList: string[] = [];\n  const [minValue, maxValue, unit, direction] = breakpoint;\n  let str;\n\n  // Min value\n  if (minValue !== 0) {\n    str = `${minValue}${unit}`;\n    mediaList.push(`(min-${direction}:${str})`);\n  }\n\n  // Max value\n  if (maxValue !== Infinity) {\n    str = `${maxValue}${unit}`;\n    mediaList.push(`(max-${direction}:${str})`);\n  }\n\n  return \" \" + mediaList.join(\" and \");\n}\n","import { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\nexport function mediaQueryBuilder(breakpoints: Breakpoints) {\n  return function toMediaQuery(on = \"\"): string {\n    if (!on) {\n      return \"\";\n    }\n    const rawBreakpointNames = on.split(\" \");\n    const filteredBreakpoints = rawBreakpointNames.map((breakpointName) => breakpoints[breakpointName]).filter(Boolean);\n    const mediaQuery = filteredBreakpoints\n      .map((breakpoint) => fromBreakpointToMedia(breakpoint))\n      .filter(Boolean)\n      .join(\",\");\n    if (!mediaQuery) {\n      const isUniqBreakpoint = rawBreakpointNames.length === 1;\n      console.error(\n        `\"${rawBreakpointNames.join('\", \"')}\" ${isUniqBreakpoint ? \"is\" : \"are\"}n't ${\n          isUniqBreakpoint ? \"a \" : \"\"\n        }valid breakpoint${isUniqBreakpoint ? \"\" : \"s\"}`,\n      );\n    }\n    return mediaQuery;\n  };\n}\n","import * as React from \"react\";\n\nexport function useMediaQuery(mediaQuery: string): boolean {\n  const mediaQueryList = React.useMemo(() => matchMedia(mediaQuery), [mediaQuery]);\n\n  // Those are important updates, so we don't want to use transitions on them\n  return React.useSyncExternalStore(\n    React.useCallback(\n      (callback) => {\n        // cannot use addEventListener for IE 11 and safari 13-\n        mediaQueryList.addListener(callback);\n        return () => mediaQueryList.removeListener(callback);\n      },\n      [mediaQueryList],\n    ),\n    () => mediaQueryList.matches,\n    () => mediaQueryList.matches,\n  );\n}\n","import * as React from \"react\";\n\nimport { BreakpointsContext } from \"./BreakpointsContext\";\n\nimport { mediaQueryBuilder } from \"./mediaQueryBuilder\";\n\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport function useBreakpoint(on?: string): boolean {\n  const breakpoints = React.useContext(BreakpointsContext);\n  const toMediaQuery = React.useMemo(() => mediaQueryBuilder(breakpoints), [breakpoints]);\n\n  const mediaQuery = React.useMemo(() => toMediaQuery(on), [toMediaQuery, on]);\n\n  return useMediaQuery(mediaQuery || \"-\");\n}\n","import * as React from \"react\";\n\nimport { useBreakpoint } from \"./useBreakpoint\";\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport type OnlyProps<OtherProps = Record<string, never>> = OtherProps & {\n  matchMedia?: string;\n  on?: string;\n  as?: string | React.ComponentType<OtherProps>;\n};\n\nexport function Only<OtherProps = Record<string, never>>({\n  matchMedia,\n  on,\n  as,\n  children,\n  ...props\n}: React.PropsWithChildren<OnlyProps<OtherProps>>): React.ReactElement | null {\n  const matchOn = useBreakpoint(on);\n  const matchQuery = useMediaQuery(matchMedia || \"-\");\n  const isShown = matchOn || matchQuery;\n\n  if (!isShown) {\n    return null;\n  }\n\n  return React.createElement(\n    // @ts-expect-error – this is a complex type\n    as || React.Fragment,\n    as ? (props as OtherProps) : undefined,\n    children,\n  );\n}\n"],"mappings":"+jBAiBA,MAAM,EAAgC,CACpC,KACA,KACA,IACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,MACA,KACA,KACA,OACA,OACD,CAIK,EAA0C,CAAC,QAAS,SAAS,CAiBnE,SAAgB,EAAS,EAAgD,CACvE,OAAO,OAAO,KAAK,EAAc,CAAC,QAAqB,EAAa,IAAmB,CACrF,IAAM,EAAa,EAAc,GAEjC,GAAI,CAAC,MAAM,QAAQ,EAAW,EAAI,EAAW,QAAU,EACrD,OAAO,EAGT,GAAM,CAAC,EAAa,EAAa,EAAS,GAAG,GAAQ,EACrD,GAAI,EAAK,OAAS,EAAG,CACnB,IAAM,EAAY,MAAM,yBAAyB,EAAK,qBAAqB,CAC3E,QAAQ,MAAM,EAAM,CAGtB,GAAI,OAAO,GAAgB,UAAY,OAAO,GAAgB,SAC5D,OAAO,EAGT,IAAI,EACA,EACA,OAAO,GAAY,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