Packages

A Sketch runtime package, made to generate CSS!

Current section

Files

Jump to
sketch_css src sketch_css@module@functions.erl
Raw

src/sketch_css@module@functions.erl

-module(sketch_css@module@functions).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-define(FILEPATH, "src/sketch_css/module/functions.gleam").
-export([is_dependent/2]).
-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).
-file("src/sketch_css/module/functions.gleam", 80).
?DOC(false).
-spec extract_field(glance:field(QNU)) -> {ok, QNU} | {error, nil}.
extract_field(Field) ->
case Field of
{unlabelled_field, Expression} ->
{ok, Expression};
{labelled_field, _, Expression@1} ->
{ok, Expression@1};
{shorthand_field, _} ->
{error, nil}
end.
-file("src/sketch_css/module/functions.gleam", 35).
?DOC(false).
-spec in_expression(glance:expression(), binary()) -> boolean().
in_expression(Expression, Other) ->
case Expression of
{variable, Var} ->
Var =:= Other;
{negate_int, Expr} ->
in_expression(Expr, Other);
{negate_bool, Expr@1} ->
in_expression(Expr@1, Other);
{field_access, Container, _} ->
in_expression(Container, Other);
{tuple_index, Tuple, _} ->
in_expression(Tuple, Other);
{block, Statements} ->
in_statements(Statements, Other);
{tuple, Expressions} ->
in_expressions(Expressions, Other);
{fn, _, _, Body} ->
in_statements(Body, Other);
{list, Elements, Rest} ->
_pipe = Rest,
_pipe@1 = gleam@option:map(
_pipe,
fun(_capture) -> gleam@list:prepend(Elements, _capture) end
),
_pipe@2 = gleam@option:unwrap(_pipe@1, Elements),
in_expressions(_pipe@2, Other);
{call, Function, Arguments} ->
_pipe@3 = Arguments,
_pipe@4 = gleam@list:filter_map(_pipe@3, fun extract_field/1),
_pipe@5 = gleam@list:prepend(_pipe@4, Function),
in_expressions(_pipe@5, Other);
{fn_capture, _, Function@1, Arguments_before, Arguments_after} ->
_pipe@6 = lists:append(Arguments_before, Arguments_after),
_pipe@7 = gleam@list:filter_map(_pipe@6, fun extract_field/1),
_pipe@8 = gleam@list:prepend(_pipe@7, Function@1),
in_expressions(_pipe@8, Other);
{'case', Subjects, Clauses} ->
_pipe@9 = Clauses,
_pipe@10 = gleam@list:map(
_pipe@9,
fun(Clause) -> erlang:element(4, Clause) end
),
_pipe@11 = lists:append(Subjects, _pipe@10),
in_expressions(_pipe@11, Other);
{binary_operator, _, Left, Right} ->
in_expression(Left, Other) orelse in_expression(Right, Other);
_ ->
false
end.
-file("src/sketch_css/module/functions.gleam", 29).
?DOC(false).
-spec in_expressions(list(glance:expression()), binary()) -> boolean().
in_expressions(Expressions, Other) ->
gleam@list:fold(
Expressions,
false,
fun(Found, Expression) ->
gleam@bool:guard(
Found,
Found,
fun() -> in_expression(Expression, Other) end
)
end
).
-file("src/sketch_css/module/functions.gleam", 21).
?DOC(false).
-spec in_statement(glance:statement(), binary()) -> boolean().
in_statement(Statement, Other) ->
case Statement of
{expression, Expression} ->
in_expression(Expression, Other);
{assignment, _, _, _, Value} ->
in_expression(Value, Other);
{use, _, Function} ->
in_expression(Function, Other)
end.
-file("src/sketch_css/module/functions.gleam", 15).
?DOC(false).
-spec in_statements(list(glance:statement()), binary()) -> boolean().
in_statements(Statements, Other) ->
gleam@list:fold(
Statements,
false,
fun(Found, Statement) ->
gleam@bool:guard(
Found,
Found,
fun() -> in_statement(Statement, Other) end
)
end
).
-file("src/sketch_css/module/functions.gleam", 8).
?DOC(false).
-spec is_dependent(glance:function_(), glance:function_()) -> gleam@order:order().
is_dependent(A, B) ->
case in_statements(erlang:element(6, B), erlang:element(2, A)) of
true ->
lt;
false ->
gt
end.