Skip to content

pantoken / packages/core/src / toVectorDrawable

函式: toVectorDrawable()

toVectorDrawable(svg, options?): string

Beta(測試)

將內嵌 SVG 轉換為 Android VectorDrawable XML 字串。基於筆畫的圖示 (Lucide) 會輸出 strokeColor/strokeWidth; 基於填充的圖示 (Custom) 會輸出 fillColor

參數

svg

string

內嵌 SVG 標記。

options?

VectorDrawableOptions = {}

VectorDrawableOptions.

回傳

string

VectorDrawable 的 XML。

範例

基於筆畫(Lucide)的圖示會輸出 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"

帶有色調的基於填充(Custom)圖示會輸出 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"