@iconify/tools 2.0.2 → 2.0.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/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,7 +62,14 @@ 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',
|
|
@@ -79,7 +88,7 @@ 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
|
}
|
package/lib/optimise/svgo.mjs
CHANGED
|
@@ -44,12 +44,17 @@ 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: {
|
|
@@ -62,7 +67,7 @@ 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
|
}
|
|
@@ -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.3",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bugs": "https://github.com/iconify/tools/issues",
|
|
8
8
|
"homepage": "https://github.com/iconify/tools",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"extract-zip": "^2.0.1",
|
|
32
32
|
"node-fetch": "^2.6.6",
|
|
33
33
|
"pathe": "^0.2.0",
|
|
34
|
-
"svgo": "^2.
|
|
34
|
+
"svgo": "^2.8.0",
|
|
35
35
|
"tar": "^6.1.11"
|
|
36
36
|
},
|
|
37
37
|
"exports": {
|