@iconify/tools 2.0.0 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/colors/parse.d.ts +1 -1
- package/lib/colors/parse.js +3 -1
- package/lib/colors/parse.mjs +2 -1
- package/lib/colors/validate.d.ts +11 -0
- package/lib/colors/validate.js +45 -0
- package/lib/colors/validate.mjs +33 -0
- package/lib/download/git/index.d.ts +7 -3
- package/lib/download/git/index.js +0 -3
- package/lib/download/github/index.d.ts +7 -3
- package/lib/download/github/index.js +13 -10
- package/lib/download/github/index.mjs +12 -8
- package/lib/download/helpers/untar.d.ts +4 -0
- package/lib/download/helpers/untar.js +14 -0
- package/lib/download/helpers/untar.mjs +11 -0
- package/lib/download/npm/index.d.ts +7 -3
- package/lib/download/npm/index.js +43 -15
- package/lib/download/npm/index.mjs +35 -9
- package/lib/export/helpers/types-version.js +3 -5
- package/lib/export/helpers/types-version.mjs +33 -1
- package/lib/icon-set/index.js +1 -1
- package/lib/icon-set/merge.js +1 -1
- package/lib/import/figma/index.d.ts +3 -2
- package/lib/import/figma/index.js +0 -3
- package/lib/import/figma/query.d.ts +3 -2
- package/lib/import/figma/query.js +0 -3
- package/lib/import/figma/types/options.d.ts +4 -2
- package/lib/index.d.ts +9 -3
- package/lib/index.js +20 -6
- package/lib/index.mjs +16 -3
- package/lib/misc/bump-version.d.ts +4 -0
- package/lib/misc/bump-version.js +19 -0
- package/lib/misc/bump-version.mjs +15 -0
- package/lib/misc/compare-dirs.d.ts +9 -0
- package/lib/misc/compare-dirs.js +84 -0
- package/lib/misc/compare-dirs.mjs +71 -0
- package/lib/optimise/svgo.js +15 -4
- package/lib/optimise/svgo.mjs +10 -4
- package/lib/svg/cleanup/bad-tags.js +0 -2
- package/lib/svg/cleanup/bad-tags.mjs +0 -3
- package/lib/svg/data/tags.d.ts +0 -4
- package/lib/svg/data/tags.js +1 -9
- package/lib/svg/data/tags.mjs +0 -6
- package/package.json +29 -5
|
@@ -17,8 +17,10 @@ interface FigmaImportCommonOptions {
|
|
|
17
17
|
file: string;
|
|
18
18
|
version?: string;
|
|
19
19
|
}
|
|
20
|
-
export interface
|
|
21
|
-
ifModifiedSince
|
|
20
|
+
export interface FigmaIfModifiedSinceOption {
|
|
21
|
+
ifModifiedSince: string | Date | true;
|
|
22
|
+
}
|
|
23
|
+
export interface FigmaFilesQueryOptions extends FigmaImportCommonOptions, Partial<FigmaIfModifiedSinceOption> {
|
|
22
24
|
ids?: string[];
|
|
23
25
|
depth?: number;
|
|
24
26
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -17,15 +17,21 @@ export { downloadGitHubRepo } from './download/github/index';
|
|
|
17
17
|
export { getGitHubRepoHash } from './download/github/hash';
|
|
18
18
|
export { downloadNPMPackage } from './download/npm/index';
|
|
19
19
|
export { getNPMVersion, getPackageVersion } from './download/npm/version';
|
|
20
|
-
export { parseColors } from './colors/parse';
|
|
20
|
+
export { parseColors, isEmptyColor } from './colors/parse';
|
|
21
|
+
export { validateColors } from './colors/validate';
|
|
21
22
|
export { runSVGO } from './optimise/svgo';
|
|
22
23
|
export { deOptimisePaths } from './optimise/flags';
|
|
23
24
|
export { scaleSVG } from './optimise/scale';
|
|
24
25
|
export { exportToDirectory } from './export/directory';
|
|
25
26
|
export { exportIconPackage } from './export/icon-package';
|
|
26
27
|
export { exportJSONPackage } from './export/json-package';
|
|
28
|
+
export { writeJSONFile } from './misc/write-json';
|
|
29
|
+
export { prepareDirectoryForExport } from './export/helpers/prepare';
|
|
30
|
+
export { scanDirectory } from './misc/scan';
|
|
31
|
+
export { compareDirectories } from './misc/compare-dirs';
|
|
32
|
+
export { unzip } from './download/helpers/unzip';
|
|
33
|
+
export { untar } from './download/helpers/untar';
|
|
27
34
|
export { execAsync } from './misc/exec';
|
|
28
35
|
export { cleanupIconKeyword } from './misc/keyword';
|
|
29
|
-
export {
|
|
30
|
-
export { writeJSONFile } from './misc/write-json';
|
|
36
|
+
export { bumpVersion } from './misc/bump-version';
|
|
31
37
|
export { sendAPIQuery } from './download/api/index';
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sendAPIQuery = exports.
|
|
3
|
+
exports.sendAPIQuery = exports.bumpVersion = exports.cleanupIconKeyword = exports.execAsync = exports.untar = exports.unzip = exports.compareDirectories = exports.scanDirectory = exports.prepareDirectoryForExport = exports.writeJSONFile = exports.exportJSONPackage = exports.exportIconPackage = exports.exportToDirectory = exports.scaleSVG = exports.deOptimisePaths = exports.runSVGO = exports.validateColors = exports.isEmptyColor = exports.parseColors = exports.getPackageVersion = exports.getNPMVersion = exports.downloadNPMPackage = exports.getGitHubRepoHash = exports.downloadGitHubRepo = exports.getGitRepoHash = exports.downloadGitRepo = exports.importDirectory = exports.importFromFigma = exports.mergeIconSets = exports.blankIconSet = exports.IconSet = exports.convertStyleToAttrs = exports.cleanupSVGRoot = exports.cleanupInlineStyle = exports.checkBadTags = exports.removeBadAttributes = exports.cleanupSVG = exports.parseSVGStyle = exports.parseSVG = exports.SVG = void 0;
|
|
4
4
|
// SVG class and functions
|
|
5
5
|
var index_1 = require("./svg/index");
|
|
6
6
|
Object.defineProperty(exports, "SVG", { enumerable: true, get: function () { return index_1.SVG; } });
|
|
@@ -49,6 +49,9 @@ Object.defineProperty(exports, "getPackageVersion", { enumerable: true, get: fun
|
|
|
49
49
|
// Manipulation
|
|
50
50
|
var parse_2 = require("./colors/parse");
|
|
51
51
|
Object.defineProperty(exports, "parseColors", { enumerable: true, get: function () { return parse_2.parseColors; } });
|
|
52
|
+
Object.defineProperty(exports, "isEmptyColor", { enumerable: true, get: function () { return parse_2.isEmptyColor; } });
|
|
53
|
+
var validate_1 = require("./colors/validate");
|
|
54
|
+
Object.defineProperty(exports, "validateColors", { enumerable: true, get: function () { return validate_1.validateColors; } });
|
|
52
55
|
var svgo_1 = require("./optimise/svgo");
|
|
53
56
|
Object.defineProperty(exports, "runSVGO", { enumerable: true, get: function () { return svgo_1.runSVGO; } });
|
|
54
57
|
var flags_1 = require("./optimise/flags");
|
|
@@ -62,14 +65,25 @@ var icon_package_1 = require("./export/icon-package");
|
|
|
62
65
|
Object.defineProperty(exports, "exportIconPackage", { enumerable: true, get: function () { return icon_package_1.exportIconPackage; } });
|
|
63
66
|
var json_package_1 = require("./export/json-package");
|
|
64
67
|
Object.defineProperty(exports, "exportJSONPackage", { enumerable: true, get: function () { return json_package_1.exportJSONPackage; } });
|
|
65
|
-
// Misc
|
|
68
|
+
// Misc: files, directories and archives
|
|
69
|
+
var write_json_1 = require("./misc/write-json");
|
|
70
|
+
Object.defineProperty(exports, "writeJSONFile", { enumerable: true, get: function () { return write_json_1.writeJSONFile; } });
|
|
71
|
+
var prepare_1 = require("./export/helpers/prepare");
|
|
72
|
+
Object.defineProperty(exports, "prepareDirectoryForExport", { enumerable: true, get: function () { return prepare_1.prepareDirectoryForExport; } });
|
|
73
|
+
var scan_1 = require("./misc/scan");
|
|
74
|
+
Object.defineProperty(exports, "scanDirectory", { enumerable: true, get: function () { return scan_1.scanDirectory; } });
|
|
75
|
+
var compare_dirs_1 = require("./misc/compare-dirs");
|
|
76
|
+
Object.defineProperty(exports, "compareDirectories", { enumerable: true, get: function () { return compare_dirs_1.compareDirectories; } });
|
|
77
|
+
var unzip_1 = require("./download/helpers/unzip");
|
|
78
|
+
Object.defineProperty(exports, "unzip", { enumerable: true, get: function () { return unzip_1.unzip; } });
|
|
79
|
+
var untar_1 = require("./download/helpers/untar");
|
|
80
|
+
Object.defineProperty(exports, "untar", { enumerable: true, get: function () { return untar_1.untar; } });
|
|
81
|
+
// Misc: other
|
|
66
82
|
var exec_1 = require("./misc/exec");
|
|
67
83
|
Object.defineProperty(exports, "execAsync", { enumerable: true, get: function () { return exec_1.execAsync; } });
|
|
68
84
|
var keyword_1 = require("./misc/keyword");
|
|
69
85
|
Object.defineProperty(exports, "cleanupIconKeyword", { enumerable: true, get: function () { return keyword_1.cleanupIconKeyword; } });
|
|
70
|
-
var
|
|
71
|
-
Object.defineProperty(exports, "
|
|
72
|
-
var write_json_1 = require("./misc/write-json");
|
|
73
|
-
Object.defineProperty(exports, "writeJSONFile", { enumerable: true, get: function () { return write_json_1.writeJSONFile; } });
|
|
86
|
+
var bump_version_1 = require("./misc/bump-version");
|
|
87
|
+
Object.defineProperty(exports, "bumpVersion", { enumerable: true, get: function () { return bump_version_1.bumpVersion; } });
|
|
74
88
|
var index_7 = require("./download/api/index");
|
|
75
89
|
Object.defineProperty(exports, "sendAPIQuery", { enumerable: true, get: function () { return index_7.sendAPIQuery; } });
|
package/lib/index.mjs
CHANGED
|
@@ -18,27 +18,35 @@ import { downloadGitHubRepo } from "./download/github/index.mjs";
|
|
|
18
18
|
import { getGitHubRepoHash } from "./download/github/hash.mjs";
|
|
19
19
|
import { downloadNPMPackage } from "./download/npm/index.mjs";
|
|
20
20
|
import { getNPMVersion, getPackageVersion } from "./download/npm/version.mjs";
|
|
21
|
-
import { parseColors } from "./colors/parse.mjs";
|
|
21
|
+
import { parseColors, isEmptyColor } from "./colors/parse.mjs";
|
|
22
|
+
import { validateColors } from "./colors/validate.mjs";
|
|
22
23
|
import { runSVGO } from "./optimise/svgo.mjs";
|
|
23
24
|
import { deOptimisePaths } from "./optimise/flags.mjs";
|
|
24
25
|
import { scaleSVG } from "./optimise/scale.mjs";
|
|
25
26
|
import { exportToDirectory } from "./export/directory.mjs";
|
|
26
27
|
import { exportIconPackage } from "./export/icon-package.mjs";
|
|
27
28
|
import { exportJSONPackage } from "./export/json-package.mjs";
|
|
29
|
+
import { writeJSONFile } from "./misc/write-json.mjs";
|
|
30
|
+
import { prepareDirectoryForExport } from "./export/helpers/prepare.mjs";
|
|
31
|
+
import { scanDirectory } from "./misc/scan.mjs";
|
|
32
|
+
import { compareDirectories } from "./misc/compare-dirs.mjs";
|
|
33
|
+
import { unzip } from "./download/helpers/unzip.mjs";
|
|
34
|
+
import { untar } from "./download/helpers/untar.mjs";
|
|
28
35
|
import { execAsync } from "./misc/exec.mjs";
|
|
29
36
|
import { cleanupIconKeyword } from "./misc/keyword.mjs";
|
|
30
|
-
import {
|
|
31
|
-
import { writeJSONFile } from "./misc/write-json.mjs";
|
|
37
|
+
import { bumpVersion } from "./misc/bump-version.mjs";
|
|
32
38
|
import { sendAPIQuery } from "./download/api/index.mjs";
|
|
33
39
|
export {
|
|
34
40
|
IconSet,
|
|
35
41
|
SVG,
|
|
36
42
|
blankIconSet,
|
|
43
|
+
bumpVersion,
|
|
37
44
|
checkBadTags,
|
|
38
45
|
cleanupIconKeyword,
|
|
39
46
|
cleanupInlineStyle,
|
|
40
47
|
cleanupSVG,
|
|
41
48
|
cleanupSVGRoot,
|
|
49
|
+
compareDirectories,
|
|
42
50
|
convertStyleToAttrs,
|
|
43
51
|
deOptimisePaths,
|
|
44
52
|
downloadGitHubRepo,
|
|
@@ -54,14 +62,19 @@ export {
|
|
|
54
62
|
getPackageVersion,
|
|
55
63
|
importDirectory,
|
|
56
64
|
importFromFigma,
|
|
65
|
+
isEmptyColor,
|
|
57
66
|
mergeIconSets,
|
|
58
67
|
parseColors,
|
|
59
68
|
parseSVG,
|
|
60
69
|
parseSVGStyle,
|
|
70
|
+
prepareDirectoryForExport,
|
|
61
71
|
removeBadAttributes,
|
|
62
72
|
runSVGO,
|
|
63
73
|
scaleSVG,
|
|
64
74
|
scanDirectory,
|
|
65
75
|
sendAPIQuery,
|
|
76
|
+
untar,
|
|
77
|
+
unzip,
|
|
78
|
+
validateColors,
|
|
66
79
|
writeJSONFile
|
|
67
80
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bumpVersion = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Bump version number
|
|
6
|
+
*/
|
|
7
|
+
function bumpVersion(version) {
|
|
8
|
+
const versionParts = version.split('.');
|
|
9
|
+
const lastPart = versionParts.pop();
|
|
10
|
+
const num = parseInt(lastPart);
|
|
11
|
+
if (isNaN(num) || num + '' !== lastPart) {
|
|
12
|
+
versionParts.push(lastPart + '.1');
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
versionParts.push(num + 1 + '');
|
|
16
|
+
}
|
|
17
|
+
return versionParts.join('.');
|
|
18
|
+
}
|
|
19
|
+
exports.bumpVersion = bumpVersion;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/misc/bump-version.ts
|
|
2
|
+
function bumpVersion(version) {
|
|
3
|
+
const versionParts = version.split(".");
|
|
4
|
+
const lastPart = versionParts.pop();
|
|
5
|
+
const num = parseInt(lastPart);
|
|
6
|
+
if (isNaN(num) || num + "" !== lastPart) {
|
|
7
|
+
versionParts.push(lastPart + ".1");
|
|
8
|
+
} else {
|
|
9
|
+
versionParts.push(num + 1 + "");
|
|
10
|
+
}
|
|
11
|
+
return versionParts.join(".");
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
bumpVersion
|
|
15
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface CompareDirectoriesOptions {
|
|
2
|
+
ignoreNewLine?: boolean;
|
|
3
|
+
ignoreVersions?: boolean;
|
|
4
|
+
textExtensions?: string[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Compare directories. Returns true if files are identical, false if different
|
|
8
|
+
*/
|
|
9
|
+
export declare function compareDirectories(dir1: string, dir2: string, options?: CompareDirectoriesOptions): Promise<boolean>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compareDirectories = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const prepare_1 = require("../export/helpers/prepare");
|
|
6
|
+
const scan_1 = require("./scan");
|
|
7
|
+
/**
|
|
8
|
+
* Extensions that are treated as text
|
|
9
|
+
*/
|
|
10
|
+
const textFileExtensions = [
|
|
11
|
+
'json',
|
|
12
|
+
'ts',
|
|
13
|
+
'js',
|
|
14
|
+
'mjs',
|
|
15
|
+
'cjs',
|
|
16
|
+
'jsx',
|
|
17
|
+
'tsx',
|
|
18
|
+
'vue',
|
|
19
|
+
'svelte',
|
|
20
|
+
'svg',
|
|
21
|
+
'txt',
|
|
22
|
+
'md',
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* Compare directories. Returns true if files are identical, false if different
|
|
26
|
+
*/
|
|
27
|
+
async function compareDirectories(dir1, dir2, options) {
|
|
28
|
+
dir1 = (0, prepare_1.normalizeDir)(dir1);
|
|
29
|
+
dir2 = (0, prepare_1.normalizeDir)(dir2);
|
|
30
|
+
// Get all files
|
|
31
|
+
const files1 = await (0, scan_1.scanDirectory)(dir1);
|
|
32
|
+
const files2 = await (0, scan_1.scanDirectory)(dir2);
|
|
33
|
+
if (files1.length !== files2.length) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
// Options
|
|
37
|
+
options = options || {};
|
|
38
|
+
const ignoreNewLine = options.ignoreNewLine !== false;
|
|
39
|
+
const ignoreVersions = options.ignoreVersions !== false;
|
|
40
|
+
const textExtensions = new Set((options.textExtensions || []).concat(textFileExtensions));
|
|
41
|
+
// Check all files
|
|
42
|
+
for (let i = 0; i < files1.length; i++) {
|
|
43
|
+
const file = files1[i];
|
|
44
|
+
if (files2.indexOf(file) === -1) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
const ext = file.split('.').pop().toLowerCase();
|
|
48
|
+
const isText = textExtensions.has(ext);
|
|
49
|
+
if (!isText) {
|
|
50
|
+
// Compare binary files
|
|
51
|
+
const content1 = await fs_1.promises.readFile(dir1 + '/' + file);
|
|
52
|
+
const content2 = await fs_1.promises.readFile(dir2 + '/' + file);
|
|
53
|
+
if (Buffer.compare(content1, content2) !== 0) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
// Text files
|
|
59
|
+
let content1 = await fs_1.promises.readFile(dir1 + '/' + file, 'utf8');
|
|
60
|
+
let content2 = await fs_1.promises.readFile(dir2 + '/' + file, 'utf8');
|
|
61
|
+
if (content1 === content2) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (ignoreNewLine) {
|
|
65
|
+
// Remove space before new line (\r\n -> \n), remove new line at the end
|
|
66
|
+
content1 = content1.replace(/\s+\n/g, '\n').trimRight();
|
|
67
|
+
content2 = content2.replace(/\s+\n/g, '\n').trimRight();
|
|
68
|
+
}
|
|
69
|
+
if (ignoreVersions && file.split('/').pop() === 'package.json') {
|
|
70
|
+
// Ignore versions in package.json
|
|
71
|
+
const data1 = JSON.parse(content1);
|
|
72
|
+
const data2 = JSON.parse(content2);
|
|
73
|
+
delete data1.version;
|
|
74
|
+
delete data2.version;
|
|
75
|
+
content1 = JSON.stringify(data1);
|
|
76
|
+
content2 = JSON.stringify(data2);
|
|
77
|
+
}
|
|
78
|
+
if (content1 !== content2) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
exports.compareDirectories = compareDirectories;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// src/misc/compare-dirs.ts
|
|
2
|
+
import { promises as fs } from "fs";
|
|
3
|
+
import { normalizeDir } from "../export/helpers/prepare.mjs";
|
|
4
|
+
import { scanDirectory } from "./scan.mjs";
|
|
5
|
+
var textFileExtensions = [
|
|
6
|
+
"json",
|
|
7
|
+
"ts",
|
|
8
|
+
"js",
|
|
9
|
+
"mjs",
|
|
10
|
+
"cjs",
|
|
11
|
+
"jsx",
|
|
12
|
+
"tsx",
|
|
13
|
+
"vue",
|
|
14
|
+
"svelte",
|
|
15
|
+
"svg",
|
|
16
|
+
"txt",
|
|
17
|
+
"md"
|
|
18
|
+
];
|
|
19
|
+
async function compareDirectories(dir1, dir2, options) {
|
|
20
|
+
dir1 = normalizeDir(dir1);
|
|
21
|
+
dir2 = normalizeDir(dir2);
|
|
22
|
+
const files1 = await scanDirectory(dir1);
|
|
23
|
+
const files2 = await scanDirectory(dir2);
|
|
24
|
+
if (files1.length !== files2.length) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
options = options || {};
|
|
28
|
+
const ignoreNewLine = options.ignoreNewLine !== false;
|
|
29
|
+
const ignoreVersions = options.ignoreVersions !== false;
|
|
30
|
+
const textExtensions = new Set((options.textExtensions || []).concat(textFileExtensions));
|
|
31
|
+
for (let i = 0; i < files1.length; i++) {
|
|
32
|
+
const file = files1[i];
|
|
33
|
+
if (files2.indexOf(file) === -1) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const ext = file.split(".").pop().toLowerCase();
|
|
37
|
+
const isText = textExtensions.has(ext);
|
|
38
|
+
if (!isText) {
|
|
39
|
+
const content12 = await fs.readFile(dir1 + "/" + file);
|
|
40
|
+
const content22 = await fs.readFile(dir2 + "/" + file);
|
|
41
|
+
if (Buffer.compare(content12, content22) !== 0) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
let content1 = await fs.readFile(dir1 + "/" + file, "utf8");
|
|
47
|
+
let content2 = await fs.readFile(dir2 + "/" + file, "utf8");
|
|
48
|
+
if (content1 === content2) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (ignoreNewLine) {
|
|
52
|
+
content1 = content1.replace(/\s+\n/g, "\n").trimRight();
|
|
53
|
+
content2 = content2.replace(/\s+\n/g, "\n").trimRight();
|
|
54
|
+
}
|
|
55
|
+
if (ignoreVersions && file.split("/").pop() === "package.json") {
|
|
56
|
+
const data1 = JSON.parse(content1);
|
|
57
|
+
const data2 = JSON.parse(content2);
|
|
58
|
+
delete data1.version;
|
|
59
|
+
delete data2.version;
|
|
60
|
+
content1 = JSON.stringify(data1);
|
|
61
|
+
content2 = JSON.stringify(data2);
|
|
62
|
+
}
|
|
63
|
+
if (content1 !== content2) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
compareDirectories
|
|
71
|
+
};
|
package/lib/optimise/svgo.js
CHANGED
|
@@ -52,6 +52,8 @@ exports.shapeModifiyingSVGOPlugins = [
|
|
|
52
52
|
* Run SVGO on icon
|
|
53
53
|
*/
|
|
54
54
|
async function runSVGO(svg, options = {}) {
|
|
55
|
+
// Code
|
|
56
|
+
const code = svg.toString();
|
|
55
57
|
// Options
|
|
56
58
|
const multipass = options.multipass !== false;
|
|
57
59
|
// Plugins list
|
|
@@ -60,14 +62,21 @@ async function runSVGO(svg, options = {}) {
|
|
|
60
62
|
plugins = options.plugins;
|
|
61
63
|
}
|
|
62
64
|
else {
|
|
63
|
-
|
|
65
|
+
// Check for animations: convertShapeToPath and removeHiddenElems plugins currently might ruin animations
|
|
66
|
+
let keepShapes = options.keepShapes;
|
|
67
|
+
if (keepShapes === void 0 &&
|
|
68
|
+
(code.indexOf('<animate') !== -1 || code.indexOf('<set') !== -1)) {
|
|
69
|
+
// Do not check animations: just assume they might break
|
|
70
|
+
keepShapes = true;
|
|
71
|
+
}
|
|
72
|
+
plugins = exports.defaultSVGOPlugins.concat(keepShapes ? [] : exports.shapeModifiyingSVGOPlugins, options.cleanupIDs !== false
|
|
64
73
|
? [
|
|
65
74
|
{
|
|
66
75
|
name: 'cleanupIDs',
|
|
67
76
|
params: {
|
|
68
77
|
prefix: typeof options.cleanupIDs === 'string'
|
|
69
78
|
? options.cleanupIDs
|
|
70
|
-
: '
|
|
79
|
+
: 'svgID',
|
|
71
80
|
},
|
|
72
81
|
},
|
|
73
82
|
]
|
|
@@ -79,10 +88,12 @@ async function runSVGO(svg, options = {}) {
|
|
|
79
88
|
multipass,
|
|
80
89
|
};
|
|
81
90
|
// Load data (changing type because SVGO types do not include error ?????)
|
|
82
|
-
const result = (0, svgo_1.optimize)(
|
|
91
|
+
const result = (0, svgo_1.optimize)(code, pluginOptions);
|
|
83
92
|
if (typeof result.error === 'string') {
|
|
84
93
|
throw new Error(result.error);
|
|
85
94
|
}
|
|
86
|
-
|
|
95
|
+
// Sometimes empty definitions are not removed: remove them
|
|
96
|
+
const content = result.data.replace(/<defs\/>/g, '');
|
|
97
|
+
svg.load(content);
|
|
87
98
|
}
|
|
88
99
|
exports.runSVGO = runSVGO;
|
package/lib/optimise/svgo.mjs
CHANGED
|
@@ -44,16 +44,21 @@ var shapeModifiyingSVGOPlugins = [
|
|
|
44
44
|
"reusePaths"
|
|
45
45
|
];
|
|
46
46
|
async function runSVGO(svg, options = {}) {
|
|
47
|
+
const code = svg.toString();
|
|
47
48
|
const multipass = options.multipass !== false;
|
|
48
49
|
let plugins;
|
|
49
50
|
if (options.plugins) {
|
|
50
51
|
plugins = options.plugins;
|
|
51
52
|
} else {
|
|
52
|
-
|
|
53
|
+
let keepShapes = options.keepShapes;
|
|
54
|
+
if (keepShapes === void 0 && (code.indexOf("<animate") !== -1 || code.indexOf("<set") !== -1)) {
|
|
55
|
+
keepShapes = true;
|
|
56
|
+
}
|
|
57
|
+
plugins = defaultSVGOPlugins.concat(keepShapes ? [] : shapeModifiyingSVGOPlugins, options.cleanupIDs !== false ? [
|
|
53
58
|
{
|
|
54
59
|
name: "cleanupIDs",
|
|
55
60
|
params: {
|
|
56
|
-
prefix: typeof options.cleanupIDs === "string" ? options.cleanupIDs : "
|
|
61
|
+
prefix: typeof options.cleanupIDs === "string" ? options.cleanupIDs : "svgID"
|
|
57
62
|
}
|
|
58
63
|
}
|
|
59
64
|
] : []);
|
|
@@ -62,11 +67,12 @@ async function runSVGO(svg, options = {}) {
|
|
|
62
67
|
plugins,
|
|
63
68
|
multipass
|
|
64
69
|
};
|
|
65
|
-
const result = optimize(
|
|
70
|
+
const result = optimize(code, pluginOptions);
|
|
66
71
|
if (typeof result.error === "string") {
|
|
67
72
|
throw new Error(result.error);
|
|
68
73
|
}
|
|
69
|
-
|
|
74
|
+
const content = result.data.replace(/<defs\/>/g, "");
|
|
75
|
+
svg.load(content);
|
|
70
76
|
}
|
|
71
77
|
export {
|
|
72
78
|
defaultSVGOPlugins,
|
|
@@ -17,8 +17,6 @@ requiredParentTags.set(tags_1.filterTag, tags_1.filterChildTags);
|
|
|
17
17
|
requiredParentTags.set(tags_1.defsTag, tags_1.tagsInsideDefs);
|
|
18
18
|
// <stop> must be inside gradient
|
|
19
19
|
requiredParentTags.set(tags_1.gradientTags, tags_1.gradientChildTags);
|
|
20
|
-
// Animations must be inside shapes or filters
|
|
21
|
-
requiredParentTags.set(tags_1.tagsBeforeAnimation, tags_1.animateTags);
|
|
22
20
|
// <mpath> must be inside <animateMotion>
|
|
23
21
|
requiredParentTags.set(new Set(['animateMotion']), tags_1.animateMotionChildTags);
|
|
24
22
|
/**
|
|
@@ -3,7 +3,6 @@ import { parseSVG } from "../parse.mjs";
|
|
|
3
3
|
import {
|
|
4
4
|
allValidTags,
|
|
5
5
|
animateMotionChildTags,
|
|
6
|
-
animateTags,
|
|
7
6
|
badTags,
|
|
8
7
|
defsTag,
|
|
9
8
|
feComponentTransferChildTag,
|
|
@@ -14,7 +13,6 @@ import {
|
|
|
14
13
|
filterTag,
|
|
15
14
|
gradientChildTags,
|
|
16
15
|
gradientTags,
|
|
17
|
-
tagsBeforeAnimation,
|
|
18
16
|
tagsInsideDefs,
|
|
19
17
|
unsupportedTags
|
|
20
18
|
} from "../data/tags.mjs";
|
|
@@ -25,7 +23,6 @@ requiredParentTags.set(feLightningTags, feLightningChildTags);
|
|
|
25
23
|
requiredParentTags.set(filterTag, filterChildTags);
|
|
26
24
|
requiredParentTags.set(defsTag, tagsInsideDefs);
|
|
27
25
|
requiredParentTags.set(gradientTags, gradientChildTags);
|
|
28
|
-
requiredParentTags.set(tagsBeforeAnimation, animateTags);
|
|
29
26
|
requiredParentTags.set(new Set(["animateMotion"]), animateMotionChildTags);
|
|
30
27
|
async function checkBadTags(svg) {
|
|
31
28
|
await parseSVG(svg, (item) => {
|
package/lib/svg/data/tags.d.ts
CHANGED
|
@@ -79,10 +79,6 @@ export declare const feMergeChildTags: Set<string>;
|
|
|
79
79
|
* Tags that can be used only inside <defs>
|
|
80
80
|
*/
|
|
81
81
|
export declare const tagsInsideDefs: Set<string>;
|
|
82
|
-
/**
|
|
83
|
-
* Parent tags for animations
|
|
84
|
-
*/
|
|
85
|
-
export declare const tagsBeforeAnimation: Set<string>;
|
|
86
82
|
/**
|
|
87
83
|
* All supported tags
|
|
88
84
|
*/
|
package/lib/svg/data/tags.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Icons cannot have anything that requires external resources, anything that renders inconsistently.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.allValidTags = exports.
|
|
7
|
+
exports.allValidTags = exports.tagsInsideDefs = exports.feMergeChildTags = exports.feLightningChildTags = exports.feComponentTransferChildTag = exports.filterChildTags = exports.feLightningTags = exports.filterTag = exports.patternTag = exports.gradientChildTags = exports.gradientTags = exports.animateMotionChildTags = exports.animateTags = exports.markerTag = exports.groupTag = exports.useTag = exports.shapeTags = exports.maskAndSymbolTags = exports.defsTag = exports.styleTag = exports.unsupportedTags = exports.badTags = void 0;
|
|
8
8
|
/**
|
|
9
9
|
* Bad tags
|
|
10
10
|
*
|
|
@@ -153,14 +153,6 @@ exports.tagsInsideDefs = new Set([
|
|
|
153
153
|
...exports.patternTag,
|
|
154
154
|
...exports.markerTag,
|
|
155
155
|
]);
|
|
156
|
-
/**
|
|
157
|
-
* Parent tags for animations
|
|
158
|
-
*/
|
|
159
|
-
exports.tagsBeforeAnimation = new Set([
|
|
160
|
-
...exports.shapeTags,
|
|
161
|
-
...exports.filterChildTags,
|
|
162
|
-
...exports.feComponentTransferChildTag,
|
|
163
|
-
]);
|
|
164
156
|
/**
|
|
165
157
|
* All supported tags
|
|
166
158
|
*/
|
package/lib/svg/data/tags.mjs
CHANGED
|
@@ -85,11 +85,6 @@ var tagsInsideDefs = new Set([
|
|
|
85
85
|
...patternTag,
|
|
86
86
|
...markerTag
|
|
87
87
|
]);
|
|
88
|
-
var tagsBeforeAnimation = new Set([
|
|
89
|
-
...shapeTags,
|
|
90
|
-
...filterChildTags,
|
|
91
|
-
...feComponentTransferChildTag
|
|
92
|
-
]);
|
|
93
88
|
var allValidTags = new Set([
|
|
94
89
|
...styleTag,
|
|
95
90
|
...defsTag,
|
|
@@ -129,7 +124,6 @@ export {
|
|
|
129
124
|
patternTag,
|
|
130
125
|
shapeTags,
|
|
131
126
|
styleTag,
|
|
132
|
-
tagsBeforeAnimation,
|
|
133
127
|
tagsInsideDefs,
|
|
134
128
|
unsupportedTags,
|
|
135
129
|
useTag
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@iconify/tools",
|
|
3
3
|
"description": "Collection of functions for cleaning up and parsing SVG for Iconify project",
|
|
4
4
|
"author": "Vjacheslav Trushkin",
|
|
5
|
-
"version": "2.0.
|
|
5
|
+
"version": "2.0.4",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bugs": "https://github.com/iconify/tools/issues",
|
|
8
8
|
"homepage": "https://github.com/iconify/tools",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "git://github.com/iconify/tools.git"
|
|
12
12
|
},
|
|
13
|
-
"main": "
|
|
13
|
+
"main": "./lib/index.js",
|
|
14
|
+
"module": "./lib/index.mjs",
|
|
14
15
|
"scripts": {
|
|
15
16
|
"clean": "rimraf lib tests-compiled tsconfig.tsbuildinfo",
|
|
16
17
|
"lint": "eslint src/**/*.ts",
|
|
@@ -21,17 +22,24 @@
|
|
|
21
22
|
"test": "npm run test:jest && npm run test:jasmine"
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
|
-
"@iconify/utils": "^1.0.
|
|
25
|
+
"@iconify/utils": "^1.0.21",
|
|
25
26
|
"@types/cheerio": "^0.22.30",
|
|
26
27
|
"@types/node-fetch": "^2.5.12",
|
|
28
|
+
"@types/svgo": "^2.6.0",
|
|
29
|
+
"@types/tar": "^6.1.0",
|
|
27
30
|
"cheerio": "^1.0.0-rc.10",
|
|
28
31
|
"extract-zip": "^2.0.1",
|
|
29
|
-
"node-fetch": "^2.
|
|
32
|
+
"node-fetch": "^3.2.0",
|
|
30
33
|
"pathe": "^0.2.0",
|
|
31
|
-
"svgo": "^2.
|
|
34
|
+
"svgo": "^2.8.0",
|
|
35
|
+
"tar": "^6.1.11"
|
|
32
36
|
},
|
|
33
37
|
"exports": {
|
|
34
38
|
"./*": "./*",
|
|
39
|
+
".": {
|
|
40
|
+
"require": "./lib/index.js",
|
|
41
|
+
"import": "./lib/index.mjs"
|
|
42
|
+
},
|
|
35
43
|
"./lib/colors/attribs": {
|
|
36
44
|
"require": "./lib/colors/attribs.js",
|
|
37
45
|
"import": "./lib/colors/attribs.mjs"
|
|
@@ -40,6 +48,10 @@
|
|
|
40
48
|
"require": "./lib/colors/parse.js",
|
|
41
49
|
"import": "./lib/colors/parse.mjs"
|
|
42
50
|
},
|
|
51
|
+
"./lib/colors/validate": {
|
|
52
|
+
"require": "./lib/colors/validate.js",
|
|
53
|
+
"import": "./lib/colors/validate.mjs"
|
|
54
|
+
},
|
|
43
55
|
"./lib/css/parse": {
|
|
44
56
|
"require": "./lib/css/parse.js",
|
|
45
57
|
"import": "./lib/css/parse.mjs"
|
|
@@ -120,6 +132,10 @@
|
|
|
120
132
|
"require": "./lib/download/github/types.js",
|
|
121
133
|
"import": "./lib/download/github/types.mjs"
|
|
122
134
|
},
|
|
135
|
+
"./lib/download/helpers/untar": {
|
|
136
|
+
"require": "./lib/download/helpers/untar.js",
|
|
137
|
+
"import": "./lib/download/helpers/untar.mjs"
|
|
138
|
+
},
|
|
123
139
|
"./lib/download/helpers/unzip": {
|
|
124
140
|
"require": "./lib/download/helpers/unzip.js",
|
|
125
141
|
"import": "./lib/download/helpers/unzip.mjs"
|
|
@@ -236,6 +252,14 @@
|
|
|
236
252
|
"require": "./lib/index.js",
|
|
237
253
|
"import": "./lib/index.mjs"
|
|
238
254
|
},
|
|
255
|
+
"./lib/misc/bump-version": {
|
|
256
|
+
"require": "./lib/misc/bump-version.js",
|
|
257
|
+
"import": "./lib/misc/bump-version.mjs"
|
|
258
|
+
},
|
|
259
|
+
"./lib/misc/compare-dirs": {
|
|
260
|
+
"require": "./lib/misc/compare-dirs.js",
|
|
261
|
+
"import": "./lib/misc/compare-dirs.mjs"
|
|
262
|
+
},
|
|
239
263
|
"./lib/misc/exec": {
|
|
240
264
|
"require": "./lib/misc/exec.js",
|
|
241
265
|
"import": "./lib/misc/exec.mjs"
|