private static CssSelector Flatten(CssComplexSelector complex)
        {
            if (complex.Items.Length != 1)
            {
                return(complex);
            }
            var compound = complex.Items[0].Selector;

            if (compound.Selectors.Length == 1)
            {
                return(compound.Selectors[0]);
            }
            return(compound);
        }
        private static bool TryParseComplexSelector(CssStringStreamReader reader, out CssComplexSelector selector)
        {
            var items = new List <CssComplexSelectorItem>();

            while (!reader.IsEndOfStream)
            {
                if (!TryParseCompoundSelector(reader, out var compound))
                {
                    if (items.Count > 0)
                    {
                        var last = items[items.Count - 1];
                        if (last.Combinator == CssCombinatorType.Descendant)
                        {
                            // remove the last items combinator
                            items[items.Count - 1] = new CssComplexSelectorItem(last.Selector, null);
                        }
                        else
                        {
                            items.Clear();
                        }
                    }
                    break;
                }

                var hasCombinator = reader.TryReadCombinatorType(out var combinator);

                items.Add(hasCombinator
                    ? new CssComplexSelectorItem(compound, combinator)
                    : new CssComplexSelectorItem(compound, null));

                if (!hasCombinator)
                {
                    break;
                }
            }
            selector = items.Count > 0 ? new CssComplexSelector(items.ToArray()) : null;
            return(selector != null);
        }
Esempio n. 3
0
 public virtual void VisitComplexSelector(CssComplexSelector selector)
 => DefaultVisit(selector);