org.jboss.elemento.Elements Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2015-2016 Red Hat, Inc, and individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.elemento;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import elemental2.core.JsArray;
import elemental2.dom.Element;
import elemental2.dom.HTMLAnchorElement;
import elemental2.dom.HTMLAreaElement;
import elemental2.dom.HTMLAudioElement;
import elemental2.dom.HTMLBRElement;
import elemental2.dom.HTMLBodyElement;
import elemental2.dom.HTMLButtonElement;
import elemental2.dom.HTMLCanvasElement;
import elemental2.dom.HTMLDListElement;
import elemental2.dom.HTMLDataListElement;
import elemental2.dom.HTMLDivElement;
import elemental2.dom.HTMLElement;
import elemental2.dom.HTMLEmbedElement;
import elemental2.dom.HTMLFieldSetElement;
import elemental2.dom.HTMLFormElement;
import elemental2.dom.HTMLHRElement;
import elemental2.dom.HTMLHeadingElement;
import elemental2.dom.HTMLIFrameElement;
import elemental2.dom.HTMLImageElement;
import elemental2.dom.HTMLInputElement;
import elemental2.dom.HTMLLIElement;
import elemental2.dom.HTMLLabelElement;
import elemental2.dom.HTMLLegendElement;
import elemental2.dom.HTMLMapElement;
import elemental2.dom.HTMLMeterElement;
import elemental2.dom.HTMLModElement;
import elemental2.dom.HTMLOListElement;
import elemental2.dom.HTMLObjectElement;
import elemental2.dom.HTMLOptGroupElement;
import elemental2.dom.HTMLOptionElement;
import elemental2.dom.HTMLOutputElement;
import elemental2.dom.HTMLParagraphElement;
import elemental2.dom.HTMLParamElement;
import elemental2.dom.HTMLPreElement;
import elemental2.dom.HTMLProgressElement;
import elemental2.dom.HTMLQuoteElement;
import elemental2.dom.HTMLScriptElement;
import elemental2.dom.HTMLSelectElement;
import elemental2.dom.HTMLSourceElement;
import elemental2.dom.HTMLTableCaptionElement;
import elemental2.dom.HTMLTableCellElement;
import elemental2.dom.HTMLTableColElement;
import elemental2.dom.HTMLTableElement;
import elemental2.dom.HTMLTableRowElement;
import elemental2.dom.HTMLTableSectionElement;
import elemental2.dom.HTMLTextAreaElement;
import elemental2.dom.HTMLTrackElement;
import elemental2.dom.HTMLUListElement;
import elemental2.dom.HTMLVideoElement;
import elemental2.dom.Node;
import elemental2.dom.NodeList;
import jsinterop.base.Js;
import jsinterop.base.JsArrayLike;
import org.gwtproject.safehtml.shared.SafeHtml;
import static elemental2.dom.DomGlobal.document;
import static java.util.Collections.emptyIterator;
import static java.util.Collections.emptyList;
import static java.util.Spliterators.spliteratorUnknownSize;
import static jsinterop.base.Js.cast;
/**
* Helper methods for working with {@link elemental2.dom.HTMLElement}s and/or {@link IsElement}.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element
*/
public final class Elements {
static ElementCreator createElement = new ElementCreator() {
@Override
public E create(String element, Class type) {
return cast(document.createElement(element));
}
};
// ------------------------------------------------------ body
/** Returns an HTML content builder for the document body. */
public static HtmlContentBuilder body() {
return new HtmlContentBuilder<>(document.body);
}
// ------------------------------------------------------ content sectioning
public static HtmlContentBuilder address() {
return htmlElement("address", HTMLElement.class);
}
public static HtmlContentBuilder address(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder article() {
return htmlElement("article", HTMLElement.class);
}
public static HtmlContentBuilder article(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder aside() {
return htmlElement("aside", HTMLElement.class);
}
public static HtmlContentBuilder aside(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder footer() {
return htmlElement("footer", HTMLElement.class);
}
public static HtmlContentBuilder footer(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder h(int n) {
return htmlElement("h" + n, HTMLHeadingElement.class);
}
public static HtmlContentBuilder h(int n, String text) {
return h(n).textContent(text);
}
public static HtmlContentBuilder h(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder header() {
return htmlElement("header", HTMLElement.class);
}
public static HtmlContentBuilder header(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder hgroup() {
return htmlElement("hgroup", HTMLElement.class);
}
public static HtmlContentBuilder hgroup(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder nav() {
return htmlElement("nav", HTMLElement.class);
}
public static HtmlContentBuilder nav(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder section() {
return htmlElement("section", HTMLElement.class);
}
public static HtmlContentBuilder section(Element element) {
return wrapHtmlElement(cast(element));
}
// ------------------------------------------------------ text content
public static HtmlContentBuilder blockquote() {
return htmlElement("blockquote", HTMLQuoteElement.class);
}
public static HtmlContentBuilder blockquote(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder dd() {
return htmlElement("dd", HTMLElement.class);
}
public static HtmlContentBuilder dd(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder div() {
return htmlElement("div", HTMLDivElement.class);
}
public static HtmlContentBuilder div(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder dl() {
return htmlElement("dl", HTMLDListElement.class);
}
public static HtmlContentBuilder dl(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder dt() {
return htmlElement("dt", HTMLElement.class);
}
public static HtmlContentBuilder dt(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder figcaption() {
return htmlElement("figcaption", HTMLElement.class);
}
public static HtmlContentBuilder figcaption(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder figure() {
return htmlElement("figure", HTMLElement.class);
}
public static HtmlContentBuilder figure(Element element) {
return wrapHtmlElement(cast(element));
}
public static EmptyContentBuilder hr() {
return emptyElement("hr", HTMLHRElement.class);
}
public static EmptyContentBuilder hr(Element element) {
return wrapEmptyElement(cast(element));
}
public static HtmlContentBuilder li() {
return htmlElement("li", HTMLLIElement.class);
}
public static HtmlContentBuilder li(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder main() {
return htmlElement("main", HTMLElement.class);
}
public static HtmlContentBuilder main(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder ol() {
return htmlElement("ol", HTMLOListElement.class);
}
public static HtmlContentBuilder ol(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder p() {
return htmlElement("p", HTMLParagraphElement.class);
}
public static HtmlContentBuilder p(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder pre() {
return htmlElement("pre", HTMLPreElement.class);
}
public static HtmlContentBuilder pre(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder ul() {
return htmlElement("ul", HTMLUListElement.class);
}
public static HtmlContentBuilder ul(Element element) {
return wrapHtmlElement(cast(element));
}
// ------------------------------------------------------ inline text semantics
public static HtmlContentBuilder a() {
return htmlElement("a", HTMLAnchorElement.class);
}
public static HtmlContentBuilder a(String href) {
return a().attr("href", href);
}
public static HtmlContentBuilder a(String href, String target) {
return a().attr("href", href).attr("target", target);
}
public static HtmlContentBuilder a(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder abbr() {
return htmlElement("abbr", HTMLElement.class);
}
public static HtmlContentBuilder abbr(String text) {
return htmlElement("abbr", HTMLElement.class).textContent(text);
}
public static HtmlContentBuilder abbr(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder b() {
return htmlElement("b", HTMLElement.class);
}
public static HtmlContentBuilder b(String text) {
return htmlElement("b", HTMLElement.class).textContent(text);
}
public static HtmlContentBuilder b(Element element) {
return wrapHtmlElement(cast(element));
}
public static EmptyContentBuilder br() {
return emptyElement("br", HTMLBRElement.class);
}
public static EmptyContentBuilder br(Element element) {
return wrapEmptyElement(cast(element));
}
public static HtmlContentBuilder cite() {
return htmlElement("cite", HTMLElement.class);
}
public static HtmlContentBuilder cite(String text) {
return htmlElement("cite", HTMLElement.class).textContent(text);
}
public static HtmlContentBuilder cite(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder code() {
return htmlElement("code", HTMLElement.class);
}
public static HtmlContentBuilder code(String text) {
return htmlElement("code", HTMLElement.class).textContent(text);
}
public static HtmlContentBuilder code(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder dfn() {
return htmlElement("dfn", HTMLElement.class);
}
public static HtmlContentBuilder dfn(String text) {
return htmlElement("dfn", HTMLElement.class).textContent(text);
}
public static HtmlContentBuilder dfn(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder em() {
return htmlElement("em", HTMLElement.class);
}
public static HtmlContentBuilder em(String text) {
return htmlElement("em", HTMLElement.class).textContent(text);
}
public static HtmlContentBuilder em(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder i() {
return htmlElement("i", HTMLElement.class);
}
public static HtmlContentBuilder i(String text) {
return htmlElement("i", HTMLElement.class).textContent(text);
}
public static HtmlContentBuilder i(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder kbd() {
return htmlElement("kbd", HTMLElement.class);
}
public static HtmlContentBuilder kbd(String text) {
return htmlElement("kbd", HTMLElement.class).textContent(text);
}
public static HtmlContentBuilder kbd(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder mark() {
return htmlElement("mark", HTMLElement.class);
}
public static HtmlContentBuilder mark(String text) {
return htmlElement("mark", HTMLElement.class).textContent(text);
}
public static HtmlContentBuilder mark(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder q() {
return htmlElement("q", HTMLQuoteElement.class);
}
public static HtmlContentBuilder q(String text) {
return htmlElement("q", HTMLQuoteElement.class).textContent(text);
}
public static HtmlContentBuilder q(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder small() {
return htmlElement("small", HTMLElement.class);
}
public static HtmlContentBuilder small(String text) {
return htmlElement("small", HTMLElement.class).textContent(text);
}
public static HtmlContentBuilder small(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder span() {
return htmlElement("span", HTMLElement.class);
}
public static HtmlContentBuilder span(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder strong() {
return htmlElement("strong", HTMLElement.class);
}
public static HtmlContentBuilder strong(String text) {
return htmlElement("strong", HTMLElement.class).textContent(text);
}
public static HtmlContentBuilder strong(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder sub() {
return htmlElement("sub", HTMLElement.class);
}
public static HtmlContentBuilder sub(String text) {
return htmlElement("sub", HTMLElement.class).textContent(text);
}
public static HtmlContentBuilder sub(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder sup() {
return htmlElement("sup", HTMLElement.class);
}
public static HtmlContentBuilder sup(String text) {
return htmlElement("sup", HTMLElement.class).textContent(text);
}
public static HtmlContentBuilder sup(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder time() {
return htmlElement("time", HTMLElement.class);
}
public static HtmlContentBuilder time(String text) {
return htmlElement("time", HTMLElement.class).textContent(text);
}
public static HtmlContentBuilder time(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder u() {
return htmlElement("u", HTMLElement.class);
}
public static HtmlContentBuilder u(String text) {
return htmlElement("u", HTMLElement.class).textContent(text);
}
public static HtmlContentBuilder u(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder var() {
return htmlElement("var", HTMLElement.class);
}
public static HtmlContentBuilder var(String text) {
return htmlElement("var", HTMLElement.class).textContent(text);
}
public static HtmlContentBuilder var(Element element) {
return wrapHtmlElement(cast(element));
}
public static EmptyContentBuilder wbr() {
return emptyElement("wbr", HTMLElement.class);
}
public static EmptyContentBuilder wbr(Element element) {
return wrapEmptyElement(cast(element));
}
// ------------------------------------------------------ image and multimedia
public static EmptyContentBuilder area() {
return emptyElement("area", HTMLAreaElement.class);
}
public static EmptyContentBuilder area(Element element) {
return wrapEmptyElement(cast(element));
}
public static HtmlContentBuilder audio() {
return htmlElement("audio", HTMLAudioElement.class);
}
public static HtmlContentBuilder audio(Element element) {
return wrapHtmlElement(cast(element));
}
public static EmptyContentBuilder img() {
return emptyElement("img", HTMLImageElement.class);
}
public static EmptyContentBuilder img(String src) {
return emptyElement("img", HTMLImageElement.class).attr("src", src);
}
public static EmptyContentBuilder img(Element element) {
return wrapEmptyElement(cast(element));
}
public static HtmlContentBuilder map() {
return htmlElement("map", HTMLMapElement.class);
}
public static HtmlContentBuilder map(Element element) {
return wrapHtmlElement(cast(element));
}
public static EmptyContentBuilder track() {
return emptyElement("track", HTMLTrackElement.class);
}
public static EmptyContentBuilder track(Element element) {
return wrapEmptyElement(cast(element));
}
public static HtmlContentBuilder video() {
return htmlElement("video", HTMLVideoElement.class);
}
public static HtmlContentBuilder video(Element element) {
return wrapHtmlElement(cast(element));
}
// ------------------------------------------------------ embedded content
public static HtmlContentBuilder canvas() {
return htmlElement("canvas", HTMLCanvasElement.class);
}
public static HtmlContentBuilder canvas(Element element) {
return wrapHtmlElement(cast(element));
}
public static EmptyContentBuilder embed() {
return emptyElement("embed", HTMLEmbedElement.class);
}
public static EmptyContentBuilder embed(Element element) {
return wrapEmptyElement(cast(element));
}
public static HtmlContentBuilder iframe() {
return htmlElement("iframe", HTMLIFrameElement.class);
}
public static HtmlContentBuilder iframe(String src) {
return iframe().attr("src", src);
}
public static HtmlContentBuilder iframe(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder object() {
return htmlElement("object", HTMLObjectElement.class);
}
public static HtmlContentBuilder object(Element element) {
return wrapHtmlElement(cast(element));
}
public static EmptyContentBuilder param() {
return emptyElement("param", HTMLParamElement.class);
}
public static EmptyContentBuilder param(Element element) {
return wrapEmptyElement(cast(element));
}
public static EmptyContentBuilder source() {
return emptyElement("source", HTMLSourceElement.class);
}
public static EmptyContentBuilder source(Element element) {
return wrapEmptyElement(cast(element));
}
// ------------------------------------------------------ scripting
public static HtmlContentBuilder noscript() {
return htmlElement("noscript", HTMLElement.class);
}
public static HtmlContentBuilder noscript(Element element) {
return wrapHtmlElement(cast(element));
}
public static TextContentBuilder script() {
return textElement("script", HTMLScriptElement.class);
}
public static TextContentBuilder script(Element element) {
return wrapTextElement(cast(element));
}
// ------------------------------------------------------ demarcating edits
public static HtmlContentBuilder del() {
return htmlElement("del", HTMLModElement.class);
}
public static HtmlContentBuilder del(String text) {
return htmlElement("del", HTMLModElement.class).textContent(text);
}
public static HtmlContentBuilder del(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder ins() {
return htmlElement("ins", HTMLModElement.class);
}
public static HtmlContentBuilder ins(String text) {
return htmlElement("ins", HTMLModElement.class).textContent(text);
}
public static HtmlContentBuilder ins(Element element) {
return wrapHtmlElement(cast(element));
}
// ------------------------------------------------------ table content
public static HtmlContentBuilder caption() {
return htmlElement("caption", HTMLTableCaptionElement.class);
}
public static HtmlContentBuilder caption(Element element) {
return wrapHtmlElement(cast(element));
}
public static EmptyContentBuilder col() {
return emptyElement("col", HTMLTableColElement.class);
}
public static EmptyContentBuilder col(Element element) {
return wrapEmptyElement(cast(element));
}
public static HtmlContentBuilder colgroup() {
return htmlElement("colgroup", HTMLTableColElement.class);
}
public static HtmlContentBuilder colgroup(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder table() {
return htmlElement("table", HTMLTableElement.class);
}
public static HtmlContentBuilder table(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder tbody() {
return htmlElement("tbody", HTMLTableSectionElement.class);
}
public static HtmlContentBuilder tbody(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder td() {
return htmlElement("td", HTMLTableCellElement.class);
}
public static HtmlContentBuilder td(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder tfoot() {
return htmlElement("tfoot", HTMLTableSectionElement.class);
}
public static HtmlContentBuilder tfoot(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder th() {
return htmlElement("th", HTMLTableCellElement.class);
}
public static HtmlContentBuilder th(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder thead() {
return htmlElement("thead", HTMLTableSectionElement.class);
}
public static HtmlContentBuilder thead(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder tr() {
return htmlElement("tr", HTMLTableRowElement.class);
}
public static HtmlContentBuilder tr(Element element) {
return wrapHtmlElement(cast(element));
}
// ------------------------------------------------------ forms
public static HtmlContentBuilder button() {
return htmlElement("button", HTMLButtonElement.class);
}
public static HtmlContentBuilder button(String text) {
return button().textContent(text);
}
public static HtmlContentBuilder button(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder datalist() {
return htmlElement("datalist", HTMLDataListElement.class);
}
public static HtmlContentBuilder datalist(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder fieldset() {
return htmlElement("fieldset", HTMLFieldSetElement.class);
}
public static HtmlContentBuilder fieldset(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder form() {
return htmlElement("form", HTMLFormElement.class);
}
public static HtmlContentBuilder form(Element element) {
return wrapHtmlElement(cast(element));
}
public static InputBuilder input(InputType type) {
return input(type.name());
}
public static InputBuilder input(String type) {
return input(type, HTMLInputElement.class);
}
public static InputBuilder input(String type, Class jType) {
E el = createElement("input", jType);
el.type = type;
return new InputBuilder<>(el);
}
public static InputBuilder input(Element element) {
return wrapInputElement(cast(element));
}
public static HtmlContentBuilder label() {
return htmlElement("label", HTMLLabelElement.class);
}
public static HtmlContentBuilder label(String text) {
return label().textContent(text);
}
public static HtmlContentBuilder label(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder legend() {
return htmlElement("legend", HTMLLegendElement.class);
}
public static HtmlContentBuilder legend(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder meter() {
return htmlElement("meter", HTMLMeterElement.class);
}
public static HtmlContentBuilder meter(String text) {
return htmlElement("meter", HTMLMeterElement.class).textContent(text);
}
public static HtmlContentBuilder meter(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder optgroup() {
return htmlElement("optgroup", HTMLOptGroupElement.class);
}
public static HtmlContentBuilder optgroup(Element element) {
return wrapHtmlElement(cast(element));
}
public static TextContentBuilder option() {
return textElement("option", HTMLOptionElement.class);
}
public static TextContentBuilder option(String text) {
return option().textContent(text);
}
public static TextContentBuilder option(Element element) {
return wrapTextElement(cast(element));
}
public static HtmlContentBuilder output() {
return htmlElement("output", HTMLOutputElement.class);
}
public static HtmlContentBuilder output(String text) {
return htmlElement("output", HTMLOutputElement.class).textContent(text);
}
public static HtmlContentBuilder output(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder progress() {
return htmlElement("progress", HTMLProgressElement.class);
}
public static HtmlContentBuilder progress(Element element) {
return wrapHtmlElement(cast(element));
}
public static HtmlContentBuilder select() {
return htmlElement("select", HTMLSelectElement.class);
}
public static HtmlContentBuilder select(Element element) {
return wrapHtmlElement(cast(element));
}
public static TextContentBuilder textarea() {
return textElement("textarea", HTMLTextAreaElement.class);
}
public static TextContentBuilder textarea(Element element) {
return wrapTextElement(cast(element));
}
// ------------------------------------------------------ builder factories
/** Returns a builder to collect {@link HTMLElement}s. */
public static ElementsBag bag() {
return new ElementsBag();
}
/** Returns a builder for the specified empty element. */
public static EmptyContentBuilder emptyElement(String element, Class type) {
return new EmptyContentBuilder<>(createElement(element, type));
}
/** Returns a builder for the specified text element. */
public static TextContentBuilder textElement(String element, Class type) {
return new TextContentBuilder<>(createElement(element, type));
}
/** Returns a builder for the specified HTML element. */
public static HtmlContentBuilder htmlElement(String element, Class type) {
return new HtmlContentBuilder<>(createElement(element, type));
}
/** Creates the specified HTML element. */
public static E createElement(String element, Class type) {
return createElement.create(element, type);
}
// ------------------------------------------------------ wrapper methods
/** Returns a builder for the existing empty element. */
public static EmptyContentBuilder wrapEmptyElement(E element) {
return new EmptyContentBuilder<>(element);
}
/** Returns a builder for the existing text element. */
public static TextContentBuilder wrapTextElement(E element) {
return new TextContentBuilder<>(element);
}
/** Returns a builder for the existing input element. */
public static InputBuilder wrapInputElement(E element) {
return new InputBuilder<>(element);
}
/** Returns a builder for the existing HTML element. */
public static HtmlContentBuilder wrapHtmlElement(E element) {
return new HtmlContentBuilder<>(element);
}
// ------------------------------------------------------ finder methods
/** Finds all HTML elements for the given selector. */
public static Iterable findAll(Node node, By selector) {
if (node != null) {
NodeList nodes = node.querySelectorAll(selector.selector());
JsArray htmlElements = new JsArray<>();
for (int i = 0; i < nodes.length; i++) {
Element element = nodes.getAt(i);
if (element instanceof HTMLElement) {
htmlElements.push((HTMLElement) element);
}
}
return () -> iterator(htmlElements);
}
return emptyList();
}
/** Finds all HTML elements for the given selector. */
public static Iterable findAll(IsElement element, By selector) {
return findAll(element.element(), selector);
}
/** Finds a single HTML elements for the given selector. */
public static E find(Node node, By selector) {
return cast(node.querySelector(selector.selector()));
}
/** Finds a single HTML elements for the given selector. */
public static F find(IsElement element, By selector) {
return find(element.element(), selector);
}
/** Finds the closest HTML elements for the given selector. */
public static E closest(Element element, By selector) {
return cast(element.closest(selector.selector()));
}
/** Finds the closest HTML elements for the given selector. */
public static F closest(IsElement element, By selector) {
return cast(element.element().closest(selector.selector()));
}
// ------------------------------------------------------ iterator methods
/**
* Returns an iterator over the given array-like. The iterator does not support the {@link
* Iterator#remove()} operation.
*/
public static Iterator iterator(JsArrayLike data) {
return data != null ? new JsArrayLikeIterator<>(data) : emptyIterator();
}
/**
* Returns an iterator over the children of the given parent node. The iterator supports the {@link
* Iterator#remove()} operation, which removes the current node from its parent.
*/
public static Iterator iterator(Node parent) {
return parent != null ? new JsArrayNodeIterator(parent) : emptyIterator();
}
/**
* Returns an iterator over the children of the given parent element. The iterator supports the {@link
* Iterator#remove()} operation, which removes the current node from its parent.
*/
public static Iterator iterator(HTMLElement parent) {
return parent != null ? new JsArrayElementIterator(parent) : emptyIterator();
}
/**
* Returns an iterator over the children of the given parent element. The iterator supports the {@link
* Iterator#remove()} operation, which removes the current node from its parent.
*/
public static Iterator iterator(IsElement parent) {
return parent != null ? iterator(parent.element()) : emptyIterator();
}
// ------------------------------------------------------ iterable methods
/** Returns an iterable for the elements in the given array-like. */
public static Iterable elements(JsArrayLike nodes) {
return () -> iterator(nodes);
}
/** Returns an iterable for the child nodes of the given parent node. */
public static Iterable children(Node parent) {
return () -> iterator(parent);
}
/** Returns an iterable for the child elements of the given parent element. */
public static Iterable children(HTMLElement parent) {
return () -> iterator(parent);
}
/** Returns an iterable for the child elements of the given parent element. */
public static Iterable children(IsElement parent) {
return () -> iterator(parent);
}
// ------------------------------------------------------ predicates and functions
/**
* Returns a predicate for {@linkplain HTMLElement HTML elements}. Useful in streams of {@linkplain Node nodes} or
* {@linkplain Element elements}.
*/
public static