-module(lustre@element). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function]). -export([element/3, namespaced/4, text/1, map/2, to_string/1, to_string_builder/1]). -export_type([element/1]). -opaque element(FPI) :: {text, binary()} | {element, binary(), list(lustre@attribute:attribute(FPI)), list(element(FPI))} | {element_ns, binary(), list(lustre@attribute:attribute(FPI)), list(element(FPI)), binary()}. -spec element( binary(), list(lustre@attribute:attribute(FPJ)), list(element(FPJ)) ) -> element(FPJ). element(Tag, Attrs, Children) -> {element, Tag, Attrs, Children}. -spec namespaced( binary(), binary(), list(lustre@attribute:attribute(FPP)), list(element(FPP)) ) -> element(FPP). namespaced(Namespace, Tag, Attrs, Children) -> {element_ns, Tag, Attrs, Children, Namespace}. -spec text(binary()) -> element(any()). text(Content) -> {text, Content}. -spec escape(binary(), binary()) -> binary(). escape(Escaped, Content) -> case Content of <<"<"/utf8, Rest/binary>> -> escape(<>, Rest); <<">"/utf8, Rest@1/binary>> -> escape(<>, Rest@1); <<"&"/utf8, Rest@2/binary>> -> escape(<>, Rest@2); <<"\""/utf8, Rest@3/binary>> -> escape(<>, Rest@3); <<"'"/utf8, Rest@4/binary>> -> escape(<>, Rest@4); _ -> case gleam@string:pop_grapheme(Content) of {ok, {X, Xs}} -> escape(<>, Xs); {error, _} -> Escaped end end. -spec map(element(FPX), fun((FPX) -> FPZ)) -> element(FPZ). map(Element, F) -> case Element of {text, Content} -> {text, Content}; {element, Tag, Attrs, Children} -> {element, Tag, gleam@list:map( Attrs, fun(_capture) -> lustre@attribute:map(_capture, F) end ), gleam@list:map( Children, fun(_capture@1) -> map(_capture@1, F) end )}; {element_ns, Tag@1, Attrs@1, Children@1, Namespace} -> {element_ns, Tag@1, gleam@list:map( Attrs@1, fun(_capture@2) -> lustre@attribute:map(_capture@2, F) end ), gleam@list:map( Children@1, fun(_capture@3) -> map(_capture@3, F) end ), Namespace} end. -spec attrs_to_string_builder(list(lustre@attribute:attribute(any()))) -> {gleam@string_builder:string_builder(), binary()}. attrs_to_string_builder(Attrs) -> {Html@1, Class@1, Style@1, Inner_html@1} = begin Init = {gleam@string_builder:new(), <<""/utf8>>, <<""/utf8>>, <<""/utf8>>}, gleam@list:fold( Attrs, Init, fun(_use0, Attr) -> {Html, Class, Style, Inner_html} = _use0, case lustre@attribute:to_string_parts(Attr) of {ok, {<<"dangerous-unescaped-html"/utf8>>, Val}} -> {Html, Class, Style, <>}; {ok, {<<"class"/utf8>>, Val@1}} when Class =:= <<""/utf8>> -> {Html, Val@1, Style, Inner_html}; {ok, {<<"class"/utf8>>, Val@2}} -> {Html, <<<>/binary, Val@2/binary>>, Style, Inner_html}; {ok, {<<"style"/utf8>>, Val@3}} when Style =:= <<""/utf8>> -> {Html, Class, Val@3, Inner_html}; {ok, {<<"style"/utf8>>, Val@4}} -> {Html, Class, <<<