{"version":3,"file":"merge-mantine-theme.mjs","names":[],"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"],"mappings":";;AAGA,MAAa,8BACX;AAEF,MAAa,8BACX;AAEF,SAAS,oBAAoB,OAAe;AAC1C,KAAI,QAAQ,KAAK,QAAQ,EACvB,QAAO;AAGT,QAAO,SAAS,MAAM,UAAU,EAAE,GAAG,KAAK;;AAG5C,SAAgB,qBAAqB,OAAoD;AACvF,KAAI,EAAE,MAAM,gBAAgB,MAAM,QAChC,OAAM,IAAI,MAAM,4BAA4B;AAG9C,KAAI,OAAO,MAAM,iBAAiB;MAE9B,CAAC,oBAAoB,MAAM,aAAa,KAAK,IAC7C,CAAC,oBAAoB,MAAM,aAAa,MAAM,CAE9C,OAAM,IAAI,MAAM,4BAA4B;;AAIhD,KAAI,OAAO,MAAM,iBAAiB,YAAY,CAAC,oBAAoB,MAAM,aAAa,CACpF,OAAM,IAAI,MAAM,4BAA4B;;AAIhD,SAAgB,kBACd,cACA,eACA;AACA,KAAI,CAAC,eAAe;AAClB,uBAAqB,aAAa;AAClC,SAAO;;CAGT,MAAM,SAAS,UAAU,cAAc,cAAc;AAErD,KAAI,cAAc,cAAc,CAAC,cAAc,UAAU,WACvD,QAAO,SAAS,aAAa,cAAc;AAG7C,sBAAqB,OAAO;AAC5B,QAAO"}