@iconify/tools 2.2.0-beta.1 → 2.2.0-beta.3
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/download/git/index.cjs +1 -0
- package/lib/download/git/index.mjs +1 -0
- package/lib/download/git/reset.cjs +1 -0
- package/lib/download/git/reset.mjs +1 -0
- package/lib/download/index.cjs +1 -0
- package/lib/download/index.mjs +1 -0
- package/lib/import/directory.cjs +1 -0
- package/lib/import/directory.mjs +1 -0
- package/lib/import/figma/index.cjs +1 -0
- package/lib/import/figma/index.mjs +1 -0
- package/lib/index.cjs +1 -0
- package/lib/index.mjs +1 -0
- package/lib/optimise/scale.cjs +1 -0
- package/lib/optimise/scale.mjs +1 -0
- package/lib/optimise/svgo.cjs +23 -10
- package/lib/optimise/svgo.d.ts +3 -3
- package/lib/optimise/svgo.mjs +23 -10
- package/lib/svg/cleanup/svgo-style.cjs +1 -0
- package/lib/svg/cleanup/svgo-style.mjs +1 -0
- package/lib/svg/cleanup.cjs +1 -0
- package/lib/svg/cleanup.mjs +1 -0
- package/package.json +2 -2
|
@@ -15,6 +15,7 @@ require('../../svg/data/tags.cjs');
|
|
|
15
15
|
require('../../svg/cleanup/bad-tags.cjs');
|
|
16
16
|
require('../../svg/parse.cjs');
|
|
17
17
|
require('svgo');
|
|
18
|
+
require('@iconify/utils/lib/svg/id');
|
|
18
19
|
require('@iconify/utils/lib/icon/defaults');
|
|
19
20
|
require('@iconify/utils/lib/svg/build');
|
|
20
21
|
require('@iconify/utils/lib/icon-set/minify');
|
|
@@ -13,6 +13,7 @@ import '../../svg/data/tags.mjs';
|
|
|
13
13
|
import '../../svg/cleanup/bad-tags.mjs';
|
|
14
14
|
import '../../svg/parse.mjs';
|
|
15
15
|
import 'svgo';
|
|
16
|
+
import '@iconify/utils/lib/svg/id';
|
|
16
17
|
import '@iconify/utils/lib/icon/defaults';
|
|
17
18
|
import '@iconify/utils/lib/svg/build';
|
|
18
19
|
import '@iconify/utils/lib/icon-set/minify';
|
|
@@ -6,6 +6,7 @@ require('../../svg/data/attributes.cjs');
|
|
|
6
6
|
require('../../svg/data/tags.cjs');
|
|
7
7
|
require('../../svg/cleanup/bad-tags.cjs');
|
|
8
8
|
require('svgo');
|
|
9
|
+
require('@iconify/utils/lib/svg/id');
|
|
9
10
|
require('@iconify/utils/lib/icon/defaults');
|
|
10
11
|
require('@iconify/utils/lib/svg/build');
|
|
11
12
|
require('@iconify/utils/lib/icon-set/minify');
|
|
@@ -4,6 +4,7 @@ import '../../svg/data/attributes.mjs';
|
|
|
4
4
|
import '../../svg/data/tags.mjs';
|
|
5
5
|
import '../../svg/cleanup/bad-tags.mjs';
|
|
6
6
|
import 'svgo';
|
|
7
|
+
import '@iconify/utils/lib/svg/id';
|
|
7
8
|
import '@iconify/utils/lib/icon/defaults';
|
|
8
9
|
import '@iconify/utils/lib/svg/build';
|
|
9
10
|
import '@iconify/utils/lib/icon-set/minify';
|
package/lib/download/index.cjs
CHANGED
|
@@ -30,6 +30,7 @@ require('../svg/data/tags.cjs');
|
|
|
30
30
|
require('../svg/cleanup/bad-tags.cjs');
|
|
31
31
|
require('../svg/parse.cjs');
|
|
32
32
|
require('svgo');
|
|
33
|
+
require('@iconify/utils/lib/svg/id');
|
|
33
34
|
require('@iconify/utils/lib/icon/defaults');
|
|
34
35
|
require('@iconify/utils/lib/svg/build');
|
|
35
36
|
require('@iconify/utils/lib/icon-set/minify');
|
package/lib/download/index.mjs
CHANGED
|
@@ -28,6 +28,7 @@ import '../svg/data/tags.mjs';
|
|
|
28
28
|
import '../svg/cleanup/bad-tags.mjs';
|
|
29
29
|
import '../svg/parse.mjs';
|
|
30
30
|
import 'svgo';
|
|
31
|
+
import '@iconify/utils/lib/svg/id';
|
|
31
32
|
import '@iconify/utils/lib/icon/defaults';
|
|
32
33
|
import '@iconify/utils/lib/svg/build';
|
|
33
34
|
import '@iconify/utils/lib/icon-set/minify';
|
package/lib/import/directory.cjs
CHANGED
|
@@ -33,6 +33,7 @@ require('../svg/cleanup/root-svg.cjs');
|
|
|
33
33
|
require('../svg/cleanup/svgo-style.cjs');
|
|
34
34
|
require('../optimise/svgo.cjs');
|
|
35
35
|
require('svgo');
|
|
36
|
+
require('@iconify/utils/lib/svg/id');
|
|
36
37
|
|
|
37
38
|
async function importDirectory(path, options = {}) {
|
|
38
39
|
const files = await misc_scan.scanDirectory(path, (ext, file, subdir, path2) => {
|
package/lib/import/directory.mjs
CHANGED
|
@@ -31,6 +31,7 @@ import '../svg/cleanup/root-svg.mjs';
|
|
|
31
31
|
import '../svg/cleanup/svgo-style.mjs';
|
|
32
32
|
import '../optimise/svgo.mjs';
|
|
33
33
|
import 'svgo';
|
|
34
|
+
import '@iconify/utils/lib/svg/id';
|
|
34
35
|
|
|
35
36
|
async function importDirectory(path, options = {}) {
|
|
36
37
|
const files = await scanDirectory(path, (ext, file, subdir, path2) => {
|
|
@@ -32,6 +32,7 @@ require('../../svg/cleanup/root-svg.cjs');
|
|
|
32
32
|
require('../../svg/cleanup/svgo-style.cjs');
|
|
33
33
|
require('../../optimise/svgo.cjs');
|
|
34
34
|
require('svgo');
|
|
35
|
+
require('@iconify/utils/lib/svg/id');
|
|
35
36
|
require('../../download/api/index.cjs');
|
|
36
37
|
require('node-fetch');
|
|
37
38
|
require('../../download/api/cache.cjs');
|
|
@@ -30,6 +30,7 @@ import '../../svg/cleanup/root-svg.mjs';
|
|
|
30
30
|
import '../../svg/cleanup/svgo-style.mjs';
|
|
31
31
|
import '../../optimise/svgo.mjs';
|
|
32
32
|
import 'svgo';
|
|
33
|
+
import '@iconify/utils/lib/svg/id';
|
|
33
34
|
import '../../download/api/index.mjs';
|
|
34
35
|
import 'node-fetch';
|
|
35
36
|
import '../../download/api/cache.mjs';
|
package/lib/index.cjs
CHANGED
|
@@ -61,6 +61,7 @@ require('./svg/data/attributes.cjs');
|
|
|
61
61
|
require('./svg/data/tags.cjs');
|
|
62
62
|
require('./svg/analyse/error.cjs');
|
|
63
63
|
require('svgo');
|
|
64
|
+
require('@iconify/utils/lib/svg/id');
|
|
64
65
|
require('@iconify/utils/lib/icon/defaults');
|
|
65
66
|
require('@iconify/utils/lib/svg/build');
|
|
66
67
|
require('@iconify/utils/lib/icon-set/minify');
|
package/lib/index.mjs
CHANGED
|
@@ -59,6 +59,7 @@ import './svg/data/attributes.mjs';
|
|
|
59
59
|
import './svg/data/tags.mjs';
|
|
60
60
|
import './svg/analyse/error.mjs';
|
|
61
61
|
import 'svgo';
|
|
62
|
+
import '@iconify/utils/lib/svg/id';
|
|
62
63
|
import '@iconify/utils/lib/icon/defaults';
|
|
63
64
|
import '@iconify/utils/lib/svg/build';
|
|
64
65
|
import '@iconify/utils/lib/icon-set/minify';
|
package/lib/optimise/scale.cjs
CHANGED
package/lib/optimise/scale.mjs
CHANGED
package/lib/optimise/svgo.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const svgo = require('svgo');
|
|
4
|
+
const id = require('@iconify/utils/lib/svg/id');
|
|
4
5
|
|
|
5
6
|
function getSVGOPlugins(options) {
|
|
6
7
|
return [
|
|
@@ -43,15 +44,7 @@ function getSVGOPlugins(options) {
|
|
|
43
44
|
}
|
|
44
45
|
},
|
|
45
46
|
"reusePaths"
|
|
46
|
-
]
|
|
47
|
-
...options.cleanupIDs !== false ? [
|
|
48
|
-
{
|
|
49
|
-
name: "cleanupIds",
|
|
50
|
-
params: {
|
|
51
|
-
prefix: typeof options.cleanupIDs === "string" ? options.cleanupIDs : "svgID"
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
] : []
|
|
47
|
+
]
|
|
55
48
|
];
|
|
56
49
|
}
|
|
57
50
|
function runSVGO(svg, options = {}) {
|
|
@@ -75,7 +68,27 @@ function runSVGO(svg, options = {}) {
|
|
|
75
68
|
if (typeof result.error === "string") {
|
|
76
69
|
throw new Error(result.error);
|
|
77
70
|
}
|
|
78
|
-
|
|
71
|
+
let content = result.data.replace(/<defs\/>/g, "");
|
|
72
|
+
if (!options.plugins) {
|
|
73
|
+
const prefix = options.cleanupIDs !== void 0 ? options.cleanupIDs : "svgID";
|
|
74
|
+
if (prefix !== false) {
|
|
75
|
+
let counter = 0;
|
|
76
|
+
content = id.replaceIDs(
|
|
77
|
+
content,
|
|
78
|
+
typeof prefix === "string" ? () => {
|
|
79
|
+
return prefix + (counter++).toString(36);
|
|
80
|
+
} : prefix
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (!options.plugins || options.plugins.find((item) => {
|
|
85
|
+
if (typeof item === "string") {
|
|
86
|
+
return item === "reusePaths";
|
|
87
|
+
}
|
|
88
|
+
return item.name === "reusePaths";
|
|
89
|
+
})) {
|
|
90
|
+
content = content.replace(' xmlns:xlink="http://www.w3.org/1999/xlink"', "").replaceAll("xlink:href=", "href=");
|
|
91
|
+
}
|
|
79
92
|
svg.load(content);
|
|
80
93
|
}
|
|
81
94
|
|
package/lib/optimise/svgo.d.ts
CHANGED
|
@@ -4,16 +4,16 @@ import '@iconify/types';
|
|
|
4
4
|
import '@iconify/utils/lib/customisations/defaults';
|
|
5
5
|
|
|
6
6
|
interface CleanupIDsOption {
|
|
7
|
-
cleanupIDs?: string | false;
|
|
7
|
+
cleanupIDs?: string | ((id: string) => string) | false;
|
|
8
8
|
}
|
|
9
|
-
interface
|
|
9
|
+
interface GetSVGOPluginOptions extends CleanupIDsOption {
|
|
10
10
|
animated?: boolean;
|
|
11
11
|
keepShapes?: boolean;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Get list of plugins
|
|
15
15
|
*/
|
|
16
|
-
declare function getSVGOPlugins(options:
|
|
16
|
+
declare function getSVGOPlugins(options: GetSVGOPluginOptions): PluginConfig[];
|
|
17
17
|
/**
|
|
18
18
|
* Options
|
|
19
19
|
*/
|
package/lib/optimise/svgo.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { optimize } from 'svgo';
|
|
2
|
+
import { replaceIDs } from '@iconify/utils/lib/svg/id';
|
|
2
3
|
|
|
3
4
|
function getSVGOPlugins(options) {
|
|
4
5
|
return [
|
|
@@ -41,15 +42,7 @@ function getSVGOPlugins(options) {
|
|
|
41
42
|
}
|
|
42
43
|
},
|
|
43
44
|
"reusePaths"
|
|
44
|
-
]
|
|
45
|
-
...options.cleanupIDs !== false ? [
|
|
46
|
-
{
|
|
47
|
-
name: "cleanupIds",
|
|
48
|
-
params: {
|
|
49
|
-
prefix: typeof options.cleanupIDs === "string" ? options.cleanupIDs : "svgID"
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
] : []
|
|
45
|
+
]
|
|
53
46
|
];
|
|
54
47
|
}
|
|
55
48
|
function runSVGO(svg, options = {}) {
|
|
@@ -73,7 +66,27 @@ function runSVGO(svg, options = {}) {
|
|
|
73
66
|
if (typeof result.error === "string") {
|
|
74
67
|
throw new Error(result.error);
|
|
75
68
|
}
|
|
76
|
-
|
|
69
|
+
let content = result.data.replace(/<defs\/>/g, "");
|
|
70
|
+
if (!options.plugins) {
|
|
71
|
+
const prefix = options.cleanupIDs !== void 0 ? options.cleanupIDs : "svgID";
|
|
72
|
+
if (prefix !== false) {
|
|
73
|
+
let counter = 0;
|
|
74
|
+
content = replaceIDs(
|
|
75
|
+
content,
|
|
76
|
+
typeof prefix === "string" ? () => {
|
|
77
|
+
return prefix + (counter++).toString(36);
|
|
78
|
+
} : prefix
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (!options.plugins || options.plugins.find((item) => {
|
|
83
|
+
if (typeof item === "string") {
|
|
84
|
+
return item === "reusePaths";
|
|
85
|
+
}
|
|
86
|
+
return item.name === "reusePaths";
|
|
87
|
+
})) {
|
|
88
|
+
content = content.replace(' xmlns:xlink="http://www.w3.org/1999/xlink"', "").replaceAll("xlink:href=", "href=");
|
|
89
|
+
}
|
|
77
90
|
svg.load(content);
|
|
78
91
|
}
|
|
79
92
|
|
package/lib/svg/cleanup.cjs
CHANGED
|
@@ -19,6 +19,7 @@ require('../css/parser/export.cjs');
|
|
|
19
19
|
require('../css/parser/tree.cjs');
|
|
20
20
|
require('../optimise/svgo.cjs');
|
|
21
21
|
require('svgo');
|
|
22
|
+
require('@iconify/utils/lib/svg/id');
|
|
22
23
|
|
|
23
24
|
async function cleanupSVG(svg) {
|
|
24
25
|
await svg_cleanup_inlineStyle.cleanupInlineStyle(svg);
|
package/lib/svg/cleanup.mjs
CHANGED
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.2.0-beta.
|
|
6
|
+
"version": "2.2.0-beta.3",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"bugs": "https://github.com/iconify/tools/issues",
|
|
9
9
|
"homepage": "https://github.com/iconify/tools",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"module": "./lib/index.mjs",
|
|
16
16
|
"types": "./lib/index.d.ts",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@iconify/utils": "^2.0.
|
|
18
|
+
"@iconify/utils": "^2.0.9",
|
|
19
19
|
"@types/cheerio": "^0.22.31",
|
|
20
20
|
"@types/node-fetch": "^2.6.2",
|
|
21
21
|
"@types/tar": "^6.1.3",
|