oxvg
repository·main·Indexed 20 days ago
https://github.com/noahbald/oxvgA high-performance vector image toolchain for transforming SVG documents into JSX and React components. It features an optimization engine as a high-performance alternative to SVGO, available via native NAPI bindings, WASM, and a Rust-based CLI. The toolset includes libraries for SVG manipulation (oxvg_ast, oxvg_collections), a linter, and a JSX transformer that follows SVGR configuration options.
What's inside oxvg
- OXVG provides a JSX transformer designed to convert SVG documents into JSX modules compatible with React, Preact, React Native, or any other JSX-compatible environment. The implementation aims to follow the SVGR standard as closely as possible.
Use the OXVG Linter
mainThe OXVG Linter helps catch issues in SVG documents. It is available as a printer or as a language server, similar to tools likesvglintorvnu.Use OXVG for SVG Optimization
mainThe OXVG Optimiser is a high-performance alternative to SVGO. It is designed to run multiple times faster on certain tasks.
Note: It is not an exact clone of SVGO, and users requiring strict parity with SVGO should continue using SVGO for now. Differences in behavior are documented in the project wiki and within the specific struct/interface declarations.
Use OXVG Actions to manipulate SVGs
mainActions are a set of commands used to manipulate an SVG document or extract information from it. They are similar to InkScape's actions but operate without a dependency on a UI or rendering engine.
Note: The
oxvg_actionscrate is currently marked as Unstable.Install @oxvg/napi-darwin-x64
mainThe@oxvg/napi-darwin-x64package provides the x86_64-apple-darwin (Intel-based macOS) binary for the@oxvg/napiNode.js addon. Use this specific package if you are running on an Intel-based Mac and require the native NAPI bindings for OXVG.Deselect elements in a document
mainTo deselect elements within a document, use the-deselectaction. This operation works by removing theoxvg:selectionselement from the document, effectively clearing all current selections.-deselectRun correctness tests
mainTo run the test suite that evaluates the correctness of OXVG's optimisation presets, use the following command. Note that this package follows the
svgcleanertesting methodology.Before running tests, ensure you have extracted the necessary test assets:
- Extract W3C SVG test suite into the
w3c/directory. - Extract Oxygen icons into the
oxygen/directory.
pnpm run test- Extract W3C SVG test suite into the
Migrate from SVGR to @oxvg/jsx
mainWhile
@oxvg/jsxsupports most SVGR features, there are key differences to note during migration:- Templates: Template chunks are strings instead of Babel objects, and templates must return a string.
- Optimization: The
svgo_configoption is replaced byoxvg_config. UseconvertSvgoConfigfrom@oxvg/napito migrate your existing SVGO configuration. - Optimization Engine: The
svgooption is an alias foroxvgand uses the OXVG engine instead of SVGO. - Environment:
@oxvg/jsxuses native NAPI bindings and is only compatible with native (non-web) environments. - Omitted Options: The following SVGR options are not supported:
jsx(in templates)plugins(process input/output manually instead)runtimeConfig,configFile,indexTemplate,index(the library does not use the filesystem; read/write files manually)
Build OXVG from source
mainIf you want to build the project manually from the repository, use the following commands to clone the repo and build the release profile for the
oxvgpackage.git clone git@github.com:noahbald/oxvg.git cd oxvg cargo build --profile release --package oxvg ./target/release/oxvg.exe --helpToggle element classes with the -class command
mainUse the
-class "<name>"command to toggle a specific class name on the currently selected elements. If the class is already present on the elements, it will be removed; if the class is not present, it will be added.# Effects: History, Document -class "<name>"Rotate elements using the rotate action
mainThe
rotateaction applies a rotation to selected SVG elements by appending to theirtransformattribute. The rotation is applied in SVG 1.1 format and includes units.Key Behaviors:
- Attribute Handling: It appends to the existing
transformattribute. If the attribute currently has an"inherit"value, it will be overwritten. - Compatibility: The action has no effect on elements that do not accept
transformas part of their SVG content model. - Origin: You can specify an
xandyorigin. Ifxoryare omitted, the origin defaults to0 0. - Parameters: Accepts an
angle(in degrees) and optionalxandycoordinates as floating-point numbers.
# Rotate by an angle (e.g., 45 degrees) around origin 0,0 -rotate 45 # Rotate by an angle (e.g., 90 degrees) around specific x,y coordinates (e.g., 10,20) -rotate 90 10 20- Attribute Handling: It appends to the existing
Install @oxvg/jsx-linux-x64-gnu
mainThe@oxvg/jsx-linux-x64-gnupackage provides the x86_64-unknown-linux-gnu binary for the@oxvg/jsxlibrary. Use this specific package if you are running on a Linux environment with the x86_64 architecture and the GNU C library (glibc).