Current section
Files
Jump to
Current section
Files
src/sketch_css@module@stylesheet.erl
-module(sketch_css@module@stylesheet).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-define(FILEPATH, "src/sketch_css/module/stylesheet.gleam").
-export([convert/2]).
-export_type([value/0, style_sheet/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(false).
-type value() :: {int_value, integer()} |
{float_value, float()} |
{string_value, binary()} |
{length_value, sketch@css@length:length()} |
{class_value, sketch@internals@cache@cache:class()} |
{angle_value, sketch@css@angle:angle()} |
{transform_value, sketch@css@transform:transform()} |
{style_value, sketch@internals@cache@cache:style()} |
{list_value, list(value())} |
{tuple_value, list(value())} |
{media_value, sketch@css@media:'query'()} |
{at_rule_value, sketch@internals@cache@cache:at_rule()} |
{keyframe_value, sketch@css@keyframe:keyframe()} |
{font_face_value, sketch@css@font_face:font_face()}.
-type style_sheet() :: {style_sheet,
list({binary(), value()}),
list({binary(), sketch@internals@cache@cache:class()}),
list(sketch@internals@cache@cache:at_rule()),
list({binary(), sketch@internals@cache@cache:style()})}.
-file("src/sketch_css/module/stylesheet.gleam", 202).
?DOC(false).
-spec add_function_parameters(glance:function_(), style_sheet()) -> style_sheet().
add_function_parameters(Function, Env) ->
gleam@list:fold(
erlang:element(4, Function),
Env,
fun(Env@1, Parameter) -> case erlang:element(3, Parameter) of
{discarded, _} ->
Env@1;
{named, Argument} ->
Var = <<<<"var(--"/utf8, Argument/binary>>/binary,
")"/utf8>>,
Var@1 = {string_value, Var},
Environment = [{Argument, Var@1} | erlang:element(2, Env@1)],
_record = Env@1,
{style_sheet,
Environment,
erlang:element(3, _record),
erlang:element(4, _record),
erlang:element(5, _record)}
end end
).
-file("src/sketch_css/module/stylesheet.gleam", 254).
?DOC(false).
-spec convert_length(
binary(),
list(glance:field(glance:expression())),
style_sheet(),
list({binary(), style_sheet()})
) -> {ok, value()} | {error, nil}.
convert_length(Label, Arguments, Env, Modules) ->
case Arguments of
[{unlabelled_field, Item}] ->
gleam@result:'try'(
convert_expression(Item, Env, Modules),
fun(Value) -> case {Label, Value} of
{<<"px"/utf8>>, {int_value, I}} ->
{ok, {length_value, sketch@css@length:px(I)}};
{<<"px_"/utf8>>, {float_value, F}} ->
{ok, {length_value, sketch@css@length:px_(F)}};
{<<"cm"/utf8>>, {int_value, I@1}} ->
{ok, {length_value, sketch@css@length:cm(I@1)}};
{<<"mm"/utf8>>, {int_value, I@2}} ->
{ok, {length_value, sketch@css@length:mm(I@2)}};
{<<"q"/utf8>>, {int_value, I@3}} ->
{ok, {length_value, sketch@css@length:q(I@3)}};
{<<"in"/utf8>>, {int_value, I@4}} ->
{ok, {length_value, sketch@css@length:in(I@4)}};
{<<"pc"/utf8>>, {int_value, I@5}} ->
{ok, {length_value, sketch@css@length:pc(I@5)}};
{<<"cm_"/utf8>>, {float_value, F@1}} ->
{ok, {length_value, sketch@css@length:cm_(F@1)}};
{<<"mm_"/utf8>>, {float_value, F@2}} ->
{ok, {length_value, sketch@css@length:mm_(F@2)}};
{<<"q_"/utf8>>, {float_value, F@3}} ->
{ok, {length_value, sketch@css@length:q_(F@3)}};
{<<"in_"/utf8>>, {float_value, F@4}} ->
{ok, {length_value, sketch@css@length:in_(F@4)}};
{<<"pc_"/utf8>>, {float_value, F@5}} ->
{ok, {length_value, sketch@css@length:pc_(F@5)}};
{<<"pt"/utf8>>, {int_value, I@6}} ->
{ok, {length_value, sketch@css@length:pt(I@6)}};
{<<"pt_"/utf8>>, {float_value, F@6}} ->
{ok, {length_value, sketch@css@length:pt_(F@6)}};
{<<"percent"/utf8>>, {int_value, I@7}} ->
{ok, {length_value, sketch@css@length:percent(I@7)}};
{<<"percent_"/utf8>>, {float_value, F@7}} ->
{ok,
{length_value, sketch@css@length:percent_(F@7)}};
{<<"vh"/utf8>>, {int_value, I@8}} ->
{ok, {length_value, sketch@css@length:vh(I@8)}};
{<<"vh_"/utf8>>, {float_value, F@8}} ->
{ok, {length_value, sketch@css@length:vh_(F@8)}};
{<<"vw"/utf8>>, {int_value, I@9}} ->
{ok, {length_value, sketch@css@length:vw(I@9)}};
{<<"vw_"/utf8>>, {float_value, F@9}} ->
{ok, {length_value, sketch@css@length:vw_(F@9)}};
{<<"em"/utf8>>, {float_value, F@10}} ->
{ok, {length_value, sketch@css@length:em(F@10)}};
{<<"rem"/utf8>>, {float_value, F@11}} ->
{ok, {length_value, sketch@css@length:'rem'(F@11)}};
{<<"lh"/utf8>>, {float_value, F@12}} ->
{ok, {length_value, sketch@css@length:lh(F@12)}};
{<<"rlh"/utf8>>, {float_value, F@13}} ->
{ok, {length_value, sketch@css@length:rlh(F@13)}};
{<<"ch"/utf8>>, {float_value, F@14}} ->
{ok, {length_value, sketch@css@length:ch(F@14)}};
{<<"cap"/utf8>>, {float_value, F@15}} ->
{ok, {length_value, sketch@css@length:cap(F@15)}};
{<<"ex"/utf8>>, {float_value, F@16}} ->
{ok, {length_value, sketch@css@length:ex(F@16)}};
{<<"ic"/utf8>>, {float_value, F@17}} ->
{ok, {length_value, sketch@css@length:ic(F@17)}};
{<<"rcap"/utf8>>, {float_value, F@18}} ->
{ok, {length_value, sketch@css@length:rcap(F@18)}};
{<<"rch"/utf8>>, {float_value, F@19}} ->
{ok, {length_value, sketch@css@length:rch(F@19)}};
{<<"rex"/utf8>>, {float_value, F@20}} ->
{ok, {length_value, sketch@css@length:rex(F@20)}};
{<<"ric"/utf8>>, {float_value, F@21}} ->
{ok, {length_value, sketch@css@length:ric(F@21)}};
{<<"vmax"/utf8>>, {int_value, F@22}} ->
{ok, {length_value, sketch@css@length:vmax(F@22)}};
{<<"vmax_"/utf8>>, {float_value, F@23}} ->
{ok, {length_value, sketch@css@length:vmax_(F@23)}};
{<<"vmin"/utf8>>, {int_value, F@24}} ->
{ok, {length_value, sketch@css@length:vmin(F@24)}};
{<<"vmin_"/utf8>>, {float_value, F@25}} ->
{ok, {length_value, sketch@css@length:vmin_(F@25)}};
{<<"vb"/utf8>>, {int_value, F@26}} ->
{ok, {length_value, sketch@css@length:vb(F@26)}};
{<<"vb_"/utf8>>, {float_value, F@27}} ->
{ok, {length_value, sketch@css@length:vb_(F@27)}};
{<<"vi"/utf8>>, {int_value, F@28}} ->
{ok, {length_value, sketch@css@length:vi(F@28)}};
{<<"vi_"/utf8>>, {float_value, F@29}} ->
{ok, {length_value, sketch@css@length:vi_(F@29)}};
{<<"cqw"/utf8>>, {int_value, F@30}} ->
{ok, {length_value, sketch@css@length:cqw(F@30)}};
{<<"cqw_"/utf8>>, {float_value, F@31}} ->
{ok, {length_value, sketch@css@length:cqw_(F@31)}};
{<<"cqh"/utf8>>, {int_value, F@32}} ->
{ok, {length_value, sketch@css@length:cqh(F@32)}};
{<<"cqh_"/utf8>>, {float_value, F@33}} ->
{ok, {length_value, sketch@css@length:cqh_(F@33)}};
{<<"cqi"/utf8>>, {int_value, F@34}} ->
{ok, {length_value, sketch@css@length:cqi(F@34)}};
{<<"cqi_"/utf8>>, {float_value, F@35}} ->
{ok, {length_value, sketch@css@length:cqi_(F@35)}};
{<<"cqb"/utf8>>, {int_value, F@36}} ->
{ok, {length_value, sketch@css@length:cqb(F@36)}};
{<<"cqb_"/utf8>>, {float_value, F@37}} ->
{ok, {length_value, sketch@css@length:cqb_(F@37)}};
{<<"cqmin"/utf8>>, {int_value, F@38}} ->
{ok, {length_value, sketch@css@length:cqmin(F@38)}};
{<<"cqmin_"/utf8>>, {float_value, F@39}} ->
{ok, {length_value, sketch@css@length:cqmin_(F@39)}};
{<<"cqmax"/utf8>>, {int_value, F@40}} ->
{ok, {length_value, sketch@css@length:cqmax(F@40)}};
{<<"cqmax_"/utf8>>, {float_value, F@41}} ->
{ok, {length_value, sketch@css@length:cqmax_(F@41)}};
{_, _} ->
{error, nil}
end end
);
_ ->
{error, nil}
end.
-file("src/sketch_css/module/stylesheet.gleam", 77).
?DOC(false).
-spec convert_expression(
glance:expression(),
style_sheet(),
list({binary(), style_sheet()})
) -> {ok, value()} | {error, nil}.
convert_expression(Value, Env, Modules) ->
case Value of
{int, Int} ->
_pipe = gleam_stdlib:parse_int(Int),
gleam@result:map(_pipe, fun(Field@0) -> {int_value, Field@0} end);
{float, Float} ->
_pipe@1 = gleam_stdlib:parse_float(Float),
gleam@result:map(
_pipe@1,
fun(Field@0) -> {float_value, Field@0} end
);
{string, String} ->
{ok, {string_value, String}};
{variable, Variable} ->
gleam@list:key_find(erlang:element(2, Env), Variable);
{list, Elements, _} ->
_pipe@2 = Elements,
_pipe@3 = gleam@list:try_map(
_pipe@2,
fun(_capture) -> convert_expression(_capture, Env, Modules) end
),
gleam@result:map(_pipe@3, fun(Field@0) -> {list_value, Field@0} end);
{tuple, Expressions} ->
_pipe@4 = Expressions,
_pipe@5 = gleam@list:try_map(
_pipe@4,
fun(_capture@1) ->
convert_expression(_capture@1, Env, Modules)
end
),
gleam@result:map(
_pipe@5,
fun(Field@0) -> {tuple_value, Field@0} end
);
{tuple_index, Tuple, Index} ->
gleam@result:'try'(
convert_expression(Tuple, Env, Modules),
fun(Value@1) -> case Value@1 of
{tuple_value, Elements@1} ->
sketch_css@utils:at(Elements@1, Index);
_ ->
{error, nil}
end end
);
{field_access, {variable, Module}, Label} ->
gleam@result:'try'(
gleam@list:key_find(Modules, Module),
fun(Module@1) -> _pipe@6 = erlang:element(2, Module@1),
_pipe@7 = gleam@list:key_find(_pipe@6, Label),
_pipe@10 = gleam@result:try_recover(
_pipe@7,
fun(_) -> _pipe@8 = erlang:element(5, Module@1),
_pipe@9 = gleam@list:key_find(_pipe@8, Label),
gleam@result:map(
_pipe@9,
fun(Field@0) -> {style_value, Field@0} end
) end
),
gleam@result:try_recover(
_pipe@10,
fun(_) -> _pipe@11 = erlang:element(3, Module@1),
_pipe@12 = gleam@list:key_find(_pipe@11, Label),
gleam@result:map(
_pipe@12,
fun(Field@0) -> {class_value, Field@0} end
) end
) end
);
{call, Function, Arguments} ->
case Function of
{field_access, {variable, <<"sketch/css"/utf8>>}, Label@1} ->
case Label@1 of
<<"class"/utf8>> ->
convert_class_call(Arguments, Env, Modules);
<<"compose"/utf8>> ->
convert_compose_call(Arguments, Env, Modules);
<<"media"/utf8>> ->
convert_media_call(Arguments, Env, Modules);
<<"selector"/utf8>> ->
convert_selector_call(Arguments, Env, Modules);
<<"property"/utf8>> ->
convert_property_call(Arguments, Env, Modules);
<<"important"/utf8>> ->
convert_important_call(Arguments, Env, Modules);
<<"transform"/utf8>> ->
convert_transform_call(Arguments, Env, Modules);
<<"keyframes"/utf8>> ->
convert_keyframes_call(Arguments, Env, Modules);
<<"font_face"/utf8>> ->
convert_font_face_call(Arguments, Env, Modules);
Label@2 ->
convert_generic_call(
Label@2,
Arguments,
Env,
Modules
)
end;
{field_access, {variable, <<"sketch/css/svg"/utf8>>}, Label@3} ->
convert_generic_call(Label@3, Arguments, Env, Modules);
{field_access,
{variable, <<"sketch/css/transform"/utf8>>},
Label@4} ->
convert_transform(Label@4, Arguments, Env, Modules);
{field_access, {variable, <<"sketch/css/media"/utf8>>}, Label@5} ->
convert_media(Label@5, Arguments, Env, Modules);
{field_access,
{variable, <<"sketch/css/length"/utf8>>},
Label@6} ->
convert_length(Label@6, Arguments, Env, Modules);
{field_access, {variable, <<"sketch/css/angle"/utf8>>}, Label@7} ->
convert_angle(Label@7, Arguments, Env, Modules);
{field_access,
{variable, <<"sketch/css/keyframe"/utf8>>},
Label@8} ->
convert_keyframe(Label@8, Arguments, Env, Modules);
{field_access,
{variable, <<"sketch/css/font_face"/utf8>>},
Label@9} ->
convert_font_face(Label@9, Arguments, Env, Modules);
{field_access, {variable, Container}, Label@10} ->
Stylesheet = gleam@list:key_find(Modules, Container),
Classes = gleam@result:map(
Stylesheet,
fun(S) -> erlang:element(3, S) end
),
Styles = gleam@result:map(
Stylesheet,
fun(S@1) -> erlang:element(5, S@1) end
),
_pipe@13 = Classes,
_pipe@14 = gleam@result:then(
_pipe@13,
fun(_capture@2) ->
gleam@list:key_find(_capture@2, Label@10)
end
),
_pipe@15 = gleam@result:map(
_pipe@14,
fun(Field@0) -> {class_value, Field@0} end
),
gleam@result:try_recover(
_pipe@15,
fun(_) -> _pipe@16 = Styles,
_pipe@17 = gleam@result:then(
_pipe@16,
fun(_capture@3) ->
gleam@list:key_find(_capture@3, Label@10)
end
),
gleam@result:map(
_pipe@17,
fun(Field@0) -> {style_value, Field@0} end
) end
);
{variable, Label@11} ->
_pipe@18 = erlang:element(3, Env),
_pipe@19 = gleam@list:key_find(_pipe@18, Label@11),
_pipe@20 = gleam@result:map(
_pipe@19,
fun(Field@0) -> {class_value, Field@0} end
),
gleam@result:try_recover(
_pipe@20,
fun(_) -> _pipe@21 = erlang:element(5, Env),
_pipe@22 = gleam@list:key_find(_pipe@21, Label@11),
gleam@result:map(
_pipe@22,
fun(Field@0) -> {style_value, Field@0} end
) end
);
_ ->
{error, nil}
end;
_ ->
{error, nil}
end.
-file("src/sketch_css/module/stylesheet.gleam", 48).
?DOC(false).
-spec init_environment(
list(glance:definition(glance:constant())),
list({binary(), style_sheet()})
) -> list({binary(), value()}).
init_environment(Constants, Modules) ->
gleam@list:fold(
Constants,
[],
fun(Env, Constant) ->
_pipe = erlang:element(5, erlang:element(3, Constant)),
_pipe@1 = convert_expression(
_pipe,
{style_sheet, Env, [], [], []},
Modules
),
_pipe@2 = gleam@result:map(
_pipe@1,
fun(_capture) ->
gleam@list:key_set(
Env,
erlang:element(2, erlang:element(3, Constant)),
_capture
)
end
),
gleam@result:unwrap(_pipe@2, Env)
end
).
-file("src/sketch_css/module/stylesheet.gleam", 215).
?DOC(false).
-spec convert_body(
glance:function_(),
style_sheet(),
list({binary(), style_sheet()})
) -> style_sheet().
convert_body(Function, Env, Modules) ->
gleam@list:fold(
erlang:element(6, Function),
Env,
fun(Env@1, Statement) -> case Statement of
{assignment, _, {pattern_variable, Name}, _, Value} ->
case convert_expression(Value, Env@1, Modules) of
{error, _} ->
Env@1;
{ok, Value@1} ->
_pipe = gleam@list:key_set(
erlang:element(2, Env@1),
Name,
Value@1
),
(fun(E) -> _record = Env@1,
{style_sheet,
E,
erlang:element(3, _record),
erlang:element(4, _record),
erlang:element(5, _record)} end)(_pipe)
end;
{expression, Expression} ->
case convert_expression(Expression, Env@1, Modules) of
{ok, {class_value, Class}} ->
Classes = [{erlang:element(2, Function), Class} |
erlang:element(3, Env@1)],
_record@1 = Env@1,
{style_sheet,
erlang:element(2, _record@1),
Classes,
erlang:element(4, _record@1),
erlang:element(5, _record@1)};
{ok, {style_value, Style}} ->
Styles = [{erlang:element(2, Function), Style} |
erlang:element(5, Env@1)],
_record@2 = Env@1,
{style_sheet,
erlang:element(2, _record@2),
erlang:element(3, _record@2),
erlang:element(4, _record@2),
Styles};
{ok, {at_rule_value, Rule}} ->
At_rules = [Rule | erlang:element(4, Env@1)],
_record@3 = Env@1,
{style_sheet,
erlang:element(2, _record@3),
erlang:element(3, _record@3),
At_rules,
erlang:element(5, _record@3)};
_ ->
Env@1
end;
_ ->
Env@1
end end
).
-file("src/sketch_css/module/stylesheet.gleam", 194).
?DOC(false).
-spec convert_functions(list({binary(), style_sheet()})) -> fun((style_sheet(), glance:function_()) -> style_sheet()).
convert_functions(Modules) ->
fun(Env, Function) ->
gleam@bool:guard(
erlang:element(3, Function) =:= private,
Env,
fun() ->
Env@1 = add_function_parameters(Function, Env),
convert_body(Function, Env@1, Modules)
end
)
end.
-file("src/sketch_css/module/stylesheet.gleam", 59).
?DOC(false).
-spec convert(list({binary(), style_sheet()}), {binary(), glance:module_()}) -> list({binary(),
style_sheet()}).
convert(Modules, Module) ->
{Name, {module, _, _, _, Constants, Functions}} = Module,
Environment = init_environment(Constants, Modules),
Convert_fn = convert_functions(Modules),
Stylesheet = begin
_pipe = Functions,
_pipe@1 = gleam@list:map(
_pipe,
fun(Function) -> erlang:element(3, Function) end
),
_pipe@2 = gleam@list:sort(
_pipe@1,
fun sketch_css@module@functions:is_dependent/2
),
gleam@list:fold(
_pipe@2,
{style_sheet, Environment, [], [], []},
Convert_fn
)
end,
[{Name,
begin
_record = Stylesheet,
{style_sheet,
Environment,
erlang:element(3, _record),
erlang:element(4, _record),
erlang:element(5, _record)}
end} |
Modules].
-file("src/sketch_css/module/stylesheet.gleam", 323).
?DOC(false).
-spec convert_font_face(
binary(),
list(glance:field(glance:expression())),
style_sheet(),
list({binary(), style_sheet()})
) -> {ok, value()} | {error, nil}.
convert_font_face(Label, Arguments, Env, Modules) ->
case Arguments of
[{unlabelled_field, Item}] ->
gleam@result:'try'(
convert_expression(Item, Env, Modules),
fun(Value) -> _pipe = case {Label, Value} of
{<<"ascent_override"/utf8>>, {float_value, F}} ->
{ok, sketch@css@font_face:ascent_override(F)};
{<<"descent_override"/utf8>>, {float_value, F@1}} ->
{ok, sketch@css@font_face:descent_override(F@1)};
{<<"font_display"/utf8>>, {string_value, F@2}} ->
{ok, sketch@css@font_face:font_display(F@2)};
{<<"font_family"/utf8>>, {string_value, F@3}} ->
{ok, sketch@css@font_face:font_family(F@3)};
{<<"font_stretch"/utf8>>, {string_value, F@4}} ->
{ok, sketch@css@font_face:font_stretch(F@4)};
{<<"font_style"/utf8>>, {string_value, F@5}} ->
{ok, sketch@css@font_face:font_style(F@5)};
{<<"font_weight"/utf8>>, {string_value, F@6}} ->
{ok, sketch@css@font_face:font_weight(F@6)};
{<<"font_feature_settings"/utf8>>, {string_value, F@7}} ->
{ok,
sketch@css@font_face:font_feature_settings(F@7)};
{<<"font_variation_settings"/utf8>>,
{string_value, F@8}} ->
{ok,
sketch@css@font_face:font_variation_settings(
F@8
)};
{<<"line_gap_override"/utf8>>, {float_value, F@9}} ->
{ok, sketch@css@font_face:line_gap_override(F@9)};
{<<"size_adjust"/utf8>>, {float_value, F@10}} ->
{ok, sketch@css@font_face:size_adjust(F@10)};
{<<"src"/utf8>>, {string_value, F@11}} ->
{ok, sketch@css@font_face:src(F@11)};
{<<"unicode_range"/utf8>>, {string_value, F@12}} ->
{ok, sketch@css@font_face:unicode_range(F@12)};
{_, _} ->
{error, nil}
end,
gleam@result:map(
_pipe,
fun(Field@0) -> {font_face_value, Field@0} end
) end
);
_ ->
{error, nil}
end.
-file("src/sketch_css/module/stylesheet.gleam", 356).
?DOC(false).
-spec convert_angle(
binary(),
list(glance:field(glance:expression())),
style_sheet(),
list({binary(), style_sheet()})
) -> {ok, value()} | {error, nil}.
convert_angle(Label, Arguments, Env, Modules) ->
case Arguments of
[{unlabelled_field, Item}] ->
gleam@result:'try'(
convert_expression(Item, Env, Modules),
fun(Value) -> case {Label, Value} of
{<<"deg"/utf8>>, {float_value, F}} ->
{ok, {angle_value, sketch@css@angle:deg(F)}};
{<<"rad"/utf8>>, {float_value, F@1}} ->
{ok, {angle_value, sketch@css@angle:rad(F@1)}};
{<<"grad"/utf8>>, {float_value, F@2}} ->
{ok, {angle_value, sketch@css@angle:grad(F@2)}};
{<<"turn"/utf8>>, {float_value, F@3}} ->
{ok, {angle_value, sketch@css@angle:turn(F@3)}};
{_, _} ->
{error, nil}
end end
);
_ ->
{error, nil}
end.
-file("src/sketch_css/module/stylesheet.gleam", 377).
?DOC(false).
-spec convert_keyframe(
binary(),
list(glance:field(glance:expression())),
style_sheet(),
list({binary(), style_sheet()})
) -> {ok, value()} | {error, nil}.
convert_keyframe(Label, Arguments, Env, Modules) ->
case Arguments of
[{unlabelled_field, {list, Items, _}}] ->
Values = gleam@list:try_map(
Items,
fun(_capture) -> convert_expression(_capture, Env, Modules) end
),
gleam@result:'try'(
Values,
fun(Values@1) ->
Values@2 = gleam@list:filter_map(
Values@1,
fun(Value) -> case Value of
{style_value, V} ->
{ok, V};
_ ->
{error, nil}
end end
),
case Label of
<<"from"/utf8>> ->
{ok,
{keyframe_value,
sketch@css@keyframe:from(Values@2)}};
<<"to"/utf8>> ->
{ok,
{keyframe_value,
sketch@css@keyframe:to(Values@2)}};
_ ->
{error, nil}
end
end
);
[{unlabelled_field, Item}, {unlabelled_field, {list, Items@1, _}}] ->
gleam@result:'try'(
convert_expression(Item, Env, Modules),
fun(Item@1) ->
Values@3 = gleam@list:try_map(
Items@1,
fun(_capture@1) ->
convert_expression(_capture@1, Env, Modules)
end
),
gleam@result:'try'(
Values@3,
fun(Values@4) -> case {Label, Item@1} of
{<<"at"/utf8>>, {int_value, F}} ->
_pipe = sketch@css@keyframe:at(
F,
begin
gleam@list:filter_map(
Values@4,
fun(Value@1) -> case Value@1 of
{style_value, V@1} ->
{ok, V@1};
_ ->
{error, nil}
end end
)
end
),
_pipe@1 = {keyframe_value, _pipe},
{ok, _pipe@1};
{_, _} ->
{error, nil}
end end
)
end
);
_ ->
{error, nil}
end.
-file("src/sketch_css/module/stylesheet.gleam", 423).
?DOC(false).
-spec convert_transform(
binary(),
list(glance:field(glance:expression())),
style_sheet(),
list({binary(), style_sheet()})
) -> {ok, value()} | {error, nil}.
convert_transform(Label, Arguments, Env, Modules) ->
_pipe = case Arguments of
[{unlabelled_field, {tuple, Items}}] ->
Items@1 = gleam@list:try_map(
Items,
fun(_capture) -> convert_expression(_capture, Env, Modules) end
),
gleam@result:'try'(Items@1, fun(Items@2) -> case {Label, Items@2} of
{<<"matrix_3d"/utf8>>,
[{tuple_value,
[{float_value, A1},
{float_value, B1},
{float_value, C1},
{float_value, D1}]},
{tuple_value,
[{float_value, A2},
{float_value, B2},
{float_value, C2},
{float_value, D2}]},
{tuple_value,
[{float_value, A3},
{float_value, B3},
{float_value, C3},
{float_value, D3}]},
{tuple_value,
[{float_value, A4},
{float_value, B4},
{float_value, C4},
{float_value, D4}]}]} ->
{ok,
sketch@css@transform:matrix_3d(
{{A1, B1, C1, D1},
{A2, B2, C2, D2},
{A3, B3, C3, D3},
({A4, B4, C4, D4})}
)};
{_, _} ->
{error, nil}
end end);
[{unlabelled_field, Item}] ->
gleam@result:'try'(
convert_expression(Item, Env, Modules),
fun(Value) -> case {Label, Value} of
{<<"translate_x"/utf8>>, {length_value, F}} ->
{ok, sketch@css@transform:translate_x(F)};
{<<"translate_y"/utf8>>, {length_value, F@1}} ->
{ok, sketch@css@transform:translate_y(F@1)};
{<<"translate_z"/utf8>>, {length_value, F@2}} ->
{ok, sketch@css@transform:translate_z(F@2)};
{<<"scale_x"/utf8>>, {float_value, F@3}} ->
{ok, sketch@css@transform:scale_x(F@3)};
{<<"scale_y"/utf8>>, {float_value, F@4}} ->
{ok, sketch@css@transform:scale_y(F@4)};
{<<"scale_z"/utf8>>, {float_value, F@5}} ->
{ok, sketch@css@transform:scale_z(F@5)};
{<<"rotate"/utf8>>, {angle_value, F@6}} ->
{ok, sketch@css@transform:rotate(F@6)};
{<<"rotate_x"/utf8>>, {angle_value, F@7}} ->
{ok, sketch@css@transform:rotate_x(F@7)};
{<<"rotate_y"/utf8>>, {angle_value, F@8}} ->
{ok, sketch@css@transform:rotate_y(F@8)};
{<<"rotate_z"/utf8>>, {angle_value, F@9}} ->
{ok, sketch@css@transform:rotate_z(F@9)};
{<<"skew_x"/utf8>>, {angle_value, F@10}} ->
{ok, sketch@css@transform:skew_x(F@10)};
{<<"skew_y"/utf8>>, {angle_value, F@11}} ->
{ok, sketch@css@transform:skew_y(F@11)};
{<<"perspective"/utf8>>, {length_value, F@12}} ->
{ok, sketch@css@transform:perspective(F@12)};
{_, _} ->
{error, nil}
end end
);
[{unlabelled_field, Fst}, {unlabelled_field, Snd}] ->
gleam@result:'try'(
convert_expression(Fst, Env, Modules),
fun(Fst@1) ->
gleam@result:'try'(
convert_expression(Snd, Env, Modules),
fun(Snd@1) -> case {Label, Fst@1, Snd@1} of
{<<"skew"/utf8>>,
{angle_value, Fst@2},
{angle_value, Snd@2}} ->
{ok,
sketch@css@transform:skew(Fst@2, Snd@2)};
{<<"translate"/utf8>>,
{length_value, Fst@3},
{length_value, Snd@3}} ->
{ok,
sketch@css@transform:translate(
Fst@3,
Snd@3
)};
{<<"scale"/utf8>>,
{float_value, Fst@4},
{float_value, Snd@4}} ->
{ok,
sketch@css@transform:scale(Fst@4, Snd@4)};
{_, _, _} ->
{error, nil}
end end
)
end
);
[{unlabelled_field, Fst@5},
{unlabelled_field, Snd@5},
{unlabelled_field, Trd}] ->
gleam@result:'try'(
convert_expression(Fst@5, Env, Modules),
fun(Fst@6) ->
gleam@result:'try'(
convert_expression(Snd@5, Env, Modules),
fun(Snd@6) ->
gleam@result:'try'(
convert_expression(Trd, Env, Modules),
fun(Trd@1) ->
case {Label, Fst@6, Snd@6, Trd@1} of
{<<"translate_3d"/utf8>>,
{length_value, Fst@7},
{length_value, Snd@7},
{length_value, Trd@2}} ->
{ok,
sketch@css@transform:translate_3d(
Fst@7,
Snd@7,
Trd@2
)};
{<<"scale_3d"/utf8>>,
{float_value, Fst@8},
{float_value, Snd@8},
{float_value, Trd@3}} ->
{ok,
sketch@css@transform:scale_3d(
Fst@8,
Snd@8,
Trd@3
)};
{_, _, _, _} ->
{error, nil}
end
end
)
end
)
end
);
[{unlabelled_field, Fst@9},
{unlabelled_field, Snd@9},
{unlabelled_field, Trd@4},
{unlabelled_field, Fth}] ->
gleam@result:'try'(
convert_expression(Fst@9, Env, Modules),
fun(Fst@10) ->
gleam@result:'try'(
convert_expression(Snd@9, Env, Modules),
fun(Snd@10) ->
gleam@result:'try'(
convert_expression(Trd@4, Env, Modules),
fun(Trd@5) ->
gleam@result:'try'(
convert_expression(Fth, Env, Modules),
fun(Fth@1) ->
case {Label,
Fst@10,
Snd@10,
Trd@5,
Fth@1} of
{<<"rotate_3d"/utf8>>,
{float_value, Fst@11},
{float_value, Snd@11},
{float_value, Trd@6},
{angle_value, Fth@2}} ->
{ok,
sketch@css@transform:rotate_3d(
Fst@11,
Snd@11,
Trd@6,
Fth@2
)};
{_, _, _, _, _} ->
{error, nil}
end
end
)
end
)
end
)
end
);
[{unlabelled_field, Fst@12},
{unlabelled_field, Snd@12},
{unlabelled_field, Trd@7},
{unlabelled_field, Fth@3},
{unlabelled_field, Fifth},
{unlabelled_field, Six}] ->
gleam@result:'try'(
convert_expression(Fst@12, Env, Modules),
fun(Fst@13) ->
gleam@result:'try'(
convert_expression(Snd@12, Env, Modules),
fun(Snd@13) ->
gleam@result:'try'(
convert_expression(Trd@7, Env, Modules),
fun(Trd@8) ->
gleam@result:'try'(
convert_expression(Fth@3, Env, Modules),
fun(Fth@4) ->
gleam@result:'try'(
convert_expression(
Fifth,
Env,
Modules
),
fun(Fifth@1) ->
gleam@result:'try'(
convert_expression(
Six,
Env,
Modules
),
fun(Six@1) ->
case {Label,
Fst@13,
Snd@13,
Trd@8,
Fth@4,
Fifth@1,
Six@1} of
{<<"matrix"/utf8>>,
{float_value,
Fst@14},
{float_value,
Snd@14},
{float_value,
Trd@9},
{float_value,
Fth@5},
{float_value,
Fifth@2},
{float_value,
Six@2}} ->
{ok,
sketch@css@transform:matrix(
Fst@14,
Snd@14,
Trd@9,
Fth@5,
Fifth@2,
Six@2
)};
{_,
_,
_,
_,
_,
_,
_} ->
{error, nil}
end
end
)
end
)
end
)
end
)
end
)
end
);
_ ->
{error, nil}
end,
gleam@result:map(_pipe, fun(Field@0) -> {transform_value, Field@0} end).
-file("src/sketch_css/module/stylesheet.gleam", 596).
?DOC(false).
-spec convert_media_arguments(
binary(),
list(glance:field(glance:expression())),
style_sheet(),
list({binary(), style_sheet()})
) -> {ok, sketch@css@media:'query'()} | {error, nil}.
convert_media_arguments(Label, Arguments, Env, Modules) ->
case Arguments of
[{unlabelled_field, Item}] ->
gleam@result:'try'(
convert_expression(Item, Env, Modules),
fun(Value) -> case {Value, Label} of
{{length_value, Value@1}, <<"max_width"/utf8>>} ->
{ok, sketch@css@media:max_width(Value@1)};
{{length_value, Value@2}, <<"min_width"/utf8>>} ->
{ok, sketch@css@media:min_width(Value@2)};
{{length_value, Value@3}, <<"max_height"/utf8>>} ->
{ok, sketch@css@media:max_height(Value@3)};
{{length_value, Value@4}, <<"min_height"/utf8>>} ->
{ok, sketch@css@media:min_height(Value@4)};
{{media_value, Value@5}, <<"not"/utf8>>} ->
{ok, sketch@css@media:'not'(Value@5)};
{{media_value, Value@6}, <<"only"/utf8>>} ->
{ok, sketch@css@media:only(Value@6)};
{_, _} ->
{error, nil}
end end
);
[{unlabelled_field, Fst}, {unlabelled_field, Snd}] ->
gleam@result:'try'(
convert_expression(Fst, Env, Modules),
fun(Fst@1) ->
gleam@result:'try'(
convert_expression(Snd, Env, Modules),
fun(Snd@1) -> case {Fst@1, Snd@1, Label} of
{{media_value, Fst@2},
{media_value, Snd@2},
<<"and"/utf8>>} ->
{ok, sketch@css@media:'and'(Fst@2, Snd@2)};
{{media_value, Fst@3},
{media_value, Snd@3},
<<"or"/utf8>>} ->
{ok, sketch@css@media:'or'(Fst@3, Snd@3)};
{_, _, _} ->
{error, nil}
end end
)
end
);
_ ->
{error, nil}
end.
-file("src/sketch_css/module/stylesheet.gleam", 577).
?DOC(false).
-spec convert_media(
binary(),
list(glance:field(glance:expression())),
style_sheet(),
list({binary(), style_sheet()})
) -> {ok, value()} | {error, nil}.
convert_media(Label, Arguments, Env, Modules) ->
_pipe = case Label of
<<"dark_theme"/utf8>> ->
{ok, sketch@css@media:dark_theme()};
<<"light_theme"/utf8>> ->
{ok, sketch@css@media:light_theme()};
<<"landscape"/utf8>> ->
{ok, sketch@css@media:landscape()};
<<"portrait"/utf8>> ->
{ok, sketch@css@media:portrait()};
<<"all"/utf8>> ->
{ok, sketch@css@media:all()};
<<"screen"/utf8>> ->
{ok, sketch@css@media:screen()};
<<"print"/utf8>> ->
{ok, sketch@css@media:print()};
_ ->
convert_media_arguments(Label, Arguments, Env, Modules)
end,
gleam@result:map(_pipe, fun(Field@0) -> {media_value, Field@0} end).
-file("src/sketch_css/module/stylesheet.gleam", 625).
?DOC(false).
-spec convert_class_call(
list(glance:field(glance:expression())),
style_sheet(),
list({binary(), style_sheet()})
) -> {ok, value()} | {error, nil}.
convert_class_call(Arguments, Env, Modules) ->
case Arguments of
[{unlabelled_field, {list, Elements, _}}] ->
_pipe = sketch@css:class(
begin
gleam@list:map(
Elements,
fun(Element) ->
case convert_expression(Element, Env, Modules) of
{ok, {style_value, V}} ->
V;
_ ->
sketch@css:none()
end
end
)
end
),
_pipe@1 = {class_value, _pipe},
{ok, _pipe@1};
_ ->
{error, nil}
end.
-file("src/sketch_css/module/stylesheet.gleam", 646).
?DOC(false).
-spec convert_keyframes_call(
list(glance:field(glance:expression())),
style_sheet(),
list({binary(), style_sheet()})
) -> {ok, value()} | {error, nil}.
convert_keyframes_call(Arguments, Env, Modules) ->
case Arguments of
[{unlabelled_field, Item}, {unlabelled_field, {list, Elements, _}}] ->
gleam@result:'try'(
convert_expression(Item, Env, Modules),
fun(Item@1) -> case Item@1 of
{string_value, S} ->
_pipe = sketch@css:keyframes(
S,
begin
gleam@list:flat_map(
Elements,
fun(Element) ->
case convert_expression(
Element,
Env,
Modules
) of
{ok, {keyframe_value, V}} ->
[V];
_ ->
[]
end
end
)
end
),
_pipe@1 = {at_rule_value, _pipe},
{ok, _pipe@1};
_ ->
{error, nil}
end end
);
_ ->
{error, nil}
end.
-file("src/sketch_css/module/stylesheet.gleam", 672).
?DOC(false).
-spec convert_font_face_call(
list(glance:field(glance:expression())),
style_sheet(),
list({binary(), style_sheet()})
) -> {ok, value()} | {error, nil}.
convert_font_face_call(Arguments, Env, Modules) ->
case Arguments of
[{unlabelled_field, {list, Elements, _}}] ->
_pipe = sketch@css:font_face(
begin
gleam@list:flat_map(
Elements,
fun(Element) ->
case convert_expression(Element, Env, Modules) of
{ok, {font_face_value, V}} ->
[V];
_ ->
[]
end
end
)
end
),
_pipe@1 = {at_rule_value, _pipe},
{ok, _pipe@1};
_ ->
{error, nil}
end.
-file("src/sketch_css/module/stylesheet.gleam", 693).
?DOC(false).
-spec convert_compose_call(
list(glance:field(glance:expression())),
style_sheet(),
list({binary(), style_sheet()})
) -> {ok, value()} | {error, nil}.
convert_compose_call(Arguments, Env, Modules) ->
case Arguments of
[{unlabelled_field, Item}] ->
gleam@result:map(
convert_expression(Item, Env, Modules),
fun(Value) -> case Value of
{class_value, Class} ->
{style_value, sketch@css:compose(Class)};
Others ->
Others
end end
);
_ ->
{error, nil}
end.
-file("src/sketch_css/module/stylesheet.gleam", 710).
?DOC(false).
-spec convert_important_call(
list(glance:field(glance:expression())),
style_sheet(),
list({binary(), style_sheet()})
) -> {ok, value()} | {error, nil}.
convert_important_call(Arguments, Env, Modules) ->
case Arguments of
[{unlabelled_field, Item}] ->
gleam@result:map(
convert_expression(Item, Env, Modules),
fun(Value) -> case Value of
{style_value, Style} ->
{style_value, sketch@css:important(Style)};
Others ->
Others
end end
);
_ ->
{error, nil}
end.
-file("src/sketch_css/module/stylesheet.gleam", 727).
?DOC(false).
-spec convert_media_call(
list(glance:field(glance:expression())),
style_sheet(),
list({binary(), style_sheet()})
) -> {ok, value()} | {error, nil}.
convert_media_call(Arguments, Env, Modules) ->
case Arguments of
[{unlabelled_field, Item}, {unlabelled_field, {list, Styles, _}}] ->
gleam@result:map(
convert_expression(Item, Env, Modules),
fun(Value) -> case Value of
{media_value, Query} ->
{style_value,
(sketch@css:media(
Query,
begin
gleam@list:filter_map(
Styles,
fun(Style) ->
gleam@result:map(
convert_expression(
Style,
Env,
Modules
),
fun(Value@1) ->
case Value@1 of
{style_value, S} ->
S;
_ ->
sketch@css:none(
)
end
end
)
end
)
end
))};
Others ->
Others
end end
);
_ ->
{error, nil}
end.
-file("src/sketch_css/module/stylesheet.gleam", 754).
?DOC(false).
-spec convert_selector_call(
list(glance:field(glance:expression())),
style_sheet(),
list({binary(), style_sheet()})
) -> {ok, value()} | {error, nil}.
convert_selector_call(Arguments, Env, Modules) ->
case Arguments of
[{unlabelled_field, Item}, {unlabelled_field, {list, Styles, _}}] ->
gleam@result:map(
convert_expression(Item, Env, Modules),
fun(Selector) -> _pipe = case Selector of
{string_value, Prop} ->
sketch@css:selector(
Prop,
begin
gleam@list:filter_map(
Styles,
fun(Style) ->
gleam@result:map(
convert_expression(
Style,
Env,
Modules
),
fun(Value) -> case Value of
{style_value, S} ->
S;
_ ->
sketch@css:none()
end end
)
end
)
end
);
_ ->
sketch@css:none()
end,
{style_value, _pipe} end
);
_ ->
{error, nil}
end.
-file("src/sketch_css/module/stylesheet.gleam", 780).
?DOC(false).
-spec convert_property_call(
list(glance:field(glance:expression())),
style_sheet(),
list({binary(), style_sheet()})
) -> {ok, value()} | {error, nil}.
convert_property_call(Arguments, Env, Modules) ->
case Arguments of
[{unlabelled_field, Property}, {unlabelled_field, Value}] ->
gleam@result:'try'(
convert_expression(Property, Env, Modules),
fun(Property@1) ->
gleam@result:map(
convert_expression(Value, Env, Modules),
fun(Value@1) -> _pipe = case {Property@1, Value@1} of
{{string_value, Prop}, {string_value, Value@2}} ->
sketch@css:property(Prop, Value@2);
{_, _} ->
sketch@css:none()
end,
{style_value, _pipe} end
)
end
);
_ ->
{error, nil}
end.
-file("src/sketch_css/module/stylesheet.gleam", 799).
?DOC(false).
-spec convert_transform_call(
list(glance:field(glance:expression())),
style_sheet(),
list({binary(), style_sheet()})
) -> {ok, value()} | {error, nil}.
convert_transform_call(Arguments, Env, Modules) ->
case Arguments of
[{unlabelled_field, {list, Transforms, _}}] ->
Styles = gleam@list:try_map(
Transforms,
fun(_capture) -> convert_expression(_capture, Env, Modules) end
),
gleam@result:'try'(
Styles,
fun(Styles@1) ->
gleam@result:map(
begin
gleam@list:try_map(
Styles@1,
fun(Value) -> case Value of
{transform_value, V} ->
{ok, V};
_ ->
{error, nil}
end end
)
end,
fun(Transforms@1) ->
{style_value, sketch@css:transform(Transforms@1)}
end
)
end
);
_ ->
{error, nil}
end.
-file("src/sketch_css/module/stylesheet.gleam", 874).
?DOC(false).
-spec convert_pseudo_selector_call(
binary(),
binary(),
list(glance:field(glance:expression())),
style_sheet(),
list({binary(), style_sheet()})
) -> {ok, value()} | {error, nil}.
convert_pseudo_selector_call(Label, Class, Arguments, Env, Modules) ->
case Label of
<<"state"/utf8>> ->
case Arguments of
[{unlabelled_field, Item},
{unlabelled_field, {list, Styles, _}}] ->
gleam@result:map(
convert_expression(Item, Env, Modules),
fun(Selector) -> _pipe = case Selector of
{string_value, Prop} ->
sketch@css:selector(
<<<<<<Class/binary, "("/utf8>>/binary,
Prop/binary>>/binary,
")"/utf8>>,
begin
gleam@list:filter_map(
Styles,
fun(Style) ->
gleam@result:map(
convert_expression(
Style,
Env,
Modules
),
fun(Value) ->
case Value of
{style_value, S} ->
S;
_ ->
sketch@css:none(
)
end
end
)
end
)
end
);
_ ->
sketch@css:none()
end,
{style_value, _pipe} end
);
_ ->
{error, nil}
end;
<<"dir"/utf8>> ->
case Arguments of
[{unlabelled_field, Item},
{unlabelled_field, {list, Styles, _}}] ->
gleam@result:map(
convert_expression(Item, Env, Modules),
fun(Selector) -> _pipe = case Selector of
{string_value, Prop} ->
sketch@css:selector(
<<<<<<Class/binary, "("/utf8>>/binary,
Prop/binary>>/binary,
")"/utf8>>,
begin
gleam@list:filter_map(
Styles,
fun(Style) ->
gleam@result:map(
convert_expression(
Style,
Env,
Modules
),
fun(Value) ->
case Value of
{style_value, S} ->
S;
_ ->
sketch@css:none(
)
end
end
)
end
)
end
);
_ ->
sketch@css:none()
end,
{style_value, _pipe} end
);
_ ->
{error, nil}
end;
<<"nth_child"/utf8>> ->
case Arguments of
[{unlabelled_field, Item},
{unlabelled_field, {list, Styles, _}}] ->
gleam@result:map(
convert_expression(Item, Env, Modules),
fun(Selector) -> _pipe = case Selector of
{string_value, Prop} ->
sketch@css:selector(
<<<<<<Class/binary, "("/utf8>>/binary,
Prop/binary>>/binary,
")"/utf8>>,
begin
gleam@list:filter_map(
Styles,
fun(Style) ->
gleam@result:map(
convert_expression(
Style,
Env,
Modules
),
fun(Value) ->
case Value of
{style_value, S} ->
S;
_ ->
sketch@css:none(
)
end
end
)
end
)
end
);
_ ->
sketch@css:none()
end,
{style_value, _pipe} end
);
_ ->
{error, nil}
end;
<<"nth_last_child"/utf8>> ->
case Arguments of
[{unlabelled_field, Item},
{unlabelled_field, {list, Styles, _}}] ->
gleam@result:map(
convert_expression(Item, Env, Modules),
fun(Selector) -> _pipe = case Selector of
{string_value, Prop} ->
sketch@css:selector(
<<<<<<Class/binary, "("/utf8>>/binary,
Prop/binary>>/binary,
")"/utf8>>,
begin
gleam@list:filter_map(
Styles,
fun(Style) ->
gleam@result:map(
convert_expression(
Style,
Env,
Modules
),
fun(Value) ->
case Value of
{style_value, S} ->
S;
_ ->
sketch@css:none(
)
end
end
)
end
)
end
);
_ ->
sketch@css:none()
end,
{style_value, _pipe} end
);
_ ->
{error, nil}
end;
<<"nth_of_type"/utf8>> ->
case Arguments of
[{unlabelled_field, Item},
{unlabelled_field, {list, Styles, _}}] ->
gleam@result:map(
convert_expression(Item, Env, Modules),
fun(Selector) -> _pipe = case Selector of
{string_value, Prop} ->
sketch@css:selector(
<<<<<<Class/binary, "("/utf8>>/binary,
Prop/binary>>/binary,
")"/utf8>>,
begin
gleam@list:filter_map(
Styles,
fun(Style) ->
gleam@result:map(
convert_expression(
Style,
Env,
Modules
),
fun(Value) ->
case Value of
{style_value, S} ->
S;
_ ->
sketch@css:none(
)
end
end
)
end
)
end
);
_ ->
sketch@css:none()
end,
{style_value, _pipe} end
);
_ ->
{error, nil}
end;
<<"nth_last_of_type"/utf8>> ->
case Arguments of
[{unlabelled_field, Item},
{unlabelled_field, {list, Styles, _}}] ->
gleam@result:map(
convert_expression(Item, Env, Modules),
fun(Selector) -> _pipe = case Selector of
{string_value, Prop} ->
sketch@css:selector(
<<<<<<Class/binary, "("/utf8>>/binary,
Prop/binary>>/binary,
")"/utf8>>,
begin
gleam@list:filter_map(
Styles,
fun(Style) ->
gleam@result:map(
convert_expression(
Style,
Env,
Modules
),
fun(Value) ->
case Value of
{style_value, S} ->
S;
_ ->
sketch@css:none(
)
end
end
)
end
)
end
);
_ ->
sketch@css:none()
end,
{style_value, _pipe} end
);
_ ->
{error, nil}
end;
_ ->
case Arguments of
[{unlabelled_field, {list, Styles@1, _}}] ->
_pipe@1 = sketch@css:selector(
Class,
begin
gleam@list:filter_map(
Styles@1,
fun(Style@1) ->
gleam@result:map(
convert_expression(
Style@1,
Env,
Modules
),
fun(Value@1) -> case Value@1 of
{style_value, S@1} ->
S@1;
_ ->
sketch@css:none()
end end
)
end
)
end
),
_pipe@2 = {style_value, _pipe@1},
{ok, _pipe@2};
_ ->
{error, nil}
end
end.
-file("src/sketch_css/module/stylesheet.gleam", 928).
?DOC(false).
-spec convert_combinator_call(
fun((sketch@internals@cache@cache:class(), list(sketch@internals@cache@cache:style())) -> sketch@internals@cache@cache:style()),
list(glance:field(glance:expression())),
style_sheet(),
list({binary(), style_sheet()})
) -> {ok, value()} | {error, nil}.
convert_combinator_call(Combinator, Arguments, Env, Modules) ->
case Arguments of
[{unlabelled_field, Item}, {unlabelled_field, {list, Styles, _}}] ->
gleam@result:map(
convert_expression(Item, Env, Modules),
fun(Class) -> _pipe = case Class of
{class_value, Class@1} ->
Combinator(
Class@1,
begin
gleam@list:filter_map(
Styles,
fun(Style) ->
gleam@result:map(
convert_expression(
Style,
Env,
Modules
),
fun(Value) -> case Value of
{style_value, S} ->
S;
_ ->
sketch@css:none()
end end
)
end
)
end
);
_ ->
sketch@css:none()
end,
{style_value, _pipe} end
);
_ ->
{error, nil}
end.
-file("src/sketch_css/module/stylesheet.gleam", 821).
?DOC(false).
-spec convert_generic_call(
binary(),
list(glance:field(glance:expression())),
style_sheet(),
list({binary(), style_sheet()})
) -> {ok, value()} | {error, nil}.
convert_generic_call(Label, Arguments, Env, Modules) ->
Is_pseudo = gleam@list:key_find(
[{<<"placeholder"/utf8>>, <<"::placeholder"/utf8>>},
{<<"selection"/utf8>>, <<"::selection"/utf8>>},
{<<"before"/utf8>>, <<"::before"/utf8>>},
{<<"after"/utf8>>, <<"::after"/utf8>>},
{<<"backdrop"/utf8>>, <<"::backdrop"/utf8>>},
{<<"cue"/utf8>>, <<"::cue"/utf8>>},
{<<"first_line"/utf8>>, <<"::first-line"/utf8>>},
{<<"grammar_error"/utf8>>, <<"::grammar-error"/utf8>>},
{<<"spelling_error"/utf8>>, <<"::spelling-error"/utf8>>},
{<<"marker"/utf8>>, <<"::marker"/utf8>>},
{<<"first_letter"/utf8>>, <<"::first-letter"/utf8>>},
{<<"file_selector_button"/utf8>>, <<"::file-selector-button"/utf8>>},
{<<"hover"/utf8>>, <<":hover"/utf8>>},
{<<"any_link"/utf8>>, <<":any-link"/utf8>>},
{<<"active"/utf8>>, <<":active"/utf8>>},
{<<"focus"/utf8>>, <<":focus"/utf8>>},
{<<"autofill"/utf8>>, <<":autofill"/utf8>>},
{<<"buffering"/utf8>>, <<":buffering"/utf8>>},
{<<"default"/utf8>>, <<":default"/utf8>>},
{<<"defined"/utf8>>, <<":defined"/utf8>>},
{<<"empty"/utf8>>, <<":empty"/utf8>>},
{<<"fullscreen"/utf8>>, <<":fullscreen"/utf8>>},
{<<"in_range"/utf8>>, <<":in-range"/utf8>>},
{<<"indeterminate"/utf8>>, <<":indeterminate"/utf8>>},
{<<"muted"/utf8>>, <<":muted"/utf8>>},
{<<"paused"/utf8>>, <<":paused"/utf8>>},
{<<"playing"/utf8>>, <<":playing"/utf8>>},
{<<"seeking"/utf8>>, <<":seeking"/utf8>>},
{<<"stalled"/utf8>>, <<":stalled"/utf8>>},
{<<"state"/utf8>>, <<":state"/utf8>>},
{<<"user_invalid"/utf8>>, <<":user-invalid"/utf8>>},
{<<"user_valid"/utf8>>, <<":user-valid"/utf8>>},
{<<"volume_locked"/utf8>>, <<":volume-locked"/utf8>>},
{<<"placeholder_shown"/utf8>>, <<":placeholder-shown"/utf8>>},
{<<"out_of_range"/utf8>>, <<":out-of-range"/utf8>>},
{<<"dir"/utf8>>, <<":dir"/utf8>>},
{<<"focus_visible"/utf8>>, <<":focus-visible"/utf8>>},
{<<"focus_within"/utf8>>, <<":focus-within"/utf8>>},
{<<"enabled"/utf8>>, <<":enabled"/utf8>>},
{<<"disabled"/utf8>>, <<":disabled"/utf8>>},
{<<"read_only"/utf8>>, <<":read-only"/utf8>>},
{<<"read_write"/utf8>>, <<":read-write"/utf8>>},
{<<"checked"/utf8>>, <<":checked"/utf8>>},
{<<"valid"/utf8>>, <<":valid"/utf8>>},
{<<"invalid"/utf8>>, <<":invalid"/utf8>>},
{<<"required"/utf8>>, <<":required"/utf8>>},
{<<"optional"/utf8>>, <<":optional"/utf8>>},
{<<"link"/utf8>>, <<":link"/utf8>>},
{<<"visited"/utf8>>, <<":visited"/utf8>>},
{<<"target"/utf8>>, <<":target"/utf8>>},
{<<"nth_child"/utf8>>, <<":nth-child"/utf8>>},
{<<"nth_last_child"/utf8>>, <<":nth-last-child"/utf8>>},
{<<"nth_of_type"/utf8>>, <<":nth-of-type"/utf8>>},
{<<"nth_last_of_type"/utf8>>, <<":nth-last-of-type"/utf8>>},
{<<"first_child"/utf8>>, <<":first-child"/utf8>>},
{<<"last_child"/utf8>>, <<":last-child"/utf8>>},
{<<"only_child"/utf8>>, <<":only-child"/utf8>>},
{<<"first_of_type"/utf8>>, <<":first-of-type"/utf8>>},
{<<"last_of_type"/utf8>>, <<":last-of-type"/utf8>>},
{<<"only_of_type"/utf8>>, <<":only-of-type"/utf8>>}],
Label
),
Is_combinator = gleam@list:key_find(
[{<<"child"/utf8>>, fun sketch@css:child/2},
{<<"descendant"/utf8>>, fun sketch@css:descendant/2},
{<<"next_sibling"/utf8>>, fun sketch@css:next_sibling/2},
{<<"subsequent_sibling"/utf8>>, fun sketch@css:subsequent_sibling/2}],
Label
),
case {Is_pseudo, Is_combinator} of
{{ok, C}, _} ->
convert_pseudo_selector_call(Label, C, Arguments, Env, Modules);
{_, {ok, C@1}} ->
convert_combinator_call(C@1, Arguments, Env, Modules);
{_, _} ->
Label@1 = begin
_pipe = Label,
_pipe@1 = sketch_css@utils:remove_trailing_underscore(_pipe),
gleam@string:replace(_pipe@1, <<"_"/utf8>>, <<"-"/utf8>>)
end,
case Arguments of
[{unlabelled_field, {list, Styles, _}}] ->
Styles@1 = gleam@list:try_map(
Styles,
fun(_capture) ->
convert_expression(_capture, Env, Modules)
end
),
gleam@result:map(
Styles@1,
fun(Styles@2) ->
_pipe@2 = gleam@list:map(
Styles@2,
fun(Value) -> case Value of
{string_value, S} ->
S;
{int_value, I} ->
erlang:integer_to_binary(I);
{float_value, F} ->
gleam_stdlib:float_to_string(F);
{length_value, S@1} ->
sketch@css@length:to_string(S@1);
{angle_value, A} ->
sketch@css@angle:to_string(A);
_ ->
<<""/utf8>>
end end
),
_pipe@3 = gleam@list:map(
_pipe@2,
fun(S@2) ->
<<<<"\""/utf8, S@2/binary>>/binary,
"\""/utf8>>
end
),
_pipe@4 = gleam@string:join(_pipe@3, <<" "/utf8>>),
_pipe@5 = sketch@css:property(Label@1, _pipe@4),
{style_value, _pipe@5}
end
);
[{unlabelled_field, Item}] ->
gleam@result:map(
convert_expression(Item, Env, Modules),
fun(Value@1) -> case Value@1 of
{string_value, S@3} ->
{style_value,
sketch@css:property(Label@1, S@3)};
{int_value, I@1} ->
{style_value,
sketch@css:property(
Label@1,
erlang:integer_to_binary(I@1)
)};
{float_value, F@1} ->
{style_value,
sketch@css:property(
Label@1,
gleam_stdlib:float_to_string(F@1)
)};
{length_value, S@4} ->
{style_value,
sketch@css:property(
Label@1,
sketch@css@length:to_string(S@4)
)};
{angle_value, A@1} ->
{style_value,
sketch@css:property(
Label@1,
sketch@css@angle:to_string(A@1)
)};
_ ->
{style_value, sketch@css:none()}
end end
);
_ ->
{error, nil}
end
end.