Exemplo n.º 1
0
        protected List <StyleRule> GetCombinedStyleRules()
        {
            if (BaseStyleSheets.Count == 0 &&
                InheritedStyleSheets.Count == 0)
            {
                return(LocalRules);
            }

            if (InheritedStyleSheets.Contains(this))
            {
                throw new InvalidOperationException("A stylesheet cannot be attached to multiple elements at the same time!");
            }

            return(InheritedStyleSheets
                   .SelectMany(x => x.Rules.ToList())
                   .Concat(BaseStyleSheets.SelectMany(x => x.Rules.ToList()))
                   .Concat(LocalRules)
                   .GroupBy(x => x.SelectorString)
                   .Select(x => new StyleRule
            {
                Selectors = x.First().Selectors,
                DeclarationBlock = new StyleDeclarationBlock(GetMergedStyleDeclarations(x.ToList()), x.SelectMany(y => y.DeclarationBlock.Triggers).ToList())
            })
                   .ToList());
        }
Exemplo n.º 2
0
        private void Invalidate()
        {
            Version++;
            Reset();

            var sheet = CssParser.Parse(content ?? "", BaseStyleSheets.LastOrDefault()?.Namespaces.FirstOrDefault(x => x.Alias == "")?.Namespace ?? CssParser.defaultCssNamespace, GetCombinedVariables());

            foreach (var error in sheet.Errors)
            {
                this.LocalErrors.Add(error);
            }
            foreach (var warning in sheet.Warnings)
            {
                this.LocalWarnings.Add(warning);
            }

            this.localNamespaces = sheet.LocalNamespaces;
            this.localRules      = sheet.LocalRules;
            this.variables       = sheet.Variables;

            EagerLoading();

            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Content"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LocalRules"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LocalNamespaces"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Errors"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Warnings"));
        }
Exemplo n.º 3
0
        protected IDictionary <string, string> GetCombinedVariables()
        {
            if (BaseStyleSheets.Count == 0 &&
                InheritedStyleSheets.Count == 0)
            {
                return(Variables);
            }

            return(InheritedStyleSheets
                   .SelectMany(x => x.Variables.ToList())
                   .Concat(BaseStyleSheets.SelectMany(x => x.Variables.ToList()))
                   .Concat(Variables)
                   .GroupBy(x => x.Key)
                   .Select(x => x.Last())
                   .ToDictionary(x => x.Key, x => x.Value));
        }
Exemplo n.º 4
0
        protected ObservableCollection <string> GetCombinedWarnings()
        {
            if (BaseStyleSheets.Count == 0 &&
                InheritedStyleSheets.Count == 0)
            {
                return(LocalWarnings);
            }

            return(new ObservableCollection <string>(
                       InheritedStyleSheets
                       .Select(x => x.Warnings)
                       .Concat(BaseStyleSheets.Select(x => x.Warnings))
                       .Aggregate((a, b) => new ObservableCollection <string>(a.Concat(b)))
                       .Concat(LocalWarnings)
                       .GroupBy(x => x)
                       .Select(x => x.First())));
        }
Exemplo n.º 5
0
        protected CssNamespaceCollection GetCombinedNamespaces()
        {
            if (BaseStyleSheets?.Count == 0 &&
                InheritedStyleSheets?.Count == 0)
            {
                return(LocalNamespaces);
            }

            return(new CssNamespaceCollection(
                       InheritedStyleSheets
                       .Select(x => x.Namespaces)
                       .Concat(BaseStyleSheets.Select(x => x.Namespaces))
                       .Aggregate((a, b) => new CssNamespaceCollection(a.Concat(b)))
                       .Concat(LocalNamespaces)
                       .GroupBy(x => x.Alias)
                       .Select(x => x.Last())));
        }
Exemplo n.º 6
0
        protected List <StyleRule> GetCombinedStyleRules()
        {
            if (BaseStyleSheets.Count == 0 &&
                InheritedStyleSheets.Count == 0)
            {
                return(LocalRules);
            }

            return(InheritedStyleSheets
                   .SelectMany(x => x.Rules.ToList())
                   .Concat(BaseStyleSheets.SelectMany(x => x.Rules.ToList()))
                   .Concat(LocalRules)
                   .GroupBy(x => x.SelectorString)
                   .Select(x => new StyleRule
            {
                Selectors = x.First().Selectors,
                DeclarationBlock = new StyleDeclarationBlock(GetMergedStyleDeclarations(x.ToList()), x.SelectMany(y => y.DeclarationBlock.Triggers).ToList())
            })
                   .ToList());
        }
Exemplo n.º 7
0
        protected CssNamespaceCollection GetCombinedNamespaces()
        {
            return("GetCombinedNamespaces".Measure(() =>
            {
                if (BaseStyleSheets.Count == 0 &&
                    InheritedStyleSheets.Count == 0)
                {
                    return LocalNamespaces;
                }

                var result = new CssNamespaceCollection(
                    InheritedStyleSheets
                    .Select(x => x.Namespaces)
                    .Concat(BaseStyleSheets.Select(x => x.Namespaces))
                    .Aggregate((a, b) => new CssNamespaceCollection(a.Concat(b)))
                    .Concat(LocalNamespaces)
                    .GroupBy(x => x.Alias)
                    .Select(x => x.Last()));

                return result;
            }));
        }