Skip to content

pantoken / packages/core/src / toVectorDrawable

Funzione: toVectorDrawable()

toVectorDrawable(svg, options?): string

Beta

Converti un SVG inline in una stringa XML VectorDrawable per Android. Le icone basate su tratti (Lucide) emettono strokeColor/strokeWidth; le icone basate sul riempimento (Custom) emettono fillColor.

Parametri

svg

string

Inserisci il markup SVG inline.

options?

VectorDrawableOptions = {}

VectorDrawableOptions.

Restituisce

string

L'XML VectorDrawable.

Esempi

Un'icona basata su tratti (Lucide) emette strokeColor

ts
import { toVectorDrawable } from "@pantoken/core";

const xml = toVectorDrawable(
  '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">' +
    '<path d="M5 12h14"/></svg>',
);
// → <vector …> with android:strokeColor and android:pathData="M5 12h14"

Un'icona basata sul riempimento (Custom) con un colore di tinta emette fillColor

ts
import { toVectorDrawable } from "@pantoken/core";

toVectorDrawable('<svg viewBox="0 0 24 24"><path d="M0 0h24v24H0z"/></svg>', {
  color: "#FF0374B5",
});
// → <vector …> with android:fillColor="#FF0374B5"