| 631 | // Style resolution |
| 632 | |
| 633 | CssStyle CssParser::resolveStyle(std::string_view tagName, std::string_view classAttr) const { |
| 634 | static bool lowHeapWarningLogged = false; |
| 635 | if (ESP.getFreeHeap() < MIN_FREE_HEAP_FOR_CSS) { |
| 636 | if (!lowHeapWarningLogged) { |
| 637 | lowHeapWarningLogged = true; |
| 638 | LOG_DBG("CSS", "Warning: low heap (%u bytes) below MIN_FREE_HEAP_FOR_CSS (%u), returning empty style", |
| 639 | ESP.getFreeHeap(), static_cast<unsigned>(MIN_FREE_HEAP_FOR_CSS)); |
| 640 | } |
| 641 | return CssStyle{}; |
| 642 | } |
| 643 | |
| 644 | CssStyle result; |
| 645 | |
| 646 | // 1. Apply element-level style (lowest priority). The map's hash/equal are |
| 647 | // case-insensitive, so the raw tagName view can be used as the lookup key. |
| 648 | if (auto it = rulesBySelector_.find(tagName); it != rulesBySelector_.end()) { |
| 649 | result.applyOver(it->second); |
| 650 | } |
| 651 | |
| 652 | if (classAttr.empty()) return result; |
| 653 | |
| 654 | // TODO: Support combinations of classes (e.g. style on .class1.class2) |
| 655 | // 2. Apply class styles (medium priority). The transparent hash/equal accept |
| 656 | // a CompositeKey, so we never materialize the concatenation. |
| 657 | forEachDelimitedToken(classAttr, isCssWhitespace, [&](std::string_view cls) { |
| 658 | if (auto it = rulesBySelector_.find(CompositeKey{".", cls}); it != rulesBySelector_.end()) { |
| 659 | result.applyOver(it->second); |
| 660 | } |
| 661 | }); |
| 662 | |
| 663 | // TODO: Support combinations of classes (e.g. style on p.class1.class2) |
| 664 | // 3. Apply element.class styles (higher priority). |
| 665 | forEachDelimitedToken(classAttr, isCssWhitespace, [&](std::string_view cls) { |
| 666 | if (auto it = rulesBySelector_.find(CompositeKey{tagName, ".", cls}); it != rulesBySelector_.end()) { |
| 667 | result.applyOver(it->second); |
| 668 | } |
| 669 | }); |
| 670 | |
| 671 | return result; |
| 672 | } |
| 673 | |
| 674 | // Inline style parsing (static - doesn't need rule database) |
| 675 |
no test coverage detected