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"