@iconify/tools 4.0.0-dev.1 → 4.0.0
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.cts +27 -0
- package/lib/colors/attribs.d.mts +27 -0
- package/lib/colors/attribs.d.ts +1 -1
- package/lib/colors/detect.cjs +2 -2
- package/lib/colors/detect.d.cts +16 -0
- package/lib/colors/detect.d.mts +16 -0
- package/lib/colors/detect.mjs +3 -3
- package/lib/colors/parse.cjs +132 -276
- package/lib/colors/parse.d.cts +60 -0
- package/lib/colors/parse.d.mts +60 -0
- package/lib/colors/parse.d.ts +7 -15
- package/lib/colors/parse.mjs +136 -279
- package/lib/colors/validate.cjs +2 -11
- package/lib/colors/validate.d.cts +20 -0
- package/lib/colors/validate.d.mts +20 -0
- package/lib/colors/validate.d.ts +4 -11
- package/lib/colors/validate.mjs +4 -12
- package/lib/css/parse.d.cts +6 -0
- package/lib/css/parse.d.mts +6 -0
- package/lib/css/parser/error.d.cts +13 -0
- package/lib/css/parser/error.d.mts +13 -0
- package/lib/css/parser/error.d.ts +1 -1
- package/lib/css/parser/export.d.cts +8 -0
- package/lib/css/parser/export.d.mts +8 -0
- package/lib/css/parser/strings.d.cts +16 -0
- package/lib/css/parser/strings.d.mts +16 -0
- package/lib/css/parser/text.d.cts +20 -0
- package/lib/css/parser/text.d.mts +20 -0
- package/lib/css/parser/tokens.d.cts +9 -0
- package/lib/css/parser/tokens.d.mts +9 -0
- package/lib/css/parser/tree.d.cts +8 -0
- package/lib/css/parser/tree.d.mts +8 -0
- package/lib/css/parser/types.d.cts +52 -0
- package/lib/css/parser/types.d.mts +52 -0
- package/lib/css/parser/types.d.ts +1 -1
- package/lib/download/api/cache.d.cts +20 -0
- package/lib/download/api/cache.d.mts +20 -0
- package/lib/download/api/config.cjs +11 -0
- package/lib/download/api/config.d.cts +18 -0
- package/lib/download/api/config.d.mts +18 -0
- package/lib/download/api/config.d.ts +18 -0
- package/lib/download/api/config.mjs +8 -0
- package/lib/download/api/download.cjs +15 -7
- package/lib/download/api/download.d.cts +8 -0
- package/lib/download/api/download.d.mts +8 -0
- package/lib/download/api/download.mjs +11 -7
- package/lib/download/api/index.cjs +23 -7
- package/lib/download/api/index.d.cts +8 -0
- package/lib/download/api/index.d.mts +8 -0
- package/lib/download/api/index.mjs +19 -7
- package/lib/download/api/queue.cjs +104 -0
- package/lib/download/api/queue.d.cts +32 -0
- package/lib/download/api/queue.d.mts +32 -0
- package/lib/download/api/queue.d.ts +32 -0
- package/lib/download/api/queue.mjs +101 -0
- package/lib/download/api/types.d.cts +17 -0
- package/lib/download/api/types.d.mts +17 -0
- package/lib/download/api/types.d.ts +1 -1
- package/lib/download/git/branch.d.cts +8 -0
- package/lib/download/git/branch.d.mts +8 -0
- package/lib/download/git/hash.d.cts +8 -0
- package/lib/download/git/hash.d.mts +8 -0
- package/lib/download/git/index.cjs +2 -4
- package/lib/download/git/index.d.cts +29 -0
- package/lib/download/git/index.d.mts +29 -0
- package/lib/download/git/index.d.ts +1 -1
- package/lib/download/git/index.mjs +2 -4
- package/lib/download/git/reset.cjs +2 -4
- package/lib/download/git/reset.d.cts +6 -0
- package/lib/download/git/reset.d.mts +6 -0
- package/lib/download/git/reset.mjs +2 -4
- package/lib/download/github/hash.cjs +2 -0
- package/lib/download/github/hash.d.cts +8 -0
- package/lib/download/github/hash.d.mts +8 -0
- package/lib/download/github/hash.mjs +2 -0
- package/lib/download/github/index.cjs +2 -2
- package/lib/download/github/index.d.cts +31 -0
- package/lib/download/github/index.d.mts +31 -0
- package/lib/download/github/index.d.ts +1 -1
- package/lib/download/github/index.mjs +2 -2
- package/lib/download/github/types.d.cts +11 -0
- package/lib/download/github/types.d.mts +11 -0
- package/lib/download/github/types.d.ts +1 -1
- package/lib/download/gitlab/hash.cjs +2 -0
- package/lib/download/gitlab/hash.d.cts +8 -0
- package/lib/download/gitlab/hash.d.mts +8 -0
- package/lib/download/gitlab/hash.mjs +2 -0
- package/lib/download/gitlab/index.cjs +2 -2
- package/lib/download/gitlab/index.d.cts +31 -0
- package/lib/download/gitlab/index.d.mts +31 -0
- package/lib/download/gitlab/index.d.ts +1 -1
- package/lib/download/gitlab/index.mjs +2 -2
- package/lib/download/gitlab/types.d.cts +15 -0
- package/lib/download/gitlab/types.d.mts +15 -0
- package/lib/download/gitlab/types.d.ts +1 -1
- package/lib/download/helpers/untar.d.cts +6 -0
- package/lib/download/helpers/untar.d.mts +6 -0
- package/lib/download/helpers/unzip.d.cts +6 -0
- package/lib/download/helpers/unzip.d.mts +6 -0
- package/lib/download/index.cjs +2 -2
- package/lib/download/index.d.cts +48 -0
- package/lib/download/index.d.mts +48 -0
- package/lib/download/index.d.ts +1 -1
- package/lib/download/index.mjs +2 -2
- package/lib/download/npm/index.cjs +2 -2
- package/lib/download/npm/index.d.cts +30 -0
- package/lib/download/npm/index.d.mts +30 -0
- package/lib/download/npm/index.d.ts +1 -1
- package/lib/download/npm/index.mjs +2 -2
- package/lib/download/npm/types.d.cts +9 -0
- package/lib/download/npm/types.d.mts +9 -0
- package/lib/download/npm/types.d.ts +1 -1
- package/lib/download/npm/version.d.cts +16 -0
- package/lib/download/npm/version.d.mts +16 -0
- package/lib/download/npm/version.d.ts +1 -1
- package/lib/download/types/modified.d.cts +6 -0
- package/lib/download/types/modified.d.mts +6 -0
- package/lib/download/types/modified.d.ts +1 -1
- package/lib/download/types/sources.d.cts +12 -0
- package/lib/download/types/sources.d.mts +12 -0
- package/lib/download/types/sources.d.ts +1 -1
- package/lib/export/directory.d.cts +26 -0
- package/lib/export/directory.d.mts +26 -0
- package/lib/export/directory.d.ts +1 -1
- package/lib/export/helpers/custom-files.d.cts +12 -0
- package/lib/export/helpers/custom-files.d.mts +12 -0
- package/lib/export/helpers/custom-files.d.ts +1 -1
- package/lib/export/helpers/prepare.d.cts +19 -0
- package/lib/export/helpers/prepare.d.mts +19 -0
- package/lib/export/helpers/prepare.d.ts +1 -1
- package/lib/export/helpers/types-version.d.cts +6 -0
- package/lib/export/helpers/types-version.d.mts +6 -0
- package/lib/export/icon-package.d.cts +26 -0
- package/lib/export/icon-package.d.mts +26 -0
- package/lib/export/icon-package.d.ts +2 -2
- package/lib/export/json-package.cjs +1 -0
- package/lib/export/json-package.d.cts +25 -0
- package/lib/export/json-package.d.mts +25 -0
- package/lib/export/json-package.d.ts +2 -1
- package/lib/export/json-package.mjs +1 -0
- package/lib/icon-set/index.cjs +25 -4
- package/lib/icon-set/index.d.cts +162 -0
- package/lib/icon-set/index.d.mts +162 -0
- package/lib/icon-set/index.mjs +25 -4
- package/lib/icon-set/match.d.cts +15 -0
- package/lib/icon-set/match.d.mts +15 -0
- package/lib/icon-set/merge.d.cts +14 -0
- package/lib/icon-set/merge.d.mts +14 -0
- package/lib/icon-set/modified.d.cts +16 -0
- package/lib/icon-set/modified.d.mts +16 -0
- package/lib/icon-set/props.d.cts +13 -0
- package/lib/icon-set/props.d.mts +13 -0
- package/lib/icon-set/tags.d.cts +23 -0
- package/lib/icon-set/tags.d.mts +23 -0
- package/lib/icon-set/types.d.cts +75 -0
- package/lib/icon-set/types.d.mts +75 -0
- package/lib/icon-set/types.d.ts +1 -1
- package/lib/import/directory.d.cts +52 -0
- package/lib/import/directory.d.mts +52 -0
- package/lib/import/directory.d.ts +1 -1
- package/lib/import/figma/index.cjs +3 -0
- package/lib/import/figma/index.d.cts +20 -0
- package/lib/import/figma/index.d.mts +20 -0
- package/lib/import/figma/index.mjs +3 -0
- package/lib/import/figma/nodes.cjs +1 -1
- package/lib/import/figma/nodes.d.cts +18 -0
- package/lib/import/figma/nodes.d.mts +18 -0
- package/lib/import/figma/nodes.mjs +1 -1
- package/lib/import/figma/query.cjs +104 -76
- package/lib/import/figma/query.d.cts +42 -0
- package/lib/import/figma/query.d.mts +42 -0
- package/lib/import/figma/query.d.ts +15 -2
- package/lib/import/figma/query.mjs +106 -78
- package/lib/import/figma/types/api.d.cts +53 -0
- package/lib/import/figma/types/api.d.mts +53 -0
- package/lib/import/figma/types/api.d.ts +1 -1
- package/lib/import/figma/types/nodes.d.cts +44 -0
- package/lib/import/figma/types/nodes.d.mts +44 -0
- package/lib/import/figma/types/nodes.d.ts +1 -1
- package/lib/import/figma/types/options.d.cts +59 -0
- package/lib/import/figma/types/options.d.mts +59 -0
- package/lib/import/figma/types/options.d.ts +1 -1
- package/lib/import/figma/types/result.d.cts +44 -0
- package/lib/import/figma/types/result.d.mts +44 -0
- package/lib/import/figma/types/result.d.ts +1 -1
- package/lib/index.cjs +14 -13
- package/lib/index.d.cts +78 -0
- package/lib/index.d.mts +78 -0
- package/lib/index.d.ts +8 -5
- package/lib/index.mjs +13 -12
- package/lib/misc/bump-version.d.cts +6 -0
- package/lib/misc/bump-version.d.mts +6 -0
- package/lib/misc/cheerio.d.cts +9 -0
- package/lib/misc/cheerio.d.mts +9 -0
- package/lib/misc/cheerio.d.ts +1 -1
- package/lib/misc/compare-dirs.cjs +3 -3
- package/lib/misc/compare-dirs.d.cts +11 -0
- package/lib/misc/compare-dirs.d.mts +11 -0
- package/lib/misc/compare-dirs.d.ts +1 -1
- package/lib/misc/compare-dirs.mjs +3 -3
- package/lib/misc/exec.d.cts +12 -0
- package/lib/misc/exec.d.mts +12 -0
- package/lib/misc/exec.d.ts +1 -1
- package/lib/misc/keyword.d.cts +6 -0
- package/lib/misc/keyword.d.mts +6 -0
- package/lib/misc/scan.d.cts +33 -0
- package/lib/misc/scan.d.mts +33 -0
- package/lib/misc/scan.d.ts +1 -1
- package/lib/misc/write-json.d.cts +6 -0
- package/lib/misc/write-json.d.mts +6 -0
- package/lib/optimise/figma.cjs +5 -5
- package/lib/optimise/figma.d.cts +11 -0
- package/lib/optimise/figma.d.mts +11 -0
- package/lib/optimise/figma.mjs +5 -5
- package/lib/optimise/flags.cjs +3 -3
- package/lib/optimise/flags.d.cts +11 -0
- package/lib/optimise/flags.d.mts +11 -0
- package/lib/optimise/flags.d.ts +1 -1
- package/lib/optimise/flags.mjs +3 -3
- package/lib/optimise/global-style.cjs +7 -7
- package/lib/optimise/global-style.d.cts +11 -0
- package/lib/optimise/global-style.d.mts +11 -0
- package/lib/optimise/global-style.d.ts +1 -1
- package/lib/optimise/global-style.mjs +7 -7
- package/lib/optimise/mask.cjs +1 -1
- package/lib/optimise/mask.d.cts +24 -0
- package/lib/optimise/mask.d.mts +24 -0
- package/lib/optimise/mask.mjs +2 -2
- package/lib/optimise/origin.d.cts +11 -0
- package/lib/optimise/origin.d.mts +11 -0
- package/lib/optimise/scale.d.cts +11 -0
- package/lib/optimise/scale.d.mts +11 -0
- package/lib/optimise/svgo.cjs +1 -1
- package/lib/optimise/svgo.d.cts +37 -0
- package/lib/optimise/svgo.d.mts +37 -0
- package/lib/optimise/svgo.mjs +1 -1
- package/lib/svg/analyse/error.d.cts +10 -0
- package/lib/svg/analyse/error.d.mts +10 -0
- package/lib/svg/analyse/error.d.ts +1 -0
- package/lib/svg/analyse/types.d.cts +92 -0
- package/lib/svg/analyse/types.d.mts +92 -0
- package/lib/svg/analyse/types.d.ts +4 -3
- package/lib/svg/analyse.cjs +2 -2
- package/lib/svg/analyse.d.cts +15 -0
- package/lib/svg/analyse.d.mts +15 -0
- package/lib/svg/analyse.d.ts +1 -0
- package/lib/svg/analyse.mjs +4 -4
- package/lib/svg/cleanup/attribs.cjs +1 -1
- package/lib/svg/cleanup/attribs.d.cts +11 -0
- package/lib/svg/cleanup/attribs.d.mts +11 -0
- package/lib/svg/cleanup/attribs.mjs +2 -2
- package/lib/svg/cleanup/bad-tags.cjs +1 -1
- package/lib/svg/cleanup/bad-tags.d.cts +17 -0
- package/lib/svg/cleanup/bad-tags.d.mts +17 -0
- package/lib/svg/cleanup/bad-tags.d.ts +1 -1
- package/lib/svg/cleanup/bad-tags.mjs +2 -2
- package/lib/svg/cleanup/inline-style.cjs +1 -1
- package/lib/svg/cleanup/inline-style.d.cts +11 -0
- package/lib/svg/cleanup/inline-style.d.mts +11 -0
- package/lib/svg/cleanup/inline-style.mjs +2 -2
- package/lib/svg/cleanup/root-style.cjs +1 -1
- package/lib/svg/cleanup/root-style.d.cts +17 -0
- package/lib/svg/cleanup/root-style.d.mts +17 -0
- package/lib/svg/cleanup/root-style.mjs +2 -2
- package/lib/svg/cleanup/root-svg.cjs +3 -3
- package/lib/svg/cleanup/root-svg.d.cts +11 -0
- package/lib/svg/cleanup/root-svg.d.mts +11 -0
- package/lib/svg/cleanup/root-svg.mjs +3 -3
- package/lib/svg/cleanup/svgo-style.cjs +2 -2
- package/lib/svg/cleanup/svgo-style.d.cts +11 -0
- package/lib/svg/cleanup/svgo-style.d.mts +11 -0
- package/lib/svg/cleanup/svgo-style.mjs +3 -3
- package/lib/svg/cleanup.d.cts +16 -0
- package/lib/svg/cleanup.d.mts +16 -0
- package/lib/svg/cleanup.d.ts +1 -1
- package/lib/svg/data/attributes.d.cts +77 -0
- package/lib/svg/data/attributes.d.mts +77 -0
- package/lib/svg/data/tags.d.cts +95 -0
- package/lib/svg/data/tags.d.mts +95 -0
- package/lib/svg/index.cjs +18 -1
- package/lib/svg/index.d.cts +52 -0
- package/lib/svg/index.d.mts +52 -0
- package/lib/svg/index.d.ts +5 -1
- package/lib/svg/index.mjs +19 -2
- package/lib/svg/parse-style.cjs +178 -235
- package/lib/svg/parse-style.d.cts +58 -0
- package/lib/svg/parse-style.d.mts +58 -0
- package/lib/svg/parse-style.d.ts +3 -9
- package/lib/svg/parse-style.mjs +180 -236
- package/lib/svg/parse.cjs +27 -59
- package/lib/svg/parse.d.cts +30 -0
- package/lib/svg/parse.d.mts +30 -0
- package/lib/svg/parse.d.ts +3 -10
- package/lib/svg/parse.mjs +28 -59
- package/package.json +26 -21
package/lib/svg/parse-style.mjs
CHANGED
|
@@ -2,161 +2,152 @@ import { parseInlineStyle } from '../css/parse.mjs';
|
|
|
2
2
|
import { tokensToString } from '../css/parser/export.mjs';
|
|
3
3
|
import { getTokens } from '../css/parser/tokens.mjs';
|
|
4
4
|
import { tokensTree } from '../css/parser/tree.mjs';
|
|
5
|
-
import { parseSVG
|
|
5
|
+
import { parseSVG } from './parse.mjs';
|
|
6
6
|
import '../css/parser/error.mjs';
|
|
7
7
|
import '../css/parser/strings.mjs';
|
|
8
8
|
import '../css/parser/text.mjs';
|
|
9
9
|
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const selectorStart = [];
|
|
25
|
-
let newTokens = [];
|
|
26
|
-
const parsedTokens = () => {
|
|
27
|
-
if (changed2) {
|
|
28
|
-
const tree = tokensTree(
|
|
29
|
-
newTokens.filter((token) => token !== null)
|
|
30
|
-
);
|
|
31
|
-
if (!tree.length) {
|
|
32
|
-
$element.remove();
|
|
33
|
-
} else {
|
|
34
|
-
const newContent = tokensToString(tree);
|
|
35
|
-
item.$element.text("\n" + newContent);
|
|
36
|
-
}
|
|
10
|
+
function assertNotOldCode(value) {
|
|
11
|
+
if (value instanceof Promise) {
|
|
12
|
+
throw new Error("parseSVGStyle does not support async callbacks");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function parseSVGStyle(svg, callback) {
|
|
16
|
+
parseSVG(svg, (item) => {
|
|
17
|
+
const tagName = item.tagName;
|
|
18
|
+
const $element = item.$element;
|
|
19
|
+
function parseStyleItem() {
|
|
20
|
+
const content = $element.text();
|
|
21
|
+
if (typeof content !== "string") {
|
|
22
|
+
$element.remove();
|
|
23
|
+
return;
|
|
37
24
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const token = tokens.shift();
|
|
42
|
-
if (token === void 0) {
|
|
43
|
-
return parsedTokens();
|
|
25
|
+
const tokens = getTokens(content);
|
|
26
|
+
if (!(tokens instanceof Array)) {
|
|
27
|
+
throw new Error("Error parsing style");
|
|
44
28
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
29
|
+
let changed2 = false;
|
|
30
|
+
const selectorStart = [];
|
|
31
|
+
let newTokens = [];
|
|
32
|
+
while (tokens.length) {
|
|
33
|
+
const token = tokens.shift();
|
|
34
|
+
if (!token) {
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
switch (token.type) {
|
|
38
|
+
case "selector":
|
|
39
|
+
selectorStart.push(newTokens.length);
|
|
40
|
+
newTokens.push(token);
|
|
41
|
+
break;
|
|
42
|
+
case "close":
|
|
43
|
+
selectorStart.pop();
|
|
44
|
+
newTokens.push(token);
|
|
45
|
+
break;
|
|
46
|
+
case "at-rule": {
|
|
47
|
+
selectorStart.push(newTokens.length);
|
|
48
|
+
const prop = token.rule;
|
|
49
|
+
const value = token.value;
|
|
50
|
+
const isAnimation = prop === "keyframes" || prop.slice(0, 1) === "-" && prop.split("-").pop() === "keyframes";
|
|
51
|
+
const childTokens = [];
|
|
52
|
+
const animationRules = /* @__PURE__ */ Object.create(null);
|
|
53
|
+
let depth = 1;
|
|
54
|
+
let index = 0;
|
|
55
|
+
let isFrom = false;
|
|
56
|
+
while (depth > 0) {
|
|
57
|
+
const childToken = tokens[index];
|
|
58
|
+
index++;
|
|
59
|
+
if (!childToken) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
"Something went wrong parsing CSS"
|
|
62
|
+
);
|
|
76
63
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
64
|
+
childTokens.push(childToken);
|
|
65
|
+
switch (childToken.type) {
|
|
66
|
+
case "close": {
|
|
67
|
+
depth--;
|
|
68
|
+
isFrom = false;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
case "selector": {
|
|
72
|
+
depth++;
|
|
73
|
+
if (isAnimation) {
|
|
74
|
+
const rule = childToken.code;
|
|
75
|
+
if (rule === "from" || rule === "0%") {
|
|
76
|
+
isFrom = true;
|
|
77
|
+
}
|
|
83
78
|
}
|
|
79
|
+
break;
|
|
84
80
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
81
|
+
case "at-rule": {
|
|
82
|
+
depth++;
|
|
83
|
+
if (isAnimation) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
"Nested at-rule in keyframes ???"
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
93
89
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
90
|
+
case "rule": {
|
|
91
|
+
if (isAnimation && isFrom) {
|
|
92
|
+
animationRules[childToken.prop] = childToken.value;
|
|
93
|
+
}
|
|
94
|
+
break;
|
|
99
95
|
}
|
|
100
|
-
break;
|
|
101
96
|
}
|
|
102
97
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
(result)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
newTokens.push(token);
|
|
132
|
-
for (let i = 0; i < skipCount; i++) {
|
|
133
|
-
tokens.shift();
|
|
134
|
-
}
|
|
135
|
-
newTokens = newTokens.concat(childTokens);
|
|
136
|
-
} else {
|
|
137
|
-
if (result !== value) {
|
|
138
|
-
throw new Error(
|
|
139
|
-
"Changing value for at-rule is not supported"
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
newTokens.push(token);
|
|
98
|
+
const skipCount = childTokens.length;
|
|
99
|
+
const result = callback(
|
|
100
|
+
isAnimation ? {
|
|
101
|
+
type: "keyframes",
|
|
102
|
+
prop,
|
|
103
|
+
value,
|
|
104
|
+
token,
|
|
105
|
+
childTokens,
|
|
106
|
+
from: animationRules,
|
|
107
|
+
prevTokens: newTokens,
|
|
108
|
+
nextTokens: tokens.slice(0)
|
|
109
|
+
} : {
|
|
110
|
+
type: "at-rule",
|
|
111
|
+
prop,
|
|
112
|
+
value,
|
|
113
|
+
token,
|
|
114
|
+
childTokens,
|
|
115
|
+
prevTokens: newTokens,
|
|
116
|
+
nextTokens: tokens.slice(0)
|
|
117
|
+
}
|
|
118
|
+
);
|
|
119
|
+
if (result !== void 0) {
|
|
120
|
+
assertNotOldCode(result);
|
|
121
|
+
if (isAnimation) {
|
|
122
|
+
if (result !== value) {
|
|
123
|
+
changed2 = true;
|
|
124
|
+
token.value = result;
|
|
143
125
|
}
|
|
144
|
-
|
|
145
|
-
changed2 = true;
|
|
126
|
+
newTokens.push(token);
|
|
146
127
|
for (let i = 0; i < skipCount; i++) {
|
|
147
128
|
tokens.shift();
|
|
148
129
|
}
|
|
130
|
+
newTokens = newTokens.concat(childTokens);
|
|
131
|
+
} else {
|
|
132
|
+
if (result !== value) {
|
|
133
|
+
throw new Error(
|
|
134
|
+
"Changing value for at-rule is not supported"
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
newTokens.push(token);
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
changed2 = true;
|
|
141
|
+
for (let i = 0; i < skipCount; i++) {
|
|
142
|
+
tokens.shift();
|
|
149
143
|
}
|
|
150
|
-
nextToken();
|
|
151
144
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
callback(
|
|
159
|
-
{
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
case "rule": {
|
|
148
|
+
const value = token.value;
|
|
149
|
+
const selectorTokens = selectorStart.map((index) => newTokens[index]).filter((item2) => item2 !== null);
|
|
150
|
+
const result = callback({
|
|
160
151
|
type: "global",
|
|
161
152
|
prop: token.prop,
|
|
162
153
|
value,
|
|
@@ -177,121 +168,74 @@ function parseItem(item, callback, done) {
|
|
|
177
168
|
),
|
|
178
169
|
prevTokens: newTokens,
|
|
179
170
|
nextTokens: tokens.slice(0)
|
|
180
|
-
}
|
|
181
|
-
(result)
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
changed2 = true;
|
|
185
|
-
token.value = result;
|
|
186
|
-
}
|
|
187
|
-
newTokens.push(token);
|
|
188
|
-
} else {
|
|
171
|
+
});
|
|
172
|
+
if (result !== void 0) {
|
|
173
|
+
assertNotOldCode(result);
|
|
174
|
+
if (result !== value) {
|
|
189
175
|
changed2 = true;
|
|
176
|
+
token.value = result;
|
|
190
177
|
}
|
|
191
|
-
|
|
178
|
+
newTokens.push(token);
|
|
179
|
+
} else {
|
|
180
|
+
changed2 = true;
|
|
192
181
|
}
|
|
193
|
-
|
|
194
|
-
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
195
184
|
}
|
|
196
185
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const parsedStyle = parseInlineStyle(attribs.style);
|
|
208
|
-
if (parsedStyle === null) {
|
|
209
|
-
$element.removeAttr("style");
|
|
210
|
-
return done();
|
|
211
|
-
}
|
|
212
|
-
const propsQueue = Object.keys(parsedStyle);
|
|
213
|
-
let changed = false;
|
|
214
|
-
const parsedProps = () => {
|
|
215
|
-
if (changed) {
|
|
216
|
-
const newStyle = Object.keys(parsedStyle).map((key) => key + ":" + parsedStyle[key] + ";").join("");
|
|
217
|
-
if (!newStyle.length) {
|
|
218
|
-
$element.removeAttr("style");
|
|
219
|
-
} else {
|
|
220
|
-
$element.attr("style", newStyle);
|
|
186
|
+
if (changed2) {
|
|
187
|
+
const tree = tokensTree(
|
|
188
|
+
newTokens.filter((token) => token !== null)
|
|
189
|
+
);
|
|
190
|
+
if (!tree.length) {
|
|
191
|
+
$element.remove();
|
|
192
|
+
} else {
|
|
193
|
+
const newContent = tokensToString(tree);
|
|
194
|
+
item.$element.text("\n" + newContent);
|
|
195
|
+
}
|
|
221
196
|
}
|
|
222
197
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
198
|
+
if (tagName === "style") {
|
|
199
|
+
parseStyleItem();
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const attribs = item.element.attribs;
|
|
203
|
+
if (attribs.style === void 0) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const parsedStyle = parseInlineStyle(attribs.style);
|
|
207
|
+
if (parsedStyle === null) {
|
|
208
|
+
$element.removeAttr("style");
|
|
209
|
+
return;
|
|
229
210
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
211
|
+
let changed = false;
|
|
212
|
+
for (const prop in parsedStyle) {
|
|
213
|
+
const value = parsedStyle[prop];
|
|
214
|
+
const result = callback({
|
|
233
215
|
type: "inline",
|
|
234
216
|
prop,
|
|
235
217
|
value,
|
|
236
218
|
item
|
|
237
|
-
}
|
|
238
|
-
(result)
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
219
|
+
});
|
|
220
|
+
assertNotOldCode(result);
|
|
221
|
+
if (result !== value) {
|
|
222
|
+
changed = true;
|
|
223
|
+
if (result === void 0) {
|
|
224
|
+
delete parsedStyle[prop];
|
|
225
|
+
} else {
|
|
226
|
+
parsedStyle[prop] = result;
|
|
246
227
|
}
|
|
247
|
-
nextProp();
|
|
248
|
-
}
|
|
249
|
-
);
|
|
250
|
-
};
|
|
251
|
-
nextProp();
|
|
252
|
-
}
|
|
253
|
-
async function parseSVGStyle(svg, callback) {
|
|
254
|
-
return parseSVG(svg, (item) => {
|
|
255
|
-
return new Promise((fulfill, reject) => {
|
|
256
|
-
try {
|
|
257
|
-
parseItem(
|
|
258
|
-
item,
|
|
259
|
-
(styleItem, done) => {
|
|
260
|
-
try {
|
|
261
|
-
const result = callback(styleItem);
|
|
262
|
-
if (result instanceof Promise) {
|
|
263
|
-
result.then(done).catch(reject);
|
|
264
|
-
} else {
|
|
265
|
-
done(result);
|
|
266
|
-
}
|
|
267
|
-
} catch (err) {
|
|
268
|
-
reject(err);
|
|
269
|
-
}
|
|
270
|
-
},
|
|
271
|
-
fulfill
|
|
272
|
-
);
|
|
273
|
-
} catch (err) {
|
|
274
|
-
reject(err);
|
|
275
228
|
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
item,
|
|
284
|
-
(styleItem, done) => {
|
|
285
|
-
done(callback(styleItem));
|
|
286
|
-
},
|
|
287
|
-
() => {
|
|
288
|
-
if (!isSync) {
|
|
289
|
-
throw new Error("parseSVGStyleSync callback was async");
|
|
290
|
-
}
|
|
229
|
+
}
|
|
230
|
+
if (changed) {
|
|
231
|
+
const newStyle = Object.keys(parsedStyle).map((key) => key + ":" + parsedStyle[key] + ";").join("");
|
|
232
|
+
if (!newStyle.length) {
|
|
233
|
+
$element.removeAttr("style");
|
|
234
|
+
} else {
|
|
235
|
+
$element.attr("style", newStyle);
|
|
291
236
|
}
|
|
292
|
-
|
|
237
|
+
}
|
|
293
238
|
});
|
|
294
|
-
isSync = false;
|
|
295
239
|
}
|
|
296
240
|
|
|
297
|
-
export { parseSVGStyle
|
|
241
|
+
export { parseSVGStyle };
|
package/lib/svg/parse.cjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
function
|
|
4
|
-
|
|
3
|
+
function parseSVG(svg, callback) {
|
|
4
|
+
const cheerio = svg.$svg;
|
|
5
|
+
const $root = svg.$svg(":root");
|
|
6
|
+
function checkNode(element, parents) {
|
|
5
7
|
if (element.type !== "tag") {
|
|
6
|
-
return
|
|
8
|
+
return;
|
|
7
9
|
}
|
|
8
|
-
const $element =
|
|
10
|
+
const $element = cheerio(element);
|
|
9
11
|
const tagName = element.tagName;
|
|
10
12
|
const item = {
|
|
11
13
|
tagName,
|
|
@@ -16,63 +18,29 @@ function parse(svg, callback, done) {
|
|
|
16
18
|
testChildren: true,
|
|
17
19
|
removeNode: false
|
|
18
20
|
};
|
|
19
|
-
callback(item
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
checkNode(queueItem, newParents, next);
|
|
36
|
-
};
|
|
37
|
-
next();
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
const cheerio2 = svg.$svg;
|
|
41
|
-
const $root = svg.$svg(":root");
|
|
42
|
-
checkNode($root.get(0), [], done);
|
|
43
|
-
}
|
|
44
|
-
function parseSVG(svg, callback) {
|
|
45
|
-
return new Promise((fulfill, reject) => {
|
|
46
|
-
parse(
|
|
47
|
-
svg,
|
|
48
|
-
(item, next) => {
|
|
49
|
-
const result = callback(item);
|
|
50
|
-
if (result instanceof Promise) {
|
|
51
|
-
result.then(next).catch(reject);
|
|
52
|
-
} else {
|
|
53
|
-
next();
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
fulfill
|
|
57
|
-
);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
function parseSVGSync(svg, callback) {
|
|
61
|
-
let isSync = true;
|
|
62
|
-
parse(
|
|
63
|
-
svg,
|
|
64
|
-
(item, next) => {
|
|
65
|
-
callback(item);
|
|
66
|
-
next();
|
|
67
|
-
},
|
|
68
|
-
() => {
|
|
69
|
-
if (!isSync) {
|
|
70
|
-
throw new Error("parseSVGSync callback was async");
|
|
21
|
+
const callbackResult = callback(item);
|
|
22
|
+
if (callbackResult instanceof Promise) {
|
|
23
|
+
throw new Error("parseSVG does not support async callbacks");
|
|
24
|
+
}
|
|
25
|
+
const newParents = parents.slice(0);
|
|
26
|
+
newParents.unshift(item);
|
|
27
|
+
let queue = [];
|
|
28
|
+
if (tagName !== "style" && item.testChildren && !item.removeNode) {
|
|
29
|
+
const children = $element.children().toArray();
|
|
30
|
+
queue = children.slice(0);
|
|
31
|
+
}
|
|
32
|
+
while (queue.length) {
|
|
33
|
+
const queueItem = queue.shift();
|
|
34
|
+
if (!queueItem || item.removeNode) {
|
|
35
|
+
break;
|
|
71
36
|
}
|
|
37
|
+
checkNode(queueItem, newParents);
|
|
38
|
+
}
|
|
39
|
+
if (item.removeNode) {
|
|
40
|
+
$element.remove();
|
|
72
41
|
}
|
|
73
|
-
|
|
74
|
-
|
|
42
|
+
}
|
|
43
|
+
checkNode($root.get(0), []);
|
|
75
44
|
}
|
|
76
45
|
|
|
77
46
|
exports.parseSVG = parseSVG;
|
|
78
|
-
exports.parseSVGSync = parseSVGSync;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CheerioElement, WrappedCheerioElement } from '../misc/cheerio.cjs';
|
|
2
|
+
import { SVG } from './index.cjs';
|
|
3
|
+
import 'cheerio';
|
|
4
|
+
import '@iconify/types';
|
|
5
|
+
import '@iconify/utils/lib/customisations/defaults';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Item in callback
|
|
9
|
+
*/
|
|
10
|
+
interface ParseSVGCallbackItem {
|
|
11
|
+
tagName: string;
|
|
12
|
+
element: CheerioElement;
|
|
13
|
+
$element: WrappedCheerioElement;
|
|
14
|
+
svg: SVG;
|
|
15
|
+
parents: ParseSVGCallbackItem[];
|
|
16
|
+
testChildren: boolean;
|
|
17
|
+
removeNode: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Callback function
|
|
21
|
+
*/
|
|
22
|
+
type ParseSVGCallback = (item: ParseSVGCallbackItem) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Parse SVG
|
|
25
|
+
*
|
|
26
|
+
* This function finds all elements in SVG and calls callback for each element.
|
|
27
|
+
*/
|
|
28
|
+
declare function parseSVG(svg: SVG, callback: ParseSVGCallback): void;
|
|
29
|
+
|
|
30
|
+
export { type ParseSVGCallback, type ParseSVGCallbackItem, parseSVG };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CheerioElement, WrappedCheerioElement } from '../misc/cheerio.mjs';
|
|
2
|
+
import { SVG } from './index.mjs';
|
|
3
|
+
import 'cheerio';
|
|
4
|
+
import '@iconify/types';
|
|
5
|
+
import '@iconify/utils/lib/customisations/defaults';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Item in callback
|
|
9
|
+
*/
|
|
10
|
+
interface ParseSVGCallbackItem {
|
|
11
|
+
tagName: string;
|
|
12
|
+
element: CheerioElement;
|
|
13
|
+
$element: WrappedCheerioElement;
|
|
14
|
+
svg: SVG;
|
|
15
|
+
parents: ParseSVGCallbackItem[];
|
|
16
|
+
testChildren: boolean;
|
|
17
|
+
removeNode: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Callback function
|
|
21
|
+
*/
|
|
22
|
+
type ParseSVGCallback = (item: ParseSVGCallbackItem) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Parse SVG
|
|
25
|
+
*
|
|
26
|
+
* This function finds all elements in SVG and calls callback for each element.
|
|
27
|
+
*/
|
|
28
|
+
declare function parseSVG(svg: SVG, callback: ParseSVGCallback): void;
|
|
29
|
+
|
|
30
|
+
export { type ParseSVGCallback, type ParseSVGCallbackItem, parseSVG };
|
package/lib/svg/parse.d.ts
CHANGED
|
@@ -19,19 +19,12 @@ interface ParseSVGCallbackItem {
|
|
|
19
19
|
/**
|
|
20
20
|
* Callback function
|
|
21
21
|
*/
|
|
22
|
-
type
|
|
23
|
-
type ParseSVGCallback = Callback<void | Promise<void>>;
|
|
24
|
-
type ParseSVGCallbackSync = Callback<void>;
|
|
22
|
+
type ParseSVGCallback = (item: ParseSVGCallbackItem) => void;
|
|
25
23
|
/**
|
|
26
24
|
* Parse SVG
|
|
27
25
|
*
|
|
28
26
|
* This function finds all elements in SVG and calls callback for each element.
|
|
29
|
-
* Callback can be asynchronous.
|
|
30
27
|
*/
|
|
31
|
-
declare function parseSVG(svg: SVG, callback: ParseSVGCallback):
|
|
32
|
-
/**
|
|
33
|
-
* Sync version
|
|
34
|
-
*/
|
|
35
|
-
declare function parseSVGSync(svg: SVG, callback: ParseSVGCallbackSync): void;
|
|
28
|
+
declare function parseSVG(svg: SVG, callback: ParseSVGCallback): void;
|
|
36
29
|
|
|
37
|
-
export { ParseSVGCallback, ParseSVGCallbackItem,
|
|
30
|
+
export { type ParseSVGCallback, type ParseSVGCallbackItem, parseSVG };
|