Merge branch 'trunk' of https://gitea.mcmorgans.us/gavin/labelmaker into trunk
This commit is contained in:
@@ -3,37 +3,3 @@
|
|||||||
@import 'tailwindcss/utilities';
|
@import 'tailwindcss/utilities';
|
||||||
|
|
||||||
/* This file is for your main application CSS */
|
/* This file is for your main application CSS */
|
||||||
|
|
||||||
.outline-black {
|
|
||||||
text-shadow:
|
|
||||||
-1px -1px 0 black,
|
|
||||||
1px -1px 0 black,
|
|
||||||
-1px 1px 0 black,
|
|
||||||
1px 1px 0 black;
|
|
||||||
}
|
|
||||||
|
|
||||||
.outline-gray {
|
|
||||||
text-shadow:
|
|
||||||
-1px -1px 0 gray,
|
|
||||||
1px -1px 0 gray,
|
|
||||||
-1px 1px 0 gray,
|
|
||||||
1px 1px 0 gray;
|
|
||||||
}
|
|
||||||
|
|
||||||
.outline-white {
|
|
||||||
color: white;
|
|
||||||
text-shadow:
|
|
||||||
-1px -1px 0 white,
|
|
||||||
1px -1px 0 white,
|
|
||||||
-1px 1px 0 white,
|
|
||||||
1px 1px 0 white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.outline-danger {
|
|
||||||
color: #ff6b6b;
|
|
||||||
text-shadow:
|
|
||||||
-1px -1px 0 #ff6b6b,
|
|
||||||
1px -1px 0 #ff6b6b,
|
|
||||||
-1px 1px 0 #ff6b6b,
|
|
||||||
1px 1px 0 #ff6b6b;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -19,42 +19,63 @@ defmodule LabelmakerWeb.Constants do
|
|||||||
|> Map.keys()
|
|> Map.keys()
|
||||||
|> Enum.map(&Atom.to_string/1)
|
|> Enum.map(&Atom.to_string/1)
|
||||||
|
|
||||||
@colors System.cmd("magick", ["-list", "color"])
|
@colors [
|
||||||
|> elem(0)
|
"black",
|
||||||
|> String.split("\n")
|
"blue",
|
||||||
# drop header stuff
|
"brown",
|
||||||
|> Enum.drop(5)
|
"gray",
|
||||||
|> Enum.map(fn color_info -> color_info |> String.split() |> List.first() end)
|
"green",
|
||||||
|> Enum.reject(&is_nil/1)
|
"orange",
|
||||||
# filter out colors that end in a number (no CSS equivalent)
|
"pink",
|
||||||
|> Enum.reject(fn color -> String.match?(color, ~r/\d+$/) end)
|
"purple",
|
||||||
|> Enum.uniq()
|
"red",
|
||||||
|
"white",
|
||||||
|
"yellow"
|
||||||
|
]
|
||||||
|
|
||||||
@fonts System.cmd("magick", ["-list", "font"])
|
@danger "#FF6B6B"
|
||||||
|> elem(0)
|
|
||||||
|> String.split("\n")
|
@font_map %{
|
||||||
|> Enum.filter(&String.starts_with?(&1, " Font:"))
|
"cs" => "Comic-Sans-MS",
|
||||||
|> Enum.reject(&String.starts_with?(&1, " Font: ."))
|
"comic" => "Comic-Sans-MS",
|
||||||
|> Enum.map(&String.trim_leading(&1, " Font: "))
|
"comic sans" => "Comic-Sans-MS",
|
||||||
|
"comic-sans" => "Comic-Sans-MS",
|
||||||
|
"comic-sans-ms" => "Comic-Sans-MS",
|
||||||
|
"cr" => "Courier",
|
||||||
|
"courier" => "Courier",
|
||||||
|
"g" => "Georgia",
|
||||||
|
"georgia" => "Georgia",
|
||||||
|
"h" => "Helvetica",
|
||||||
|
"helvetica" => "Helvetica",
|
||||||
|
"i" => "Impact",
|
||||||
|
"impact" => "Impact",
|
||||||
|
"v" => "Verdana",
|
||||||
|
"verdana" => "Verdana"
|
||||||
|
}
|
||||||
|
|
||||||
@max_label_length 64
|
@max_label_length 64
|
||||||
@max_label_error "64-character maximum"
|
@max_label_error "64-character maximum"
|
||||||
|
|
||||||
@outlines ~w(none white black gray)
|
|
||||||
|
|
||||||
@sizes 16..128
|
@sizes 16..128
|
||||||
|> Enum.to_list()
|
|> Enum.to_list()
|
||||||
|> Enum.take_every(8)
|
|> Enum.take_every(8)
|
||||||
|> Enum.map(&Integer.to_string/1)
|
|> Enum.map(&Integer.to_string/1)
|
||||||
|
|
||||||
def colors, do: @colors
|
def colors, do: @colors
|
||||||
def color_count, do: @colors |> length()
|
def danger, do: @danger
|
||||||
def defaults, do: @defaults
|
def defaults, do: @defaults
|
||||||
def fonts, do: @fonts
|
|
||||||
def font_count, do: @fonts |> length()
|
def fonts,
|
||||||
|
do:
|
||||||
|
@font_map
|
||||||
|
|> Map.values()
|
||||||
|
|> Enum.uniq()
|
||||||
|
|> Enum.map(fn color -> color |> String.replace("-MS", "") |> String.replace("-", " ") end)
|
||||||
|
|
||||||
|
def font_map, do: @font_map
|
||||||
def max_label_length, do: @max_label_length
|
def max_label_length, do: @max_label_length
|
||||||
def max_label_error, do: @max_label_error
|
def max_label_error, do: @max_label_error
|
||||||
def outlines, do: @outlines
|
def outlines, do: ["none" | @colors]
|
||||||
def permitted_keys, do: @permitted_keys
|
def permitted_keys, do: @permitted_keys
|
||||||
def preview, do: @preview
|
def preview, do: @preview
|
||||||
def sizes, do: @sizes
|
def sizes, do: @sizes
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ defmodule LabelmakerWeb.Home do
|
|||||||
case assigns.preview_bg do
|
case assigns.preview_bg do
|
||||||
"r" -> "bg-[linear-gradient(to_right,_black_33%,_white_67%)]"
|
"r" -> "bg-[linear-gradient(to_right,_black_33%,_white_67%)]"
|
||||||
"b" -> "bg-[linear-gradient(to_bottom,_black_33%,_white_67%)]"
|
"b" -> "bg-[linear-gradient(to_bottom,_black_33%,_white_67%)]"
|
||||||
"c" -> "bg-[#{assigns.color}]"
|
"c" -> ""
|
||||||
_ -> "bg-[linear-gradient(to_right,_black_33%,_white_67%)]"
|
_ -> "bg-[linear-gradient(to_right,_black_33%,_white_67%)]"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ defmodule LabelmakerWeb.Home do
|
|||||||
<div
|
<div
|
||||||
class={
|
class={
|
||||||
"flex justify-center items-center p-4 overflow-hidden whitespace-nowrap border rounded transition duration-300 #{@preview_background} #{if @label_too_long, do: "border-danger", else: "border-primary"} #{if @label_too_long, do: "outline-danger", else: @outline != "none" && "outline-#{@outline}"}"}
|
"flex justify-center items-center p-4 overflow-hidden whitespace-nowrap border rounded transition duration-300 #{@preview_background} #{if @label_too_long, do: "border-danger", else: "border-primary"} #{if @label_too_long, do: "outline-danger", else: @outline != "none" && "outline-#{@outline}"}"}
|
||||||
style={"height: calc(2rem + #{@preview_height}px); color: #{if @label_too_long, do: "white", else: @color}; font-family: #{@font}; font-size: #{@size}px; line-height: #{@size}px; background-color: #{if @preview_bg == "c", do: @color, else: ""}"}
|
style={"height: calc(2rem + #{@preview_height}px); color: #{if @label_too_long, do: "white", else: @color}; #{Tools.outline(@outline, @label_too_long)} font-family: #{@font}; font-size: #{@size}px; line-height: #{@size}px; background-color: #{if @preview_bg == "c", do: @color, else: ""}"}
|
||||||
>
|
>
|
||||||
<%= if @label_too_long do %>
|
<%= if @label_too_long do %>
|
||||||
{Constants.max_label_error()}
|
{Constants.max_label_error()}
|
||||||
@@ -74,7 +74,7 @@ defmodule LabelmakerWeb.Home do
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex flex-row justify-between" style="margin-top: 5px;">
|
<div class="flex flex-row justify-between" style="margin-top: 5px;">
|
||||||
<p class="text-xs text-gray-600 dark:text-gray-400 m-0 ml-1">
|
<p class="text-xs text-gray-600 dark:text-gray-400 m-0 ml-1">
|
||||||
Note: not all fonts and colors are available for preview.
|
Note: not all fonts are available for preview.
|
||||||
</p>
|
</p>
|
||||||
<div class="flex flex-row gap-1">
|
<div class="flex flex-row gap-1">
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ defmodule LabelmakerWeb.Tools do
|
|||||||
alias LabelmakerWeb.Constants
|
alias LabelmakerWeb.Constants
|
||||||
|
|
||||||
def process_parameters(parameters) do
|
def process_parameters(parameters) do
|
||||||
|
# ensure our defaults are in place to cover any missing parameters
|
||||||
%{"label" => label, "size" => size} =
|
%{"label" => label, "size" => size} =
|
||||||
Constants.defaults()
|
Constants.defaults()
|
||||||
|> Map.new(fn {k, v} -> {Atom.to_string(k), v} end)
|
|> Map.new(fn {k, v} -> {Atom.to_string(k), v} end)
|
||||||
@@ -22,6 +23,9 @@ defmodule LabelmakerWeb.Tools do
|
|||||||
|> Map.take(Constants.permitted_keys())
|
|> Map.take(Constants.permitted_keys())
|
||||||
|> Map.new(fn {k, v} -> {String.to_atom(k), v} end)
|
|> Map.new(fn {k, v} -> {String.to_atom(k), v} end)
|
||||||
|> Enum.map(fn
|
|> Enum.map(fn
|
||||||
|
{:font, font} ->
|
||||||
|
{:font, Constants.font_map()[String.downcase(font)]}
|
||||||
|
|
||||||
{:label, label} ->
|
{:label, label} ->
|
||||||
if String.length(label) > Constants.max_label_length(),
|
if String.length(label) > Constants.max_label_length(),
|
||||||
do: {:label, String.slice(label, 0, Constants.max_label_length() + 1)},
|
do: {:label, String.slice(label, 0, Constants.max_label_length() + 1)},
|
||||||
@@ -41,7 +45,7 @@ defmodule LabelmakerWeb.Tools do
|
|||||||
end)
|
end)
|
||||||
|> Enum.filter(fn
|
|> Enum.filter(fn
|
||||||
{:color, color} -> color in Constants.colors()
|
{:color, color} -> color in Constants.colors()
|
||||||
{:font, font} -> font in Constants.fonts()
|
{:font, font} -> font in Map.values(Constants.font_map())
|
||||||
{:outline, outline} -> outline in Constants.outlines()
|
{:outline, outline} -> outline in Constants.outlines()
|
||||||
{:size, size} -> size in Constants.sizes()
|
{:size, size} -> size in Constants.sizes()
|
||||||
_ -> true
|
_ -> true
|
||||||
@@ -50,4 +54,11 @@ defmodule LabelmakerWeb.Tools do
|
|||||||
|
|
||||||
Map.merge(Constants.defaults(), parameters)
|
Map.merge(Constants.defaults(), parameters)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def outline(_, error: true), do: outline(Constants.danger(), false)
|
||||||
|
def outline("none", _error), do: ""
|
||||||
|
|
||||||
|
def outline(color, _error),
|
||||||
|
do:
|
||||||
|
"text-shadow: -1px -1px 0 #{color}, 1px -1px 0 #{color}, -1px 1px 0 #{color}, 1px 1px 0 #{color};"
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user