From affaf1bea0f128b1e19a400e903e80c9a5cc5659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20S=C3=A1nchez=20Jim=C3=A9nez?= Date: Sat, 26 Feb 2022 17:47:57 +0100 Subject: [PATCH] chore: handle scale --- packages/utils/src/loader/custom.ts | 1 + packages/utils/src/loader/modern.ts | 1 + packages/utils/src/loader/utils.ts | 9 +++++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/utils/src/loader/custom.ts b/packages/utils/src/loader/custom.ts index 37fb304..6e7c9c7 100644 --- a/packages/utils/src/loader/custom.ts +++ b/packages/utils/src/loader/custom.ts @@ -42,6 +42,7 @@ export async function getCustomIcon( icon, additionalProps, options?.addXmlNs === true, + options?.scale, undefined, iconCustomizer, ); diff --git a/packages/utils/src/loader/modern.ts b/packages/utils/src/loader/modern.ts index 46f7425..3965653 100644 --- a/packages/utils/src/loader/modern.ts +++ b/packages/utils/src/loader/modern.ts @@ -39,6 +39,7 @@ export async function searchForIcon( id, additionalProps, options?.addXmlNs === true, + options?.scale, () => attributes, iconCustomizer ); diff --git a/packages/utils/src/loader/utils.ts b/packages/utils/src/loader/utils.ts index 4d0bb10..0978c3f 100644 --- a/packages/utils/src/loader/utils.ts +++ b/packages/utils/src/loader/utils.ts @@ -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, addXmlNs: boolean, + scale?: number, propsProvider?: () => Awaitable>, iconCustomizer?: IconCustomizer, ): Promise { const props: Record = (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];