Packages

Zero runtime syntax highlighter for lustre/ssg.

Current section

Files

Jump to
glimra src glimra@theme.erl
Raw

src/glimra@theme.erl

-module(glimra@theme).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([default_theme/0, to_css/1]).
-export_type([color/0, style/0, theme/0]).
-type color() :: {color, integer(), integer(), integer()}.
-type style() :: {style, color(), boolean()}.
-type theme() :: {theme,
color(),
float(),
float(),
float(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style(),
style()}.
-spec default_theme() -> theme().
default_theme() ->
{theme,
{color, 30, 30, 30},
1.5,
1.25,
0.5,
{style, {color, 205, 214, 244}, false},
{style, {color, 243, 139, 168}, false},
{style, {color, 205, 214, 244}, false},
{style, {color, 235, 160, 172}, false},
{style, {color, 235, 160, 172}, false},
{style, {color, 250, 179, 135}, false},
{style, {color, 250, 179, 135}, false},
{style, {color, 203, 166, 247}, false},
{style, {color, 180, 190, 254}, true},
{style, {color, 116, 199, 236}, false},
{style, {color, 166, 227, 161}, false},
{style, {color, 108, 112, 134}, false},
{style, {color, 245, 194, 231}, false},
{style, {color, 250, 179, 135}, false},
{style, {color, 245, 194, 231}, false},
{style, {color, 148, 226, 213}, false},
{style, {color, 245, 194, 231}, false},
{style, {color, 250, 179, 135}, false},
{style, {color, 250, 179, 135}, false},
{style, {color, 249, 226, 175}, false},
{style, {color, 249, 226, 175}, false},
{style, {color, 249, 226, 175}, false},
{style, {color, 250, 179, 135}, false},
{style, {color, 250, 179, 135}, false},
{style, {color, 180, 190, 254}, false},
{style, {color, 137, 180, 250}, false},
{style, {color, 250, 179, 135}, false},
{style, {color, 137, 180, 250}, false},
{style, {color, 148, 226, 213}, false},
{style, {color, 137, 180, 250}, false},
{style, {color, 137, 180, 250}, false},
{style, {color, 116, 199, 236}, false},
{style, {color, 137, 220, 235}, false},
{style, {color, 203, 166, 247}, false},
{style, {color, 203, 166, 247}, false},
{style, {color, 203, 166, 247}, false},
{style, {color, 203, 166, 247}, false},
{style, {color, 203, 166, 247}, false},
{style, {color, 203, 166, 247}, false},
{style, {color, 203, 166, 247}, false},
{style, {color, 203, 166, 247}, false},
{style, {color, 203, 166, 247}, false},
{style, {color, 245, 194, 231}, false},
{style, {color, 203, 166, 247}, false},
{style, {color, 203, 166, 247}, false},
{style, {color, 203, 166, 247}, false},
{style, {color, 147, 153, 178}, false},
{style, {color, 147, 153, 178}, false},
{style, {color, 147, 153, 178}, false},
{style, {color, 245, 194, 231}, false},
{style, {color, 108, 112, 134}, true},
{style, {color, 108, 112, 134}, true},
{style, {color, 203, 166, 247}, false},
{style, {color, 203, 166, 247}, false},
{style, {color, 148, 226, 213}, true},
{style, {color, 137, 220, 235}, false}}.
-spec color_to_css(color()) -> binary().
color_to_css(Color) ->
<<<<<<<<<<<<"rgb("/utf8,
(gleam@int:to_string(erlang:element(2, Color)))/binary>>/binary,
", "/utf8>>/binary,
(gleam@int:to_string(erlang:element(3, Color)))/binary>>/binary,
", "/utf8>>/binary,
(gleam@int:to_string(erlang:element(4, Color)))/binary>>/binary,
")"/utf8>>.
-spec style_to_css(binary(), style()) -> binary().
style_to_css(Class_name, Style) ->
<<<<<<<<"."/utf8, Class_name/binary>>/binary, " { color: "/utf8>>/binary,
(color_to_css(erlang:element(2, Style)))/binary>>/binary,
"; }\n"/utf8>>.
-spec to_css(theme()) -> binary().
to_css(Theme) ->
_pipe = gleam@string_builder:new(),
_pipe@1 = gleam@string_builder:append(
_pipe,
<<"\n/* identifiers */\n"/utf8>>
),
_pipe@2 = gleam@string_builder:append(
_pipe@1,
style_to_css(<<"variable"/utf8>>, erlang:element(6, Theme))
),
_pipe@3 = gleam@string_builder:append(
_pipe@2,
style_to_css(<<"variable.builtin"/utf8>>, erlang:element(7, Theme))
),
_pipe@4 = gleam@string_builder:append(
_pipe@3,
style_to_css(<<"variable.member"/utf8>>, erlang:element(8, Theme))
),
_pipe@5 = gleam@string_builder:append(
_pipe@4,
style_to_css(
<<"variable.parameter.builtin"/utf8>>,
erlang:element(9, Theme)
)
),
_pipe@6 = gleam@string_builder:append(
_pipe@5,
style_to_css(<<"variable.parameter"/utf8>>, erlang:element(10, Theme))
),
_pipe@7 = gleam@string_builder:append(
_pipe@6,
style_to_css(<<"constant"/utf8>>, erlang:element(11, Theme))
),
_pipe@8 = gleam@string_builder:append(
_pipe@7,
style_to_css(<<"constant.builtin"/utf8>>, erlang:element(12, Theme))
),
_pipe@9 = gleam@string_builder:append(
_pipe@8,
style_to_css(<<"constant.macro"/utf8>>, erlang:element(13, Theme))
),
_pipe@10 = gleam@string_builder:append(
_pipe@9,
style_to_css(<<"module"/utf8>>, erlang:element(14, Theme))
),
_pipe@11 = gleam@string_builder:append(
_pipe@10,
style_to_css(<<"label"/utf8>>, erlang:element(15, Theme))
),
_pipe@12 = gleam@string_builder:append(
_pipe@11,
<<"\n/* literals */\n"/utf8>>
),
_pipe@13 = gleam@string_builder:append(
_pipe@12,
style_to_css(<<"string"/utf8>>, erlang:element(16, Theme))
),
_pipe@14 = gleam@string_builder:append(
_pipe@13,
style_to_css(<<"string.documentation"/utf8>>, erlang:element(17, Theme))
),
_pipe@15 = gleam@string_builder:append(
_pipe@14,
style_to_css(<<"string.escape"/utf8>>, erlang:element(18, Theme))
),
_pipe@16 = gleam@string_builder:append(
_pipe@15,
style_to_css(<<"string.regexp"/utf8>>, erlang:element(19, Theme))
),
_pipe@17 = gleam@string_builder:append(
_pipe@16,
style_to_css(<<"string.special"/utf8>>, erlang:element(20, Theme))
),
_pipe@18 = gleam@string_builder:append(
_pipe@17,
style_to_css(<<"character"/utf8>>, erlang:element(21, Theme))
),
_pipe@19 = gleam@string_builder:append(
_pipe@18,
style_to_css(<<"character.special"/utf8>>, erlang:element(22, Theme))
),
_pipe@20 = gleam@string_builder:append(
_pipe@19,
style_to_css(<<"boolean"/utf8>>, erlang:element(23, Theme))
),
_pipe@21 = gleam@string_builder:append(
_pipe@20,
style_to_css(<<"number"/utf8>>, erlang:element(24, Theme))
),
_pipe@22 = gleam@string_builder:append(_pipe@21, <<"\n/* types */\n"/utf8>>),
_pipe@23 = gleam@string_builder:append(
_pipe@22,
style_to_css(<<"type"/utf8>>, erlang:element(25, Theme))
),
_pipe@24 = gleam@string_builder:append(
_pipe@23,
style_to_css(<<"type.builtin"/utf8>>, erlang:element(26, Theme))
),
_pipe@25 = gleam@string_builder:append(
_pipe@24,
style_to_css(<<"type.definition"/utf8>>, erlang:element(27, Theme))
),
_pipe@26 = gleam@string_builder:append(
_pipe@25,
style_to_css(<<"attribute"/utf8>>, erlang:element(28, Theme))
),
_pipe@27 = gleam@string_builder:append(
_pipe@26,
style_to_css(<<"attribute.builtin"/utf8>>, erlang:element(29, Theme))
),
_pipe@28 = gleam@string_builder:append(
_pipe@27,
style_to_css(<<"property"/utf8>>, erlang:element(30, Theme))
),
_pipe@29 = gleam@string_builder:append(
_pipe@28,
<<"\n/* functions */\n"/utf8>>
),
_pipe@30 = gleam@string_builder:append(
_pipe@29,
style_to_css(<<"function"/utf8>>, erlang:element(31, Theme))
),
_pipe@31 = gleam@string_builder:append(
_pipe@30,
style_to_css(<<"function.builtin"/utf8>>, erlang:element(32, Theme))
),
_pipe@32 = gleam@string_builder:append(
_pipe@31,
style_to_css(<<"function.call"/utf8>>, erlang:element(33, Theme))
),
_pipe@33 = gleam@string_builder:append(
_pipe@32,
style_to_css(<<"function.macro"/utf8>>, erlang:element(34, Theme))
),
_pipe@34 = gleam@string_builder:append(
_pipe@33,
style_to_css(<<"function.method"/utf8>>, erlang:element(35, Theme))
),
_pipe@35 = gleam@string_builder:append(
_pipe@34,
style_to_css(<<"function.method.call"/utf8>>, erlang:element(36, Theme))
),
_pipe@36 = gleam@string_builder:append(
_pipe@35,
style_to_css(<<"constructor"/utf8>>, erlang:element(37, Theme))
),
_pipe@37 = gleam@string_builder:append(
_pipe@36,
style_to_css(<<"operator"/utf8>>, erlang:element(38, Theme))
),
_pipe@38 = gleam@string_builder:append(
_pipe@37,
<<"\n/* keywords */\n"/utf8>>
),
_pipe@39 = gleam@string_builder:append(
_pipe@38,
style_to_css(<<"keyword"/utf8>>, erlang:element(39, Theme))
),
_pipe@40 = gleam@string_builder:append(
_pipe@39,
style_to_css(<<"keyword.coroutine"/utf8>>, erlang:element(40, Theme))
),
_pipe@41 = gleam@string_builder:append(
_pipe@40,
style_to_css(<<"keyword.function"/utf8>>, erlang:element(41, Theme))
),
_pipe@42 = gleam@string_builder:append(
_pipe@41,
style_to_css(<<"keyword.operator"/utf8>>, erlang:element(42, Theme))
),
_pipe@43 = gleam@string_builder:append(
_pipe@42,
style_to_css(<<"keyword.import"/utf8>>, erlang:element(43, Theme))
),
_pipe@44 = gleam@string_builder:append(
_pipe@43,
style_to_css(<<"keyword.type"/utf8>>, erlang:element(44, Theme))
),
_pipe@45 = gleam@string_builder:append(
_pipe@44,
style_to_css(<<"keyword.modifier"/utf8>>, erlang:element(45, Theme))
),
_pipe@46 = gleam@string_builder:append(
_pipe@45,
style_to_css(<<"keyword.repeat"/utf8>>, erlang:element(46, Theme))
),
_pipe@47 = gleam@string_builder:append(
_pipe@46,
style_to_css(<<"keyword.return"/utf8>>, erlang:element(47, Theme))
),
_pipe@48 = gleam@string_builder:append(
_pipe@47,
style_to_css(<<"keyword.debug"/utf8>>, erlang:element(48, Theme))
),
_pipe@49 = gleam@string_builder:append(
_pipe@48,
style_to_css(<<"keyword.exception"/utf8>>, erlang:element(49, Theme))
),
_pipe@50 = gleam@string_builder:append(
_pipe@49,
style_to_css(<<"keyword.conditional"/utf8>>, erlang:element(50, Theme))
),
_pipe@51 = gleam@string_builder:append(
_pipe@50,
style_to_css(
<<"keyword.conditional.ternary"/utf8>>,
erlang:element(51, Theme)
)
),
_pipe@52 = gleam@string_builder:append(
_pipe@51,
<<"\n/* punctuation */\n"/utf8>>
),
_pipe@53 = gleam@string_builder:append(
_pipe@52,
style_to_css(<<"punctuation"/utf8>>, erlang:element(52, Theme))
),
_pipe@54 = gleam@string_builder:append(
_pipe@53,
style_to_css(<<"punctuation.bracket"/utf8>>, erlang:element(53, Theme))
),
_pipe@55 = gleam@string_builder:append(
_pipe@54,
style_to_css(
<<"punctuation.delimiter"/utf8>>,
erlang:element(54, Theme)
)
),
_pipe@56 = gleam@string_builder:append(
_pipe@55,
style_to_css(<<"punctuation.special"/utf8>>, erlang:element(55, Theme))
),
_pipe@57 = gleam@string_builder:append(
_pipe@56,
<<"\n/* comments */\n"/utf8>>
),
_pipe@58 = gleam@string_builder:append(
_pipe@57,
style_to_css(<<"comment"/utf8>>, erlang:element(56, Theme))
),
_pipe@59 = gleam@string_builder:append(
_pipe@58,
style_to_css(
<<"comment.documentation"/utf8>>,
erlang:element(57, Theme)
)
),
_pipe@60 = gleam@string_builder:append(_pipe@59, <<"\n/* tags */\n"/utf8>>),
_pipe@61 = gleam@string_builder:append(
_pipe@60,
style_to_css(<<"tag"/utf8>>, erlang:element(58, Theme))
),
_pipe@62 = gleam@string_builder:append(
_pipe@61,
style_to_css(<<"tag.builtin"/utf8>>, erlang:element(59, Theme))
),
_pipe@63 = gleam@string_builder:append(
_pipe@62,
style_to_css(<<"tag.attribute"/utf8>>, erlang:element(60, Theme))
),
_pipe@64 = gleam@string_builder:append(
_pipe@63,
style_to_css(<<"tag.delimiter"/utf8>>, erlang:element(61, Theme))
),
gleam@string_builder:to_string(_pipe@64).