mirror of
https://github.com/iconify/iconify.git
synced 2024-10-24 01:22:04 +00:00
25 lines
646 B
TypeScript
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';
|
||
|
}
|