public override ISelector?Produce()
            {
                var valid = _selector.IsValid;
                var sel   = _selector.GetResult();

                if (valid)
                {
                    var code = PseudoClassNames.HostContext.CssFunction(sel !.Text);
                    return(new PseudoClassSelector(el =>
                    {
                        var shadowRoot = el.Parent as IShadowRoot;
                        var host = shadowRoot?.Host;

                        while (host != null)
                        {
                            if (sel.Match(host))
                            {
                                return true;
                            }

                            host = host.ParentElement;
                        }

                        return false;
                    }, code));
                }

                return(null);
            }
            public override ISelector?Produce()
            {
                var valid         = _nested.IsValid;
                var sel           = _nested.GetResult();
                var selText       = sel !.Text;
                var matchSiblings = _matchSiblings || selText.Contains(":" + PseudoClassNames.Scope);

                if (valid)
                {
                    var code = PseudoClassNames.Has.CssFunction(selText);

                    return(new PseudoClassSelector(el =>
                    {
                        var elements = default(IEnumerable <IElement>);

                        if (matchSiblings)
                        {
                            elements = el.ParentElement?.Children;
                        }
                        else
                        {
                            elements = el.Children;
                        }

                        if (elements is null)
                        {
                            elements = Array.Empty <IElement>();
                        }

                        return sel.MatchAny(elements, el) != null;
                    }, code));
                }

                return(null);
            }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the given selector constructor to the pool and gets the
        /// constructed selector.
        /// </summary>
        /// <param name="ctor">The constructor to recycle.</param>
        /// <returns>The Selector that is created in the constructor.</returns>
        public static ISelector ToPool(this CssSelectorConstructor ctor)
        {
            var result = ctor.GetResult();

            lock (_lock)
            {
                _selector.Push(ctor);
            }

            return(result);
        }
            public override ISelector?Produce()
            {
                var invalid = !_valid || (_nested != null && !_nested.IsValid);

                if (!invalid)
                {
                    var sel = _nested?.GetResult() ?? AllSelector.Instance;
                    return(_creator.Invoke(_step, _offset, sel));
                }

                return(null);
            }
            public override ISelector?Produce()
            {
                var valid = _selector.IsValid;
                var sel   = _selector.GetResult();

                if (valid)
                {
                    var code = PseudoClassNames.Matches.CssFunction(sel !.Text);
                    return(new PseudoClassSelector(el => sel.Match(el), code));
                }

                return(null);
            }