@iconify/tools 2.0.16 → 2.0.17
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/import/directory.d.ts +3 -3
- package/lib/optimise/svgo.cjs +58 -56
- package/lib/optimise/svgo.d.ts +11 -6
- package/lib/optimise/svgo.mjs +58 -55
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ import '../svg/index.js';
|
|
|
7
7
|
/**
|
|
8
8
|
* Entry for file
|
|
9
9
|
*/
|
|
10
|
-
interface
|
|
10
|
+
interface ImportDirectoryFileEntry {
|
|
11
11
|
path: string;
|
|
12
12
|
subdir: string;
|
|
13
13
|
file: string;
|
|
@@ -23,7 +23,7 @@ interface ImportDirectpryFileEntry {
|
|
|
23
23
|
* Callback can be asynchronous
|
|
24
24
|
*/
|
|
25
25
|
declare type ImportDirectoryKeywordCallbackResult = string | undefined;
|
|
26
|
-
declare type ImportDirectoryKeywordCallback = (file:
|
|
26
|
+
declare type ImportDirectoryKeywordCallback = (file: ImportDirectoryFileEntry, defaultKeyword: string, iconSet: IconSet) => ImportDirectoryKeywordCallbackResult | Promise<ImportDirectoryKeywordCallbackResult>;
|
|
27
27
|
/**
|
|
28
28
|
* Options
|
|
29
29
|
*/
|
|
@@ -38,4 +38,4 @@ interface ImportDirectoryOptions {
|
|
|
38
38
|
*/
|
|
39
39
|
declare function importDirectory(path: string, options?: ImportDirectoryOptions): Promise<IconSet>;
|
|
40
40
|
|
|
41
|
-
export {
|
|
41
|
+
export { ImportDirectoryFileEntry, ImportDirectoryKeywordCallback, importDirectory };
|
package/lib/optimise/svgo.cjs
CHANGED
|
@@ -4,48 +4,58 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
const svgo = require('svgo');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
]
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
]
|
|
7
|
+
function getSVGOPlugins(options) {
|
|
8
|
+
return [
|
|
9
|
+
"cleanupAttrs",
|
|
10
|
+
"mergeStyles",
|
|
11
|
+
"inlineStyles",
|
|
12
|
+
"removeComments",
|
|
13
|
+
"removeUselessDefs",
|
|
14
|
+
"removeEditorsNSData",
|
|
15
|
+
"removeEmptyAttrs",
|
|
16
|
+
"removeEmptyContainers",
|
|
17
|
+
"convertStyleToAttrs",
|
|
18
|
+
"convertColors",
|
|
19
|
+
"convertTransform",
|
|
20
|
+
"removeUnknownsAndDefaults",
|
|
21
|
+
"removeNonInheritableGroupAttrs",
|
|
22
|
+
"removeUnusedNS",
|
|
23
|
+
"cleanupNumericValues",
|
|
24
|
+
"cleanupListOfValues",
|
|
25
|
+
"moveElemsAttrsToGroup",
|
|
26
|
+
"moveGroupAttrsToElems",
|
|
27
|
+
"collapseGroups",
|
|
28
|
+
"sortDefsChildren",
|
|
29
|
+
"sortAttrs",
|
|
30
|
+
...options.animated ? [] : ["removeUselessStrokeAndFill"],
|
|
31
|
+
...options.animated || options.keepShapes ? [] : [
|
|
32
|
+
"removeHiddenElems",
|
|
33
|
+
"convertShapeToPath",
|
|
34
|
+
"convertEllipseToCircle",
|
|
35
|
+
{
|
|
36
|
+
name: "convertPathData",
|
|
37
|
+
params: {
|
|
38
|
+
noSpaceAfterFlags: true
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: "mergePaths",
|
|
43
|
+
params: {
|
|
44
|
+
noSpaceAfterFlags: true
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"reusePaths"
|
|
48
|
+
],
|
|
49
|
+
...options.cleanupIDs !== false ? [
|
|
50
|
+
{
|
|
51
|
+
name: "cleanupIDs",
|
|
52
|
+
params: {
|
|
53
|
+
prefix: typeof options.cleanupIDs === "string" ? options.cleanupIDs : "svgID"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
] : []
|
|
57
|
+
];
|
|
58
|
+
}
|
|
49
59
|
async function runSVGO(svg, options = {}) {
|
|
50
60
|
const code = svg.toString();
|
|
51
61
|
const multipass = options.multipass !== false;
|
|
@@ -53,18 +63,11 @@ async function runSVGO(svg, options = {}) {
|
|
|
53
63
|
if (options.plugins) {
|
|
54
64
|
plugins = options.plugins;
|
|
55
65
|
} else {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
{
|
|
62
|
-
name: "cleanupIDs",
|
|
63
|
-
params: {
|
|
64
|
-
prefix: typeof options.cleanupIDs === "string" ? options.cleanupIDs : "svgID"
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
] : []);
|
|
66
|
+
const animated = code.indexOf("<animate") !== -1 || code.indexOf("<set") !== -1;
|
|
67
|
+
plugins = getSVGOPlugins({
|
|
68
|
+
...options,
|
|
69
|
+
animated
|
|
70
|
+
});
|
|
68
71
|
}
|
|
69
72
|
const pluginOptions = {
|
|
70
73
|
plugins,
|
|
@@ -78,6 +81,5 @@ async function runSVGO(svg, options = {}) {
|
|
|
78
81
|
svg.load(content);
|
|
79
82
|
}
|
|
80
83
|
|
|
81
|
-
exports.
|
|
84
|
+
exports.getSVGOPlugins = getSVGOPlugins;
|
|
82
85
|
exports.runSVGO = runSVGO;
|
|
83
|
-
exports.shapeModifiyingSVGOPlugins = shapeModifiyingSVGOPlugins;
|
package/lib/optimise/svgo.d.ts
CHANGED
|
@@ -3,11 +3,17 @@ import { SVG } from '../svg/index.js';
|
|
|
3
3
|
import '@iconify/types';
|
|
4
4
|
import '@iconify/utils/lib/customisations';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
interface CleanupIDsOption {
|
|
7
|
+
cleanupIDs?: string | false;
|
|
8
|
+
}
|
|
9
|
+
interface GetSVGOPluingOptions extends CleanupIDsOption {
|
|
10
|
+
animated?: boolean;
|
|
11
|
+
keepShapes?: boolean;
|
|
12
|
+
}
|
|
7
13
|
/**
|
|
8
|
-
*
|
|
14
|
+
* Get list of plugins
|
|
9
15
|
*/
|
|
10
|
-
declare
|
|
16
|
+
declare function getSVGOPlugins(options: GetSVGOPluingOptions): Plugin[];
|
|
11
17
|
/**
|
|
12
18
|
* Options
|
|
13
19
|
*/
|
|
@@ -17,10 +23,9 @@ interface SVGOCommonOptions {
|
|
|
17
23
|
interface SVGOOptionsWithPlugin extends SVGOCommonOptions {
|
|
18
24
|
plugins: Plugin[];
|
|
19
25
|
}
|
|
20
|
-
interface SVGOptionsWithoutPlugin extends SVGOCommonOptions {
|
|
26
|
+
interface SVGOptionsWithoutPlugin extends SVGOCommonOptions, CleanupIDsOption {
|
|
21
27
|
plugins?: undefined;
|
|
22
28
|
keepShapes?: boolean;
|
|
23
|
-
cleanupIDs?: string | false;
|
|
24
29
|
}
|
|
25
30
|
declare type SVGOOptions = SVGOOptionsWithPlugin | SVGOptionsWithoutPlugin;
|
|
26
31
|
/**
|
|
@@ -28,4 +33,4 @@ declare type SVGOOptions = SVGOOptionsWithPlugin | SVGOptionsWithoutPlugin;
|
|
|
28
33
|
*/
|
|
29
34
|
declare function runSVGO(svg: SVG, options?: SVGOOptions): Promise<void>;
|
|
30
35
|
|
|
31
|
-
export {
|
|
36
|
+
export { getSVGOPlugins, runSVGO };
|
package/lib/optimise/svgo.mjs
CHANGED
|
@@ -1,47 +1,57 @@
|
|
|
1
1
|
import { optimize } from 'svgo';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
]
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
]
|
|
3
|
+
function getSVGOPlugins(options) {
|
|
4
|
+
return [
|
|
5
|
+
"cleanupAttrs",
|
|
6
|
+
"mergeStyles",
|
|
7
|
+
"inlineStyles",
|
|
8
|
+
"removeComments",
|
|
9
|
+
"removeUselessDefs",
|
|
10
|
+
"removeEditorsNSData",
|
|
11
|
+
"removeEmptyAttrs",
|
|
12
|
+
"removeEmptyContainers",
|
|
13
|
+
"convertStyleToAttrs",
|
|
14
|
+
"convertColors",
|
|
15
|
+
"convertTransform",
|
|
16
|
+
"removeUnknownsAndDefaults",
|
|
17
|
+
"removeNonInheritableGroupAttrs",
|
|
18
|
+
"removeUnusedNS",
|
|
19
|
+
"cleanupNumericValues",
|
|
20
|
+
"cleanupListOfValues",
|
|
21
|
+
"moveElemsAttrsToGroup",
|
|
22
|
+
"moveGroupAttrsToElems",
|
|
23
|
+
"collapseGroups",
|
|
24
|
+
"sortDefsChildren",
|
|
25
|
+
"sortAttrs",
|
|
26
|
+
...options.animated ? [] : ["removeUselessStrokeAndFill"],
|
|
27
|
+
...options.animated || options.keepShapes ? [] : [
|
|
28
|
+
"removeHiddenElems",
|
|
29
|
+
"convertShapeToPath",
|
|
30
|
+
"convertEllipseToCircle",
|
|
31
|
+
{
|
|
32
|
+
name: "convertPathData",
|
|
33
|
+
params: {
|
|
34
|
+
noSpaceAfterFlags: true
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "mergePaths",
|
|
39
|
+
params: {
|
|
40
|
+
noSpaceAfterFlags: true
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"reusePaths"
|
|
44
|
+
],
|
|
45
|
+
...options.cleanupIDs !== false ? [
|
|
46
|
+
{
|
|
47
|
+
name: "cleanupIDs",
|
|
48
|
+
params: {
|
|
49
|
+
prefix: typeof options.cleanupIDs === "string" ? options.cleanupIDs : "svgID"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
] : []
|
|
53
|
+
];
|
|
54
|
+
}
|
|
45
55
|
async function runSVGO(svg, options = {}) {
|
|
46
56
|
const code = svg.toString();
|
|
47
57
|
const multipass = options.multipass !== false;
|
|
@@ -49,18 +59,11 @@ async function runSVGO(svg, options = {}) {
|
|
|
49
59
|
if (options.plugins) {
|
|
50
60
|
plugins = options.plugins;
|
|
51
61
|
} else {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
{
|
|
58
|
-
name: "cleanupIDs",
|
|
59
|
-
params: {
|
|
60
|
-
prefix: typeof options.cleanupIDs === "string" ? options.cleanupIDs : "svgID"
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
] : []);
|
|
62
|
+
const animated = code.indexOf("<animate") !== -1 || code.indexOf("<set") !== -1;
|
|
63
|
+
plugins = getSVGOPlugins({
|
|
64
|
+
...options,
|
|
65
|
+
animated
|
|
66
|
+
});
|
|
64
67
|
}
|
|
65
68
|
const pluginOptions = {
|
|
66
69
|
plugins,
|
|
@@ -74,4 +77,4 @@ async function runSVGO(svg, options = {}) {
|
|
|
74
77
|
svg.load(content);
|
|
75
78
|
}
|
|
76
79
|
|
|
77
|
-
export {
|
|
80
|
+
export { getSVGOPlugins, runSVGO };
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "Collection of functions for cleaning up and parsing SVG for Iconify project",
|
|
5
5
|
"author": "Vjacheslav Trushkin",
|
|
6
|
-
"version": "2.0.
|
|
6
|
+
"version": "2.0.17",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"bugs": "https://github.com/iconify/tools/issues",
|
|
9
9
|
"homepage": "https://github.com/iconify/tools",
|