Skip to content
hlindsetPublic

About

Elixir bindings for the OXVG SVG optimizer, powered by a precompiled Rust NIF.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

oxvg

Elixir bindings for the OXVG SVG optimizer. Oxvg.optimize/2 accepts an SVG binary and returns an optimized SVG.

Installation

def deps do
  [{:oxvg, "~> 0.1.0"}]
end

Optimize SVG

{:ok, optimized_svg} = Oxvg.optimize(svg)

preset: is one of :default, :safe, or :none and defaults to :default. Adding a job never changes the selected preset. Use preset: :none for a custom-only job set.

# Default preset plus prefixIds.
Oxvg.optimize(svg,
  jobs: %{prefix_ids: %{prefix: "icon", delim: "-"}}
)

# Only prefixIds.
Oxvg.optimize(svg,
  preset: :none,
  jobs: %{prefix_ids: %{prefix: "icon", delim: "-"}}
)

Each job can be in one of four states:

  • Missing: inherit the preset's state.
  • :default: enable the job with OXVG's default configuration.
  • :disable: disable the job, including one inherited from a preset.
  • Any other JSON-compatible value: enable the job with that exact upstream configuration value. Accepted values are valid UTF-8 binaries, integers in the supported JSON i64-minimum through u64-maximum domain, floats, booleans, nil, proper lists, and maps. Only :default and :disable are accepted atoms. Unsupported values return an :invalid_value configuration error.

false is a configuration value, not a disable sentinel. Atom keys are recursively converted from snake_case to OXVG camelCase. Binary keys are passed through unchanged so callers can use upstream camelCase job and option names directly.

Errors and bang API

optimize/2 returns {:ok, binary} or {:error, %Oxvg.Error{stage, reason, message, path, value}}.

  • stage is :config, :parse, :optimize, or :serialize.
  • reason is a stable atom. Configuration failures use :invalid_source, :invalid_options, :unknown_option, :invalid_preset, :invalid_jobs, :invalid_key, :key_collision, or :invalid_value. Native failures use :invalid_configuration, :invalid_svg, :optimization_failed, or :serialization_failed.
  • message is a human-readable binary. path retains the original Elixir keys and zero-based list indexes for configuration errors (or is nil for native failures). value is the rejected configuration value when known (or is nil for native failures).

Oxvg.optimize!/2 returns the optimized SVG on success and raises the returned Oxvg.Error on failure.

Builds and supported targets

Published packages download precompiled NIFs for:

aarch64-apple-darwin
x86_64-apple-darwin
x86_64-unknown-linux-gnu
aarch64-unknown-linux-gnu
x86_64-unknown-linux-musl
aarch64-unknown-linux-musl
x86_64-pc-windows-msvc

Set OXVG_BUILD=1 to build from source during development or on unsupported targets:

OXVG_BUILD=1 mix test

LLM Development Notice

This library was developed with help from LLMs.

License

MIT. See the license text.

About

Elixir bindings for the OXVG SVG optimizer, powered by a precompiled Rust NIF.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages