1
0
mirror of https://github.com/tabler/tabler-icons.git synced 2025-01-17 04:38:28 +01:00

icons optimize

This commit is contained in:
codecalm 2020-12-05 17:26:57 +01:00
parent d64e4d75e2
commit d48ad82e37
15 changed files with 91 additions and 46 deletions

View File

@ -4,6 +4,7 @@ const gulp = require('gulp'),
fs = require('fs'), fs = require('fs'),
path = require('path'), path = require('path'),
p = require('./package.json'), p = require('./package.json'),
csv = require('csv-parser'),
zip = require('gulp-zip'), zip = require('gulp-zip'),
puppeteer = require('puppeteer'), puppeteer = require('puppeteer'),
outlineStroke = require('svg-outline-stroke'), outlineStroke = require('svg-outline-stroke'),
@ -12,6 +13,8 @@ const gulp = require('gulp'),
sass = require('node-sass'), sass = require('node-sass'),
cleanCSS = require('clean-css'), cleanCSS = require('clean-css'),
argv = require('minimist')(process.argv.slice(2)), argv = require('minimist')(process.argv.slice(2)),
svgParse = require('parse-svg-path'),
svgpath = require('svgpath'),
svgr = require('@svgr/core').default; svgr = require('@svgr/core').default;
async function asyncForEach(array, callback) { async function asyncForEach(array, callback) {
@ -404,6 +407,17 @@ gulp.task('optimize', function (cb) {
return Math.round((parseFloat(n1) + parseFloat(n2)) * 1000) / 1000 return Math.round((parseFloat(n1) + parseFloat(n2)) * 1000) / 1000
}; };
const optimizePath = function(path) {
let transformed = svgpath(path)
.rel()
.round(3)
.toString();
return svgParse(transformed).map(function(a){
return a.join(' ');
}).join(' ');
};
glob("src/_icons/*.svg", {}, function (er, files) { glob("src/_icons/*.svg", {}, function (er, files) {
files.forEach(function (file, i) { files.forEach(function (file, i) {
@ -416,6 +430,11 @@ gulp.task('optimize', function (cb) {
.replace(/\s?\/>/g, ' />') .replace(/\s?\/>/g, ' />')
.replace(/\n\s*<(line|circle|path|polyline|rect)/g, "\n <$1") .replace(/\n\s*<(line|circle|path|polyline|rect)/g, "\n <$1")
.replace(/polyline points="([0-9.]+)\s([0-9.]+)\s([0-9.]+)\s([0-9.]+)"/g, 'line x1="$1" y1="$2" x2="$3" y2="$4"') .replace(/polyline points="([0-9.]+)\s([0-9.]+)\s([0-9.]+)\s([0-9.]+)"/g, 'line x1="$1" y1="$2" x2="$3" y2="$4"')
.replace(/<path d="([^"]+)"/g, function(f, r1) {
r1 = optimizePath(r1);
return `<path d="${r1}"`;
})
.replace(/d="m/g, 'd="M') .replace(/d="m/g, 'd="M')
.replace(/([Aa])\s?([0-9.]+)\s([0-9.]+)\s([0-9.]+)\s?([0-1])\s?([0-1])\s?(-?[0-9.]+)\s?(-?[0-9.]+)/gi, '$1$2 $3 $4 $5 $6 $7 $8') .replace(/([Aa])\s?([0-9.]+)\s([0-9.]+)\s([0-9.]+)\s?([0-1])\s?([0-1])\s?(-?[0-9.]+)\s?(-?[0-9.]+)/gi, '$1$2 $3 $4 $5 $6 $7 $8')
.replace(/\n\n+/g, "\n") .replace(/\n\n+/g, "\n")
@ -439,9 +458,6 @@ gulp.task('optimize', function (cb) {
}) })
; ;
//
//
if (svgFile.toString() !== svgFileContent) { if (svgFile.toString() !== svgFileContent) {
fs.writeFileSync(file, svgFileContent); fs.writeFileSync(file, svgFileContent);
} }
@ -610,17 +626,17 @@ const setVersions = function(version, files) {
if (fs.existsSync(`src/_icons/${file}.svg`)) { if (fs.existsSync(`src/_icons/${file}.svg`)) {
let svgFile = fs.readFileSync(`src/_icons/${file}.svg`).toString(); let svgFile = fs.readFileSync(`src/_icons/${file}.svg`).toString();
if(!svgFile.match(/version: ([0-9.]+)/i)) { if(!svgFile.match(/version: ([0-9.]+)/i)) {
svgFile = svgFile.replace(/---\n<svg>/i, function(m){ svgFile = svgFile.replace(/---\n<svg>/i, function(m){
return `version: ${version}\n${m}`; return `version: ${version}\n${m}`;
}); });
fs.writeFileSync(`src/_icons/${file}.svg`, svgFile); fs.writeFileSync(`src/_icons/${file}.svg`, svgFile);
} else { } else {
console.log(`File ${file} already has version`); console.log(`File ${file} already has version`);
} }
} else { } else {
console.log(`File ${file} doesn't exists`); console.log(`File ${file} doesn't exists`);
} }
@ -636,7 +652,7 @@ gulp.task('update-icons-version', function (cb) {
cp.exec(`git diff v${version} HEAD --name-status`, function (err, ret) { cp.exec(`git diff v${version} HEAD --name-status`, function (err, ret) {
let newIcons = []; let newIcons = [];
ret.replace(/[A]\s+src\/_icons\/([a-z0-9-]+)\.svg/g, function (m, fileName) { ret.replace(/[A]\s+src\/_icons\/([a-z0-9-]+)\.svg/g, function (m, fileName) {
newIcons.push(fileName); newIcons.push(fileName);
}); });
@ -650,6 +666,35 @@ gulp.task('update-icons-version', function (cb) {
cb(); cb();
}); });
gulp.task('import-tags', function(cb) {
fs.createReadStream('./_import.csv')
.pipe(csv({
headers: false,
separator: "\t"
}))
.on('data', (row) => {
console.log(row[0], row[1]);
const filename = `src/_icons/${row[0]}.svg`;
let data = fs.readFileSync(filename).toString();
data = data.replace(/(---[\s\S]+?---)/, function(m, headerContent){
headerContent = headerContent.replace(/tags: .*\n/, '');
headerContent = headerContent.replace(/---/, `---\ntags: [${row[1]}]`);
return headerContent;
});
fs.writeFileSync(filename, data);
})
.on('end', () => {
console.log('CSV file successfully processed');
});
cb();
});
gulp.task("build-react", function (cb) { gulp.task("build-react", function (cb) {
cp.exec("npm run build-react", function () { cp.exec("npm run build-react", function () {
cb(); cb();

View File

@ -2,5 +2,5 @@
category: Arrows category: Arrows
--- ---
<svg> <svg>
<path d="M15 4v8h3.586a1 1 0 0 1 .707 1.707l-6.586 6.586a1 1 0 0 1-1.414 0l-6.586-6.586A1 1 0 0 1 5.414 12H9V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1z"/> <path d="M15 4v8h3.586a1 1 0 0 1 .707 1.707l-6.586 6.586a1 1 0 0 1 -1.414 0l-6.586 -6.586a1 1 0 0 1 .707 -1.707h3.586v-8a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1z" />
</svg> </svg>

View File

@ -2,5 +2,5 @@
category: Arrows category: Arrows
--- ---
<svg> <svg>
<path d="M20 15h-8v3.586a1 1 0 0 1-1.707.707l-6.586-6.586a1 1 0 0 1 0-1.414l6.586-6.586A1 1 0 0 1 12 5.414V9h8a1 1 0 0 1 1 1v4a1 1 0 0 1-1 1z"/> <path d="M20 15h-8v3.586a1 1 0 0 1 -1.707 .707l-6.586 -6.586a1 1 0 0 1 0 -1.414l6.586 -6.586a1 1 0 0 1 1.707 .707v3.586h8a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1z" />
</svg> </svg>

View File

@ -2,5 +2,5 @@
category: Arrows category: Arrows
--- ---
<svg> <svg>
<path d="M4 9h8V5.414a1 1 0 0 1 1.707-.707l6.586 6.586a1 1 0 0 1 0 1.414l-6.586 6.586A1 1 0 0 1 12 18.586V15H4a1 1 0 0 1-1-1v-4a1 1 0 0 1 1-1z"/> <path d="M4 9h8v-3.586a1 1 0 0 1 1.707 -.707l6.586 6.586a1 1 0 0 1 0 1.414l-6.586 6.586a1 1 0 0 1 -1.707 -.707v-3.586h-8a1 1 0 0 1 -1 -1v-4a1 1 0 0 1 1 -1z" />
</svg> </svg>

View File

@ -2,5 +2,5 @@
category: Arrows category: Arrows
--- ---
<svg> <svg>
<path d="M9 20v-8H5.414a1 1 0 0 1-.707-1.707l6.586-6.586a1 1 0 0 1 1.414 0l6.586 6.586A1 1 0 0 1 18.586 12H15v8a1 1 0 0 1-1 1h-4a1 1 0 0 1-1-1z"/> <path d="M9 20v-8h-3.586a1 1 0 0 1 -.707 -1.707l6.586 -6.586a1 1 0 0 1 1.414 0l6.586 6.586a1 1 0 0 1 -.707 1.707h-3.586v8a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1z" />
</svg> </svg>

View File

@ -2,8 +2,8 @@
category: Arrows category: Arrows
--- ---
<svg> <svg>
<path d="M3 14L14 3"/> <path d="M3 14L14 3" />
<path d="M10 3h4v4"/> <path d="M10 3h4v4" />
<path d="M10 17v4h4"/> <path d="M10 17v4h4" />
<path d="M21 10L10 21"/> <path d="M21 10L10 21" />
</svg> </svg>

View File

@ -2,8 +2,8 @@
category: Arrows category: Arrows
--- ---
<svg> <svg>
<path d="M14 21L3 10"/> <path d="M14 21L3 10" />
<path d="M3 14v-4h4"/> <path d="M3 14v-4h4" />
<path d="M17 14h4v-4"/> <path d="M17 14h4v-4" />
<path d="M10 3l11 11"/> <line x1="10" y1="3" x2="21" y2="14" />
</svg> </svg>

View File

@ -2,8 +2,8 @@
category: Arrows category: Arrows
--- ---
<svg> <svg>
<path d="M3 10l11 11"/> <line x1="3" y1="10" x2="14" y2="21" />
<path d="M14 17v4h-4"/> <path d="M14 17v4h-4" />
<path d="M14 3h-4v4"/> <path d="M14 3h-4v4" />
<path d="M21 14L10 3"/> <path d="M21 14L10 3" />
</svg> </svg>

View File

@ -2,8 +2,8 @@
category: Arrows category: Arrows
--- ---
<svg> <svg>
<path d="M14 3L3 14"/> <path d="M14 3L3 14" />
<path d="M3 10v4h4"/> <path d="M3 10v4h4" />
<path d="M17 10h4v4"/> <path d="M17 10h4v4" />
<path d="M10 21l11-11"/> <path d="M10 21l11-11" />
</svg> </svg>

View File

@ -2,7 +2,7 @@
category: System category: System
--- ---
<svg> <svg>
<path d="M10 5a2 2 0 1 1 4 0 7 7 0 0 1 4 6v3a4 4 0 0 0 2 3H4a4 4 0 0 0 2-3v-3a7 7 0 0 1 4-6"/> <path d="M10 5a2 2 0 1 1 4 0 7 7 0 0 1 4 6v3a4 4 0 0 0 2 3H4a4 4 0 0 0 2 -3v-3a7 7 0 0 1 4 -6" />
<path d="M9 17v1a3 3 0 0 0 6 0v-1"/> <path d="M9 17v1a3 3 0 0 0 6 0v-1" />
<path d="M10 11h4"/> <line x1="10" y1="11" x2="14" y2="11" />
</svg> </svg>

View File

@ -2,8 +2,8 @@
category: System category: System
--- ---
<svg> <svg>
<path d="M10 5a2 2 0 1 1 4 0 7 7 0 0 1 4 6v3a4 4 0 0 0 2 3H4a4 4 0 0 0 2-3v-3a7 7 0 0 1 4-6"/> <path d="M10 5a2 2 0 1 1 4 0 7 7 0 0 1 4 6v3a4 4 0 0 0 2 3H4a4 4 0 0 0 2 -3v-3a7 7 0 0 1 4 -6" />
<path d="M9 17v1a3 3 0 0 0 6 0v-1"/> <path d="M9 17v1a3 3 0 0 0 6 0v-1" />
<path d="M10 11h4"/> <line x1="10" y1="11" x2="14" y2="11" />
<path d="M12 9v4"/> <line x1="12" y1="9" x2="12" y2="13" />
</svg> </svg>

View File

@ -2,7 +2,7 @@
category: System category: System
--- ---
<svg> <svg>
<path d="M10 5a2 2 0 1 1 4 0 7 7 0 0 1 4 6v3a4 4 0 0 0 2 3H4a4 4 0 0 0 2-3v-3a7 7 0 0 1 4-6"/> <path d="M10 5a2 2 0 1 1 4 0 7 7 0 0 1 4 6v3a4 4 0 0 0 2 3H4a4 4 0 0 0 2 -3v-3a7 7 0 0 1 4 -6" />
<path d="M9 17v1a3 3 0 0 0 6 0v-1"/> <path d="M9 17v1a3 3 0 0 0 6 0v-1" />
<path d="M10.5 9.5l3 3m0-3l-3 3"/> <path d="M10.5 9.5l3 3m0-3l-3 3" />
</svg> </svg>

View File

@ -5,6 +5,6 @@ category: Document
<svg> <svg>
<path d="M14 3v4a1 1 0 0 0 1 1h4" /> <path d="M14 3v4a1 1 0 0 0 1 1h4" />
<path d="M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2z" /> <path d="M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2z" />
<path d="M12 17h.01" /> <line x1="12" y1="17" x2="12.01" y2="17" />
<path d="M12 11v3" /> <line x1="12" y1="11" x2="12" y2="14" />
</svg> </svg>

View File

@ -5,7 +5,7 @@ category: Document
<svg> <svg>
<path d="M14 3v4a1 1 0 0 0 1 1h4" /> <path d="M14 3v4a1 1 0 0 0 1 1h4" />
<path d="M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2z" /> <path d="M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2z" />
<path d="M9 17v-5" /> <line x1="9" y1="17" x2="9" y2="12" />
<path d="M12 17v-1" /> <line x1="12" y1="17" x2="12" y2="16" />
<path d="M15 17v-3" /> <line x1="15" y1="17" x2="15" y2="14" />
</svg> </svg>

View File

@ -2,8 +2,8 @@
category: Map category: Map
--- ---
<svg> <svg>
<circle cx="10" cy="10" r="7"/> <circle cx="10" cy="10" r="7" />
<path d="M21 21l-6-6"/> <path d="M21 21l-6-6" />
<path d="M10 13v.01"/> <line x1="10" y1="13" x2="10" y2="13.01" />
<path d="M10 10a1.5 1.5 0 1 0-1.14-2.474"/> <path d="M10 10a1.5 1.5 0 1 0 -1.14 -2.474" />
</svg> </svg>