Urara-Blog/node_modules/.pnpm-store/v3/files/34/9cddbb0bd3b4f3c0899af6e68df465a3f959f5c6573b88c2375c03016dc6fdbb502c6605440dd7ef8b7125aa184ba74db5f5ba4ff45a52782a5a7b21aa4c5c
2022-08-14 01:14:53 +08:00

29 lines
1.1 KiB
Text

import createDebugger from 'debug';
import { mergeIconProps } from './utils.mjs';
import { trimSVG } from '../svg/trim.mjs';
const debug = createDebugger("@iconify-loader:custom");
async function getCustomIcon(custom, collection, icon, options) {
let result;
debug(`${collection}:${icon}`);
if (typeof custom === "function") {
result = await custom(icon);
} else {
const inline = custom[icon];
result = typeof inline === "function" ? await inline() : inline;
}
if (result) {
const cleanupIdx = result.indexOf("<svg");
if (cleanupIdx > 0)
result = result.slice(cleanupIdx);
const { transform } = options?.customizations ?? {};
result = typeof transform === "function" ? await transform(result, collection, icon) : result;
if (!result.startsWith("<svg")) {
console.warn(`Custom icon "${icon}" in "${collection}" is not a valid SVG`);
return result;
}
return await mergeIconProps(options?.customizations?.trimCustomSvg === true ? trimSVG(result) : result, collection, icon, options, void 0);
}
}
export { getCustomIcon };