LedgerUI.Icons.Hugeicons (LedgerUI v0.2.0)

Copy Markdown View Source

Reads Hugeicons Stroke Rounded SVGs and converts them to the kit's stroke format.

Upstream files hard-code stroke="#141B34", stroke-width="1.5" and the line caps on every shape. The kit's dictionary (priv/icons.json) keeps only the shapes and lets the .lu-i rule of ledger.css supply stroke: currentColor, the 1.5 width and the round caps, so convert/1 does the same: it keeps the geometry, drops the stroke attributes and the fill="none", and turns a solid fill into fill="currentColor" stroke="none". Only shape elements and a fixed list of attributes survive, so a vendored file can never inject script or styles.

names_in/1 finds the icon names a source file uses, for mix ledger_ui.icons sync.

Summary

Functions

Converts an upstream SVG to the kit's format: the inner shapes only, as a string.

The inner shapes of a vendored file (what wrap/1 wrote), or :error when it is not an SVG. Run through convert/1 again, so a hand-edited file is sanitized the same way.

Sorted, unique icon names (without huge-) used by <.icon name="..."> or written as huge-*.

Names in every source file under roots.

"huge-x", "hugeicons:x" and "x" all become "x".

Whether name looks like an upstream file name (search-01).

Wraps converted inner shapes in a standalone <svg> (what the task vendors).

Functions

convert(svg)

@spec convert(binary()) :: {:ok, String.t()} | {:error, :no_shapes}

Converts an upstream SVG to the kit's format: the inner shapes only, as a string.

Returns {:ok, inner} or {:error, :no_shapes}.

iex> svg = ~s(<svg viewBox="0 0 24 24" fill="none"><path d="M1 1L2 2" stroke="#141B34" stroke-width="1.5"/></svg>)
iex> LedgerUI.Icons.Hugeicons.convert(svg)
{:ok, ~s(<path d="M1 1L2 2"/>)}

inner(svg)

@spec inner(binary()) :: {:ok, String.t()} | :error

The inner shapes of a vendored file (what wrap/1 wrote), or :error when it is not an SVG. Run through convert/1 again, so a hand-edited file is sanitized the same way.

names_in(text)

@spec names_in(String.t()) :: [String.t()]

Sorted, unique icon names (without huge-) used by <.icon name="..."> or written as huge-*.

scan(roots)

@spec scan([String.t()]) :: [String.t()]

Names in every source file under roots.

strip_prefix(name)

@spec strip_prefix(String.t()) :: String.t()

"huge-x", "hugeicons:x" and "x" all become "x".

valid_name?(name)

@spec valid_name?(String.t()) :: boolean()

Whether name looks like an upstream file name (search-01).

wrap(inner)

@spec wrap(String.t()) :: String.t()

Wraps converted inner shapes in a standalone <svg> (what the task vendors).