Skip to content

pantoken / packages/core/src / toVectorDrawable

ฟังก์ชัน: toVectorDrawable()

toVectorDrawable(svg, options?): string

เบต้า

แปลง SVG แบบฝังเป็นสตริง XML ของ Android VectorDrawable. ไอคอนแบบใช้เส้น (Lucide) จะส่งออก strokeColor/strokeWidth; ไอคอนแบบเติม (Custom) จะส่งออก fillColor.

พารามิเตอร์

svg

string

มาร์กอัป SVG แบบอินไลน์.

options?

VectorDrawableOptions = {}

VectorDrawableOptions.

คืนค่า

string

XML ของ VectorDrawable.

ตัวอย่าง

ไอคอนแบบใช้เส้น (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"