@iconify/tools 2.0.14 → 2.0.15
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 +589 -0
- package/lib/icon-set/index.d.ts +9 -6
- package/lib/icon-set/index.mjs +40 -53
- 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 +137 -0
- package/lib/index.d.ts +65 -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 +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 -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
package/lib/misc/scan.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Stats } from 'fs';
|
|
2
|
+
|
|
3
3
|
/**
|
|
4
4
|
* Callback
|
|
5
5
|
*
|
|
@@ -17,10 +17,11 @@ declare type ScanDirectoryCallbackFalseResult = boolean | null | undefined;
|
|
|
17
17
|
declare type ScanDirectoryCallbackStringResult = ScanDirectoryCallbackFalseResult | string;
|
|
18
18
|
declare type ScanDirectoryCallbackAsString = (ext: string, file: string, subdir: string, path: string, stat: Stats) => ScanDirectoryCallbackStringResult | Promise<ScanDirectoryCallbackStringResult>;
|
|
19
19
|
declare type ScanDirectoryCallbackAsCustom<T> = (ext: string, file: string, subdir: string, path: string, stat: Stats) => T | ScanDirectoryCallbackFalseResult | Promise<T | ScanDirectoryCallbackFalseResult>;
|
|
20
|
-
|
|
20
|
+
declare type ScanDirectoryCallback = ScanDirectoryCallbackAsCustom<unknown> | ScanDirectoryCallbackAsString;
|
|
21
21
|
/**
|
|
22
22
|
* Find all files in directory
|
|
23
23
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
declare function scanDirectory(path: string, callback?: ScanDirectoryCallbackAsString, subdirs?: boolean): Promise<string[]>;
|
|
25
|
+
declare function scanDirectory<T>(path: string, callback: ScanDirectoryCallbackAsCustom<T>, subdirs?: boolean): Promise<T[]>;
|
|
26
|
+
|
|
27
|
+
export { ScanDirectoryCallback, scanDirectory };
|
package/lib/misc/scan.mjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { promises } from 'fs';
|
|
2
|
+
|
|
3
3
|
async function scanDirectory(path, callback, subdirs = true) {
|
|
4
4
|
const results = [];
|
|
5
5
|
if (path.length && path.slice(-1) !== "/") {
|
|
6
6
|
path += "/";
|
|
7
7
|
}
|
|
8
8
|
async function scan(subdir) {
|
|
9
|
-
const files = await
|
|
9
|
+
const files = await promises.readdir(path + subdir);
|
|
10
10
|
for (let i = 0; i < files.length; i++) {
|
|
11
11
|
const filename = files[i];
|
|
12
12
|
if (filename.slice(0, 1) === ".") {
|
|
13
13
|
continue;
|
|
14
14
|
}
|
|
15
|
-
const stat = await
|
|
15
|
+
const stat = await promises.stat(path + subdir + filename);
|
|
16
16
|
if (stat.isDirectory()) {
|
|
17
17
|
if (subdirs) {
|
|
18
18
|
await scan(subdir + filename + "/");
|
|
@@ -43,6 +43,5 @@ async function scanDirectory(path, callback, subdirs = true) {
|
|
|
43
43
|
await scan("");
|
|
44
44
|
return results;
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
};
|
|
46
|
+
|
|
47
|
+
export { scanDirectory };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
|
|
7
|
+
async function writeJSONFile(filename, data) {
|
|
8
|
+
return fs.promises.writeFile(filename, JSON.stringify(data, null, " ") + "\n");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
exports.writeJSONFile = writeJSONFile;
|
package/lib/misc/write-json.d.ts
CHANGED
package/lib/misc/write-json.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { promises } from 'fs';
|
|
2
|
+
|
|
3
3
|
async function writeJSONFile(filename, data) {
|
|
4
|
-
return
|
|
4
|
+
return promises.writeFile(filename, JSON.stringify(data, null, " ") + "\n");
|
|
5
5
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
6
|
+
|
|
7
|
+
export { writeJSONFile };
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const svg_parse = require('../svg/parse.cjs');
|
|
6
|
+
|
|
7
|
+
const CLOSE_PATH = 1;
|
|
8
|
+
const MOVE_TO = 2;
|
|
9
|
+
const HORIZ_LINE_TO = 4;
|
|
10
|
+
const VERT_LINE_TO = 8;
|
|
11
|
+
const LINE_TO = 16;
|
|
12
|
+
const CURVE_TO = 32;
|
|
13
|
+
const SMOOTH_CURVE_TO = 64;
|
|
14
|
+
const QUAD_TO = 128;
|
|
15
|
+
const SMOOTH_QUAD_TO = 256;
|
|
16
|
+
const ARC = 512;
|
|
17
|
+
const argCount = {
|
|
18
|
+
[MOVE_TO]: 2,
|
|
19
|
+
[LINE_TO]: 2,
|
|
20
|
+
[HORIZ_LINE_TO]: 1,
|
|
21
|
+
[VERT_LINE_TO]: 1,
|
|
22
|
+
[CLOSE_PATH]: 0,
|
|
23
|
+
[QUAD_TO]: 4,
|
|
24
|
+
[SMOOTH_QUAD_TO]: 2,
|
|
25
|
+
[CURVE_TO]: 6,
|
|
26
|
+
[SMOOTH_CURVE_TO]: 4,
|
|
27
|
+
[ARC]: 7
|
|
28
|
+
};
|
|
29
|
+
const isDigit = (num) => num >= 48 && num <= 57;
|
|
30
|
+
const isWhiteSpace = (num) => num === 32 || num === 9 || num === 13 || num === 10;
|
|
31
|
+
function cleanPath(path) {
|
|
32
|
+
const commands = [];
|
|
33
|
+
const length = path.length;
|
|
34
|
+
let currentNumber = "";
|
|
35
|
+
let currentNumberHasExp = false;
|
|
36
|
+
let currentNumberHasExpDigits = false;
|
|
37
|
+
let currentNumberHasDecimal = false;
|
|
38
|
+
let canParseCommandOrComma = true;
|
|
39
|
+
let currentCommand = null;
|
|
40
|
+
let currentCommandType = null;
|
|
41
|
+
let currentArgs = [];
|
|
42
|
+
let i = 0;
|
|
43
|
+
const finishCommand = () => {
|
|
44
|
+
if (currentCommand !== null) {
|
|
45
|
+
commands.push({
|
|
46
|
+
command: currentCommand,
|
|
47
|
+
params: currentArgs.slice(0)
|
|
48
|
+
});
|
|
49
|
+
currentArgs = [];
|
|
50
|
+
canParseCommandOrComma = true;
|
|
51
|
+
switch (currentCommand) {
|
|
52
|
+
case "M":
|
|
53
|
+
currentCommand = "L";
|
|
54
|
+
break;
|
|
55
|
+
case "m":
|
|
56
|
+
currentCommand = "l";
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const parseNumber = () => {
|
|
62
|
+
if (currentNumber !== "" && currentCommandType) {
|
|
63
|
+
let value = Number(currentNumber);
|
|
64
|
+
if (isNaN(value)) {
|
|
65
|
+
throw new Error('Invalid number "' + currentNumber + '" at ' + i);
|
|
66
|
+
}
|
|
67
|
+
if (currentCommandType === ARC) {
|
|
68
|
+
if (currentArgs.length < 2 && value <= 0) {
|
|
69
|
+
throw new Error('Expected positive number, got "' + value + '" at ' + i);
|
|
70
|
+
}
|
|
71
|
+
while (true) {
|
|
72
|
+
if (currentArgs.length < 3 || currentArgs.length > 4) {
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
if (currentNumber === "0" || currentNumber === "1") {
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
const slice = currentNumber.slice(0, 1);
|
|
79
|
+
const newNumber = currentNumber.slice(1);
|
|
80
|
+
const newValue = Number(newNumber);
|
|
81
|
+
if (slice === "0" || slice === "1") {
|
|
82
|
+
if (isNaN(newValue)) {
|
|
83
|
+
throw new Error('Invalid number "' + currentNumber + '" at ' + i);
|
|
84
|
+
}
|
|
85
|
+
currentArgs.push(slice);
|
|
86
|
+
currentNumber = newNumber;
|
|
87
|
+
value = newValue;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
throw new Error('Expected a flag, got "' + currentNumber + '" at ' + i);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
currentArgs.push(currentNumber);
|
|
94
|
+
if (currentArgs.length === argCount[currentCommandType]) {
|
|
95
|
+
finishCommand();
|
|
96
|
+
}
|
|
97
|
+
currentNumber = "";
|
|
98
|
+
currentNumberHasExpDigits = false;
|
|
99
|
+
currentNumberHasExp = false;
|
|
100
|
+
currentNumberHasDecimal = false;
|
|
101
|
+
canParseCommandOrComma = true;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
for (i = 0; i < length; i++) {
|
|
105
|
+
const char = path[i];
|
|
106
|
+
const num = char.charCodeAt(0);
|
|
107
|
+
if (isDigit(num)) {
|
|
108
|
+
currentNumber += char;
|
|
109
|
+
currentNumberHasExpDigits = currentNumberHasExp;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (char === "e" || char === "E") {
|
|
113
|
+
currentNumber += char;
|
|
114
|
+
currentNumberHasExp = true;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if ((char === "-" || char === "+") && currentNumberHasExp && !currentNumberHasExpDigits) {
|
|
118
|
+
currentNumber += char;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (char === "." && !currentNumberHasExp && !currentNumberHasDecimal) {
|
|
122
|
+
currentNumber += char;
|
|
123
|
+
currentNumberHasDecimal = true;
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
parseNumber();
|
|
127
|
+
if (isWhiteSpace(num)) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (canParseCommandOrComma && char === ",") {
|
|
131
|
+
canParseCommandOrComma = false;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (char === "+" || char === "-" || char === ".") {
|
|
135
|
+
currentNumber = char;
|
|
136
|
+
currentNumberHasDecimal = char === ".";
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (currentArgs.length > 0) {
|
|
140
|
+
throw new Error("Unexpected command at " + i);
|
|
141
|
+
}
|
|
142
|
+
if (!canParseCommandOrComma) {
|
|
143
|
+
throw new Error("Command cannot follow comma at " + i);
|
|
144
|
+
}
|
|
145
|
+
canParseCommandOrComma = false;
|
|
146
|
+
currentCommand = char;
|
|
147
|
+
switch (char) {
|
|
148
|
+
case "z":
|
|
149
|
+
case "Z":
|
|
150
|
+
commands.push({
|
|
151
|
+
command: char,
|
|
152
|
+
params: []
|
|
153
|
+
});
|
|
154
|
+
canParseCommandOrComma = true;
|
|
155
|
+
currentCommandType = null;
|
|
156
|
+
currentCommand = null;
|
|
157
|
+
break;
|
|
158
|
+
case "h":
|
|
159
|
+
case "H":
|
|
160
|
+
currentCommandType = HORIZ_LINE_TO;
|
|
161
|
+
break;
|
|
162
|
+
case "v":
|
|
163
|
+
case "V":
|
|
164
|
+
currentCommandType = VERT_LINE_TO;
|
|
165
|
+
break;
|
|
166
|
+
case "m":
|
|
167
|
+
case "M":
|
|
168
|
+
currentCommandType = MOVE_TO;
|
|
169
|
+
break;
|
|
170
|
+
case "l":
|
|
171
|
+
case "L":
|
|
172
|
+
currentCommandType = LINE_TO;
|
|
173
|
+
break;
|
|
174
|
+
case "c":
|
|
175
|
+
case "C":
|
|
176
|
+
currentCommandType = CURVE_TO;
|
|
177
|
+
break;
|
|
178
|
+
case "s":
|
|
179
|
+
case "S":
|
|
180
|
+
currentCommandType = SMOOTH_CURVE_TO;
|
|
181
|
+
break;
|
|
182
|
+
case "q":
|
|
183
|
+
case "Q":
|
|
184
|
+
currentCommandType = QUAD_TO;
|
|
185
|
+
break;
|
|
186
|
+
case "t":
|
|
187
|
+
case "T":
|
|
188
|
+
currentCommandType = SMOOTH_QUAD_TO;
|
|
189
|
+
break;
|
|
190
|
+
case "a":
|
|
191
|
+
case "A":
|
|
192
|
+
currentCommandType = ARC;
|
|
193
|
+
break;
|
|
194
|
+
default:
|
|
195
|
+
throw new Error('Unexpected character "' + char + '" at ' + i);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
parseNumber();
|
|
199
|
+
if (currentArgs.length) {
|
|
200
|
+
if (!currentCommandType) {
|
|
201
|
+
throw new Error("Empty path");
|
|
202
|
+
}
|
|
203
|
+
if (currentArgs.length !== argCount[currentCommandType]) {
|
|
204
|
+
throw new Error("Unexpected end of path at " + i);
|
|
205
|
+
}
|
|
206
|
+
finishCommand();
|
|
207
|
+
}
|
|
208
|
+
let output = "";
|
|
209
|
+
commands.forEach((item) => {
|
|
210
|
+
output += item.command;
|
|
211
|
+
item.params.forEach((value, index) => {
|
|
212
|
+
if (index > 0) {
|
|
213
|
+
const char = value[0];
|
|
214
|
+
switch (char) {
|
|
215
|
+
case "-":
|
|
216
|
+
case "+":
|
|
217
|
+
break;
|
|
218
|
+
case ".":
|
|
219
|
+
if (index < 1) {
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
if (item.params[index - 1].indexOf(".") !== -1) {
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
default:
|
|
226
|
+
output += " ";
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
output += value;
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
return output;
|
|
233
|
+
}
|
|
234
|
+
async function deOptimisePaths(svg) {
|
|
235
|
+
await svg_parse.parseSVG(svg, (item) => {
|
|
236
|
+
if (item.tagName !== "path") {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const d = item.element.attribs.d;
|
|
240
|
+
if (typeof d === "string") {
|
|
241
|
+
try {
|
|
242
|
+
const optimised = cleanPath(d);
|
|
243
|
+
if (optimised !== d) {
|
|
244
|
+
item.$element.attr("d", optimised);
|
|
245
|
+
}
|
|
246
|
+
} catch (err) {
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
exports.deOptimisePaths = deOptimisePaths;
|
package/lib/optimise/flags.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { SVG } from '../svg/index.js';
|
|
2
|
+
import '@iconify/types';
|
|
3
|
+
import '@iconify/utils/lib/customisations';
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* De-optimise paths. Compressed paths are still not supported by some software.
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
declare function deOptimisePaths(svg: SVG): Promise<void>;
|
|
9
|
+
|
|
10
|
+
export { deOptimisePaths };
|
package/lib/optimise/flags.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { parseSVG } from '../svg/parse.mjs';
|
|
2
|
+
|
|
3
|
+
const CLOSE_PATH = 1;
|
|
4
|
+
const MOVE_TO = 2;
|
|
5
|
+
const HORIZ_LINE_TO = 4;
|
|
6
|
+
const VERT_LINE_TO = 8;
|
|
7
|
+
const LINE_TO = 16;
|
|
8
|
+
const CURVE_TO = 32;
|
|
9
|
+
const SMOOTH_CURVE_TO = 64;
|
|
10
|
+
const QUAD_TO = 128;
|
|
11
|
+
const SMOOTH_QUAD_TO = 256;
|
|
12
|
+
const ARC = 512;
|
|
13
|
+
const argCount = {
|
|
14
14
|
[MOVE_TO]: 2,
|
|
15
15
|
[LINE_TO]: 2,
|
|
16
16
|
[HORIZ_LINE_TO]: 1,
|
|
@@ -22,8 +22,8 @@ var argCount = {
|
|
|
22
22
|
[SMOOTH_CURVE_TO]: 4,
|
|
23
23
|
[ARC]: 7
|
|
24
24
|
};
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const isDigit = (num) => num >= 48 && num <= 57;
|
|
26
|
+
const isWhiteSpace = (num) => num === 32 || num === 9 || num === 13 || num === 10;
|
|
27
27
|
function cleanPath(path) {
|
|
28
28
|
const commands = [];
|
|
29
29
|
const length = path.length;
|
|
@@ -136,7 +136,7 @@ function cleanPath(path) {
|
|
|
136
136
|
throw new Error("Unexpected command at " + i);
|
|
137
137
|
}
|
|
138
138
|
if (!canParseCommandOrComma) {
|
|
139
|
-
throw new Error("Command cannot follow comma at " + i
|
|
139
|
+
throw new Error("Command cannot follow comma at " + i);
|
|
140
140
|
}
|
|
141
141
|
canParseCommandOrComma = false;
|
|
142
142
|
currentCommand = char;
|
|
@@ -244,6 +244,5 @@ async function deOptimisePaths(svg) {
|
|
|
244
244
|
}
|
|
245
245
|
});
|
|
246
246
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
};
|
|
247
|
+
|
|
248
|
+
export { deOptimisePaths };
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const svg_data_tags = require('../svg/data/tags.cjs');
|
|
6
|
+
const svg_parse = require('../svg/parse.cjs');
|
|
7
|
+
const svg_parseStyle = require('../svg/parse-style.cjs');
|
|
8
|
+
require('../css/parse.cjs');
|
|
9
|
+
require('../css/parser/tokens.cjs');
|
|
10
|
+
require('../css/parser/error.cjs');
|
|
11
|
+
require('../css/parser/strings.cjs');
|
|
12
|
+
require('../css/parser/text.cjs');
|
|
13
|
+
require('../css/parser/export.cjs');
|
|
14
|
+
require('../css/parser/tree.cjs');
|
|
15
|
+
|
|
16
|
+
function getClassList(value) {
|
|
17
|
+
return value?.split(/\s+/);
|
|
18
|
+
}
|
|
19
|
+
const tempDataAttrbiute = "data-gstyle-temp";
|
|
20
|
+
async function cleanupGlobalStyle(svg) {
|
|
21
|
+
const backup = svg.toString();
|
|
22
|
+
let containsTempAttr = false;
|
|
23
|
+
const animatedClasses = /* @__PURE__ */ new Set();
|
|
24
|
+
await svg_parse.parseSVG(svg, (item) => {
|
|
25
|
+
if (!svg_data_tags.animateTags.has(item.tagName)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const $element = item.$element;
|
|
29
|
+
if ($element.attr("attributeName") !== "class") {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
["from", "to", "values"].forEach((attr) => {
|
|
33
|
+
const value = $element.attr(attr);
|
|
34
|
+
if (typeof value !== "string") {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
value.split(";").forEach((item2) => {
|
|
38
|
+
getClassList(item2).forEach((className) => {
|
|
39
|
+
animatedClasses.add(className);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
try {
|
|
45
|
+
await svg_parseStyle.parseSVGStyle(svg, async (styleItem) => {
|
|
46
|
+
const returnValue = styleItem.value;
|
|
47
|
+
if (styleItem.type !== "global") {
|
|
48
|
+
return returnValue;
|
|
49
|
+
}
|
|
50
|
+
const selectorTokens = styleItem.selectorTokens;
|
|
51
|
+
for (let i = 0; i < selectorTokens.length; i++) {
|
|
52
|
+
const selectorToken = selectorTokens[i];
|
|
53
|
+
if (selectorToken.type !== "selector") {
|
|
54
|
+
return returnValue;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const selectors = styleItem.selectors;
|
|
58
|
+
const matches = [];
|
|
59
|
+
for (let i = 0; i < selectors.length; i++) {
|
|
60
|
+
const selector = styleItem.selectors[i];
|
|
61
|
+
const firstChar = selector.charAt(0);
|
|
62
|
+
let matchType;
|
|
63
|
+
if (firstChar === ".") {
|
|
64
|
+
matchType = "class";
|
|
65
|
+
} else if (firstChar === "#") {
|
|
66
|
+
matchType = "id";
|
|
67
|
+
} else if (svg_data_tags.allValidTags.has(selector)) {
|
|
68
|
+
matchType = "tag";
|
|
69
|
+
} else {
|
|
70
|
+
return returnValue;
|
|
71
|
+
}
|
|
72
|
+
const valueMatch = matchType === "tag" ? selector : selector.slice(1);
|
|
73
|
+
if (matchType === "class" && animatedClasses.has(valueMatch)) {
|
|
74
|
+
return returnValue;
|
|
75
|
+
}
|
|
76
|
+
matches.push({
|
|
77
|
+
type: matchType,
|
|
78
|
+
value: valueMatch
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const isMatch = (tagName, $element) => {
|
|
82
|
+
for (let i = 0; i < matches.length; i++) {
|
|
83
|
+
const { type, value } = matches[i];
|
|
84
|
+
switch (type) {
|
|
85
|
+
case "id":
|
|
86
|
+
if ($element.attr("id") === value) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
break;
|
|
90
|
+
case "tag":
|
|
91
|
+
if (tagName === value) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
break;
|
|
95
|
+
case "class": {
|
|
96
|
+
const className = $element.attr("class");
|
|
97
|
+
if (className && getClassList(className).indexOf(value) !== -1) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
};
|
|
105
|
+
await svg_parse.parseSVG(svg, (svgItem) => {
|
|
106
|
+
const tagName = svgItem.tagName;
|
|
107
|
+
const $element = svgItem.$element;
|
|
108
|
+
if (!isMatch(tagName, $element)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const addedAttributes = new Set($element.attr(tempDataAttrbiute)?.split(/\s+/));
|
|
112
|
+
const prop = styleItem.prop;
|
|
113
|
+
if ($element.attr(prop) !== void 0) {
|
|
114
|
+
if (addedAttributes.has(prop)) {
|
|
115
|
+
throw new Error("Duplicate attribute");
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
$element.attr(prop, styleItem.value);
|
|
119
|
+
addedAttributes.add(prop);
|
|
120
|
+
$element.attr(tempDataAttrbiute, Array.from(addedAttributes).join(" "));
|
|
121
|
+
containsTempAttr = true;
|
|
122
|
+
});
|
|
123
|
+
const classMatches = matches.filter((item) => item.type === "class").map((item) => item.value);
|
|
124
|
+
if (classMatches.length && styleItem.nextTokens[0]?.type === "close") {
|
|
125
|
+
await svg_parse.parseSVG(svg, (svgItem) => {
|
|
126
|
+
const $element = svgItem.$element;
|
|
127
|
+
if (!isMatch("", $element)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const classList = getClassList($element.attr("class"));
|
|
131
|
+
if (!classList) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const filtered = classList.filter((item) => classMatches.indexOf(item) === -1);
|
|
135
|
+
if (!filtered.length) {
|
|
136
|
+
$element.removeAttr("class");
|
|
137
|
+
} else {
|
|
138
|
+
$element.attr("class", filtered.join(" "));
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
return;
|
|
143
|
+
});
|
|
144
|
+
if (containsTempAttr) {
|
|
145
|
+
await svg_parse.parseSVG(svg, (item) => {
|
|
146
|
+
item.$element.removeAttr(tempDataAttrbiute);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
} catch (err) {
|
|
150
|
+
svg.load(backup);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
exports.cleanupGlobalStyle = cleanupGlobalStyle;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { SVG } from '../svg/index.js';
|
|
2
|
+
import '@iconify/types';
|
|
3
|
+
import '@iconify/utils/lib/customisations';
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Expand global style
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
declare function cleanupGlobalStyle(svg: SVG): Promise<void>;
|
|
9
|
+
|
|
10
|
+
export { cleanupGlobalStyle };
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import { allValidTags, animateTags } from '../svg/data/tags.mjs';
|
|
2
|
+
import { parseSVG } from '../svg/parse.mjs';
|
|
3
|
+
import { parseSVGStyle } from '../svg/parse-style.mjs';
|
|
4
|
+
import '../css/parse.mjs';
|
|
5
|
+
import '../css/parser/tokens.mjs';
|
|
6
|
+
import '../css/parser/error.mjs';
|
|
7
|
+
import '../css/parser/strings.mjs';
|
|
8
|
+
import '../css/parser/text.mjs';
|
|
9
|
+
import '../css/parser/export.mjs';
|
|
10
|
+
import '../css/parser/tree.mjs';
|
|
11
|
+
|
|
6
12
|
function getClassList(value) {
|
|
7
|
-
return value
|
|
13
|
+
return value?.split(/\s+/);
|
|
8
14
|
}
|
|
9
|
-
|
|
15
|
+
const tempDataAttrbiute = "data-gstyle-temp";
|
|
10
16
|
async function cleanupGlobalStyle(svg) {
|
|
11
17
|
const backup = svg.toString();
|
|
12
18
|
let containsTempAttr = false;
|
|
13
|
-
const animatedClasses = new Set();
|
|
19
|
+
const animatedClasses = /* @__PURE__ */ new Set();
|
|
14
20
|
await parseSVG(svg, (item) => {
|
|
15
21
|
if (!animateTags.has(item.tagName)) {
|
|
16
22
|
return;
|
|
@@ -33,7 +39,6 @@ async function cleanupGlobalStyle(svg) {
|
|
|
33
39
|
});
|
|
34
40
|
try {
|
|
35
41
|
await parseSVGStyle(svg, async (styleItem) => {
|
|
36
|
-
var _a;
|
|
37
42
|
const returnValue = styleItem.value;
|
|
38
43
|
if (styleItem.type !== "global") {
|
|
39
44
|
return returnValue;
|
|
@@ -94,13 +99,12 @@ async function cleanupGlobalStyle(svg) {
|
|
|
94
99
|
return false;
|
|
95
100
|
};
|
|
96
101
|
await parseSVG(svg, (svgItem) => {
|
|
97
|
-
var _a2;
|
|
98
102
|
const tagName = svgItem.tagName;
|
|
99
103
|
const $element = svgItem.$element;
|
|
100
104
|
if (!isMatch(tagName, $element)) {
|
|
101
105
|
return;
|
|
102
106
|
}
|
|
103
|
-
const addedAttributes = new Set(
|
|
107
|
+
const addedAttributes = new Set($element.attr(tempDataAttrbiute)?.split(/\s+/));
|
|
104
108
|
const prop = styleItem.prop;
|
|
105
109
|
if ($element.attr(prop) !== void 0) {
|
|
106
110
|
if (addedAttributes.has(prop)) {
|
|
@@ -113,7 +117,7 @@ async function cleanupGlobalStyle(svg) {
|
|
|
113
117
|
containsTempAttr = true;
|
|
114
118
|
});
|
|
115
119
|
const classMatches = matches.filter((item) => item.type === "class").map((item) => item.value);
|
|
116
|
-
if (classMatches.length &&
|
|
120
|
+
if (classMatches.length && styleItem.nextTokens[0]?.type === "close") {
|
|
117
121
|
await parseSVG(svg, (svgItem) => {
|
|
118
122
|
const $element = svgItem.$element;
|
|
119
123
|
if (!isMatch("", $element)) {
|
|
@@ -142,6 +146,5 @@ async function cleanupGlobalStyle(svg) {
|
|
|
142
146
|
svg.load(backup);
|
|
143
147
|
}
|
|
144
148
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
};
|
|
149
|
+
|
|
150
|
+
export { cleanupGlobalStyle };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const optimise_svgo = require('./svgo.cjs');
|
|
6
|
+
require('svgo');
|
|
7
|
+
|
|
8
|
+
async function scaleSVG(svg, scale) {
|
|
9
|
+
const viewBox = svg.viewBox;
|
|
10
|
+
const width = viewBox.width * scale;
|
|
11
|
+
const height = viewBox.height * scale;
|
|
12
|
+
const left = viewBox.left * scale;
|
|
13
|
+
const top = viewBox.top * scale;
|
|
14
|
+
const content = '<svg width="' + width + '" height="' + height + '" viewBox="' + left + " " + top + " " + width + " " + height + '"><g transform="scale(' + scale + ')">' + svg.getBody() + "</g></svg>";
|
|
15
|
+
svg.load(content);
|
|
16
|
+
await optimise_svgo.runSVGO(svg, {
|
|
17
|
+
plugins: [
|
|
18
|
+
"collapseGroups",
|
|
19
|
+
"convertTransform",
|
|
20
|
+
"convertPathData",
|
|
21
|
+
"sortAttrs"
|
|
22
|
+
]
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
exports.scaleSVG = scaleSVG;
|