@iconify/tools 2.0.13 → 2.0.16
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/attribs.cjs +30 -0
- package/lib/colors/attribs.d.ts +13 -10
- package/lib/colors/attribs.mjs +7 -13
- package/lib/colors/parse.cjs +269 -0
- package/lib/colors/parse.d.ts +15 -11
- package/lib/colors/parse.mjs +27 -31
- package/lib/colors/validate.cjs +52 -0
- package/lib/colors/validate.d.ts +11 -4
- package/lib/colors/validate.mjs +19 -6
- package/lib/css/parse.cjs +26 -0
- package/lib/css/parse.d.ts +3 -1
- package/lib/css/parse.mjs +8 -6
- package/lib/css/parser/error.cjs +25 -0
- package/lib/css/parser/error.d.ts +4 -2
- package/lib/css/parser/error.mjs +2 -4
- package/lib/css/parser/export.cjs +48 -0
- package/lib/css/parser/export.d.ts +5 -2
- package/lib/css/parser/export.mjs +4 -6
- package/lib/css/parser/strings.cjs +77 -0
- package/lib/css/parser/strings.d.ts +6 -3
- package/lib/css/parser/strings.mjs +4 -6
- package/lib/css/parser/text.cjs +135 -0
- package/lib/css/parser/text.d.ts +8 -5
- package/lib/css/parser/text.mjs +3 -8
- package/lib/css/parser/tokens.cjs +184 -0
- package/lib/css/parser/tokens.d.ts +6 -3
- package/lib/css/parser/tokens.mjs +7 -13
- package/lib/css/parser/tree.cjs +42 -0
- package/lib/css/parser/tree.d.ts +5 -2
- package/lib/css/parser/tree.mjs +2 -4
- package/lib/css/parser/types.cjs +2 -0
- package/lib/css/parser/types.d.ts +13 -11
- package/lib/css/parser/types.mjs +1 -0
- package/lib/download/api/cache.cjs +86 -0
- package/lib/download/api/cache.d.ts +8 -5
- package/lib/download/api/cache.mjs +14 -19
- package/lib/download/api/download.cjs +28 -0
- package/lib/download/api/download.d.ts +5 -2
- package/lib/download/api/download.mjs +8 -9
- package/lib/download/api/index.cjs +51 -0
- package/lib/download/api/index.d.ts +5 -2
- package/lib/download/api/index.mjs +8 -6
- package/lib/download/api/types.cjs +2 -0
- package/lib/download/api/types.d.ts +4 -2
- package/lib/download/api/types.mjs +1 -0
- package/lib/download/git/branch.cjs +22 -0
- package/lib/download/git/branch.d.ts +5 -2
- package/lib/download/git/branch.mjs +5 -5
- package/lib/download/git/hash.cjs +15 -0
- package/lib/download/git/hash.d.ts +5 -2
- package/lib/download/git/hash.mjs +5 -5
- package/lib/download/git/index.cjs +76 -0
- package/lib/download/git/index.d.ts +10 -8
- package/lib/download/git/index.mjs +41 -26
- package/lib/download/git/reset.cjs +41 -0
- package/lib/download/git/reset.d.ts +3 -1
- package/lib/download/git/reset.mjs +29 -5
- package/lib/download/github/hash.cjs +32 -0
- package/lib/download/github/hash.d.ts +5 -2
- package/lib/download/github/hash.mjs +10 -7
- package/lib/download/github/index.cjs +98 -0
- package/lib/download/github/index.d.ts +11 -9
- package/lib/download/github/index.mjs +23 -17
- package/lib/download/github/types.cjs +2 -0
- package/lib/download/github/types.d.ts +3 -1
- package/lib/download/github/types.mjs +1 -0
- package/lib/download/gitlab/hash.cjs +32 -0
- package/lib/download/gitlab/hash.d.ts +5 -2
- package/lib/download/gitlab/hash.mjs +10 -6
- package/lib/download/gitlab/index.cjs +98 -0
- package/lib/download/gitlab/index.d.ts +11 -9
- package/lib/download/gitlab/index.mjs +24 -18
- package/lib/download/gitlab/types.cjs +7 -0
- package/lib/download/gitlab/types.d.ts +4 -2
- package/lib/download/gitlab/types.mjs +3 -5
- package/lib/download/helpers/untar.cjs +14 -0
- package/lib/download/helpers/untar.d.ts +3 -1
- package/lib/download/helpers/untar.mjs +4 -5
- package/lib/download/helpers/unzip.cjs +19 -0
- package/lib/download/helpers/unzip.d.ts +3 -1
- package/lib/download/helpers/unzip.mjs +6 -7
- package/lib/download/index.cjs +64 -0
- package/lib/download/index.d.ts +18 -13
- package/lib/download/index.mjs +46 -19
- package/lib/download/npm/index.cjs +82 -0
- package/lib/download/npm/index.d.ts +10 -8
- package/lib/download/npm/index.mjs +16 -13
- package/lib/download/npm/types.cjs +2 -0
- package/lib/download/npm/types.d.ts +3 -1
- package/lib/download/npm/types.mjs +1 -0
- package/lib/download/npm/version.cjs +23 -0
- package/lib/download/npm/version.d.ts +7 -4
- package/lib/download/npm/version.mjs +8 -10
- package/lib/download/types/modified.cjs +2 -0
- package/lib/download/types/modified.d.ts +3 -1
- package/lib/download/types/modified.mjs +1 -0
- package/lib/download/types/sources.cjs +2 -0
- package/lib/download/types/sources.d.ts +4 -2
- package/lib/download/types/sources.mjs +1 -0
- package/lib/export/directory.cjs +45 -0
- package/lib/export/directory.d.ts +11 -4
- package/lib/export/directory.mjs +8 -8
- package/lib/export/helpers/custom-files.cjs +28 -0
- package/lib/export/helpers/custom-files.d.ts +4 -2
- package/lib/export/helpers/custom-files.mjs +8 -9
- package/lib/export/helpers/prepare.cjs +36 -0
- package/lib/export/helpers/prepare.d.ts +5 -3
- package/lib/export/helpers/prepare.mjs +7 -9
- package/lib/export/helpers/types-version.cjs +22 -0
- package/lib/export/helpers/types-version.d.ts +3 -1
- package/lib/export/helpers/types-version.mjs +15 -37
- package/lib/export/icon-package.cjs +59 -0
- package/lib/export/icon-package.d.ts +12 -5
- package/lib/export/icon-package.mjs +15 -16
- package/lib/export/json-package.cjs +133 -0
- package/lib/export/json-package.d.ts +12 -5
- package/lib/export/json-package.mjs +20 -21
- package/lib/icon-set/index.cjs +588 -0
- package/lib/icon-set/index.d.ts +9 -6
- package/lib/icon-set/index.mjs +40 -54
- package/lib/icon-set/match.cjs +58 -0
- package/lib/icon-set/match.d.ts +10 -3
- package/lib/icon-set/match.mjs +5 -6
- package/lib/icon-set/merge.cjs +83 -0
- package/lib/icon-set/merge.d.ts +9 -2
- package/lib/icon-set/merge.mjs +15 -10
- package/lib/icon-set/props.cjs +28 -0
- package/lib/icon-set/props.d.ts +8 -4
- package/lib/icon-set/props.mjs +7 -10
- package/lib/icon-set/types.cjs +2 -0
- package/lib/icon-set/types.d.ts +19 -17
- package/lib/icon-set/types.mjs +1 -0
- package/lib/import/directory.cjs +76 -0
- package/lib/import/directory.d.ts +11 -5
- package/lib/import/directory.mjs +36 -11
- package/lib/import/figma/index.cjs +105 -0
- package/lib/import/figma/index.d.ts +15 -5
- package/lib/import/figma/index.mjs +40 -13
- package/lib/import/figma/nodes.cjs +86 -0
- package/lib/import/figma/nodes.d.ts +13 -4
- package/lib/import/figma/nodes.mjs +3 -11
- package/lib/import/figma/query.cjs +218 -0
- package/lib/import/figma/query.d.ts +18 -9
- package/lib/import/figma/query.mjs +9 -12
- package/lib/import/figma/types/api.cjs +2 -0
- package/lib/import/figma/types/api.d.ts +8 -7
- package/lib/import/figma/types/api.mjs +1 -0
- package/lib/import/figma/types/nodes.cjs +2 -0
- package/lib/import/figma/types/nodes.d.ts +16 -9
- package/lib/import/figma/types/nodes.mjs +1 -0
- package/lib/import/figma/types/options.cjs +2 -0
- package/lib/import/figma/types/options.d.ts +17 -10
- package/lib/import/figma/types/options.mjs +1 -0
- package/lib/import/figma/types/result.cjs +2 -0
- package/lib/import/figma/types/result.d.ts +12 -5
- package/lib/import/figma/types/result.mjs +1 -0
- package/lib/index.cjs +138 -0
- package/lib/index.d.ts +66 -44
- package/lib/index.mjs +83 -94
- package/lib/misc/bump-version.cjs +17 -0
- package/lib/misc/bump-version.d.ts +3 -1
- package/lib/misc/bump-version.mjs +2 -4
- package/lib/misc/compare-dirs.cjs +75 -0
- package/lib/misc/compare-dirs.d.ts +4 -2
- package/lib/misc/compare-dirs.mjs +12 -12
- package/lib/misc/exec.cjs +25 -0
- package/lib/misc/exec.d.ts +6 -4
- package/lib/misc/exec.mjs +4 -5
- package/lib/misc/keyword.cjs +19 -0
- package/lib/misc/keyword.d.ts +3 -1
- package/lib/misc/keyword.mjs +2 -4
- package/lib/misc/scan.cjs +51 -0
- package/lib/misc/scan.d.ts +7 -6
- package/lib/misc/scan.mjs +6 -7
- package/lib/misc/write-json.cjs +11 -0
- package/lib/misc/write-json.d.ts +3 -1
- package/lib/misc/write-json.mjs +5 -6
- package/lib/optimise/flags.cjs +252 -0
- package/lib/optimise/flags.d.ts +7 -2
- package/lib/optimise/flags.mjs +18 -19
- package/lib/optimise/global-style.cjs +154 -0
- package/lib/optimise/global-style.d.ts +7 -2
- package/lib/optimise/global-style.mjs +68 -47
- package/lib/optimise/scale.cjs +26 -0
- package/lib/optimise/scale.d.ts +7 -2
- package/lib/optimise/scale.mjs +5 -5
- package/lib/optimise/svgo.cjs +83 -0
- package/lib/optimise/svgo.d.ts +10 -6
- package/lib/optimise/svgo.mjs +6 -9
- package/lib/svg/analyse/error.cjs +18 -0
- package/lib/svg/analyse/error.d.ts +5 -2
- package/lib/svg/analyse/error.mjs +2 -4
- package/lib/svg/analyse/types.cjs +2 -0
- package/lib/svg/analyse/types.d.ts +11 -11
- package/lib/svg/analyse/types.mjs +1 -0
- package/lib/svg/analyse.cjs +291 -0
- package/lib/svg/analyse.d.ts +8 -3
- package/lib/svg/analyse.mjs +15 -30
- package/lib/svg/cleanup/attribs.cjs +41 -0
- package/lib/svg/cleanup/attribs.d.ts +7 -2
- package/lib/svg/cleanup/attribs.mjs +6 -12
- package/lib/svg/cleanup/bad-tags.cjs +51 -0
- package/lib/svg/cleanup/bad-tags.d.ts +7 -2
- package/lib/svg/cleanup/bad-tags.mjs +10 -25
- package/lib/svg/cleanup/inline-style.cjs +64 -0
- package/lib/svg/cleanup/inline-style.d.ts +7 -2
- package/lib/svg/cleanup/inline-style.mjs +14 -19
- package/lib/svg/cleanup/root-svg.cjs +81 -0
- package/lib/svg/cleanup/root-svg.d.ts +7 -2
- package/lib/svg/cleanup/root-svg.mjs +7 -18
- package/lib/svg/cleanup/svgo-style.cjs +38 -0
- package/lib/svg/cleanup/svgo-style.d.ts +7 -2
- package/lib/svg/cleanup/svgo-style.mjs +16 -11
- package/lib/svg/cleanup.cjs +32 -0
- package/lib/svg/cleanup.d.ts +7 -2
- package/lib/svg/cleanup.mjs +21 -9
- package/lib/svg/data/attributes.cjs +355 -0
- package/lib/svg/data/attributes.d.ts +27 -25
- package/lib/svg/data/attributes.mjs +90 -115
- package/lib/svg/data/tags.cjs +137 -0
- package/lib/svg/data/tags.d.ts +25 -23
- package/lib/svg/data/tags.mjs +25 -49
- package/lib/svg/index.cjs +130 -0
- package/lib/svg/index.d.ts +16 -5
- package/lib/svg/index.mjs +48 -11
- package/lib/svg/parse-style.cjs +134 -0
- package/lib/svg/parse-style.d.ts +12 -8
- package/lib/svg/parse-style.mjs +11 -9
- package/lib/svg/parse.cjs +42 -0
- package/lib/svg/parse.d.ts +11 -7
- package/lib/svg/parse.mjs +2 -4
- package/package.json +99 -94
- package/lib/colors/attribs.js +0 -26
- package/lib/colors/parse.js +0 -341
- package/lib/colors/validate.js +0 -48
- package/lib/css/parse.js +0 -23
- package/lib/css/parser/error.js +0 -27
- package/lib/css/parser/export.js +0 -69
- package/lib/css/parser/strings.js +0 -93
- package/lib/css/parser/text.js +0 -171
- package/lib/css/parser/tokens.js +0 -200
- package/lib/css/parser/tree.js +0 -44
- package/lib/css/parser/types.js +0 -2
- package/lib/download/api/cache.js +0 -108
- package/lib/download/api/download.js +0 -27
- package/lib/download/api/index.js +0 -52
- package/lib/download/api/types.js +0 -2
- package/lib/download/git/branch.js +0 -22
- package/lib/download/git/hash.js +0 -14
- package/lib/download/git/index.js +0 -75
- package/lib/download/git/reset.js +0 -16
- package/lib/download/github/hash.js +0 -28
- package/lib/download/github/index.js +0 -116
- package/lib/download/github/types.js +0 -2
- package/lib/download/gitlab/hash.js +0 -27
- package/lib/download/gitlab/index.js +0 -115
- package/lib/download/gitlab/types.js +0 -7
- package/lib/download/helpers/untar.js +0 -14
- package/lib/download/helpers/unzip.js +0 -18
- package/lib/download/index.js +0 -27
- package/lib/download/npm/index.js +0 -91
- package/lib/download/npm/types.js +0 -2
- package/lib/download/npm/version.js +0 -27
- package/lib/download/types/modified.js +0 -2
- package/lib/download/types/sources.js +0 -2
- package/lib/export/directory.js +0 -52
- package/lib/export/helpers/custom-files.js +0 -32
- package/lib/export/helpers/prepare.js +0 -49
- package/lib/export/helpers/types-version.js +0 -12
- package/lib/export/icon-package.js +0 -77
- package/lib/export/json-package.js +0 -156
- package/lib/icon-set/index.js +0 -749
- package/lib/icon-set/match.js +0 -66
- package/lib/icon-set/merge.js +0 -90
- package/lib/icon-set/props.js +0 -34
- package/lib/icon-set/types.js +0 -2
- package/lib/import/directory.js +0 -59
- package/lib/import/figma/index.js +0 -90
- package/lib/import/figma/nodes.js +0 -106
- package/lib/import/figma/query.js +0 -244
- package/lib/import/figma/types/api.js +0 -12
- package/lib/import/figma/types/nodes.js +0 -2
- package/lib/import/figma/types/options.js +0 -2
- package/lib/import/figma/types/result.js +0 -2
- package/lib/index.js +0 -103
- package/lib/misc/bump-version.js +0 -19
- package/lib/misc/compare-dirs.js +0 -84
- package/lib/misc/exec.js +0 -26
- package/lib/misc/keyword.js +0 -31
- package/lib/misc/scan.js +0 -55
- package/lib/misc/write-json.js +0 -11
- package/lib/optimise/flags.js +0 -312
- package/lib/optimise/global-style.js +0 -158
- package/lib/optimise/scale.js +0 -42
- package/lib/optimise/svgo.js +0 -99
- package/lib/svg/analyse/error.js +0 -22
- package/lib/svg/analyse/types.js +0 -2
- package/lib/svg/analyse.js +0 -352
- package/lib/svg/cleanup/attribs.js +0 -51
- package/lib/svg/cleanup/bad-tags.js +0 -65
- package/lib/svg/cleanup/inline-style.js +0 -77
- package/lib/svg/cleanup/root-svg.js +0 -107
- package/lib/svg/cleanup/svgo-style.js +0 -35
- package/lib/svg/cleanup.js +0 -24
- package/lib/svg/data/attributes.js +0 -403
- package/lib/svg/data/tags.js +0 -188
- package/lib/svg/index.js +0 -125
- package/lib/svg/parse-style.js +0 -151
- package/lib/svg/parse.js +0 -49
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.removeBadAttributes = void 0;
|
|
4
|
-
const attributes_1 = require("../data/attributes");
|
|
5
|
-
const tags_1 = require("../data/tags");
|
|
6
|
-
const parse_1 = require("../parse");
|
|
7
|
-
/**
|
|
8
|
-
* Remove useless attributes
|
|
9
|
-
*/
|
|
10
|
-
async function removeBadAttributes(svg) {
|
|
11
|
-
await (0, parse_1.parseSVG)(svg, (item) => {
|
|
12
|
-
const tagName = item.tagName;
|
|
13
|
-
const attribs = item.element.attribs;
|
|
14
|
-
const $element = item.$element;
|
|
15
|
-
// Common tags
|
|
16
|
-
Object.keys(attribs).forEach((attr) => {
|
|
17
|
-
// Bad attributes, events
|
|
18
|
-
if (attr.slice(0, 2) === 'on' ||
|
|
19
|
-
attributes_1.badAttributes.has(attr) ||
|
|
20
|
-
attributes_1.badSoftwareAttributes.has(attr) ||
|
|
21
|
-
attributes_1.badAttributePrefixes.has(attr.split('-').shift())) {
|
|
22
|
-
$element.removeAttr(attr);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
// Attributes on <defs> aren't passed to child nodes, so remove everything)
|
|
26
|
-
if (tags_1.defsTag.has(tagName) &&
|
|
27
|
-
!attributes_1.tagSpecificPresentationalAttributes[tagName].has(attr)) {
|
|
28
|
-
$element.removeAttr(attr);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
// Check for namespace
|
|
32
|
-
const nsParts = attr.split(':');
|
|
33
|
-
if (nsParts.length > 1) {
|
|
34
|
-
const namespace = nsParts.shift();
|
|
35
|
-
const newAttr = nsParts.join(':');
|
|
36
|
-
switch (namespace) {
|
|
37
|
-
case 'xlink': {
|
|
38
|
-
// Deprecated: use without namespace
|
|
39
|
-
if (attribs[newAttr] === void 0) {
|
|
40
|
-
$element.attr(newAttr, attribs[attr]);
|
|
41
|
-
}
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
// Remove all namespace attributes
|
|
46
|
-
$element.removeAttr(attr);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
exports.removeBadAttributes = removeBadAttributes;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkBadTags = void 0;
|
|
4
|
-
const parse_1 = require("../parse");
|
|
5
|
-
const tags_1 = require("../data/tags");
|
|
6
|
-
// List of required parent tags
|
|
7
|
-
const requiredParentTags = new Map();
|
|
8
|
-
// <feFunc*> must be children of <feComponentTransfer>
|
|
9
|
-
requiredParentTags.set(new Set(['feComponentTransfer']), tags_1.feComponentTransferChildTag);
|
|
10
|
-
// <feMergeNode> must be children of <feMerge>
|
|
11
|
-
requiredParentTags.set(new Set(['feMerge']), tags_1.feMergeChildTags);
|
|
12
|
-
// Children of <fe*Lightning>
|
|
13
|
-
requiredParentTags.set(tags_1.feLightningTags, tags_1.feLightningChildTags);
|
|
14
|
-
// Filter tags must be children of <filter>
|
|
15
|
-
requiredParentTags.set(tags_1.filterTag, tags_1.filterChildTags);
|
|
16
|
-
// <stop> must be inside gradient
|
|
17
|
-
requiredParentTags.set(tags_1.gradientTags, tags_1.gradientChildTags);
|
|
18
|
-
// <mpath> must be inside <animateMotion>
|
|
19
|
-
requiredParentTags.set(new Set(['animateMotion']), tags_1.animateMotionChildTags);
|
|
20
|
-
/**
|
|
21
|
-
* Test for bag tags
|
|
22
|
-
*/
|
|
23
|
-
async function checkBadTags(svg) {
|
|
24
|
-
await (0, parse_1.parseSVG)(svg, (item) => {
|
|
25
|
-
var _a;
|
|
26
|
-
const tagName = item.tagName;
|
|
27
|
-
const $element = item.$element;
|
|
28
|
-
// SVG as root
|
|
29
|
-
if (tagName === 'svg') {
|
|
30
|
-
if (item.parents.length) {
|
|
31
|
-
// Technically code is correct, but it badly complicates parsing, so not supported
|
|
32
|
-
throw new Error(`Unexpected element: <${tagName}>`);
|
|
33
|
-
}
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
// Unsupported: quietly remove it
|
|
37
|
-
if (tags_1.unsupportedTags.has(tagName)) {
|
|
38
|
-
$element.remove();
|
|
39
|
-
item.testChildren = false;
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
// Bad or unknown element
|
|
43
|
-
if (tags_1.badTags.has(tagName) || !tags_1.allValidTags.has(tagName)) {
|
|
44
|
-
const parts = tagName.split(':');
|
|
45
|
-
if (parts.length > 1) {
|
|
46
|
-
// Custom tag, most likely Inkscape junk
|
|
47
|
-
$element.remove();
|
|
48
|
-
item.testChildren = false;
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
throw new Error(`Unexpected element: <${tagName}>`);
|
|
52
|
-
}
|
|
53
|
-
// Check for valid parent tag
|
|
54
|
-
const parentTagName = (_a = item.parents[0]) === null || _a === void 0 ? void 0 : _a.tagName;
|
|
55
|
-
for (const [parents, children] of requiredParentTags) {
|
|
56
|
-
if (children.has(tagName)) {
|
|
57
|
-
if (!parents.has(parentTagName)) {
|
|
58
|
-
throw new Error(`Element <${tagName}> has wrong parent element`);
|
|
59
|
-
}
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
exports.checkBadTags = checkBadTags;
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cleanupInlineStyle = void 0;
|
|
4
|
-
const parse_1 = require("../../css/parse");
|
|
5
|
-
const attributes_1 = require("../data/attributes");
|
|
6
|
-
const parse_2 = require("../parse");
|
|
7
|
-
/**
|
|
8
|
-
* Expand inline style
|
|
9
|
-
*/
|
|
10
|
-
async function cleanupInlineStyle(svg) {
|
|
11
|
-
await (0, parse_2.parseSVG)(svg, (item) => {
|
|
12
|
-
const $element = item.$element;
|
|
13
|
-
const attribs = item.element.attribs;
|
|
14
|
-
const tagName = item.tagName;
|
|
15
|
-
// Expand style
|
|
16
|
-
if (attribs.style) {
|
|
17
|
-
const parsedStyle = (0, parse_1.parseInlineStyle)(attribs.style);
|
|
18
|
-
if (parsedStyle === null) {
|
|
19
|
-
// Ignore style
|
|
20
|
-
$element.removeAttr('style');
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
const newStyle = Object.create(null);
|
|
24
|
-
const checkRule = (prop, value) => {
|
|
25
|
-
var _a, _b, _c;
|
|
26
|
-
function warn() {
|
|
27
|
-
console.warn(`Removing unexpected style on "${tagName}": ${prop}`);
|
|
28
|
-
}
|
|
29
|
-
// Check for bad attributes that should be removed
|
|
30
|
-
if (attributes_1.badAttributes.has(prop) ||
|
|
31
|
-
((_a = attributes_1.tagSpecificNonPresentationalAttributes[tagName]) === null || _a === void 0 ? void 0 : _a.has(prop))) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
// Valid attributes
|
|
35
|
-
if (((_b = attributes_1.tagSpecificAnimatedAttributes[tagName]) === null || _b === void 0 ? void 0 : _b.has(prop)) ||
|
|
36
|
-
((_c = attributes_1.tagSpecificPresentationalAttributes[tagName]) === null || _c === void 0 ? void 0 : _c.has(prop))) {
|
|
37
|
-
$element.attr(prop, value);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
// Attributes inside <clipPath>
|
|
41
|
-
if (attributes_1.insideClipPathAttributes.has(prop)) {
|
|
42
|
-
if (item.parents.find((item) => item.tagName === 'clipPath')) {
|
|
43
|
-
$element.attr(prop, value);
|
|
44
|
-
}
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
// Bad software stuff
|
|
48
|
-
if (attributes_1.badSoftwareAttributes.has(prop) ||
|
|
49
|
-
attributes_1.badAttributePrefixes.has(prop.split('-').shift())) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
// Vendor specific junk
|
|
53
|
-
if (prop.slice(0, 1) === '-') {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
// Unknown
|
|
57
|
-
warn();
|
|
58
|
-
};
|
|
59
|
-
// Check all properties
|
|
60
|
-
for (const prop in parsedStyle) {
|
|
61
|
-
checkRule(prop, parsedStyle[prop]);
|
|
62
|
-
}
|
|
63
|
-
// Update style
|
|
64
|
-
const newStyleStr = Object.keys(newStyle)
|
|
65
|
-
.map((key) => key + ':' + newStyle[key] + ';')
|
|
66
|
-
.join('');
|
|
67
|
-
if (newStyleStr.length) {
|
|
68
|
-
$element.attr('style', newStyleStr);
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
$element.removeAttr('style');
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
exports.cleanupInlineStyle = cleanupInlineStyle;
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cleanupSVGRoot = void 0;
|
|
4
|
-
const attributes_1 = require("../data/attributes");
|
|
5
|
-
const tags_1 = require("../data/tags");
|
|
6
|
-
/**
|
|
7
|
-
* Clean up SVG
|
|
8
|
-
*/
|
|
9
|
-
async function cleanupSVGRoot(svg) {
|
|
10
|
-
const cheerio = svg.$svg;
|
|
11
|
-
const $root = svg.$svg(':root');
|
|
12
|
-
const root = $root.get(0);
|
|
13
|
-
const tagName = 'svg';
|
|
14
|
-
if (root.tagName !== tagName) {
|
|
15
|
-
throw new Error(`Unexpected root tag <${root.tagName}>`);
|
|
16
|
-
}
|
|
17
|
-
const attribs = root.attribs;
|
|
18
|
-
// Check attributes
|
|
19
|
-
const moveToChildren = {};
|
|
20
|
-
Object.keys(attribs).forEach((attr) => {
|
|
21
|
-
var _a, _b;
|
|
22
|
-
const value = attribs[attr];
|
|
23
|
-
// Bad attributes, irrelevant common attributes, namespaces
|
|
24
|
-
if (attributes_1.commonAttributes.has(attr) ||
|
|
25
|
-
attributes_1.badAttributes.has(attr) ||
|
|
26
|
-
attributes_1.junkSVGAttributes.has(attr) ||
|
|
27
|
-
attributes_1.badSoftwareAttributes.has(attr) ||
|
|
28
|
-
attributes_1.badAttributePrefixes.has(attr.split('-').shift()) ||
|
|
29
|
-
attr.split(':').length > 1) {
|
|
30
|
-
$root.removeAttr(attr);
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
// Special handling for dimensions
|
|
34
|
-
switch (attr) {
|
|
35
|
-
case 'width':
|
|
36
|
-
case 'height':
|
|
37
|
-
// Cleanup dimensions
|
|
38
|
-
if (value.slice(-2) === 'px') {
|
|
39
|
-
// Remove 'px'
|
|
40
|
-
const num = value.replace('px', '');
|
|
41
|
-
if (parseFloat(num) + '' === num) {
|
|
42
|
-
$root.attr(attr, num);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
// Attributes that belong to <svg>
|
|
48
|
-
if ((_a = attributes_1.tagSpecificNonPresentationalAttributes[tagName]) === null || _a === void 0 ? void 0 : _a.has(attr)) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
// Presentational attributes: move to child elements
|
|
52
|
-
if (((_b = attributes_1.tagSpecificPresentationalAttributes[tagName]) === null || _b === void 0 ? void 0 : _b.has(attr)) &&
|
|
53
|
-
attributes_1.tagSpecificPresentationalAttributes.g.has(attr)) {
|
|
54
|
-
moveToChildren[attr] = value;
|
|
55
|
-
$root.removeAttr(attr);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
// Styling: 'style' should be checked by expandInlineStyle(), remove others
|
|
59
|
-
if (attributes_1.stylingAttributes.has(attr)) {
|
|
60
|
-
switch (attr) {
|
|
61
|
-
case 'style':
|
|
62
|
-
return;
|
|
63
|
-
case 'class':
|
|
64
|
-
$root.removeAttr(attr);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
throw new Error(`Unexpected attribute "${attr}" on <${tagName}>`);
|
|
68
|
-
}
|
|
69
|
-
// Junk from bad editors, mostly Adobe Illustrator and Inkscape
|
|
70
|
-
if (
|
|
71
|
-
// Events
|
|
72
|
-
attr.slice(0, 2) === 'on' ||
|
|
73
|
-
// aria-stuff
|
|
74
|
-
attr.slice(0, 5) === 'aria-' ||
|
|
75
|
-
// Junk
|
|
76
|
-
attr.slice(0, 6) === 'xmlns:') {
|
|
77
|
-
$root.removeAttr(attr);
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
console.warn(`Removing unexpected attribute on SVG: ${attr}`);
|
|
81
|
-
$root.removeAttr(attr);
|
|
82
|
-
});
|
|
83
|
-
if (Object.keys(moveToChildren).length) {
|
|
84
|
-
// Wrap child elements
|
|
85
|
-
const $wrapper = cheerio('<g />');
|
|
86
|
-
for (const key in moveToChildren) {
|
|
87
|
-
$wrapper.attr(key, moveToChildren[key]);
|
|
88
|
-
}
|
|
89
|
-
$root.children().each((_index, child) => {
|
|
90
|
-
const $child = cheerio(child);
|
|
91
|
-
if (child.type !== 'tag') {
|
|
92
|
-
$child.appendTo($wrapper);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
const tagName = child.tagName;
|
|
96
|
-
if (tagName === 'style' ||
|
|
97
|
-
tags_1.reusableElementsWithPalette.has(tagName) ||
|
|
98
|
-
tags_1.maskTags.has(tagName)) {
|
|
99
|
-
// Do not wrap these elements
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
$child.appendTo($wrapper);
|
|
103
|
-
});
|
|
104
|
-
$wrapper.appendTo($root);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
exports.cleanupSVGRoot = cleanupSVGRoot;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertStyleToAttrs = void 0;
|
|
4
|
-
const attributes_1 = require("../data/attributes");
|
|
5
|
-
const parse_style_1 = require("../parse-style");
|
|
6
|
-
const svgo_1 = require("../../optimise/svgo");
|
|
7
|
-
/**
|
|
8
|
-
* Expand inline style
|
|
9
|
-
*/
|
|
10
|
-
async function convertStyleToAttrs(svg) {
|
|
11
|
-
let hasStyle = false;
|
|
12
|
-
// Clean up style, removing useless junk
|
|
13
|
-
await (0, parse_style_1.parseSVGStyle)(svg, (item) => {
|
|
14
|
-
const prop = item.prop;
|
|
15
|
-
if (
|
|
16
|
-
// Attributes / properties now allowed
|
|
17
|
-
attributes_1.badAttributes.has(prop) ||
|
|
18
|
-
attributes_1.badSoftwareAttributes.has(prop) ||
|
|
19
|
-
attributes_1.badAttributePrefixes.has(prop.split('-').shift())) {
|
|
20
|
-
return void 0;
|
|
21
|
-
}
|
|
22
|
-
hasStyle = true;
|
|
23
|
-
return item.value;
|
|
24
|
-
});
|
|
25
|
-
// Nothing to check?
|
|
26
|
-
if (!hasStyle) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
// Run SVGO
|
|
30
|
-
await (0, svgo_1.runSVGO)(svg, {
|
|
31
|
-
plugins: ['convertStyleToAttrs', 'inlineStyles'],
|
|
32
|
-
multipass: true,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
exports.convertStyleToAttrs = convertStyleToAttrs;
|
package/lib/svg/cleanup.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cleanupSVG = void 0;
|
|
4
|
-
const attribs_1 = require("./cleanup/attribs");
|
|
5
|
-
const bad_tags_1 = require("./cleanup/bad-tags");
|
|
6
|
-
const inline_style_1 = require("./cleanup/inline-style");
|
|
7
|
-
const root_svg_1 = require("./cleanup/root-svg");
|
|
8
|
-
const svgo_style_1 = require("./cleanup/svgo-style");
|
|
9
|
-
/**
|
|
10
|
-
* Clean up SVG before parsing/optimising it
|
|
11
|
-
*/
|
|
12
|
-
async function cleanupSVG(svg) {
|
|
13
|
-
// Remove junk from style
|
|
14
|
-
await (0, inline_style_1.cleanupInlineStyle)(svg);
|
|
15
|
-
// Expand style
|
|
16
|
-
await (0, svgo_style_1.convertStyleToAttrs)(svg);
|
|
17
|
-
// Cleanup <svg> element
|
|
18
|
-
await (0, root_svg_1.cleanupSVGRoot)(svg);
|
|
19
|
-
// Check for bad tags
|
|
20
|
-
await (0, bad_tags_1.checkBadTags)(svg);
|
|
21
|
-
// Remove attributes
|
|
22
|
-
await (0, attribs_1.removeBadAttributes)(svg);
|
|
23
|
-
}
|
|
24
|
-
exports.cleanupSVG = cleanupSVG;
|