2021-05-24 10:25:02 +00:00
|
|
|
import type { IconifyOptional } from '@iconify/types';
|
2021-09-16 21:07:22 +00:00
|
|
|
import type { FullIconifyIcon, IconifyIcon } from './index';
|
|
|
|
import { iconDefaults } from './index';
|
2021-05-24 10:25:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Merge icon and alias
|
|
|
|
*/
|
|
|
|
export function mergeIconData<T extends IconifyIcon | FullIconifyIcon>(
|
|
|
|
icon: T,
|
|
|
|
alias: IconifyOptional
|
|
|
|
): T {
|
|
|
|
const result = { ...icon };
|
|
|
|
for (const key in iconDefaults) {
|
|
|
|
const prop = key as keyof IconifyOptional;
|
|
|
|
if (alias[prop] !== void 0) {
|
|
|
|
const value = alias[prop];
|
|
|
|
|
|
|
|
if (result[prop] === void 0) {
|
|
|
|
// Missing value
|
|
|
|
(result as unknown as Record<string, unknown>)[prop] = value;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (prop) {
|
|
|
|
case 'rotate':
|
|
|
|
(result[prop] as number) =
|
|
|
|
((result[prop] as number) + (value as number)) % 4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'hFlip':
|
|
|
|
case 'vFlip':
|
|
|
|
result[prop] = value !== result[prop];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Overwrite value
|
|
|
|
(result as unknown as Record<string, unknown>)[prop] =
|
|
|
|
value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|