2
0
mirror of https://github.com/iconify/iconify.git synced 2024-09-19 16:59:02 +00:00

chore: handle scale

This commit is contained in:
Joaquín Sánchez Jiménez 2022-02-26 17:47:57 +01:00
parent e507252841
commit affaf1bea0
3 changed files with 9 additions and 2 deletions

View File

@ -42,6 +42,7 @@ export async function getCustomIcon(
icon,
additionalProps,
options?.addXmlNs === true,
options?.scale,
undefined,
iconCustomizer,
);

View File

@ -39,6 +39,7 @@ export async function searchForIcon(
id,
additionalProps,
options?.addXmlNs === true,
options?.scale,
() => attributes,
iconCustomizer
);

View File

@ -1,18 +1,23 @@
import type { Awaitable } from '@antfu/utils';
import type { IconCustomizer } from './types';
export const isNode = typeof process < 'u' && typeof process.stdout < 'u'
export async function mergeIconProps(
svg: string,
collection: string,
icon: string,
additionalProps: Record<string, string | undefined>,
addXmlNs: boolean,
scale?: number,
propsProvider?: () => Awaitable<Record<string, string>>,
iconCustomizer?: IconCustomizer,
): Promise<string> {
const props: Record<string, string> = (await propsProvider?.()) ?? {};
if (!svg.includes(" width=") && !svg.includes(" height=") && typeof scale === 'number') {
if ((typeof props.width === 'undefined' || props.width === null) && (typeof props.height === 'undefined' || props.height === null)) {
props.width = `${scale}em`;
props.height = `${scale}em`;
}
}
await iconCustomizer?.(collection, icon, props);
Object.keys(additionalProps).forEach((p) => {
const v = additionalProps[p];