22#include " Styled+Equality.hpp"
33#include " ShadowTreeUpdateManager.hpp"
44#include " Rules.hpp"
5+ #include " Helpers.hpp"
56
67#include < regex>
78#include < variant>
@@ -25,7 +26,11 @@ namespace margelo::nitro::cssnitro {
2526 (void ) prev;
2627
2728 Styled next{};
28- std::vector<std::shared_ptr<AnyMap>> styleEntries;
29+ /* *
30+ * Ideally this should an AnyMap, but settings values on an AnyMap doesn't work?
31+ * So we use an unordered_map and convert it to AnyMap at the end.
32+ */
33+ std::unordered_map<std::string, AnyValue> mergedStyles;
2934
3035 std::regex whitespace{" \\ s+" };
3136 std::sregex_token_iterator tokenIt (classNames.begin (), classNames.end (),
@@ -52,40 +57,39 @@ namespace margelo::nitro::cssnitro {
5257 }
5358
5459 if (styleRule.d .has_value ()) {
55- std::vector<std::variant<std::shared_ptr<AnyMap>, std::vector<std::shared_ptr<AnyMap>>>> stack (
56- styleRule.d ->begin (), styleRule.d ->end ());
57-
58- while (!stack.empty ()) {
59- auto current = std::move (stack.back ());
60- stack.pop_back ();
61-
62- std::visit (
63- [&stack, &styleEntries](auto &&value) {
64- using ValueType = std::decay_t <decltype (value)>;
65-
66- if constexpr (std::is_same_v<ValueType, std::shared_ptr<AnyMap>>) {
67- if (value) {
68- styleEntries.push_back (value);
69- }
70- } else if constexpr (std::is_same_v<ValueType, std::vector<std::shared_ptr<AnyMap>>>) {
71- for (const auto &nested: value) {
72- if (nested) {
73- stack.emplace_back (nested);
74- }
75- }
76- }
77- },
78- current);
60+ // Get the tuple from styleRule.d
61+ const auto &dTuple = styleRule.d .value ();
62+
63+ // Merge styleRule.d[0] into mergedStyles
64+ const auto &firstMap = std::get<0 >(std::get<0 >(dTuple));
65+ for (const auto &kv: firstMap->getMap ()) {
66+ mergedStyles[kv.first ] = kv.second ;
7967 }
68+ // Ignore the other entries for now
69+
8070 }
8171 }
8272 }
8373
84- if (!styleEntries.empty ()) {
85- next.style = std::move (styleEntries);
74+ // Convert mergedStyles to AnyMap and set next.style
75+ if (!mergedStyles.empty ()) {
76+ auto anyMap = AnyMap::make (mergedStyles.size ());
77+ for (const auto &kv: mergedStyles) {
78+ if (kv.first == " rotate" ) {
79+ if (!anyMap->contains (" transform" )) {
80+ anyMap->setArray (" transform" , AnyArray{});
81+ }
82+
83+ const auto &transformArray = anyMap->getArray (" transform" );
84+ // find the value in the array with the key "rotate" and set the key "rotate" to kv.second
85+ }
86+
87+ anyMap->setAny (kv.first , kv.second );
88+ }
89+ next.style = anyMap;
8690 }
8791
88- // Notify ShadowTreeUpdateManager with the resolved style entries
92+ // Notify ShadowTreeUpdateManager with the resolved style
8993 if (next.style .has_value ()) {
9094 shadowUpdates.addUpdates (componentId, next.style .value ());
9195 }
0 commit comments