@@ -92,21 +92,27 @@ namespace margelo::nitro::cssnitro {
9292
9393 }
9494
95- // Process the declarations
95+ // Process the declarations and props
9696 for (const HybridStyleRule &styleRule: allStyleRules) {
97+ // Check if this is an important rule (s[0] > 0)
98+ const bool isImportant = std::get<0 >(styleRule.s ) > 0 ;
99+
100+ // Process declarations (styles) from the "d" key
97101 if (styleRule.d .has_value ()) {
98102 const auto &declarations = styleRule.d .value ();
103+ auto &targetStyles = isImportant ? mergedImportantStyles : mergedStyles;
99104
100- // Check if this is an important rule (s[0] > 0)
101- const bool isImportant = std::get<0 >(styleRule.s ) > 0 ;
105+ StyledComputedFactory::processDeclarations (
106+ declarations, targetStyles, get, variableScope);
107+ }
102108
103- // Determine which maps to use based on importance
104- auto &targetStyles = isImportant ? mergedImportantStyles : mergedStyles;
109+ // Process props from the "p" key
110+ if (styleRule.p .has_value ()) {
111+ const auto &props = styleRule.p .value ();
105112 auto &targetProps = isImportant ? mergedImportantProps : mergedProps;
106113
107- // Process declarations using the helper function
108114 StyledComputedFactory::processDeclarations (
109- declarations, targetStyles , targetProps, get, variableScope);
115+ props , targetProps, get, variableScope);
110116 }
111117 }
112118
@@ -174,65 +180,33 @@ namespace margelo::nitro::cssnitro {
174180 }
175181
176182 void StyledComputedFactory::processDeclarations (
177- const auto &declarations,
178- std::unordered_map<std::string, AnyValue> &targetStyles,
179- std::unordered_map<std::string, AnyValue> &targetProps,
183+ const std::shared_ptr<AnyMap> &declarations,
184+ std::unordered_map<std::string, AnyValue> &targetMap,
180185 reactnativecss::Effect::GetProxy &get,
181186 const std::string &variableScope) {
182187
183- std::visit ([&targetStyles, &targetProps, &get, &variableScope](const auto &decl) {
184- // decl is a tuple, get the first element (the styles)
185- const auto &dStyles = std::get<0 >(decl);
186-
187- // Check if dStyles is valid before accessing
188- if (dStyles) {
189- for (const auto &kv: dStyles->getMap ()) {
190- // Only set if key doesn't already exist
191- if (targetStyles.count (kv.first ) == 0 ) {
192- // Use StyleResolver to resolve the style value (handles functions, variables, etc.)
193- auto resolvedValue = StyleResolver::resolveStyle (kv.second , variableScope,
194- get);
195-
196- // Skip if resolveStyle returns monostate (unresolved)
197- if (std::holds_alternative<std::monostate>(resolvedValue)) {
198- continue ;
199- }
188+ // declarations is a shared_ptr<AnyMap> containing the style or prop values
189+ if (!declarations) {
190+ return ;
191+ }
200192
201- targetStyles[kv.first ] = resolvedValue;
202- }
203- }
204- }
193+ // Get the map of all key-value pairs from the AnyMap
194+ const auto &map = declarations->getMap ();
205195
206- // Check if there's a second element in the tuple (props)
207- if constexpr (std::tuple_size<std::decay_t <decltype (decl)>>::value > 1 ) {
208- const auto &dPropsOpt = std::get<1 >(decl);
209-
210- // dPropsOpt is optional, check if it has a value
211- if (dPropsOpt.has_value ()) {
212- const auto &dProps = dPropsOpt.value ();
213-
214- // Check if dProps is valid before accessing
215- if (dProps) {
216- for (const auto &kv: dProps->getMap ()) {
217- // Only set if key doesn't already exist
218- if (targetProps.count (kv.first ) == 0 ) {
219- // Use StyleResolver to resolve the prop value (handles functions, variables, etc.)
220- auto resolvedValue = StyleResolver::resolveStyle (kv.second ,
221- variableScope,
222- get);
223-
224- // Skip if resolveStyle returns monostate (unresolved)
225- if (std::holds_alternative<std::monostate>(resolvedValue)) {
226- continue ;
227- }
196+ for (const auto &kv: map) {
197+ // Only set if key doesn't already exist
198+ if (targetMap.count (kv.first ) == 0 ) {
199+ // Use StyleResolver to resolve the value (handles functions, variables, etc.)
200+ auto resolvedValue = StyleResolver::resolveStyle (kv.second , variableScope, get);
228201
229- targetProps[kv.first ] = resolvedValue;
230- }
231- }
232- }
202+ // Skip if resolveStyle returns monostate (unresolved)
203+ if (std::holds_alternative<std::monostate>(resolvedValue)) {
204+ continue ;
233205 }
206+
207+ targetMap[kv.first ] = resolvedValue;
234208 }
235- }, declarations);
209+ }
236210 }
237211
238212
0 commit comments