'use strict'; import type { ConfigPropertyAlias, PlainStyle, UnknownRecord, ValueProcessor, } from '../types'; import { hasValueProcessor, isConfigPropertyAlias } from '../utils'; import { STYLE_PROPERTIES_CONFIG } from './config'; import createPropsBuilder from './createPropsBuilder'; type PropsBuilderPropertyConfig< TProps extends UnknownRecord = UnknownRecord, K extends keyof TProps = keyof TProps, > = | boolean // true - included, false - excluded | ConfigPropertyAlias // alias for another property | { // value can have any type as it is passed to CPP where we can expect a different // type than in the React Native stylesheet (e.g. number for colors instead of string) process: ValueProcessor[K], unknown>; // for custom value processing }; export type PropsBuilderConfig

= { [K in keyof Required

]: PropsBuilderPropertyConfig; }; export function createNativePropsBuilder( config: PropsBuilderConfig ) { return createPropsBuilder({ config, processConfigValue(configValue) { if (configValue === true) { // No custom processing needed return true; } if (isConfigPropertyAlias(configValue)) { return config[configValue.as]; } if (hasValueProcessor(configValue)) { return (value, context) => { 'worklet'; return configValue.process(value, context); }; } }, }); } export type NativePropsBuilder = ReturnType; export const stylePropsBuilder = createNativePropsBuilder( STYLE_PROPERTIES_CONFIG );