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AC,KAAK,EAAE,MAAM,EAAE,EAAE;QAChD,4BAAoB,CAAC,MAAM,EAAE,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC;QAC9D,OAAO,yBAAiB,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC,CAAC;SACD,OAAO,CAAC,CAAC,UAAU,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC7D,4BAAoB,CAAC,MAAM,EAAE,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC;QAC9D,4BAAoB,CAAC,MAAM,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;QACrD,OAAO,iCAAyB,CAAC,sCAA0B,CAAC,CAAC,KAAK,CAAC,CAAC;IACtE,CAAC,CAAC;SACD,OAAO,CAAC,CAAC,UAAU,EAAE,WAAW,EAAE,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QACvE,4BAAoB,CAAC,MAAM,EAAE,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC;QAC9D,4BAAoB,CAAC,MAAM,EAAE,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC,CAAC;QAC/D,OAAO,qBAAa,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEL,MAAM,eAAe,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACzD,OAAO,eAAe,CAAC;AACzB,CAAC;AAnCD,sDAmCC","sourcesContent":["import {\n IosSplashScreenConfigJSON,\n IosSplashScreenConfig,\n AndroidSplashScreenConfigJSON,\n AndroidSplashScreenConfig,\n} from '../SplashScreenConfig';\nimport { SplashScreenImageResizeMode, SplashScreenStatusBarStyle } from '../constants';\nimport FromJsonValidator from './FromJsonValidator';\nimport {\n validateColor,\n validateFileIsPng,\n ensurePropertyExists,\n generateValidateEnumValue,\n} from './utils';\n\nexport { validateEnumValue } from './utils';\n\n/**\n * Validates given iOS configuration and converts it to it's semantically ready equivalent.\n * Ensures following generic config semantic requirements are met:\n * - `config.backgroundColor` is a valid css-formatted color,\n * - `config.imagePath` is pointing to a valid .png file,\n * - `config.imageResizeMode`\n * - is provided only if `config.imagePath` is provided as well\n * - and it's a recognizable value (one of `SplashScreenResizeMode`)\n * - and its value isn't `SplashScreenImageResizeMode.NATIVE`\n *\n * - `config.statusBar.hidden` might exists\n * - `config.statusBar.style` is a recognizable value (one of `SplashScreenStatusBarStyle`),\n *\n * - `config.darkMode.backgroundColor` is a valid css-formatted color,\n * - `config.darkMode.imagePath`\n * - is provided only if `config.darkMode.backgroundColor` is provided as well\n * - and it's pointing to a valid .png file,\n */\nexport async function validateIosConfig(\n config: IosSplashScreenConfigJSON\n): Promise<IosSplashScreenConfig> {\n const validator = new FromJsonValidator<IosSplashScreenConfigJSON, IosSplashScreenConfig>()\n .addRule(['backgroundColor'], validateColor)\n .addRule(['image'], validateFileIsPng)\n .addRule(['imageResizeMode'], (value, config) => {\n ensurePropertyExists(config, ['image']);\n const result = generateValidateEnumValue(SplashScreenImageResizeMode)(value);\n if (result === SplashScreenImageResizeMode.NATIVE) {\n const { NATIVE, ...availableValues } = SplashScreenImageResizeMode;\n throw new Error(\n `Invalid value '${value}'. This value is not supported on iOS platform. Available values on iOS platform are ${Object.values(\n availableValues\n )\n .map(v => `\"${v}\"`)\n .join(' | ')}.`\n );\n }\n return result;\n })\n .addRule(['statusBar', 'hidden'])\n .addRule(['statusBar', 'style'], generateValidateEnumValue(SplashScreenStatusBarStyle))\n .addRule(['darkMode', 'backgroundColor'], validateColor)\n .addRule(['darkMode', 'image'], (value, config) => {\n ensurePropertyExists(config, ['darkMode', 'backgroundColor']);\n return validateFileIsPng(value);\n });\n\n const validatedConfig = await validator.validate(config);\n return validatedConfig;\n}\n\n/**\n * Validates given Android configuration and converts it to it's semantically ready equivalent.\n *\n * Ensures following generic config semantic requirements are met:\n * - `config.backgroundColor` is a valid css-formatted color,\n * - `config.imagePath` is pointing to a valid .png file,\n * - `config.imageResizeMode`\n * - is provided only if `config.imagePath` is provided as well\n * - and it's a recognizable value (one of `SplashScreenResizeMode`)\n *\n * - `config.statusBar.hidden` might exists,\n * - `config.statusBar.style` is a recognizable value (one of `SplashScreenStatusBarStyle`),\n * - `config.statusBar.translucent` might exist,\n * - `config.statusBar.backgroundColor` is a valid css-formatted color,\n *\n * - `config.darkMode.backgroundColor` is a valid css-formatted color,\n * - `config.darkMode.imagePath`\n * - is provided only if `config.darkMode.backgroundColor` is provided as well\n * - and it's pointing to a valid .png file,\n *\n * - `config.darkMode.statusBar.style`\n * - is provided only if `config.darkMode.backgroundColor` is provided as well\n * - and `config.statusBar.style` is provided as well\n * - and it's a recognizable value (one of `SplashScreenStatusBarStyle`),\n * - `config.darkMode.statusBar.backgroundColor`\n * - is provided only if `config.darkMode.backgroundColor` is provided as well\n * - and `config.statusBar.backgroundColor` is provided as well\n * - and it's a valid css-formatted color,\n */\nexport async function validateAndroidConfig(\n config: AndroidSplashScreenConfigJSON\n): Promise<AndroidSplashScreenConfig> {\n const validator = new FromJsonValidator<\n AndroidSplashScreenConfigJSON,\n AndroidSplashScreenConfig\n >()\n .addRule(['backgroundColor'], validateColor)\n .addRule(['image'], validateFileIsPng)\n .addRule(['imageResizeMode'], (value, config) => {\n ensurePropertyExists(config, ['image']);\n return generateValidateEnumValue(SplashScreenImageResizeMode)(value);\n })\n .addRule(['statusBar', 'hidden'])\n .addRule(['statusBar', 'style'], generateValidateEnumValue(SplashScreenStatusBarStyle))\n .addRule(['statusBar', 'translucent'])\n .addRule(['statusBar', 'backgroundColor'], validateColor)\n .addRule(['darkMode', 'backgroundColor'], validateColor)\n .addRule(['darkMode', 'image'], (value, config) => {\n ensurePropertyExists(config, ['darkMode', 'backgroundColor']);\n return validateFileIsPng(value);\n })\n .addRule(['darkMode', 'statusBar', 'style'], (value, config) => {\n ensurePropertyExists(config, ['darkMode', 'backgroundColor']);\n ensurePropertyExists(config, ['statusBar', 'style']);\n return generateValidateEnumValue(SplashScreenStatusBarStyle)(value);\n })\n .addRule(['darkMode', 'statusBar', 'backgroundColor'], (value, config) => {\n ensurePropertyExists(config, ['darkMode', 'backgroundColor']);\n ensurePropertyExists(config, ['statusBar', 'backgroundColor']);\n return validateColor(value);\n });\n\n const validatedConfig = await validator.validate(config);\n return validatedConfig;\n}\n"]} |