2
0
mirror of https://github.com/iconify/iconify.git synced 2024-10-24 01:22:04 +00:00
iconify/iconify-icon/icon/src/attributes/mode.ts

25 lines
646 B
TypeScript
Raw Normal View History

2022-04-29 20:19:22 +00:00
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';
}