diff --git a/packages/utils/src/loader/custom.ts b/packages/utils/src/loader/custom.ts
index c714bc7..a7eb746 100644
--- a/packages/utils/src/loader/custom.ts
+++ b/packages/utils/src/loader/custom.ts
@@ -5,6 +5,7 @@ import type {
InlineCollection,
} from './types';
import { mergeIconProps } from './utils';
+import { trimSVG } from '../svg/trim';
const debug = createDebugger('@iconify-loader:custom');
@@ -40,6 +41,7 @@ export async function getCustomIcon(
typeof transform === 'function' ? await transform(result) : result,
collection,
icon,
+ true,
options,
undefined
);
diff --git a/packages/utils/src/loader/modern.ts b/packages/utils/src/loader/modern.ts
index 36bc4cc..ad6fe79 100644
--- a/packages/utils/src/loader/modern.ts
+++ b/packages/utils/src/loader/modern.ts
@@ -33,6 +33,7 @@ export async function searchForIcon(
``,
collection,
id,
+ false,
options,
() => attributes
);
diff --git a/packages/utils/src/loader/types.ts b/packages/utils/src/loader/types.ts
index b5474c4..8d5c51e 100644
--- a/packages/utils/src/loader/types.ts
+++ b/packages/utils/src/loader/types.ts
@@ -33,6 +33,7 @@ export type IconCustomizer = (
* - apply `customize` with default customizations, if provided
* - apply `iconCustomizer` with `customize` customizations, if provided
* - apply `additionalProps` with `iconCustomizer` customizations, if provided
+ * - apply `trimSVG` to the final `SVG` only when using custom icon collection and `trimCustomSvg` enabled
*/
export type IconCustomizations = {
/**
@@ -63,6 +64,14 @@ export type IconCustomizations = {
* All properties without value will not be applied.
*/
additionalProps?: Record;
+ /**
+ * Should optimize the custom `svg` icon?.
+ *
+ * Enable this flag when using custom `SVG` on `CSS`.
+ *
+ * @default `false`.
+ */
+ trimCustomSvg?: boolean;
};
/**
diff --git a/packages/utils/src/loader/utils.ts b/packages/utils/src/loader/utils.ts
index 4ad4a4c..d4706fa 100644
--- a/packages/utils/src/loader/utils.ts
+++ b/packages/utils/src/loader/utils.ts
@@ -1,5 +1,6 @@
import type { Awaitable } from '@antfu/utils';
import type { IconifyLoaderOptions } from './types';
+import { trimSVG } from '../svg/trim';
const svgWidthRegex = /width\s*=\s*["'](\w+)["']/;
const svgHeightRegex = /height\s*=\s*["'](\w+)["']/;
@@ -38,6 +39,7 @@ export async function mergeIconProps(
svg: string,
collection: string,
icon: string,
+ customSvg: boolean,
options?: IconifyLoaderOptions,
propsProvider?: () => Awaitable>
): Promise {
@@ -81,7 +83,7 @@ export async function mergeIconProps(
svg = svg.replace('