-module(lustre@element). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([element/3, namespaced/4, advanced/6, text/1, none/0, map/2, to_string/1, to_string_builder/1]). -export_type([element/1]). -opaque element(HUZ) :: {text, binary()} | {element, binary(), binary(), list(lustre@attribute:attribute(HUZ)), list(element(HUZ)), boolean(), boolean()}. -spec element( binary(), list(lustre@attribute:attribute(HVA)), list(element(HVA)) ) -> element(HVA). element(Tag, Attrs, Children) -> case Tag of <<"area"/utf8>> -> {element, <<""/utf8>>, Tag, Attrs, [], false, true}; <<"base"/utf8>> -> {element, <<""/utf8>>, Tag, Attrs, [], false, true}; <<"br"/utf8>> -> {element, <<""/utf8>>, Tag, Attrs, [], false, true}; <<"col"/utf8>> -> {element, <<""/utf8>>, Tag, Attrs, [], false, true}; <<"embed"/utf8>> -> {element, <<""/utf8>>, Tag, Attrs, [], false, true}; <<"hr"/utf8>> -> {element, <<""/utf8>>, Tag, Attrs, [], false, true}; <<"img"/utf8>> -> {element, <<""/utf8>>, Tag, Attrs, [], false, true}; <<"input"/utf8>> -> {element, <<""/utf8>>, Tag, Attrs, [], false, true}; <<"link"/utf8>> -> {element, <<""/utf8>>, Tag, Attrs, [], false, true}; <<"meta"/utf8>> -> {element, <<""/utf8>>, Tag, Attrs, [], false, true}; <<"param"/utf8>> -> {element, <<""/utf8>>, Tag, Attrs, [], false, true}; <<"source"/utf8>> -> {element, <<""/utf8>>, Tag, Attrs, [], false, true}; <<"track"/utf8>> -> {element, <<""/utf8>>, Tag, Attrs, [], false, true}; <<"wbr"/utf8>> -> {element, <<""/utf8>>, Tag, Attrs, [], false, true}; _ -> {element, <<""/utf8>>, Tag, Attrs, Children, false, false} end. -spec namespaced( binary(), binary(), list(lustre@attribute:attribute(HVG)), list(element(HVG)) ) -> element(HVG). namespaced(Namespace, Tag, Attrs, Children) -> {element, Namespace, Tag, Attrs, Children, false, false}. -spec advanced( binary(), binary(), list(lustre@attribute:attribute(HVM)), list(element(HVM)), boolean(), boolean() ) -> element(HVM). advanced(Namespace, Tag, Attrs, Children, Self_closing, Void) -> {element, Tag, Namespace, Attrs, Children, Self_closing, Void}. -spec text(binary()) -> element(any()). text(Content) -> {text, Content}. -spec none() -> element(any()). none() -> {text, <<""/utf8>>}. -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(HVW), fun((HVW) -> HVY)) -> element(HVY). map(Element, F) -> case Element of {text, Content} -> {text, Content}; {element, Namespace, Tag, Attrs, Children, Self_closing, Void} -> {element, Namespace, 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 ), Self_closing, Void} 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, <<<