@iconify/tools 2.0.14 → 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/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 +18 -15
- 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 +85 -0
- package/lib/optimise/svgo.d.ts +18 -9
- package/lib/optimise/svgo.mjs +61 -61
- 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 -14
- 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 -185
- 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 -134
- package/lib/svg/parse-style.js +0 -151
- package/lib/svg/parse.js +0 -49
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const css_parse = require('../../css/parse.cjs');
|
|
6
|
+
const svg_data_attributes = require('../data/attributes.cjs');
|
|
7
|
+
const svg_parse = require('../parse.cjs');
|
|
8
|
+
require('../../css/parser/tokens.cjs');
|
|
9
|
+
require('../../css/parser/error.cjs');
|
|
10
|
+
require('../../css/parser/strings.cjs');
|
|
11
|
+
require('../../css/parser/text.cjs');
|
|
12
|
+
require('../data/tags.cjs');
|
|
13
|
+
|
|
14
|
+
async function cleanupInlineStyle(svg) {
|
|
15
|
+
await svg_parse.parseSVG(svg, (item) => {
|
|
16
|
+
const $element = item.$element;
|
|
17
|
+
const attribs = item.element.attribs;
|
|
18
|
+
const tagName = item.tagName;
|
|
19
|
+
if (attribs.style) {
|
|
20
|
+
const parsedStyle = css_parse.parseInlineStyle(attribs.style);
|
|
21
|
+
if (parsedStyle === null) {
|
|
22
|
+
$element.removeAttr("style");
|
|
23
|
+
} else {
|
|
24
|
+
const newStyle = /* @__PURE__ */ Object.create(null);
|
|
25
|
+
const checkRule = (prop, value) => {
|
|
26
|
+
function warn() {
|
|
27
|
+
console.warn(`Removing unexpected style on "${tagName}": ${prop}`);
|
|
28
|
+
}
|
|
29
|
+
if (svg_data_attributes.badAttributes.has(prop) || svg_data_attributes.tagSpecificNonPresentationalAttributes[tagName]?.has(prop)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (svg_data_attributes.tagSpecificAnimatedAttributes[tagName]?.has(prop) || svg_data_attributes.tagSpecificPresentationalAttributes[tagName]?.has(prop)) {
|
|
33
|
+
$element.attr(prop, value);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (svg_data_attributes.insideClipPathAttributes.has(prop)) {
|
|
37
|
+
if (item.parents.find((item2) => item2.tagName === "clipPath")) {
|
|
38
|
+
$element.attr(prop, value);
|
|
39
|
+
}
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (svg_data_attributes.badSoftwareAttributes.has(prop) || svg_data_attributes.badAttributePrefixes.has(prop.split("-").shift())) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (prop.slice(0, 1) === "-") {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
warn();
|
|
49
|
+
};
|
|
50
|
+
for (const prop in parsedStyle) {
|
|
51
|
+
checkRule(prop, parsedStyle[prop]);
|
|
52
|
+
}
|
|
53
|
+
const newStyleStr = Object.keys(newStyle).map((key) => key + ":" + newStyle[key] + ";").join("");
|
|
54
|
+
if (newStyleStr.length) {
|
|
55
|
+
$element.attr("style", newStyleStr);
|
|
56
|
+
} else {
|
|
57
|
+
$element.removeAttr("style");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
exports.cleanupInlineStyle = cleanupInlineStyle;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { SVG } from '../index.js';
|
|
2
|
+
import '@iconify/types';
|
|
3
|
+
import '@iconify/utils/lib/customisations';
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Expand inline style
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
declare function cleanupInlineStyle(svg: SVG): Promise<void>;
|
|
9
|
+
|
|
10
|
+
export { cleanupInlineStyle };
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
tagSpecificPresentationalAttributes
|
|
11
|
-
} from "../data/attributes.mjs";
|
|
12
|
-
import { parseSVG } from "../parse.mjs";
|
|
1
|
+
import { parseInlineStyle } from '../../css/parse.mjs';
|
|
2
|
+
import { badAttributes, tagSpecificNonPresentationalAttributes, tagSpecificAnimatedAttributes, tagSpecificPresentationalAttributes, insideClipPathAttributes, badSoftwareAttributes, badAttributePrefixes } from '../data/attributes.mjs';
|
|
3
|
+
import { parseSVG } from '../parse.mjs';
|
|
4
|
+
import '../../css/parser/tokens.mjs';
|
|
5
|
+
import '../../css/parser/error.mjs';
|
|
6
|
+
import '../../css/parser/strings.mjs';
|
|
7
|
+
import '../../css/parser/text.mjs';
|
|
8
|
+
import '../data/tags.mjs';
|
|
9
|
+
|
|
13
10
|
async function cleanupInlineStyle(svg) {
|
|
14
11
|
await parseSVG(svg, (item) => {
|
|
15
12
|
const $element = item.$element;
|
|
@@ -20,16 +17,15 @@ async function cleanupInlineStyle(svg) {
|
|
|
20
17
|
if (parsedStyle === null) {
|
|
21
18
|
$element.removeAttr("style");
|
|
22
19
|
} else {
|
|
23
|
-
const newStyle = Object.create(null);
|
|
20
|
+
const newStyle = /* @__PURE__ */ Object.create(null);
|
|
24
21
|
const checkRule = (prop, value) => {
|
|
25
|
-
var _a, _b, _c;
|
|
26
22
|
function warn() {
|
|
27
23
|
console.warn(`Removing unexpected style on "${tagName}": ${prop}`);
|
|
28
24
|
}
|
|
29
|
-
if (badAttributes.has(prop) ||
|
|
25
|
+
if (badAttributes.has(prop) || tagSpecificNonPresentationalAttributes[tagName]?.has(prop)) {
|
|
30
26
|
return;
|
|
31
27
|
}
|
|
32
|
-
if (
|
|
28
|
+
if (tagSpecificAnimatedAttributes[tagName]?.has(prop) || tagSpecificPresentationalAttributes[tagName]?.has(prop)) {
|
|
33
29
|
$element.attr(prop, value);
|
|
34
30
|
return;
|
|
35
31
|
}
|
|
@@ -60,6 +56,5 @@ async function cleanupInlineStyle(svg) {
|
|
|
60
56
|
}
|
|
61
57
|
});
|
|
62
58
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
};
|
|
59
|
+
|
|
60
|
+
export { cleanupInlineStyle };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const svg_data_attributes = require('../data/attributes.cjs');
|
|
6
|
+
const svg_data_tags = require('../data/tags.cjs');
|
|
7
|
+
|
|
8
|
+
async function cleanupSVGRoot(svg) {
|
|
9
|
+
const cheerio = svg.$svg;
|
|
10
|
+
const $root = svg.$svg(":root");
|
|
11
|
+
const root = $root.get(0);
|
|
12
|
+
const tagName = "svg";
|
|
13
|
+
if (root.tagName !== tagName) {
|
|
14
|
+
throw new Error(`Unexpected root tag <${root.tagName}>`);
|
|
15
|
+
}
|
|
16
|
+
const attribs = root.attribs;
|
|
17
|
+
const moveToChildren = {};
|
|
18
|
+
Object.keys(attribs).forEach((attr) => {
|
|
19
|
+
const value = attribs[attr];
|
|
20
|
+
if (svg_data_attributes.commonAttributes.has(attr) || svg_data_attributes.badAttributes.has(attr) || svg_data_attributes.junkSVGAttributes.has(attr) || svg_data_attributes.badSoftwareAttributes.has(attr) || svg_data_attributes.badAttributePrefixes.has(attr.split("-").shift()) || attr.split(":").length > 1) {
|
|
21
|
+
$root.removeAttr(attr);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
switch (attr) {
|
|
25
|
+
case "width":
|
|
26
|
+
case "height":
|
|
27
|
+
if (value.slice(-2) === "px") {
|
|
28
|
+
const num = value.replace("px", "");
|
|
29
|
+
if (parseFloat(num) + "" === num) {
|
|
30
|
+
$root.attr(attr, num);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (svg_data_attributes.tagSpecificNonPresentationalAttributes[tagName]?.has(attr)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (svg_data_attributes.tagSpecificPresentationalAttributes[tagName]?.has(attr) && svg_data_attributes.tagSpecificPresentationalAttributes.g.has(attr)) {
|
|
39
|
+
moveToChildren[attr] = value;
|
|
40
|
+
$root.removeAttr(attr);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (svg_data_attributes.stylingAttributes.has(attr)) {
|
|
44
|
+
switch (attr) {
|
|
45
|
+
case "style":
|
|
46
|
+
return;
|
|
47
|
+
case "class":
|
|
48
|
+
$root.removeAttr(attr);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
throw new Error(`Unexpected attribute "${attr}" on <${tagName}>`);
|
|
52
|
+
}
|
|
53
|
+
if (attr.slice(0, 2) === "on" || attr.slice(0, 5) === "aria-" || attr.slice(0, 6) === "xmlns:") {
|
|
54
|
+
$root.removeAttr(attr);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
console.warn(`Removing unexpected attribute on SVG: ${attr}`);
|
|
58
|
+
$root.removeAttr(attr);
|
|
59
|
+
});
|
|
60
|
+
if (Object.keys(moveToChildren).length) {
|
|
61
|
+
const $wrapper = cheerio("<g />");
|
|
62
|
+
for (const key in moveToChildren) {
|
|
63
|
+
$wrapper.attr(key, moveToChildren[key]);
|
|
64
|
+
}
|
|
65
|
+
$root.children().each((_index, child) => {
|
|
66
|
+
const $child = cheerio(child);
|
|
67
|
+
if (child.type !== "tag") {
|
|
68
|
+
$child.appendTo($wrapper);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const tagName2 = child.tagName;
|
|
72
|
+
if (tagName2 === "style" || svg_data_tags.reusableElementsWithPalette.has(tagName2) || svg_data_tags.maskTags.has(tagName2)) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
$child.appendTo($wrapper);
|
|
76
|
+
});
|
|
77
|
+
$wrapper.appendTo($root);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
exports.cleanupSVGRoot = cleanupSVGRoot;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { SVG } from '../index.js';
|
|
2
|
+
import '@iconify/types';
|
|
3
|
+
import '@iconify/utils/lib/customisations';
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Clean up SVG
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
declare function cleanupSVGRoot(svg: SVG): Promise<void>;
|
|
9
|
+
|
|
10
|
+
export { cleanupSVGRoot };
|
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
badAttributePrefixes,
|
|
5
|
-
badSoftwareAttributes,
|
|
6
|
-
commonAttributes,
|
|
7
|
-
junkSVGAttributes,
|
|
8
|
-
stylingAttributes,
|
|
9
|
-
tagSpecificNonPresentationalAttributes,
|
|
10
|
-
tagSpecificPresentationalAttributes
|
|
11
|
-
} from "../data/attributes.mjs";
|
|
12
|
-
import { maskTags, reusableElementsWithPalette } from "../data/tags.mjs";
|
|
1
|
+
import { commonAttributes, badAttributes, junkSVGAttributes, badSoftwareAttributes, badAttributePrefixes, tagSpecificNonPresentationalAttributes, tagSpecificPresentationalAttributes, stylingAttributes } from '../data/attributes.mjs';
|
|
2
|
+
import { reusableElementsWithPalette, maskTags } from '../data/tags.mjs';
|
|
3
|
+
|
|
13
4
|
async function cleanupSVGRoot(svg) {
|
|
14
5
|
const cheerio = svg.$svg;
|
|
15
6
|
const $root = svg.$svg(":root");
|
|
@@ -21,7 +12,6 @@ async function cleanupSVGRoot(svg) {
|
|
|
21
12
|
const attribs = root.attribs;
|
|
22
13
|
const moveToChildren = {};
|
|
23
14
|
Object.keys(attribs).forEach((attr) => {
|
|
24
|
-
var _a, _b;
|
|
25
15
|
const value = attribs[attr];
|
|
26
16
|
if (commonAttributes.has(attr) || badAttributes.has(attr) || junkSVGAttributes.has(attr) || badSoftwareAttributes.has(attr) || badAttributePrefixes.has(attr.split("-").shift()) || attr.split(":").length > 1) {
|
|
27
17
|
$root.removeAttr(attr);
|
|
@@ -38,10 +28,10 @@ async function cleanupSVGRoot(svg) {
|
|
|
38
28
|
}
|
|
39
29
|
return;
|
|
40
30
|
}
|
|
41
|
-
if (
|
|
31
|
+
if (tagSpecificNonPresentationalAttributes[tagName]?.has(attr)) {
|
|
42
32
|
return;
|
|
43
33
|
}
|
|
44
|
-
if (
|
|
34
|
+
if (tagSpecificPresentationalAttributes[tagName]?.has(attr) && tagSpecificPresentationalAttributes.g.has(attr)) {
|
|
45
35
|
moveToChildren[attr] = value;
|
|
46
36
|
$root.removeAttr(attr);
|
|
47
37
|
return;
|
|
@@ -83,6 +73,5 @@ async function cleanupSVGRoot(svg) {
|
|
|
83
73
|
$wrapper.appendTo($root);
|
|
84
74
|
}
|
|
85
75
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
};
|
|
76
|
+
|
|
77
|
+
export { cleanupSVGRoot };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const svg_data_attributes = require('../data/attributes.cjs');
|
|
6
|
+
const svg_parseStyle = require('../parse-style.cjs');
|
|
7
|
+
const optimise_svgo = require('../../optimise/svgo.cjs');
|
|
8
|
+
require('../data/tags.cjs');
|
|
9
|
+
require('../../css/parse.cjs');
|
|
10
|
+
require('../../css/parser/tokens.cjs');
|
|
11
|
+
require('../../css/parser/error.cjs');
|
|
12
|
+
require('../../css/parser/strings.cjs');
|
|
13
|
+
require('../../css/parser/text.cjs');
|
|
14
|
+
require('../../css/parser/export.cjs');
|
|
15
|
+
require('../../css/parser/tree.cjs');
|
|
16
|
+
require('../parse.cjs');
|
|
17
|
+
require('svgo');
|
|
18
|
+
|
|
19
|
+
async function convertStyleToAttrs(svg) {
|
|
20
|
+
let hasStyle = false;
|
|
21
|
+
await svg_parseStyle.parseSVGStyle(svg, (item) => {
|
|
22
|
+
const prop = item.prop;
|
|
23
|
+
if (svg_data_attributes.badAttributes.has(prop) || svg_data_attributes.badSoftwareAttributes.has(prop) || svg_data_attributes.badAttributePrefixes.has(prop.split("-").shift())) {
|
|
24
|
+
return void 0;
|
|
25
|
+
}
|
|
26
|
+
hasStyle = true;
|
|
27
|
+
return item.value;
|
|
28
|
+
});
|
|
29
|
+
if (!hasStyle) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
await optimise_svgo.runSVGO(svg, {
|
|
33
|
+
plugins: ["convertStyleToAttrs", "inlineStyles"],
|
|
34
|
+
multipass: true
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
exports.convertStyleToAttrs = convertStyleToAttrs;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { SVG } from '../index.js';
|
|
2
|
+
import '@iconify/types';
|
|
3
|
+
import '@iconify/utils/lib/customisations';
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Expand inline style
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
declare function convertStyleToAttrs(svg: SVG): Promise<void>;
|
|
9
|
+
|
|
10
|
+
export { convertStyleToAttrs };
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
import
|
|
1
|
+
import { badAttributes, badSoftwareAttributes, badAttributePrefixes } from '../data/attributes.mjs';
|
|
2
|
+
import { parseSVGStyle } from '../parse-style.mjs';
|
|
3
|
+
import { runSVGO } from '../../optimise/svgo.mjs';
|
|
4
|
+
import '../data/tags.mjs';
|
|
5
|
+
import '../../css/parse.mjs';
|
|
6
|
+
import '../../css/parser/tokens.mjs';
|
|
7
|
+
import '../../css/parser/error.mjs';
|
|
8
|
+
import '../../css/parser/strings.mjs';
|
|
9
|
+
import '../../css/parser/text.mjs';
|
|
10
|
+
import '../../css/parser/export.mjs';
|
|
11
|
+
import '../../css/parser/tree.mjs';
|
|
12
|
+
import '../parse.mjs';
|
|
13
|
+
import 'svgo';
|
|
14
|
+
|
|
9
15
|
async function convertStyleToAttrs(svg) {
|
|
10
16
|
let hasStyle = false;
|
|
11
17
|
await parseSVGStyle(svg, (item) => {
|
|
@@ -24,6 +30,5 @@ async function convertStyleToAttrs(svg) {
|
|
|
24
30
|
multipass: true
|
|
25
31
|
});
|
|
26
32
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
33
|
+
|
|
34
|
+
export { convertStyleToAttrs };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const svg_cleanup_attribs = require('./cleanup/attribs.cjs');
|
|
6
|
+
const svg_cleanup_badTags = require('./cleanup/bad-tags.cjs');
|
|
7
|
+
const svg_cleanup_inlineStyle = require('./cleanup/inline-style.cjs');
|
|
8
|
+
const svg_cleanup_rootSvg = require('./cleanup/root-svg.cjs');
|
|
9
|
+
const svg_cleanup_svgoStyle = require('./cleanup/svgo-style.cjs');
|
|
10
|
+
require('./data/attributes.cjs');
|
|
11
|
+
require('./data/tags.cjs');
|
|
12
|
+
require('./parse.cjs');
|
|
13
|
+
require('../css/parse.cjs');
|
|
14
|
+
require('../css/parser/tokens.cjs');
|
|
15
|
+
require('../css/parser/error.cjs');
|
|
16
|
+
require('../css/parser/strings.cjs');
|
|
17
|
+
require('../css/parser/text.cjs');
|
|
18
|
+
require('./parse-style.cjs');
|
|
19
|
+
require('../css/parser/export.cjs');
|
|
20
|
+
require('../css/parser/tree.cjs');
|
|
21
|
+
require('../optimise/svgo.cjs');
|
|
22
|
+
require('svgo');
|
|
23
|
+
|
|
24
|
+
async function cleanupSVG(svg) {
|
|
25
|
+
await svg_cleanup_inlineStyle.cleanupInlineStyle(svg);
|
|
26
|
+
await svg_cleanup_svgoStyle.convertStyleToAttrs(svg);
|
|
27
|
+
await svg_cleanup_rootSvg.cleanupSVGRoot(svg);
|
|
28
|
+
await svg_cleanup_badTags.checkBadTags(svg);
|
|
29
|
+
await svg_cleanup_attribs.removeBadAttributes(svg);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
exports.cleanupSVG = cleanupSVG;
|
package/lib/svg/cleanup.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { SVG } from './index.js';
|
|
2
|
+
import '@iconify/types';
|
|
3
|
+
import '@iconify/utils/lib/customisations';
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Clean up SVG before parsing/optimising it
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
declare function cleanupSVG(svg: SVG): Promise<void>;
|
|
9
|
+
|
|
10
|
+
export { cleanupSVG };
|
package/lib/svg/cleanup.mjs
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
1
|
+
import { removeBadAttributes } from './cleanup/attribs.mjs';
|
|
2
|
+
import { checkBadTags } from './cleanup/bad-tags.mjs';
|
|
3
|
+
import { cleanupInlineStyle } from './cleanup/inline-style.mjs';
|
|
4
|
+
import { cleanupSVGRoot } from './cleanup/root-svg.mjs';
|
|
5
|
+
import { convertStyleToAttrs } from './cleanup/svgo-style.mjs';
|
|
6
|
+
import './data/attributes.mjs';
|
|
7
|
+
import './data/tags.mjs';
|
|
8
|
+
import './parse.mjs';
|
|
9
|
+
import '../css/parse.mjs';
|
|
10
|
+
import '../css/parser/tokens.mjs';
|
|
11
|
+
import '../css/parser/error.mjs';
|
|
12
|
+
import '../css/parser/strings.mjs';
|
|
13
|
+
import '../css/parser/text.mjs';
|
|
14
|
+
import './parse-style.mjs';
|
|
15
|
+
import '../css/parser/export.mjs';
|
|
16
|
+
import '../css/parser/tree.mjs';
|
|
17
|
+
import '../optimise/svgo.mjs';
|
|
18
|
+
import 'svgo';
|
|
19
|
+
|
|
7
20
|
async function cleanupSVG(svg) {
|
|
8
21
|
await cleanupInlineStyle(svg);
|
|
9
22
|
await convertStyleToAttrs(svg);
|
|
@@ -11,6 +24,5 @@ async function cleanupSVG(svg) {
|
|
|
11
24
|
await checkBadTags(svg);
|
|
12
25
|
await removeBadAttributes(svg);
|
|
13
26
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
27
|
+
|
|
28
|
+
export { cleanupSVG };
|