2023-02-06 18:31:55 +00:00
|
|
|
const {
|
|
|
|
addCleanIconSelectors,
|
|
|
|
addDynamicIconSelectors,
|
2024-05-10 07:00:08 +00:00
|
|
|
addIconSelectors,
|
2023-02-06 18:31:55 +00:00
|
|
|
} = require('@iconify/tailwind');
|
2023-04-20 16:35:07 +00:00
|
|
|
const {
|
|
|
|
importDirectorySync,
|
|
|
|
cleanupSVG,
|
|
|
|
parseColorsSync,
|
|
|
|
runSVGO,
|
|
|
|
isEmptyColor,
|
|
|
|
} = require('@iconify/tools');
|
|
|
|
|
|
|
|
// Import icons from directory 'svg'
|
|
|
|
const customSet = importDirectorySync('svg');
|
|
|
|
|
|
|
|
// Clean up all icons
|
|
|
|
customSet.forEachSync((name, type) => {
|
|
|
|
if (type !== 'icon') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get SVG object for icon
|
|
|
|
const svg = customSet.toSVG(name);
|
|
|
|
if (!svg) {
|
|
|
|
// Invalid icon
|
|
|
|
customSet.remove(name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Clean up icon
|
|
|
|
cleanupSVG(svg);
|
|
|
|
|
|
|
|
// This is a monotone icon, change color to `currentColor`, add it if missing
|
|
|
|
// Skip this step if icons have palette
|
|
|
|
parseColorsSync(svg, {
|
|
|
|
defaultColor: 'currentColor',
|
|
|
|
callback: (attr, colorStr, color) => {
|
|
|
|
return !color || isEmptyColor(color)
|
|
|
|
? colorStr
|
|
|
|
: 'currentColor';
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// Optimise icon
|
|
|
|
runSVGO(svg);
|
|
|
|
} catch (err) {
|
|
|
|
// Something went wrong when parsing icon: remove it
|
|
|
|
console.error(`Error parsing ${name}:`, err);
|
|
|
|
customSet.remove(name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update icon in icon set from SVG object
|
|
|
|
customSet.fromSVG(name, svg);
|
|
|
|
});
|
2023-02-06 18:31:55 +00:00
|
|
|
|
|
|
|
/** @type {import('tailwindcss').Config} */
|
|
|
|
module.exports = {
|
|
|
|
content: ['./src/*.html'],
|
|
|
|
plugins: [
|
2024-05-10 07:00:08 +00:00
|
|
|
// Main plugin, default options
|
|
|
|
addIconSelectors(['mdi-light', 'vscode-icons']),
|
|
|
|
// Main plugin, custom options
|
|
|
|
addIconSelectors({
|
|
|
|
maskSelector: '.custom-monotone',
|
|
|
|
backgroundSelector: '.custom-background',
|
|
|
|
// Like UnoCSS
|
|
|
|
iconSelector: '.i-{prefix}-{name}',
|
|
|
|
scale: 1.5,
|
|
|
|
prefixes: [
|
|
|
|
{
|
|
|
|
prefix: 'mdi-light',
|
|
|
|
icons: ['home'],
|
|
|
|
customise: (content) =>
|
|
|
|
content.replace(/currentColor/g, '#40f'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
prefix: 'custom',
|
|
|
|
source: customSet.export(),
|
|
|
|
customise: (content) =>
|
|
|
|
content.replace(/currentColor/g, '#f20'),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
2024-05-10 12:20:32 +00:00
|
|
|
// Main plugin, no size
|
|
|
|
addIconSelectors({
|
|
|
|
maskSelector: '.iconify-nosize',
|
|
|
|
backgroundSelector: '',
|
|
|
|
scale: 0,
|
|
|
|
// Empty prefixes list: reusing data from plugin above
|
|
|
|
prefixes: [],
|
|
|
|
}),
|
2023-02-06 18:31:55 +00:00
|
|
|
// Plugin with clean selectors: requires writing all used icons in first parameter
|
|
|
|
addCleanIconSelectors(['mdi-light:home']),
|
|
|
|
// Plugin with dynamic selectors
|
2023-04-20 16:35:07 +00:00
|
|
|
addDynamicIconSelectors({
|
|
|
|
iconSets: {
|
|
|
|
custom: customSet.export(),
|
|
|
|
},
|
2024-05-06 19:43:28 +00:00
|
|
|
customise: (content, name, prefix) => {
|
|
|
|
switch (name) {
|
|
|
|
case 'spinner1':
|
|
|
|
return content.replace(
|
|
|
|
'animation:0.75s',
|
|
|
|
'animation:5s'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return content;
|
|
|
|
},
|
2023-04-20 16:35:07 +00:00
|
|
|
}),
|
2023-02-06 18:31:55 +00:00
|
|
|
// Plugin with dynamic selectors that contains only css for overriding icon
|
|
|
|
addDynamicIconSelectors({
|
|
|
|
prefix: 'icon-hover',
|
|
|
|
overrideOnly: true,
|
|
|
|
}),
|
2023-11-25 17:25:59 +00:00
|
|
|
// Icons without size
|
|
|
|
addDynamicIconSelectors({
|
|
|
|
prefix: 'scaled-icon',
|
|
|
|
scale: 0,
|
|
|
|
}),
|
2023-02-06 18:31:55 +00:00
|
|
|
],
|
|
|
|
};
|