{"version":3,"file":"weatherIcon.mjs","names":[],"sources":["../../../../package/common/weatherIcon/weatherIcon.tsx"],"sourcesContent":["import { useId, type ReactElement } from 'react';\nimport cx from 'classnames';\n\nimport { useComponentDefaults, useLabels } from '../configProvider';\nimport { useMediaQuery } from '../hooks/useMediaQuery';\nimport { WeatherType, type WeatherIconLabels, type WeatherIconProps } from './weatherIcon.types';\nimport { CLOUD_PATH, Cloud, Fog, Hail, Lightning, Moon, Rain, RainIntensity, Snow, Sun } from './parts';\nimport styles from './weatherIcon.module.pcss';\n\nconst DEFAULT_LABELS: Required<WeatherIconLabels> = {\n  [WeatherType.Sunny]: 'Sunny',\n  [WeatherType.ClearNight]: 'Clear night',\n  [WeatherType.Cloudy]: 'Cloudy',\n  [WeatherType.PartlyCloudy]: 'Partly cloudy',\n  [WeatherType.PartlyCloudyNight]: 'Partly cloudy night',\n  [WeatherType.RainyLight]: 'Light rain',\n  [WeatherType.Rainy]: 'Rain',\n  [WeatherType.RainyHeavy]: 'Heavy rain',\n  [WeatherType.Snowy]: 'Snow',\n  [WeatherType.Hail]: 'Hail',\n  [WeatherType.Foggy]: 'Fog',\n  [WeatherType.Thunderstorm]: 'Thunderstorm',\n};\n\nfunction WeatherIcon(props: WeatherIconProps): ReactElement {\n  const {\n    type,\n    size = 64,\n    animated = true,\n    labels,\n    className,\n    style,\n    ...rest\n  } = useComponentDefaults('WeatherIcon', props);\n  const text = useLabels('WeatherIcon', labels, DEFAULT_LABELS);\n  const isAnimated = animated && !useMediaQuery('(prefers-reduced-motion: reduce)');\n  // useId's characters are not all safe inside `url(#…)`, and they changed between React 19 minors.\n  const clipId = `weather-icon-clip-${useId().replace(/[^\\w-]/g, '')}`;\n\n  // The cloud is only an outline, so what sits behind it would show through without this.\n  const behindCloud = (content: ReactElement) => <g clipPath={`url(#${clipId})`}>{content}</g>;\n\n  function scene(): ReactElement {\n    switch (type) {\n      case WeatherType.ClearNight:\n        return <Moon />;\n      case WeatherType.Cloudy:\n        return (\n          <>\n            {/* The offset sits on a wrapper: the cloud's own `transform` is animated and would replace it. */}\n            {behindCloud(\n              <g className={styles.weatherIconCloudBehind}>\n                <Cloud delayed />\n              </g>,\n            )}\n            <Cloud />\n          </>\n        );\n      case WeatherType.PartlyCloudy:\n        return (\n          <>\n            {behindCloud(<Sun className={styles.weatherIconBehind} />)}\n            <Cloud />\n          </>\n        );\n      case WeatherType.PartlyCloudyNight:\n        return (\n          <>\n            {behindCloud(<Moon className={styles.weatherIconBehind} />)}\n            <Cloud />\n          </>\n        );\n      case WeatherType.RainyLight:\n      case WeatherType.Rainy:\n      case WeatherType.RainyHeavy:\n        return (\n          <>\n            <Cloud />\n            <Rain\n              animated={isAnimated}\n              intensity={\n                type === WeatherType.RainyLight\n                  ? RainIntensity.Light\n                  : type === WeatherType.RainyHeavy\n                    ? RainIntensity.Heavy\n                    : RainIntensity.Medium\n              }\n            />\n          </>\n        );\n      case WeatherType.Snowy:\n        return (\n          <>\n            <Cloud />\n            <Snow animated={isAnimated} />\n          </>\n        );\n      case WeatherType.Hail:\n        return (\n          <>\n            <Cloud />\n            <Hail animated={isAnimated} />\n          </>\n        );\n      case WeatherType.Foggy:\n        return <Fog />;\n      case WeatherType.Thunderstorm:\n        return (\n          <>\n            <Cloud />\n            {behindCloud(<Lightning />)}\n          </>\n        );\n      default:\n        return <Sun />;\n    }\n  }\n\n  return (\n    <svg\n      {...rest}\n      role='img'\n      aria-label={text[type] ?? text[WeatherType.Sunny]}\n      className={cx(styles.weatherIcon, !isAnimated && styles.weatherIconStill, className)}\n      style={{ width: size, height: size, ...style }}\n      viewBox='0 0 100 100'\n    >\n      <defs>\n        {/* One path, both contours: two separate paths in a clipPath union instead of cutting a hole. */}\n        <clipPath id={clipId} clipRule='evenodd'>\n          <path d={`M -20 -20 H 120 V 120 H -20 Z ${CLOUD_PATH}`} />\n        </clipPath>\n      </defs>\n      {scene()}\n    </svg>\n  );\n}\n\nexport default WeatherIcon;\n"],"mappings":"2iBASA,IAAM,EAA8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