{"version":3,"file":"merge-mantine-theme.cjs","sources":["../../../../src/core/MantineProvider/merge-mantine-theme/merge-mantine-theme.ts"],"sourcesContent":["import { deepMerge } from '../../utils';\nimport type { MantineTheme, MantineThemeOverride } from '../theme.types';\n\nexport const INVALID_PRIMARY_COLOR_ERROR =\n  '[@mantine/core] MantineProvider: Invalid theme.primaryColor, it accepts only key of theme.colors, learn more – https://mantine.dev/theming/colors/#primary-color';\n\nexport const INVALID_PRIMARY_SHADE_ERROR =\n  '[@mantine/core] MantineProvider: Invalid theme.primaryShade, it accepts only 0-9 integers or an object { light: 0-9, dark: 0-9 }';\n\nfunction isValidPrimaryShade(shade: number) {\n  if (shade < 0 || shade > 9) {\n    return false;\n  }\n\n  return parseInt(shade.toString(), 10) === shade;\n}\n\nexport function validateMantineTheme(theme: MantineTheme): asserts theme is MantineTheme {\n  if (!(theme.primaryColor in theme.colors)) {\n    throw new Error(INVALID_PRIMARY_COLOR_ERROR);\n  }\n\n  if (typeof theme.primaryShade === 'object') {\n    if (\n      !isValidPrimaryShade(theme.primaryShade.dark) ||\n      !isValidPrimaryShade(theme.primaryShade.light)\n    ) {\n      throw new Error(INVALID_PRIMARY_SHADE_ERROR);\n    }\n  }\n\n  if (typeof theme.primaryShade === 'number' && !isValidPrimaryShade(theme.primaryShade)) {\n    throw new Error(INVALID_PRIMARY_SHADE_ERROR);\n  }\n}\n\nexport function mergeMantineTheme(\n  currentTheme: MantineTheme,\n  themeOverride?: MantineThemeOverride\n) {\n  if (!themeOverride) {\n    validateMantineTheme(currentTheme);\n    return currentTheme;\n  }\n\n  const result = deepMerge(currentTheme, themeOverride);\n\n  if (themeOverride.fontFamily && !themeOverride.headings?.fontFamily) {\n    result.headings.fontFamily = themeOverride.fontFamily;\n  }\n\n  validateMantineTheme(result);\n  return result;\n}\n"],"names":["deepMerge"],"mappings":";;;;;;;;AAGO,MAAM,2BAAA,GACX;AAEK,MAAM,2BAAA,GACX;AAEF,SAAS,oBAAoB,KAAA,EAAe;AA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