|
3 | 3 | #include "ShadowTreeUpdateManager.hpp" |
4 | 4 | #include "Rules.hpp" |
5 | 5 | #include "Helpers.hpp" |
| 6 | +#include "StyleFunction.hpp" |
6 | 7 |
|
7 | 8 | #include <regex> |
8 | 9 | #include <variant> |
@@ -57,13 +58,34 @@ namespace margelo::nitro::cssnitro { |
57 | 58 | } |
58 | 59 |
|
59 | 60 | if (styleRule.d.has_value()) { |
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; |
| 61 | + const auto declarations = styleRule.d.value(); |
| 62 | + const auto &dStyles = std::get<0>(std::get<0>(declarations)); |
| 63 | + for (const auto &kv: dStyles->getMap()) { |
| 64 | + // Only set if key doesn't already exist |
| 65 | + if (mergedStyles.count(kv.first) == 0) { |
| 66 | + // if kv.second is an array with "fn" as the first key, resolve it |
| 67 | + if (dStyles->isArray(kv.first)) { |
| 68 | + const auto &arr = dStyles->getArray(kv.first); |
| 69 | + if (!arr.empty() && |
| 70 | + std::holds_alternative<std::string>(arr[0]) && |
| 71 | + std::get<std::string>(arr[0]) == "fn") { |
| 72 | + // arr[1] is the function name, arr[2] is the arguments array |
| 73 | + if (arr.size() == 3 && |
| 74 | + std::holds_alternative<std::string>( |
| 75 | + arr[1]) && |
| 76 | + std::holds_alternative<AnyArray>(arr[2])) { |
| 77 | + const auto &fnName = std::get<std::string>( |
| 78 | + arr[1]); |
| 79 | + const auto &fnArgs = std::get<AnyArray>( |
| 80 | + arr[2]); |
| 81 | + mergedStyles[kv.first] = StyleFunction::resolveStyleFn( |
| 82 | + fnName, fnArgs, get); |
| 83 | + continue; |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + mergedStyles[kv.first] = kv.second; |
| 88 | + } |
67 | 89 | } |
68 | 90 | // Ignore the other entries for now |
69 | 91 |
|
|
0 commit comments