ass_core/analysis/styles/analyzer/
accessors.rs1use super::{AnalysisOptions, StyleAnalysisConfig, StyleAnalyzer};
8use crate::{
9 analysis::styles::{
10 resolved_style::ResolvedStyle,
11 validation::{StyleConflict, StyleInheritance, StyleValidationIssue},
12 },
13 parser::Script,
14};
15use alloc::{collections::BTreeMap, vec::Vec};
16
17impl<'a> StyleAnalyzer<'a> {
18 #[must_use]
20 pub fn new(script: &'a Script<'a>) -> Self {
21 Self::new_with_config(script, StyleAnalysisConfig::default())
22 }
23
24 #[must_use]
26 pub fn new_with_config(script: &'a Script<'a>, config: StyleAnalysisConfig) -> Self {
27 let mut analyzer = Self {
28 script,
29 resolved_styles: BTreeMap::new(),
30 inheritance_info: BTreeMap::new(),
31 conflicts: Vec::new(),
32 config,
33 resolution_scaling: None,
34 };
35
36 analyzer.calculate_resolution_scaling();
37 analyzer.analyze_all_styles();
38 analyzer
39 }
40
41 #[must_use]
43 pub fn resolve_style(&self, name: &str) -> Option<&ResolvedStyle<'a>> {
44 self.resolved_styles.get(name)
45 }
46
47 #[must_use]
49 pub const fn resolved_styles(&self) -> &BTreeMap<&'a str, ResolvedStyle<'a>> {
50 &self.resolved_styles
51 }
52
53 #[must_use]
55 pub fn conflicts(&self) -> &[StyleConflict<'a>] {
56 &self.conflicts
57 }
58
59 #[must_use]
61 pub const fn inheritance_info(&self) -> &BTreeMap<&'a str, StyleInheritance<'a>> {
62 &self.inheritance_info
63 }
64
65 #[must_use]
67 pub fn validate_styles(&self) -> Vec<StyleValidationIssue> {
68 let mut issues = Vec::new();
69
70 for resolved in self.resolved_styles.values() {
71 if self.config.options.contains(AnalysisOptions::VALIDATION) {
72 issues.extend(self.validate_style_properties(resolved));
73 }
74
75 if self.config.options.contains(AnalysisOptions::PERFORMANCE) {
76 issues.extend(self.analyze_style_performance(resolved));
77 }
78 }
79
80 issues
81 }
82}