Skip to content

pantoken-root / packages/core/src / toVectorDrawable

Funktion: toVectorDrawable() ​

toVectorDrawable(svg, options?): string

Beta

Konvertera en inline SVG till en Android VectorDrawable XML-sträng. Streckbaserade ikoner (Lucide) avger strokeColor/strokeWidth; fyllnadsbaserade ikoner (Custom) avger fillColor.

Parametrar ​

svg ​

string

Inbäddad SVG‑markup.

options? ​

VectorDrawableOptions = {}

VectorDrawableOptions.

Returnerar ​

string

VectorDrawable XML.

Exempel ​

En streckbaserad (Lucide) ikon avger 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"

En fyllnadsbaserad (Custom) ikon med en tonfärg avger 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"