@iconify/tools 2.1.0-beta.7 → 2.1.1
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.d.ts +2 -0
- package/lib/colors/detect.cjs +68 -0
- package/lib/colors/detect.d.ts +15 -0
- package/lib/colors/detect.mjs +64 -0
- package/lib/colors/parse.cjs +31 -7
- package/lib/colors/parse.d.ts +1 -1
- package/lib/colors/parse.mjs +31 -7
- package/lib/colors/validate.cjs +9 -3
- package/lib/colors/validate.d.ts +1 -1
- package/lib/colors/validate.mjs +9 -3
- package/lib/css/parser/error.cjs +1 -1
- package/lib/css/parser/error.mjs +1 -1
- package/lib/css/parser/strings.cjs +10 -2
- package/lib/css/parser/strings.mjs +10 -2
- package/lib/css/parser/tokens.cjs +133 -109
- package/lib/css/parser/tokens.mjs +133 -109
- package/lib/download/api/cache.cjs +28 -21
- package/lib/download/api/cache.mjs +28 -21
- package/lib/download/git/branch.cjs +1 -1
- package/lib/download/git/branch.mjs +1 -1
- package/lib/download/git/hash.cjs +1 -1
- package/lib/download/git/hash.mjs +1 -1
- package/lib/download/git/index.cjs +7 -4
- package/lib/download/git/index.mjs +7 -4
- package/lib/download/git/reset.cjs +1 -2
- package/lib/download/git/reset.mjs +1 -2
- package/lib/download/github/index.cjs +10 -7
- package/lib/download/github/index.mjs +10 -7
- package/lib/download/gitlab/hash.cjs +3 -1
- package/lib/download/gitlab/hash.mjs +3 -1
- package/lib/download/gitlab/index.cjs +9 -6
- package/lib/download/gitlab/index.mjs +9 -6
- package/lib/download/index.cjs +4 -3
- package/lib/download/index.mjs +4 -3
- package/lib/download/npm/index.cjs +12 -8
- package/lib/download/npm/index.mjs +12 -8
- package/lib/download/npm/version.cjs +4 -2
- package/lib/download/npm/version.mjs +4 -2
- package/lib/export/directory.d.ts +1 -1
- package/lib/export/helpers/types-version.cjs +3 -1
- package/lib/export/helpers/types-version.mjs +3 -1
- package/lib/export/icon-package.d.ts +1 -1
- package/lib/export/json-package.cjs +13 -3
- package/lib/export/json-package.d.ts +1 -1
- package/lib/export/json-package.mjs +13 -3
- package/lib/icon-set/index.cjs +20 -8
- package/lib/icon-set/index.d.ts +1 -1
- package/lib/icon-set/index.mjs +20 -8
- package/lib/icon-set/match.d.ts +1 -1
- package/lib/icon-set/merge.d.ts +1 -1
- package/lib/icon-set/modified.d.ts +1 -1
- package/lib/icon-set/props.d.ts +1 -1
- package/lib/icon-set/tags.cjs +97 -0
- package/lib/icon-set/tags.d.ts +22 -0
- package/lib/icon-set/tags.mjs +91 -0
- package/lib/icon-set/types.d.ts +1 -1
- package/lib/import/directory.cjs +4 -1
- package/lib/import/directory.d.ts +1 -1
- package/lib/import/directory.mjs +4 -1
- package/lib/import/figma/index.cjs +5 -2
- package/lib/import/figma/index.d.ts +1 -1
- package/lib/import/figma/index.mjs +5 -2
- package/lib/import/figma/nodes.cjs +6 -2
- package/lib/import/figma/nodes.d.ts +2 -2
- package/lib/import/figma/nodes.mjs +6 -2
- package/lib/import/figma/query.cjs +29 -15
- package/lib/import/figma/query.d.ts +1 -1
- package/lib/import/figma/query.mjs +29 -15
- package/lib/import/figma/types/nodes.d.ts +1 -1
- package/lib/import/figma/types/options.d.ts +1 -1
- package/lib/import/figma/types/result.d.ts +1 -1
- package/lib/index.cjs +6 -3
- package/lib/index.d.ts +3 -1
- package/lib/index.mjs +4 -3
- package/lib/misc/compare-dirs.cjs +3 -1
- package/lib/misc/compare-dirs.mjs +3 -1
- package/lib/misc/exec.cjs +7 -8
- package/lib/misc/exec.mjs +7 -8
- package/lib/misc/keyword.cjs +4 -1
- package/lib/misc/keyword.mjs +4 -1
- package/lib/misc/scan.cjs +3 -1
- package/lib/misc/scan.mjs +3 -1
- package/lib/optimise/flags.cjs +9 -3
- package/lib/optimise/flags.d.ts +1 -1
- package/lib/optimise/flags.mjs +9 -3
- package/lib/optimise/global-style.cjs +10 -3
- package/lib/optimise/global-style.d.ts +1 -1
- package/lib/optimise/global-style.mjs +10 -3
- package/lib/optimise/scale.d.ts +1 -1
- package/lib/optimise/svgo.d.ts +1 -1
- package/lib/svg/analyse.cjs +20 -6
- package/lib/svg/analyse.d.ts +1 -1
- package/lib/svg/analyse.mjs +20 -6
- package/lib/svg/cleanup/attribs.d.ts +1 -1
- package/lib/svg/cleanup/bad-tags.cjs +7 -2
- package/lib/svg/cleanup/bad-tags.d.ts +1 -1
- package/lib/svg/cleanup/bad-tags.mjs +7 -2
- package/lib/svg/cleanup/inline-style.cjs +12 -4
- package/lib/svg/cleanup/inline-style.d.ts +1 -1
- package/lib/svg/cleanup/inline-style.mjs +12 -4
- package/lib/svg/cleanup/root-style.d.ts +1 -1
- package/lib/svg/cleanup/root-svg.d.ts +1 -1
- package/lib/svg/cleanup/svgo-style.d.ts +1 -1
- package/lib/svg/cleanup.d.ts +1 -1
- package/lib/svg/data/attributes.cjs +0 -1
- package/lib/svg/data/attributes.mjs +0 -1
- package/lib/svg/index.cjs +12 -3
- package/lib/svg/index.d.ts +2 -2
- package/lib/svg/index.mjs +12 -3
- package/lib/svg/parse-style.cjs +13 -8
- package/lib/svg/parse-style.d.ts +1 -1
- package/lib/svg/parse-style.mjs +13 -8
- package/lib/svg/parse.d.ts +1 -1
- package/package.json +24 -9
- package/lib/types-f0980297.d.ts +0 -258
package/lib/index.cjs
CHANGED
|
@@ -15,6 +15,7 @@ const svg_cleanup_rootSvg = require('./svg/cleanup/root-svg.cjs');
|
|
|
15
15
|
const svg_cleanup_svgoStyle = require('./svg/cleanup/svgo-style.cjs');
|
|
16
16
|
const iconSet_index = require('./icon-set/index.cjs');
|
|
17
17
|
const iconSet_merge = require('./icon-set/merge.cjs');
|
|
18
|
+
const iconSet_tags = require('./icon-set/tags.cjs');
|
|
18
19
|
const import_figma_index = require('./import/figma/index.cjs');
|
|
19
20
|
const import_directory = require('./import/directory.cjs');
|
|
20
21
|
const download_git_index = require('./download/git/index.cjs');
|
|
@@ -31,6 +32,7 @@ const download_index = require('./download/index.cjs');
|
|
|
31
32
|
const download_api_download = require('./download/api/download.cjs');
|
|
32
33
|
const colors_parse = require('./colors/parse.cjs');
|
|
33
34
|
const colors_validate = require('./colors/validate.cjs');
|
|
35
|
+
const colors_detect = require('./colors/detect.cjs');
|
|
34
36
|
const optimise_svgo = require('./optimise/svgo.cjs');
|
|
35
37
|
const optimise_flags = require('./optimise/flags.cjs');
|
|
36
38
|
const optimise_scale = require('./optimise/scale.cjs');
|
|
@@ -69,6 +71,8 @@ require('./icon-set/props.cjs');
|
|
|
69
71
|
require('@iconify/utils/lib/misc/objects');
|
|
70
72
|
require('./icon-set/match.cjs');
|
|
71
73
|
require('./icon-set/modified.cjs');
|
|
74
|
+
require('@iconify/utils/lib/colors');
|
|
75
|
+
require('./colors/attribs.cjs');
|
|
72
76
|
require('./import/figma/nodes.cjs');
|
|
73
77
|
require('./import/figma/query.cjs');
|
|
74
78
|
require('./download/api/cache.cjs');
|
|
@@ -76,15 +80,12 @@ require('fs');
|
|
|
76
80
|
require('crypto');
|
|
77
81
|
require('node-fetch');
|
|
78
82
|
require('pathe');
|
|
79
|
-
require('path');
|
|
80
83
|
require('child_process');
|
|
81
84
|
require('util');
|
|
82
85
|
require('stream');
|
|
83
86
|
require('extract-zip');
|
|
84
87
|
require('tar');
|
|
85
|
-
require('@iconify/utils/lib/colors');
|
|
86
88
|
require('./download/gitlab/types.cjs');
|
|
87
|
-
require('./colors/attribs.cjs');
|
|
88
89
|
require('./export/helpers/custom-files.cjs');
|
|
89
90
|
|
|
90
91
|
|
|
@@ -103,6 +104,7 @@ exports.convertStyleToAttrs = svg_cleanup_svgoStyle.convertStyleToAttrs;
|
|
|
103
104
|
exports.IconSet = iconSet_index.IconSet;
|
|
104
105
|
exports.blankIconSet = iconSet_index.blankIconSet;
|
|
105
106
|
exports.mergeIconSets = iconSet_merge.mergeIconSets;
|
|
107
|
+
exports.addTagsToIconSet = iconSet_tags.addTagsToIconSet;
|
|
106
108
|
exports.importFromFigma = import_figma_index.importFromFigma;
|
|
107
109
|
exports.importDirectory = import_directory.importDirectory;
|
|
108
110
|
exports.downloadGitRepo = download_git_index.downloadGitRepo;
|
|
@@ -121,6 +123,7 @@ exports.downloadFile = download_api_download.downloadFile;
|
|
|
121
123
|
exports.isEmptyColor = colors_parse.isEmptyColor;
|
|
122
124
|
exports.parseColors = colors_parse.parseColors;
|
|
123
125
|
exports.validateColors = colors_validate.validateColors;
|
|
126
|
+
exports.detectIconSetPalette = colors_detect.detectIconSetPalette;
|
|
124
127
|
exports.runSVGO = optimise_svgo.runSVGO;
|
|
125
128
|
exports.deOptimisePaths = optimise_flags.deOptimisePaths;
|
|
126
129
|
exports.scaleSVG = optimise_scale.scaleSVG;
|
package/lib/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export { cleanupSVGRoot } from './svg/cleanup/root-svg.js';
|
|
|
11
11
|
export { convertStyleToAttrs } from './svg/cleanup/svgo-style.js';
|
|
12
12
|
export { IconSet, blankIconSet } from './icon-set/index.js';
|
|
13
13
|
export { mergeIconSets } from './icon-set/merge.js';
|
|
14
|
+
export { addTagsToIconSet } from './icon-set/tags.js';
|
|
14
15
|
export { importFromFigma } from './import/figma/index.js';
|
|
15
16
|
export { importDirectory } from './import/directory.js';
|
|
16
17
|
export { downloadGitRepo } from './download/git/index.js';
|
|
@@ -27,6 +28,7 @@ export { downloadPackage } from './download/index.js';
|
|
|
27
28
|
export { downloadFile } from './download/api/download.js';
|
|
28
29
|
export { isEmptyColor, parseColors } from './colors/parse.js';
|
|
29
30
|
export { validateColors } from './colors/validate.js';
|
|
31
|
+
export { detectIconSetPalette } from './colors/detect.js';
|
|
30
32
|
export { runSVGO } from './optimise/svgo.js';
|
|
31
33
|
export { deOptimisePaths } from './optimise/flags.js';
|
|
32
34
|
export { scaleSVG } from './optimise/scale.js';
|
|
@@ -44,7 +46,7 @@ export { execAsync } from './misc/exec.js';
|
|
|
44
46
|
export { cleanupIconKeyword } from './misc/keyword.js';
|
|
45
47
|
export { bumpVersion } from './misc/bump-version.js';
|
|
46
48
|
export { sendAPIQuery } from './download/api/index.js';
|
|
47
|
-
import '
|
|
49
|
+
import '@iconify/types';
|
|
48
50
|
import '@iconify/utils/lib/customisations/defaults';
|
|
49
51
|
import './misc/cheerio.js';
|
|
50
52
|
import './css/parser/types.js';
|
package/lib/index.mjs
CHANGED
|
@@ -11,6 +11,7 @@ export { cleanupSVGRoot } from './svg/cleanup/root-svg.mjs';
|
|
|
11
11
|
export { convertStyleToAttrs } from './svg/cleanup/svgo-style.mjs';
|
|
12
12
|
export { IconSet, blankIconSet } from './icon-set/index.mjs';
|
|
13
13
|
export { mergeIconSets } from './icon-set/merge.mjs';
|
|
14
|
+
export { addTagsToIconSet } from './icon-set/tags.mjs';
|
|
14
15
|
export { importFromFigma } from './import/figma/index.mjs';
|
|
15
16
|
export { importDirectory } from './import/directory.mjs';
|
|
16
17
|
export { downloadGitRepo } from './download/git/index.mjs';
|
|
@@ -27,6 +28,7 @@ export { downloadPackage } from './download/index.mjs';
|
|
|
27
28
|
export { downloadFile } from './download/api/download.mjs';
|
|
28
29
|
export { isEmptyColor, parseColors } from './colors/parse.mjs';
|
|
29
30
|
export { validateColors } from './colors/validate.mjs';
|
|
31
|
+
export { detectIconSetPalette } from './colors/detect.mjs';
|
|
30
32
|
export { runSVGO } from './optimise/svgo.mjs';
|
|
31
33
|
export { deOptimisePaths } from './optimise/flags.mjs';
|
|
32
34
|
export { scaleSVG } from './optimise/scale.mjs';
|
|
@@ -65,6 +67,8 @@ import './icon-set/props.mjs';
|
|
|
65
67
|
import '@iconify/utils/lib/misc/objects';
|
|
66
68
|
import './icon-set/match.mjs';
|
|
67
69
|
import './icon-set/modified.mjs';
|
|
70
|
+
import '@iconify/utils/lib/colors';
|
|
71
|
+
import './colors/attribs.mjs';
|
|
68
72
|
import './import/figma/nodes.mjs';
|
|
69
73
|
import './import/figma/query.mjs';
|
|
70
74
|
import './download/api/cache.mjs';
|
|
@@ -72,13 +76,10 @@ import 'fs';
|
|
|
72
76
|
import 'crypto';
|
|
73
77
|
import 'node-fetch';
|
|
74
78
|
import 'pathe';
|
|
75
|
-
import 'path';
|
|
76
79
|
import 'child_process';
|
|
77
80
|
import 'util';
|
|
78
81
|
import 'stream';
|
|
79
82
|
import 'extract-zip';
|
|
80
83
|
import 'tar';
|
|
81
|
-
import '@iconify/utils/lib/colors';
|
|
82
84
|
import './download/gitlab/types.mjs';
|
|
83
|
-
import './colors/attribs.mjs';
|
|
84
85
|
import './export/helpers/custom-files.mjs';
|
|
@@ -32,7 +32,9 @@ async function compareDirectories(dir1, dir2, options) {
|
|
|
32
32
|
options = options || {};
|
|
33
33
|
const ignoreNewLine = options.ignoreNewLine !== false;
|
|
34
34
|
const ignoreVersions = options.ignoreVersions !== false;
|
|
35
|
-
const textExtensions = new Set(
|
|
35
|
+
const textExtensions = new Set(
|
|
36
|
+
(options.textExtensions || []).concat(textFileExtensions)
|
|
37
|
+
);
|
|
36
38
|
for (let i = 0; i < files1.length; i++) {
|
|
37
39
|
const file = files1[i];
|
|
38
40
|
if (files2.indexOf(file) === -1) {
|
|
@@ -28,7 +28,9 @@ async function compareDirectories(dir1, dir2, options) {
|
|
|
28
28
|
options = options || {};
|
|
29
29
|
const ignoreNewLine = options.ignoreNewLine !== false;
|
|
30
30
|
const ignoreVersions = options.ignoreVersions !== false;
|
|
31
|
-
const textExtensions = new Set(
|
|
31
|
+
const textExtensions = new Set(
|
|
32
|
+
(options.textExtensions || []).concat(textFileExtensions)
|
|
33
|
+
);
|
|
32
34
|
for (let i = 0; i < files1.length; i++) {
|
|
33
35
|
const file = files1[i];
|
|
34
36
|
if (files2.indexOf(file) === -1) {
|
package/lib/misc/exec.cjs
CHANGED
|
@@ -2,19 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const pathe = require('pathe');
|
|
6
6
|
const child_process = require('child_process');
|
|
7
7
|
|
|
8
8
|
function execAsync(cmd, options) {
|
|
9
9
|
return new Promise((fulfill, reject) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
fullOptions.cwd = path.resolve(fullOptions.cwd);
|
|
10
|
+
if (typeof options?.cwd === "string") {
|
|
11
|
+
options = {
|
|
12
|
+
...options,
|
|
13
|
+
cwd: pathe.resolve(options.cwd)
|
|
14
|
+
};
|
|
16
15
|
}
|
|
17
|
-
child_process.exec(cmd,
|
|
16
|
+
child_process.exec(cmd, options, (error, stdout, stderr) => {
|
|
18
17
|
if (error) {
|
|
19
18
|
reject(error);
|
|
20
19
|
} else {
|
package/lib/misc/exec.mjs
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { resolve } from '
|
|
1
|
+
import { resolve } from 'pathe';
|
|
2
2
|
import { exec } from 'child_process';
|
|
3
3
|
|
|
4
4
|
function execAsync(cmd, options) {
|
|
5
5
|
return new Promise((fulfill, reject) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
fullOptions.cwd = resolve(fullOptions.cwd);
|
|
6
|
+
if (typeof options?.cwd === "string") {
|
|
7
|
+
options = {
|
|
8
|
+
...options,
|
|
9
|
+
cwd: resolve(options.cwd)
|
|
10
|
+
};
|
|
12
11
|
}
|
|
13
|
-
exec(cmd,
|
|
12
|
+
exec(cmd, options, (error, stdout, stderr) => {
|
|
14
13
|
if (error) {
|
|
15
14
|
reject(error);
|
|
16
15
|
} else {
|
package/lib/misc/keyword.cjs
CHANGED
|
@@ -4,7 +4,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
function cleanupIconKeyword(keyword, convertCamelCase = false) {
|
|
6
6
|
if (convertCamelCase) {
|
|
7
|
-
keyword = keyword.replace(
|
|
7
|
+
keyword = keyword.replace(
|
|
8
|
+
/[A-Z]+/g,
|
|
9
|
+
(chars) => "_" + chars.toLowerCase()
|
|
10
|
+
);
|
|
8
11
|
}
|
|
9
12
|
keyword = keyword.toLowerCase().trim().replace(/[\s_.:]/g, "-").replace(/[^a-z0-9-]/g, "").replace(/[-]+/g, "-");
|
|
10
13
|
if (keyword.slice(0, 1) === "-") {
|
package/lib/misc/keyword.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
function cleanupIconKeyword(keyword, convertCamelCase = false) {
|
|
2
2
|
if (convertCamelCase) {
|
|
3
|
-
keyword = keyword.replace(
|
|
3
|
+
keyword = keyword.replace(
|
|
4
|
+
/[A-Z]+/g,
|
|
5
|
+
(chars) => "_" + chars.toLowerCase()
|
|
6
|
+
);
|
|
4
7
|
}
|
|
5
8
|
keyword = keyword.toLowerCase().trim().replace(/[\s_.:]/g, "-").replace(/[^a-z0-9-]/g, "").replace(/[-]+/g, "-");
|
|
6
9
|
if (keyword.slice(0, 1) === "-") {
|
package/lib/misc/scan.cjs
CHANGED
|
@@ -41,7 +41,9 @@ async function scanDirectory(path, callback, subdirs = true) {
|
|
|
41
41
|
} else {
|
|
42
42
|
callbackResult = true;
|
|
43
43
|
}
|
|
44
|
-
results.push(
|
|
44
|
+
results.push(
|
|
45
|
+
callbackResult === true ? subdir + filename : callbackResult
|
|
46
|
+
);
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
await scan("");
|
package/lib/misc/scan.mjs
CHANGED
|
@@ -37,7 +37,9 @@ async function scanDirectory(path, callback, subdirs = true) {
|
|
|
37
37
|
} else {
|
|
38
38
|
callbackResult = true;
|
|
39
39
|
}
|
|
40
|
-
results.push(
|
|
40
|
+
results.push(
|
|
41
|
+
callbackResult === true ? subdir + filename : callbackResult
|
|
42
|
+
);
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
45
|
await scan("");
|
package/lib/optimise/flags.cjs
CHANGED
|
@@ -66,7 +66,9 @@ function cleanPath(path) {
|
|
|
66
66
|
}
|
|
67
67
|
if (currentCommandType === ARC) {
|
|
68
68
|
if (currentArgs.length < 2 && value <= 0) {
|
|
69
|
-
throw new Error(
|
|
69
|
+
throw new Error(
|
|
70
|
+
`Expected positive number, got "${value}" at ${i}`
|
|
71
|
+
);
|
|
70
72
|
}
|
|
71
73
|
while (true) {
|
|
72
74
|
if (currentArgs.length < 3 || currentArgs.length > 4) {
|
|
@@ -80,14 +82,18 @@ function cleanPath(path) {
|
|
|
80
82
|
const newValue = Number(newNumber);
|
|
81
83
|
if (slice === "0" || slice === "1") {
|
|
82
84
|
if (isNaN(newValue)) {
|
|
83
|
-
throw new Error(
|
|
85
|
+
throw new Error(
|
|
86
|
+
`Invalid number "${currentNumber}" at ${i}`
|
|
87
|
+
);
|
|
84
88
|
}
|
|
85
89
|
currentArgs.push(slice);
|
|
86
90
|
currentNumber = newNumber;
|
|
87
91
|
value = newValue;
|
|
88
92
|
continue;
|
|
89
93
|
}
|
|
90
|
-
throw new Error(
|
|
94
|
+
throw new Error(
|
|
95
|
+
`Expected a flag, got "${currentNumber}" at ${i}`
|
|
96
|
+
);
|
|
91
97
|
}
|
|
92
98
|
}
|
|
93
99
|
currentArgs.push(currentNumber);
|
package/lib/optimise/flags.d.ts
CHANGED
package/lib/optimise/flags.mjs
CHANGED
|
@@ -62,7 +62,9 @@ function cleanPath(path) {
|
|
|
62
62
|
}
|
|
63
63
|
if (currentCommandType === ARC) {
|
|
64
64
|
if (currentArgs.length < 2 && value <= 0) {
|
|
65
|
-
throw new Error(
|
|
65
|
+
throw new Error(
|
|
66
|
+
`Expected positive number, got "${value}" at ${i}`
|
|
67
|
+
);
|
|
66
68
|
}
|
|
67
69
|
while (true) {
|
|
68
70
|
if (currentArgs.length < 3 || currentArgs.length > 4) {
|
|
@@ -76,14 +78,18 @@ function cleanPath(path) {
|
|
|
76
78
|
const newValue = Number(newNumber);
|
|
77
79
|
if (slice === "0" || slice === "1") {
|
|
78
80
|
if (isNaN(newValue)) {
|
|
79
|
-
throw new Error(
|
|
81
|
+
throw new Error(
|
|
82
|
+
`Invalid number "${currentNumber}" at ${i}`
|
|
83
|
+
);
|
|
80
84
|
}
|
|
81
85
|
currentArgs.push(slice);
|
|
82
86
|
currentNumber = newNumber;
|
|
83
87
|
value = newValue;
|
|
84
88
|
continue;
|
|
85
89
|
}
|
|
86
|
-
throw new Error(
|
|
90
|
+
throw new Error(
|
|
91
|
+
`Expected a flag, got "${currentNumber}" at ${i}`
|
|
92
|
+
);
|
|
87
93
|
}
|
|
88
94
|
}
|
|
89
95
|
currentArgs.push(currentNumber);
|
|
@@ -108,7 +108,9 @@ async function cleanupGlobalStyle(svg) {
|
|
|
108
108
|
if (!isMatch(tagName, $element)) {
|
|
109
109
|
return;
|
|
110
110
|
}
|
|
111
|
-
const addedAttributes = new Set(
|
|
111
|
+
const addedAttributes = new Set(
|
|
112
|
+
$element.attr(tempDataAttrbiute)?.split(/\s+/)
|
|
113
|
+
);
|
|
112
114
|
const prop = styleItem.prop;
|
|
113
115
|
if ($element.attr(prop) !== void 0) {
|
|
114
116
|
if (addedAttributes.has(prop)) {
|
|
@@ -117,7 +119,10 @@ async function cleanupGlobalStyle(svg) {
|
|
|
117
119
|
}
|
|
118
120
|
$element.attr(prop, styleItem.value);
|
|
119
121
|
addedAttributes.add(prop);
|
|
120
|
-
$element.attr(
|
|
122
|
+
$element.attr(
|
|
123
|
+
tempDataAttrbiute,
|
|
124
|
+
Array.from(addedAttributes).join(" ")
|
|
125
|
+
);
|
|
121
126
|
containsTempAttr = true;
|
|
122
127
|
});
|
|
123
128
|
const classMatches = matches.filter((item) => item.type === "class").map((item) => item.value);
|
|
@@ -131,7 +136,9 @@ async function cleanupGlobalStyle(svg) {
|
|
|
131
136
|
if (!classList) {
|
|
132
137
|
return;
|
|
133
138
|
}
|
|
134
|
-
const filtered = classList.filter(
|
|
139
|
+
const filtered = classList.filter(
|
|
140
|
+
(item) => classMatches.indexOf(item) === -1
|
|
141
|
+
);
|
|
135
142
|
if (!filtered.length) {
|
|
136
143
|
$element.removeAttr("class");
|
|
137
144
|
} else {
|
|
@@ -104,7 +104,9 @@ async function cleanupGlobalStyle(svg) {
|
|
|
104
104
|
if (!isMatch(tagName, $element)) {
|
|
105
105
|
return;
|
|
106
106
|
}
|
|
107
|
-
const addedAttributes = new Set(
|
|
107
|
+
const addedAttributes = new Set(
|
|
108
|
+
$element.attr(tempDataAttrbiute)?.split(/\s+/)
|
|
109
|
+
);
|
|
108
110
|
const prop = styleItem.prop;
|
|
109
111
|
if ($element.attr(prop) !== void 0) {
|
|
110
112
|
if (addedAttributes.has(prop)) {
|
|
@@ -113,7 +115,10 @@ async function cleanupGlobalStyle(svg) {
|
|
|
113
115
|
}
|
|
114
116
|
$element.attr(prop, styleItem.value);
|
|
115
117
|
addedAttributes.add(prop);
|
|
116
|
-
$element.attr(
|
|
118
|
+
$element.attr(
|
|
119
|
+
tempDataAttrbiute,
|
|
120
|
+
Array.from(addedAttributes).join(" ")
|
|
121
|
+
);
|
|
117
122
|
containsTempAttr = true;
|
|
118
123
|
});
|
|
119
124
|
const classMatches = matches.filter((item) => item.type === "class").map((item) => item.value);
|
|
@@ -127,7 +132,9 @@ async function cleanupGlobalStyle(svg) {
|
|
|
127
132
|
if (!classList) {
|
|
128
133
|
return;
|
|
129
134
|
}
|
|
130
|
-
const filtered = classList.filter(
|
|
135
|
+
const filtered = classList.filter(
|
|
136
|
+
(item) => classMatches.indexOf(item) === -1
|
|
137
|
+
);
|
|
131
138
|
if (!filtered.length) {
|
|
132
139
|
$element.removeAttr("class");
|
|
133
140
|
} else {
|
package/lib/optimise/scale.d.ts
CHANGED
package/lib/optimise/svgo.d.ts
CHANGED
package/lib/svg/analyse.cjs
CHANGED
|
@@ -45,7 +45,9 @@ async function analyseSVGStructure(svg, options = {}) {
|
|
|
45
45
|
const index2 = element._index;
|
|
46
46
|
const id = attribs["id"];
|
|
47
47
|
if (typeof id !== "string") {
|
|
48
|
-
const message = `Definition element ${svg_analyse_error.analyseTagError(
|
|
48
|
+
const message = `Definition element ${svg_analyse_error.analyseTagError(
|
|
49
|
+
element
|
|
50
|
+
)} does not have id`;
|
|
49
51
|
if (fixErrors) {
|
|
50
52
|
item.removeNode = true;
|
|
51
53
|
item.testChildren = false;
|
|
@@ -126,7 +128,11 @@ async function analyseSVGStructure(svg, options = {}) {
|
|
|
126
128
|
const parentReusableElement = parentElement._reusableElement;
|
|
127
129
|
if (parentReusableElement) {
|
|
128
130
|
if (element._reusableElement) {
|
|
129
|
-
throw new Error(
|
|
131
|
+
throw new Error(
|
|
132
|
+
`Reusable element ${svg_analyse_error.analyseTagError(
|
|
133
|
+
element
|
|
134
|
+
)} is inside another reusable element id="${parentReusableElement.id}"`
|
|
135
|
+
);
|
|
130
136
|
}
|
|
131
137
|
element._reusableElement = parentReusableElement;
|
|
132
138
|
}
|
|
@@ -154,7 +160,9 @@ async function analyseSVGStructure(svg, options = {}) {
|
|
|
154
160
|
const href = attribs["href"] || attribs["xlink:href"];
|
|
155
161
|
if (typeof href === "string") {
|
|
156
162
|
if (href.slice(0, 1) !== "#") {
|
|
157
|
-
throw new Error(
|
|
163
|
+
throw new Error(
|
|
164
|
+
`Invalid link in ${svg_analyse_error.analyseTagError(element)}`
|
|
165
|
+
);
|
|
158
166
|
}
|
|
159
167
|
const id = href.slice(1);
|
|
160
168
|
gotElementReference(item, id, false);
|
|
@@ -194,7 +202,9 @@ async function analyseSVGStructure(svg, options = {}) {
|
|
|
194
202
|
const parent = element.parent;
|
|
195
203
|
if (parent) {
|
|
196
204
|
if (parent._childElements) {
|
|
197
|
-
parent._childElements = parent._childElements.filter(
|
|
205
|
+
parent._childElements = parent._childElements.filter(
|
|
206
|
+
(num) => num !== index2
|
|
207
|
+
);
|
|
198
208
|
}
|
|
199
209
|
parent._belongsTo?.forEach((list) => {
|
|
200
210
|
list.indexes.delete(index2);
|
|
@@ -203,7 +213,9 @@ async function analyseSVGStructure(svg, options = {}) {
|
|
|
203
213
|
$element.remove();
|
|
204
214
|
}
|
|
205
215
|
if (element._linksTo) {
|
|
206
|
-
element._linksTo = element._linksTo.filter(
|
|
216
|
+
element._linksTo = element._linksTo.filter(
|
|
217
|
+
(item2) => item2.id !== id
|
|
218
|
+
);
|
|
207
219
|
}
|
|
208
220
|
if (!element.children.length) {
|
|
209
221
|
if (svg_data_tags.useTag.has(tagName)) {
|
|
@@ -229,7 +241,9 @@ async function analyseSVGStructure(svg, options = {}) {
|
|
|
229
241
|
return false;
|
|
230
242
|
});
|
|
231
243
|
function hasChildItem(tree2, child, canThrow) {
|
|
232
|
-
const item = tree2.children.find(
|
|
244
|
+
const item = tree2.children.find(
|
|
245
|
+
(item2) => item2.index === child.index && item2.usedAsMask === child.usedAsMask
|
|
246
|
+
);
|
|
233
247
|
if (item && canThrow) {
|
|
234
248
|
throw new Error("Recursion");
|
|
235
249
|
}
|
package/lib/svg/analyse.d.ts
CHANGED
package/lib/svg/analyse.mjs
CHANGED
|
@@ -41,7 +41,9 @@ async function analyseSVGStructure(svg, options = {}) {
|
|
|
41
41
|
const index2 = element._index;
|
|
42
42
|
const id = attribs["id"];
|
|
43
43
|
if (typeof id !== "string") {
|
|
44
|
-
const message = `Definition element ${analyseTagError(
|
|
44
|
+
const message = `Definition element ${analyseTagError(
|
|
45
|
+
element
|
|
46
|
+
)} does not have id`;
|
|
45
47
|
if (fixErrors) {
|
|
46
48
|
item.removeNode = true;
|
|
47
49
|
item.testChildren = false;
|
|
@@ -122,7 +124,11 @@ async function analyseSVGStructure(svg, options = {}) {
|
|
|
122
124
|
const parentReusableElement = parentElement._reusableElement;
|
|
123
125
|
if (parentReusableElement) {
|
|
124
126
|
if (element._reusableElement) {
|
|
125
|
-
throw new Error(
|
|
127
|
+
throw new Error(
|
|
128
|
+
`Reusable element ${analyseTagError(
|
|
129
|
+
element
|
|
130
|
+
)} is inside another reusable element id="${parentReusableElement.id}"`
|
|
131
|
+
);
|
|
126
132
|
}
|
|
127
133
|
element._reusableElement = parentReusableElement;
|
|
128
134
|
}
|
|
@@ -150,7 +156,9 @@ async function analyseSVGStructure(svg, options = {}) {
|
|
|
150
156
|
const href = attribs["href"] || attribs["xlink:href"];
|
|
151
157
|
if (typeof href === "string") {
|
|
152
158
|
if (href.slice(0, 1) !== "#") {
|
|
153
|
-
throw new Error(
|
|
159
|
+
throw new Error(
|
|
160
|
+
`Invalid link in ${analyseTagError(element)}`
|
|
161
|
+
);
|
|
154
162
|
}
|
|
155
163
|
const id = href.slice(1);
|
|
156
164
|
gotElementReference(item, id, false);
|
|
@@ -190,7 +198,9 @@ async function analyseSVGStructure(svg, options = {}) {
|
|
|
190
198
|
const parent = element.parent;
|
|
191
199
|
if (parent) {
|
|
192
200
|
if (parent._childElements) {
|
|
193
|
-
parent._childElements = parent._childElements.filter(
|
|
201
|
+
parent._childElements = parent._childElements.filter(
|
|
202
|
+
(num) => num !== index2
|
|
203
|
+
);
|
|
194
204
|
}
|
|
195
205
|
parent._belongsTo?.forEach((list) => {
|
|
196
206
|
list.indexes.delete(index2);
|
|
@@ -199,7 +209,9 @@ async function analyseSVGStructure(svg, options = {}) {
|
|
|
199
209
|
$element.remove();
|
|
200
210
|
}
|
|
201
211
|
if (element._linksTo) {
|
|
202
|
-
element._linksTo = element._linksTo.filter(
|
|
212
|
+
element._linksTo = element._linksTo.filter(
|
|
213
|
+
(item2) => item2.id !== id
|
|
214
|
+
);
|
|
203
215
|
}
|
|
204
216
|
if (!element.children.length) {
|
|
205
217
|
if (useTag.has(tagName)) {
|
|
@@ -225,7 +237,9 @@ async function analyseSVGStructure(svg, options = {}) {
|
|
|
225
237
|
return false;
|
|
226
238
|
});
|
|
227
239
|
function hasChildItem(tree2, child, canThrow) {
|
|
228
|
-
const item = tree2.children.find(
|
|
240
|
+
const item = tree2.children.find(
|
|
241
|
+
(item2) => item2.index === child.index && item2.usedAsMask === child.usedAsMask
|
|
242
|
+
);
|
|
229
243
|
if (item && canThrow) {
|
|
230
244
|
throw new Error("Recursion");
|
|
231
245
|
}
|
|
@@ -6,7 +6,10 @@ const svg_parse = require('../parse.cjs');
|
|
|
6
6
|
const svg_data_tags = require('../data/tags.cjs');
|
|
7
7
|
|
|
8
8
|
const requiredParentTags = /* @__PURE__ */ new Map();
|
|
9
|
-
requiredParentTags.set(
|
|
9
|
+
requiredParentTags.set(
|
|
10
|
+
/* @__PURE__ */ new Set(["feComponentTransfer"]),
|
|
11
|
+
svg_data_tags.feComponentTransferChildTag
|
|
12
|
+
);
|
|
10
13
|
requiredParentTags.set(/* @__PURE__ */ new Set(["feMerge"]), svg_data_tags.feMergeChildTags);
|
|
11
14
|
requiredParentTags.set(svg_data_tags.feLightningTags, svg_data_tags.feLightningChildTags);
|
|
12
15
|
requiredParentTags.set(svg_data_tags.filterTag, svg_data_tags.filterChildTags);
|
|
@@ -40,7 +43,9 @@ async function checkBadTags(svg) {
|
|
|
40
43
|
for (const [parents, children] of requiredParentTags) {
|
|
41
44
|
if (children.has(tagName)) {
|
|
42
45
|
if (!parents.has(parentTagName)) {
|
|
43
|
-
throw new Error(
|
|
46
|
+
throw new Error(
|
|
47
|
+
`Element <${tagName}> has wrong parent element`
|
|
48
|
+
);
|
|
44
49
|
}
|
|
45
50
|
return;
|
|
46
51
|
}
|
|
@@ -2,7 +2,10 @@ import { parseSVG } from '../parse.mjs';
|
|
|
2
2
|
import { feComponentTransferChildTag, feMergeChildTags, feLightningTags, feLightningChildTags, filterTag, filterChildTags, gradientTags, gradientChildTags, animateMotionChildTags, unsupportedTags, badTags, allValidTags } from '../data/tags.mjs';
|
|
3
3
|
|
|
4
4
|
const requiredParentTags = /* @__PURE__ */ new Map();
|
|
5
|
-
requiredParentTags.set(
|
|
5
|
+
requiredParentTags.set(
|
|
6
|
+
/* @__PURE__ */ new Set(["feComponentTransfer"]),
|
|
7
|
+
feComponentTransferChildTag
|
|
8
|
+
);
|
|
6
9
|
requiredParentTags.set(/* @__PURE__ */ new Set(["feMerge"]), feMergeChildTags);
|
|
7
10
|
requiredParentTags.set(feLightningTags, feLightningChildTags);
|
|
8
11
|
requiredParentTags.set(filterTag, filterChildTags);
|
|
@@ -36,7 +39,9 @@ async function checkBadTags(svg) {
|
|
|
36
39
|
for (const [parents, children] of requiredParentTags) {
|
|
37
40
|
if (children.has(tagName)) {
|
|
38
41
|
if (!parents.has(parentTagName)) {
|
|
39
|
-
throw new Error(
|
|
42
|
+
throw new Error(
|
|
43
|
+
`Element <${tagName}> has wrong parent element`
|
|
44
|
+
);
|
|
40
45
|
}
|
|
41
46
|
return;
|
|
42
47
|
}
|