2
0
mirror of https://github.com/iconify/iconify.git synced 2024-10-23 17:12:03 +00:00
iconify/iconify-icon/icon/src/attributes/mode.ts
2022-05-12 22:39:56 +03:00

25 lines
646 B
TypeScript

import type { ActualRenderMode, IconifyRenderMode } from './types';
/**
* Get render mode
*/
export function getRenderMode(body: string, mode?: string): ActualRenderMode {
switch (mode as ActualRenderMode | '') {
// Force mode
case 'svg':
case 'bg':
case 'mask':
return mode as ActualRenderMode;
}
// Check for animation, use 'style' for animated icons
// (only <a>, which should be ignored or animations start with '<a')
if ((mode as IconifyRenderMode) !== 'style' && body.indexOf('<a') === -1) {
// Render <svg>
return 'svg';
}
// Use background or mask
return body.indexOf('currentColor') === -1 ? 'bg' : 'mask';
}