Current section
Files
Jump to
Current section
Files
src/sketch@lustre@element.erl
-module(sketch@lustre@element).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([none/0, text/1, element/4, element_/3, namespaced/5, namespaced_/4, fragment/1, keyed/2, map/2, styled/1, unstyled/2]).
-export_type([element/1]).
-opaque element(NHW) :: nothing |
{text, binary()} |
{map, fun(() -> element(NHW))} |
{element,
binary(),
binary(),
binary(),
gleam@option:option(sketch@internals@cache@cache:class()),
list(lustre@internals@vdom:attribute(NHW)),
list(element(NHW))}.
-file("/Users/doctor/Workspace/sketch/sketch_lustre/src/sketch/lustre/element.gleam", 31).
-spec none() -> element(any()).
none() ->
nothing.
-file("/Users/doctor/Workspace/sketch/sketch_lustre/src/sketch/lustre/element.gleam", 36).
-spec text(binary()) -> element(any()).
text(Content) ->
{text, Content}.
-file("/Users/doctor/Workspace/sketch/sketch_lustre/src/sketch/lustre/element.gleam", 41).
-spec element(
binary(),
sketch@internals@cache@cache:class(),
list(lustre@internals@vdom:attribute(NIB)),
list(element(NIB))
) -> element(NIB).
element(Tag, Class, Attributes, Children) ->
Class@1 = {some, Class},
{element, <<""/utf8>>, <<""/utf8>>, Tag, Class@1, Attributes, Children}.
-file("/Users/doctor/Workspace/sketch/sketch_lustre/src/sketch/lustre/element.gleam", 52).
-spec element_(
binary(),
list(lustre@internals@vdom:attribute(NIH)),
list(element(NIH))
) -> element(NIH).
element_(Tag, Attributes, Children) ->
{element, <<""/utf8>>, <<""/utf8>>, Tag, none, Attributes, Children}.
-file("/Users/doctor/Workspace/sketch/sketch_lustre/src/sketch/lustre/element.gleam", 61).
-spec namespaced(
binary(),
binary(),
sketch@internals@cache@cache:class(),
list(lustre@internals@vdom:attribute(NIN)),
list(element(NIN))
) -> element(NIN).
namespaced(Namespace, Tag, Class, Attributes, Children) ->
Class@1 = {some, Class},
{element, <<""/utf8>>, Namespace, Tag, Class@1, Attributes, Children}.
-file("/Users/doctor/Workspace/sketch/sketch_lustre/src/sketch/lustre/element.gleam", 73).
-spec namespaced_(
binary(),
binary(),
list(lustre@internals@vdom:attribute(NIT)),
list(element(NIT))
) -> element(NIT).
namespaced_(Namespace, Tag, Attributes, Children) ->
{element, <<""/utf8>>, Namespace, Tag, none, Attributes, Children}.
-file("/Users/doctor/Workspace/sketch/sketch_lustre/src/sketch/lustre/element.gleam", 83).
-spec fragment(list(element(NIZ))) -> element(NIZ).
fragment(Children) ->
Attrs = [lustre@attribute:style([{<<"display"/utf8>>, <<"contents"/utf8>>}])],
{element,
<<""/utf8>>,
<<""/utf8>>,
<<"lustre-fragment"/utf8>>,
none,
Attrs,
Children}.
-file("/Users/doctor/Workspace/sketch/sketch_lustre/src/sketch/lustre/element.gleam", 99).
-spec do_keyed(element(NJK), binary()) -> element(NJK).
do_keyed(Element, Key) ->
case Element of
nothing ->
nothing;
{text, Content} ->
{text, Content};
{map, Subtree} ->
{map, fun() -> do_keyed(Subtree(), Key) end};
{element, _, Namespace, Tag, Attributes, Children, Styles} ->
{element, Key, Namespace, Tag, Attributes, Children, Styles}
end.
-file("/Users/doctor/Workspace/sketch/sketch_lustre/src/sketch/lustre/element.gleam", 89).
-spec keyed(
fun((list(element(NJD))) -> element(NJD)),
list({binary(), element(NJD)})
) -> element(NJD).
keyed(Element, Children) ->
Element(
(gleam@list:map(
Children,
fun(_use0) ->
{Key, Child} = _use0,
do_keyed(Child, Key)
end
))
).
-file("/Users/doctor/Workspace/sketch/sketch_lustre/src/sketch/lustre/element.gleam", 110).
-spec map(element(NJN), fun((NJN) -> NJP)) -> element(NJP).
map(Element, Mapper) ->
case Element of
nothing ->
nothing;
{text, Content} ->
{text, Content};
{map, Subtree} ->
{map, fun() -> map(Subtree(), Mapper) end};
{element, Key, Namespace, Tag, Class, Attributes, Children} ->
Attributes@1 = gleam@list:map(
Attributes,
fun(_capture) -> lustre@attribute:map(_capture, Mapper) end
),
Children@1 = gleam@list:map(
Children,
fun(_capture@1) -> map(_capture@1, Mapper) end
),
{element, Key, Namespace, Tag, Class, Attributes@1, Children@1}
end.
-file("/Users/doctor/Workspace/sketch/sketch_lustre/src/sketch/lustre/element.gleam", 125).
-spec styled(lustre@internals@vdom:element(NJR)) -> element(NJR).
styled(Element) ->
case Element of
{map, Subtree} ->
{map, fun() -> styled(Subtree()) end};
{text, Content} ->
{text, Content};
{element, Key, Namespace, Tag, Attrs, Children, _, _} ->
Class = none,
{element,
Key,
Namespace,
Tag,
Class,
Attrs,
gleam@list:map(Children, fun styled/1)}
end.
-file("/Users/doctor/Workspace/sketch/sketch_lustre/src/sketch/lustre/element.gleam", 171).
-spec unstyled_children(sketch:style_sheet(), list(element(NJX))) -> {sketch:style_sheet(),
list(lustre@internals@vdom:element(NJX))}.
unstyled_children(Stylesheet, Children) ->
gleam@list:fold(
lists:reverse(Children),
{Stylesheet, []},
fun(Acc, Child) ->
{Stylesheet@1, Children@1} = Acc,
{Stylesheet@2, Child@1} = unstyled(Stylesheet@1, Child),
{Stylesheet@2, [Child@1 | Children@1]}
end
).
-file("/Users/doctor/Workspace/sketch/sketch_lustre/src/sketch/lustre/element.gleam", 141).
-spec unstyled(sketch:style_sheet(), element(NJU)) -> {sketch:style_sheet(),
lustre@internals@vdom:element(NJU)}.
unstyled(Stylesheet, Element) ->
case Element of
nothing ->
{Stylesheet, lustre@element:none()};
{text, Content} ->
{Stylesheet, lustre@element:text(Content)};
{map, Subtree} ->
unstyled(Stylesheet, Subtree());
{element, Key, Namespace, Tag, Class, Attributes, Children} ->
Class@1 = gleam@option:map(
Class,
fun(_capture) -> sketch:class_name(_capture, Stylesheet) end
),
Class_name = gleam@option:map(Class@1, fun gleam@pair:second/1),
Stylesheet@1 = begin
_pipe = gleam@option:map(Class@1, fun gleam@pair:first/1),
gleam@option:unwrap(_pipe, Stylesheet)
end,
{Stylesheet@2, Children@1} = unstyled_children(
Stylesheet@1,
Children
),
Attributes@1 = case Class_name of
none ->
Attributes;
{some, Class_name@1} ->
Class_name@2 = lustre@attribute:class(Class_name@1),
[Class_name@2 | Attributes]
end,
{Stylesheet@2,
case lustre@element:element(Tag, Attributes@1, Children@1) of
{element, _, _, T, A, C, S, V} ->
{element, Key, Namespace, T, A, C, S, V};
E ->
E
end}
end.