mirror of
https://github.com/iconify/iconify.git
synced 2025-01-07 15:44:05 +00:00
chore(utils): split getIconsCSS in 2 functions
This commit is contained in:
parent
0b7cde7d56
commit
5af324a952
@ -18,14 +18,20 @@ const defaultSelectors: IconCSSSelectorOptions = {
|
|||||||
overrideSelector: commonSelector + iconSelector,
|
overrideSelector: commonSelector + iconSelector,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface CSSData {
|
||||||
|
common?: CSSUnformattedItem;
|
||||||
|
css: CSSUnformattedItem[];
|
||||||
|
errors: string[];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get CSS for icon
|
* Get data for getIconsCSS()
|
||||||
*/
|
*/
|
||||||
export function getIconsCSS(
|
export function getIconsCSSData(
|
||||||
iconSet: IconifyJSON,
|
iconSet: IconifyJSON,
|
||||||
names: string[],
|
names: string[],
|
||||||
options: IconCSSIconSetOptions = {}
|
options: IconCSSIconSetOptions = {}
|
||||||
): string {
|
): CSSData {
|
||||||
const css: CSSUnformattedItem[] = [];
|
const css: CSSUnformattedItem[] = [];
|
||||||
const errors: string[] = [];
|
const errors: string[] = [];
|
||||||
|
|
||||||
@ -115,30 +121,53 @@ export function getIconsCSS(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Result
|
||||||
|
const result: CSSData = {
|
||||||
|
css,
|
||||||
|
errors,
|
||||||
|
};
|
||||||
|
|
||||||
// Add common stuff
|
// Add common stuff
|
||||||
if (!hasCommonRules && commonSelectors.size) {
|
if (!hasCommonRules && commonSelectors.size) {
|
||||||
const selector = Array.from(commonSelectors).join(
|
const selector = Array.from(commonSelectors).join(
|
||||||
newOptions.format === 'compressed' ? ',' : ', '
|
newOptions.format === 'compressed' ? ',' : ', '
|
||||||
);
|
);
|
||||||
|
result.common = {
|
||||||
|
selector,
|
||||||
|
rules: commonRules,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get CSS for icon
|
||||||
|
*/
|
||||||
|
export function getIconsCSS(
|
||||||
|
iconSet: IconifyJSON,
|
||||||
|
names: string[],
|
||||||
|
options: IconCSSIconSetOptions = {}
|
||||||
|
): string {
|
||||||
|
const { css, errors, common } = getIconsCSSData(iconSet, names, options);
|
||||||
|
|
||||||
|
// Add common stuff
|
||||||
|
if (common) {
|
||||||
// Check for same selector
|
// Check for same selector
|
||||||
if (css.length === 1 && css[0].selector === selector) {
|
if (css.length === 1 && css[0].selector === common.selector) {
|
||||||
css[0].rules = {
|
css[0].rules = {
|
||||||
// Common first, override later
|
// Common first, override later
|
||||||
...commonRules,
|
...common.rules,
|
||||||
...css[0].rules,
|
...css[0].rules,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
css.unshift({
|
css.unshift(common);
|
||||||
selector,
|
|
||||||
rules: commonRules,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format
|
// Format
|
||||||
return (
|
return (
|
||||||
formatCSS(css, newOptions.format) +
|
formatCSS(css, options.format) +
|
||||||
(errors.length ? '\n' + errors.join('\n') + '\n' : '')
|
(errors.length ? '\n' + errors.join('\n') + '\n' : '')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user