-module(svg_path@inspect).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/svg_path/inspect.gleam").
-export([default_options/0, decimal_options/1, fixed_decimal_options/1, with_left_decimals/2, with_right_decimals/2, with_left_padding/2, path_with_options/2, path/1, path_code_with_options/2, path_code/1, subpath_with_options/2, subpath/1, subpath_code_with_options/2, subpath_code/1, segment_with_options/2, segment/1, segment_code_with_options/2, segment_code/1, point_with_options/2, point/1, point_code_with_options/2, point_code/1]).
-export_type([options/0, left_padding_style/0, left_decimal_options/0, right_decimal_options/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(
" Human-readable structural inspection for path values.\n"
"\n"
" This module is for debugging and tests, not for producing valid SVG path\n"
" data. Use `svg_path/serialize` when you need a `d` attribute string.\n"
).
-type options() :: {options, left_decimal_options(), right_decimal_options()}.
-type left_padding_style() :: zero | space.
-type left_decimal_options() :: succinct |
{auto_left_padding, left_padding_style()} |
{left_padding, integer(), left_padding_style()}.
-type right_decimal_options() :: system |
{at_most, integer()} |
{fixed, integer()}.
-file("src/svg_path/inspect.gleam", 60).
?DOC(
" Default inspection options.\n"
"\n"
" Defaults to raw float formatting with trailing decimal zeroes stripped.\n"
).
-spec default_options() -> options().
default_options() ->
{options, succinct, system}.
-file("src/svg_path/inspect.gleam", 67).
?DOC(
" Create options that round numbers to the given number of decimal places.\n"
"\n"
" Trailing zeroes are stripped. Negative decimal places are clamped to zero.\n"
).
-spec decimal_options(integer()) -> options().
decimal_options(Decimal_places) ->
{options, succinct, {at_most, Decimal_places}}.
-file("src/svg_path/inspect.gleam", 75).
?DOC(
" Create options that round numbers and keep exactly the given number of\n"
" decimal places.\n"
"\n"
" Negative decimal places are clamped to zero.\n"
).
-spec fixed_decimal_options(integer()) -> options().
fixed_decimal_options(Decimal_places) ->
{options, succinct, {fixed, Decimal_places}}.
-file("src/svg_path/inspect.gleam", 80).
?DOC(" Set left-side decimal formatting for inspection options.\n").
-spec with_left_decimals(options(), left_decimal_options()) -> options().
with_left_decimals(Options, Left_decimals) ->
{options, Left_decimals, erlang:element(3, Options)}.
-file("src/svg_path/inspect.gleam", 88).
?DOC(" Set right-side decimal formatting for inspection options.\n").
-spec with_right_decimals(options(), right_decimal_options()) -> options().
with_right_decimals(Options, Right_decimals) ->
{options, erlang:element(2, Options), Right_decimals}.
-file("src/svg_path/inspect.gleam", 96).
?DOC(" Set left-side number padding for inspection options.\n").
-spec with_left_padding(options(), left_decimal_options()) -> options().
with_left_padding(Options, Left_padding) ->
with_left_decimals(Options, Left_padding).
-file("src/svg_path/inspect.gleam", 488).
-spec right_decimals(right_decimal_options()) -> svg_path@number_format:right_decimal_options().
right_decimals(Right_decimals) ->
case Right_decimals of
system ->
system;
{at_most, Decimal_places} ->
{at_most, Decimal_places};
{fixed, Decimal_places@1} ->
{fixed, Decimal_places@1}
end.
-file("src/svg_path/inspect.gleam", 479).
-spec left_padding_style(left_padding_style()) -> svg_path@number_format:left_padding_style().
left_padding_style(Style) ->
case Style of
zero ->
zero;
space ->
space
end.
-file("src/svg_path/inspect.gleam", 466).
-spec left_decimals(left_decimal_options()) -> svg_path@number_format:left_decimal_options().
left_decimals(Left_decimals) ->
case Left_decimals of
succinct ->
succinct;
{auto_left_padding, Style} ->
{auto_left_padding, left_padding_style(Style)};
{left_padding, Width, Style@1} ->
{left_padding, Width, left_padding_style(Style@1)}
end.
-file("src/svg_path/inspect.gleam", 459).
-spec number_options(options()) -> svg_path@number_format:options().
number_options(Options) ->
{options,
left_decimals(erlang:element(2, Options)),
right_decimals(erlang:element(3, Options))}.
-file("src/svg_path/inspect.gleam", 452).
-spec number_format(options(), list(float())) -> svg_path@number_format:number_format().
number_format(Options, Numbers) ->
svg_path@number_format:prepare(number_options(Options), Numbers).
-file("src/svg_path/inspect.gleam", 555).
-spec number(float(), svg_path@number_format:number_format()) -> binary().
number(Number, Format) ->
svg_path@number_format:number(Number, Format).
-file("src/svg_path/inspect.gleam", 417).
-spec do_point(vec@vec2:vec2(float()), svg_path@number_format:number_format()) -> binary().
do_point(Point, Format) ->
<<<<(number(erlang:element(2, Point), Format))/binary, ","/utf8>>/binary,
(number(erlang:element(3, Point), Format))/binary>>.
-file("src/svg_path/inspect.gleam", 548).
-spec bool(boolean()) -> binary().
bool(Value) ->
case Value of
true ->
<<"True"/utf8>>;
false ->
<<"False"/utf8>>
end.
-file("src/svg_path/inspect.gleam", 280).
-spec do_segment(svg_path:segment(), svg_path@number_format:number_format()) -> binary().
do_segment(Segment, Format) ->
case Segment of
{line, Start, End} ->
<<<<<<<<"Line(start="/utf8, (do_point(Start, Format))/binary>>/binary,
" end="/utf8>>/binary,
(do_point(End, Format))/binary>>/binary,
")"/utf8>>;
{quadratic_bezier, Start@1, Control, End@1} ->
<<<<<<<<<<<<"QuadraticBezier(start="/utf8,
(do_point(Start@1, Format))/binary>>/binary,
" control="/utf8>>/binary,
(do_point(Control, Format))/binary>>/binary,
" end="/utf8>>/binary,
(do_point(End@1, Format))/binary>>/binary,
")"/utf8>>;
{cubic_bezier, Start@2, Control1, Control2, End@2} ->
<<<<<<<<<<<<<<<<"CubicBezier(start="/utf8,
(do_point(Start@2, Format))/binary>>/binary,
" control1="/utf8>>/binary,
(do_point(Control1, Format))/binary>>/binary,
" control2="/utf8>>/binary,
(do_point(Control2, Format))/binary>>/binary,
" end="/utf8>>/binary,
(do_point(End@2, Format))/binary>>/binary,
")"/utf8>>;
{arc, Start@3, Radius, X_axis_rotation, Large_arc, Sweep, End@3} ->
<<<<<<<<<<<<<<<<<<<<<<<<"Arc(start="/utf8,
(do_point(
Start@3,
Format
))/binary>>/binary,
" radius="/utf8>>/binary,
(do_point(Radius, Format))/binary>>/binary,
" x_axis_rotation="/utf8>>/binary,
(number(X_axis_rotation, Format))/binary>>/binary,
" large_arc="/utf8>>/binary,
(bool(Large_arc))/binary>>/binary,
" sweep="/utf8>>/binary,
(bool(Sweep))/binary>>/binary,
" end="/utf8>>/binary,
(do_point(End@3, Format))/binary>>/binary,
")"/utf8>>
end.
-file("src/svg_path/inspect.gleam", 541).
-spec indent_lines(binary()) -> binary().
indent_lines(Lines) ->
_pipe = Lines,
_pipe@1 = gleam@string:split(_pipe, <<"\n"/utf8>>),
_pipe@2 = gleam@list:map(
_pipe@1,
fun(Line) -> <<" "/utf8, Line/binary>> end
),
gleam@string:join(_pipe@2, <<"\n"/utf8>>).
-file("src/svg_path/inspect.gleam", 181).
-spec do_subpath(svg_path:subpath(), svg_path@number_format:number_format()) -> binary().
do_subpath(Subpath, Format) ->
State = case svg_path:is_closed(Subpath) of
true ->
<<"closed"/utf8>>;
false ->
<<"open"/utf8>>
end,
Start@1 = case svg_path:start(Subpath) of
{ok, Start} -> Start;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"svg_path/inspect"/utf8>>,
function => <<"do_subpath"/utf8>>,
line => 190,
value => _assert_fail,
start => 5181,
'end' => 5227,
pattern_start => 5192,
pattern_end => 5201})
end,
Start@2 = <<"start="/utf8, (do_point(Start@1, Format))/binary>>,
case svg_path:segments(Subpath) of
[] ->
<<<<<<<<"Subpath("/utf8, State/binary>>/binary, ", "/utf8>>/binary,
Start@2/binary>>/binary,
", [])"/utf8>>;
Segments ->
<<<<<<<<<<<<"Subpath("/utf8, State/binary>>/binary, ", "/utf8>>/binary,
Start@2/binary>>/binary,
", [\n"/utf8>>/binary,
(indent_lines(
begin
_pipe = Segments,
_pipe@1 = gleam@list:map(
_pipe,
fun(_capture) ->
do_segment(_capture, Format)
end
),
gleam@string:join(_pipe@1, <<",\n"/utf8>>)
end
))/binary>>/binary,
"\n])"/utf8>>
end.
-file("src/svg_path/inspect.gleam", 117).
-spec do_path(svg_path:path(), svg_path@number_format:number_format()) -> binary().
do_path(Path, Format) ->
case svg_path:subpaths(Path) of
[] ->
<<"Path([])"/utf8>>;
Subpaths ->
<<<<"Path([\n"/utf8,
(indent_lines(
begin
_pipe = Subpaths,
_pipe@1 = gleam@list:map(
_pipe,
fun(_capture) ->
do_subpath(_capture, Format)
end
),
gleam@string:join(_pipe@1, <<",\n"/utf8>>)
end
))/binary>>/binary,
"\n])"/utf8>>
end.
-file("src/svg_path/inspect.gleam", 537).
-spec point_numbers(vec@vec2:vec2(float())) -> list(float()).
point_numbers(Point) ->
[erlang:element(2, Point), erlang:element(3, Point)].
-file("src/svg_path/inspect.gleam", 516).
-spec segment_numbers(svg_path:segment()) -> list(float()).
segment_numbers(Segment) ->
case Segment of
{line, Start, End} ->
lists:append(point_numbers(Start), point_numbers(End));
{quadratic_bezier, Start@1, Control, End@1} ->
_pipe = point_numbers(Start@1),
_pipe@1 = lists:append(_pipe, point_numbers(Control)),
lists:append(_pipe@1, point_numbers(End@1));
{cubic_bezier, Start@2, Control1, Control2, End@2} ->
_pipe@2 = point_numbers(Start@2),
_pipe@3 = lists:append(_pipe@2, point_numbers(Control1)),
_pipe@4 = lists:append(_pipe@3, point_numbers(Control2)),
lists:append(_pipe@4, point_numbers(End@2));
{arc, Start@3, Radius, X_axis_rotation, _, _, End@3} ->
_pipe@5 = point_numbers(Start@3),
_pipe@6 = lists:append(_pipe@5, point_numbers(Radius)),
_pipe@7 = lists:append(_pipe@6, [X_axis_rotation]),
lists:append(_pipe@7, point_numbers(End@3))
end.
-file("src/svg_path/inspect.gleam", 506).
-spec subpath_numbers(svg_path:subpath()) -> list(float()).
subpath_numbers(Subpath) ->
Start@1 = case svg_path:start(Subpath) of
{ok, Start} -> Start;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"svg_path/inspect"/utf8>>,
function => <<"subpath_numbers"/utf8>>,
line => 507,
value => _assert_fail,
start => 13406,
'end' => 13452,
pattern_start => 13417,
pattern_end => 13426})
end,
_pipe = Subpath,
_pipe@1 = svg_path:segments(_pipe),
gleam@list:fold(
_pipe@1,
point_numbers(Start@1),
fun(Accumulated, Segment) ->
lists:append(Accumulated, segment_numbers(Segment))
end
).
-file("src/svg_path/inspect.gleam", 498).
-spec path_numbers(svg_path:path()) -> list(float()).
path_numbers(Path) ->
_pipe = Path,
_pipe@1 = svg_path:subpaths(_pipe),
gleam@list:fold(
_pipe@1,
[],
fun(Accumulated, Subpath) ->
lists:append(Accumulated, subpath_numbers(Subpath))
end
).
-file("src/svg_path/inspect.gleam", 109).
?DOC(" Inspect a path as a multiline structural string with custom options.\n").
-spec path_with_options(svg_path:path(), options()) -> binary().
path_with_options(Path, Options) ->
Format = number_format(Options, path_numbers(Path)),
do_path(Path, Format).
-file("src/svg_path/inspect.gleam", 104).
?DOC(" Inspect a path as a multiline structural string.\n").
-spec path(svg_path:path()) -> binary().
path(Path) ->
path_with_options(Path, default_options()).
-file("src/svg_path/inspect.gleam", 559).
-spec code_number(float(), svg_path@number_format:number_format()) -> binary().
code_number(Value, Format) ->
svg_path@number_format:code_number(Value, Format).
-file("src/svg_path/inspect.gleam", 441).
-spec do_point_code(
vec@vec2:vec2(float()),
svg_path@number_format:number_format()
) -> binary().
do_point_code(Point, Format) ->
<<<<<<<<"svg_path.point("/utf8,
(code_number(erlang:element(2, Point), Format))/binary>>/binary,
", "/utf8>>/binary,
(code_number(erlang:element(3, Point), Format))/binary>>/binary,
")"/utf8>>.
-file("src/svg_path/inspect.gleam", 350).
-spec do_segment_code(
svg_path:segment(),
svg_path@number_format:number_format()
) -> binary().
do_segment_code(Segment, Format) ->
case Segment of
{line, Start, End} ->
<<<<<<<<"svg_path.Line(start: "/utf8,
(do_point_code(Start, Format))/binary>>/binary,
", end: "/utf8>>/binary,
(do_point_code(End, Format))/binary>>/binary,
")"/utf8>>;
{quadratic_bezier, Start@1, Control, End@1} ->
<<<<<<<<<<<<"svg_path.QuadraticBezier(start: "/utf8,
(do_point_code(Start@1, Format))/binary>>/binary,
", control: "/utf8>>/binary,
(do_point_code(Control, Format))/binary>>/binary,
", end: "/utf8>>/binary,
(do_point_code(End@1, Format))/binary>>/binary,
")"/utf8>>;
{cubic_bezier, Start@2, Control1, Control2, End@2} ->
<<<<<<<<<<<<<<<<"svg_path.CubicBezier(start: "/utf8,
(do_point_code(Start@2, Format))/binary>>/binary,
", control1: "/utf8>>/binary,
(do_point_code(Control1, Format))/binary>>/binary,
", control2: "/utf8>>/binary,
(do_point_code(Control2, Format))/binary>>/binary,
", end: "/utf8>>/binary,
(do_point_code(End@2, Format))/binary>>/binary,
")"/utf8>>;
{arc, Start@3, Radius, X_axis_rotation, Large_arc, Sweep, End@3} ->
<<<<<<<<<<<<<<<<<<<<<<<<"svg_path.Arc(start: "/utf8,
(do_point_code(
Start@3,
Format
))/binary>>/binary,
", radius: "/utf8>>/binary,
(do_point_code(
Radius,
Format
))/binary>>/binary,
", x_axis_rotation: "/utf8>>/binary,
(code_number(
X_axis_rotation,
Format
))/binary>>/binary,
", large_arc: "/utf8>>/binary,
(bool(Large_arc))/binary>>/binary,
", sweep: "/utf8>>/binary,
(bool(Sweep))/binary>>/binary,
", end: "/utf8>>/binary,
(do_point_code(End@3, Format))/binary>>/binary,
")"/utf8>>
end.
-file("src/svg_path/inspect.gleam", 228).
-spec do_subpath_code(
svg_path:subpath(),
svg_path@number_format:number_format()
) -> binary().
do_subpath_code(Subpath, Format) ->
Start@1 = case svg_path:start(Subpath) of
{ok, Start} -> Start;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"svg_path/inspect"/utf8>>,
function => <<"do_subpath_code"/utf8>>,
line => 232,
value => _assert_fail,
start => 6269,
'end' => 6315,
pattern_start => 6280,
pattern_end => 6289})
end,
case svg_path:segments(Subpath) of
[] ->
Constructor = <<<<"svg_path.empty_subpath(at: "/utf8,
(do_point_code(Start@1, Format))/binary>>/binary,
")"/utf8>>,
case svg_path:is_closed(Subpath) of
false ->
Constructor;
true ->
<<Constructor/binary,
"\n|> svg_path.assert_set_closed(closed: True)"/utf8>>
end;
Segments ->
Constructor@1 = <<<<"svg_path.assert_subpath([\n"/utf8,
(indent_lines(
begin
_pipe = Segments,
_pipe@1 = gleam@list:map(
_pipe,
fun(_capture) ->
do_segment_code(_capture, Format)
end
),
gleam@string:join(_pipe@1, <<",\n"/utf8>>)
end
))/binary>>/binary,
"\n])"/utf8>>,
case svg_path:is_closed(Subpath) of
false ->
Constructor@1;
true ->
<<Constructor@1/binary,
"\n|> svg_path.assert_set_closed(closed: True)"/utf8>>
end
end.
-file("src/svg_path/inspect.gleam", 149).
-spec do_path_code(svg_path:path(), svg_path@number_format:number_format()) -> binary().
do_path_code(Path, Format) ->
case svg_path:subpaths(Path) of
[] ->
<<"svg_path.empty_path()"/utf8>>;
Subpaths ->
<<<<"svg_path.Path([\n"/utf8,
(indent_lines(
begin
_pipe = Subpaths,
_pipe@1 = gleam@list:map(
_pipe,
fun(_capture) ->
do_subpath_code(_capture, Format)
end
),
gleam@string:join(_pipe@1, <<",\n"/utf8>>)
end
))/binary>>/binary,
"\n])"/utf8>>
end.
-file("src/svg_path/inspect.gleam", 141).
?DOC(" Inspect a path as copy-pasteable Gleam code with custom options.\n").
-spec path_code_with_options(svg_path:path(), options()) -> binary().
path_code_with_options(Path, Options) ->
Format = number_format(Options, path_numbers(Path)),
do_path_code(Path, Format).
-file("src/svg_path/inspect.gleam", 136).
?DOC(
" Inspect a path as copy-pasteable Gleam code.\n"
"\n"
" The generated code assumes the `svg_path` package is imported as\n"
" `svg_path`.\n"
).
-spec path_code(svg_path:path()) -> binary().
path_code(Path) ->
path_code_with_options(Path, default_options()).
-file("src/svg_path/inspect.gleam", 173).
?DOC(" Inspect a subpath as a multiline structural string with custom options.\n").
-spec subpath_with_options(svg_path:subpath(), options()) -> binary().
subpath_with_options(Subpath, Options) ->
Format = number_format(Options, subpath_numbers(Subpath)),
do_subpath(Subpath, Format).
-file("src/svg_path/inspect.gleam", 168).
?DOC(" Inspect a subpath as a multiline structural string.\n").
-spec subpath(svg_path:subpath()) -> binary().
subpath(Subpath) ->
subpath_with_options(Subpath, default_options()).
-file("src/svg_path/inspect.gleam", 220).
?DOC(" Inspect a subpath as copy-pasteable Gleam code with custom options.\n").
-spec subpath_code_with_options(svg_path:subpath(), options()) -> binary().
subpath_code_with_options(Subpath, Options) ->
Format = number_format(Options, subpath_numbers(Subpath)),
do_subpath_code(Subpath, Format).
-file("src/svg_path/inspect.gleam", 215).
?DOC(
" Inspect a subpath as copy-pasteable Gleam code.\n"
"\n"
" The generated code assumes the `svg_path` package is imported as\n"
" `svg_path`.\n"
).
-spec subpath_code(svg_path:subpath()) -> binary().
subpath_code(Subpath) ->
subpath_code_with_options(Subpath, default_options()).
-file("src/svg_path/inspect.gleam", 272).
?DOC(" Inspect a segment as a single-line structural string with custom options.\n").
-spec segment_with_options(svg_path:segment(), options()) -> binary().
segment_with_options(Segment, Options) ->
Format = number_format(Options, segment_numbers(Segment)),
do_segment(Segment, Format).
-file("src/svg_path/inspect.gleam", 267).
?DOC(" Inspect a segment as a single-line structural string.\n").
-spec segment(svg_path:segment()) -> binary().
segment(Segment) ->
segment_with_options(Segment, default_options()).
-file("src/svg_path/inspect.gleam", 342).
?DOC(" Inspect a segment as copy-pasteable Gleam code with custom options.\n").
-spec segment_code_with_options(svg_path:segment(), options()) -> binary().
segment_code_with_options(Segment, Options) ->
Format = number_format(Options, segment_numbers(Segment)),
do_segment_code(Segment, Format).
-file("src/svg_path/inspect.gleam", 337).
?DOC(
" Inspect a segment as copy-pasteable Gleam code.\n"
"\n"
" The generated code assumes the `svg_path` package is imported as\n"
" `svg_path`.\n"
).
-spec segment_code(svg_path:segment()) -> binary().
segment_code(Segment) ->
segment_code_with_options(Segment, default_options()).
-file("src/svg_path/inspect.gleam", 409).
?DOC(" Inspect a point as `x,y` with custom options.\n").
-spec point_with_options(vec@vec2:vec2(float()), options()) -> binary().
point_with_options(Point, Options) ->
Format = number_format(Options, point_numbers(Point)),
do_point(Point, Format).
-file("src/svg_path/inspect.gleam", 404).
?DOC(" Inspect a point as `x,y`.\n").
-spec point(vec@vec2:vec2(float())) -> binary().
point(Point) ->
point_with_options(Point, default_options()).
-file("src/svg_path/inspect.gleam", 433).
?DOC(" Inspect a point as copy-pasteable Gleam code with custom options.\n").
-spec point_code_with_options(vec@vec2:vec2(float()), options()) -> binary().
point_code_with_options(Point, Options) ->
Format = number_format(Options, point_numbers(Point)),
do_point_code(Point, Format).
-file("src/svg_path/inspect.gleam", 428).
?DOC(
" Inspect a point as copy-pasteable Gleam code.\n"
"\n"
" The generated code assumes the `svg_path` package is imported as\n"
" `svg_path`.\n"
).
-spec point_code(vec@vec2:vec2(float())) -> binary().
point_code(Point) ->
point_code_with_options(Point, default_options()).