@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.cjs
CHANGED
|
@@ -9,156 +9,147 @@ require('../css/parser/error.cjs');
|
|
|
9
9
|
require('../css/parser/strings.cjs');
|
|
10
10
|
require('../css/parser/text.cjs');
|
|
11
11
|
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const selectorStart = [];
|
|
27
|
-
let newTokens = [];
|
|
28
|
-
const parsedTokens = () => {
|
|
29
|
-
if (changed2) {
|
|
30
|
-
const tree = css_parser_tree.tokensTree(
|
|
31
|
-
newTokens.filter((token) => token !== null)
|
|
32
|
-
);
|
|
33
|
-
if (!tree.length) {
|
|
34
|
-
$element.remove();
|
|
35
|
-
} else {
|
|
36
|
-
const newContent = css_parser_export.tokensToString(tree);
|
|
37
|
-
item.$element.text("\n" + newContent);
|
|
38
|
-
}
|
|
12
|
+
function assertNotOldCode(value) {
|
|
13
|
+
if (value instanceof Promise) {
|
|
14
|
+
throw new Error("parseSVGStyle does not support async callbacks");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function parseSVGStyle(svg, callback) {
|
|
18
|
+
svg_parse.parseSVG(svg, (item) => {
|
|
19
|
+
const tagName = item.tagName;
|
|
20
|
+
const $element = item.$element;
|
|
21
|
+
function parseStyleItem() {
|
|
22
|
+
const content = $element.text();
|
|
23
|
+
if (typeof content !== "string") {
|
|
24
|
+
$element.remove();
|
|
25
|
+
return;
|
|
39
26
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const token = tokens.shift();
|
|
44
|
-
if (token === void 0) {
|
|
45
|
-
return parsedTokens();
|
|
27
|
+
const tokens = css_parser_tokens.getTokens(content);
|
|
28
|
+
if (!(tokens instanceof Array)) {
|
|
29
|
+
throw new Error("Error parsing style");
|
|
46
30
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
31
|
+
let changed2 = false;
|
|
32
|
+
const selectorStart = [];
|
|
33
|
+
let newTokens = [];
|
|
34
|
+
while (tokens.length) {
|
|
35
|
+
const token = tokens.shift();
|
|
36
|
+
if (!token) {
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
switch (token.type) {
|
|
40
|
+
case "selector":
|
|
41
|
+
selectorStart.push(newTokens.length);
|
|
42
|
+
newTokens.push(token);
|
|
43
|
+
break;
|
|
44
|
+
case "close":
|
|
45
|
+
selectorStart.pop();
|
|
46
|
+
newTokens.push(token);
|
|
47
|
+
break;
|
|
48
|
+
case "at-rule": {
|
|
49
|
+
selectorStart.push(newTokens.length);
|
|
50
|
+
const prop = token.rule;
|
|
51
|
+
const value = token.value;
|
|
52
|
+
const isAnimation = prop === "keyframes" || prop.slice(0, 1) === "-" && prop.split("-").pop() === "keyframes";
|
|
53
|
+
const childTokens = [];
|
|
54
|
+
const animationRules = /* @__PURE__ */ Object.create(null);
|
|
55
|
+
let depth = 1;
|
|
56
|
+
let index = 0;
|
|
57
|
+
let isFrom = false;
|
|
58
|
+
while (depth > 0) {
|
|
59
|
+
const childToken = tokens[index];
|
|
60
|
+
index++;
|
|
61
|
+
if (!childToken) {
|
|
62
|
+
throw new Error(
|
|
63
|
+
"Something went wrong parsing CSS"
|
|
64
|
+
);
|
|
78
65
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
66
|
+
childTokens.push(childToken);
|
|
67
|
+
switch (childToken.type) {
|
|
68
|
+
case "close": {
|
|
69
|
+
depth--;
|
|
70
|
+
isFrom = false;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
case "selector": {
|
|
74
|
+
depth++;
|
|
75
|
+
if (isAnimation) {
|
|
76
|
+
const rule = childToken.code;
|
|
77
|
+
if (rule === "from" || rule === "0%") {
|
|
78
|
+
isFrom = true;
|
|
79
|
+
}
|
|
85
80
|
}
|
|
81
|
+
break;
|
|
86
82
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
83
|
+
case "at-rule": {
|
|
84
|
+
depth++;
|
|
85
|
+
if (isAnimation) {
|
|
86
|
+
throw new Error(
|
|
87
|
+
"Nested at-rule in keyframes ???"
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
break;
|
|
95
91
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
92
|
+
case "rule": {
|
|
93
|
+
if (isAnimation && isFrom) {
|
|
94
|
+
animationRules[childToken.prop] = childToken.value;
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
101
97
|
}
|
|
102
|
-
break;
|
|
103
98
|
}
|
|
104
99
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
(result)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
newTokens.push(token);
|
|
134
|
-
for (let i = 0; i < skipCount; i++) {
|
|
135
|
-
tokens.shift();
|
|
136
|
-
}
|
|
137
|
-
newTokens = newTokens.concat(childTokens);
|
|
138
|
-
} else {
|
|
139
|
-
if (result !== value) {
|
|
140
|
-
throw new Error(
|
|
141
|
-
"Changing value for at-rule is not supported"
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
newTokens.push(token);
|
|
100
|
+
const skipCount = childTokens.length;
|
|
101
|
+
const result = callback(
|
|
102
|
+
isAnimation ? {
|
|
103
|
+
type: "keyframes",
|
|
104
|
+
prop,
|
|
105
|
+
value,
|
|
106
|
+
token,
|
|
107
|
+
childTokens,
|
|
108
|
+
from: animationRules,
|
|
109
|
+
prevTokens: newTokens,
|
|
110
|
+
nextTokens: tokens.slice(0)
|
|
111
|
+
} : {
|
|
112
|
+
type: "at-rule",
|
|
113
|
+
prop,
|
|
114
|
+
value,
|
|
115
|
+
token,
|
|
116
|
+
childTokens,
|
|
117
|
+
prevTokens: newTokens,
|
|
118
|
+
nextTokens: tokens.slice(0)
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
if (result !== void 0) {
|
|
122
|
+
assertNotOldCode(result);
|
|
123
|
+
if (isAnimation) {
|
|
124
|
+
if (result !== value) {
|
|
125
|
+
changed2 = true;
|
|
126
|
+
token.value = result;
|
|
145
127
|
}
|
|
146
|
-
|
|
147
|
-
changed2 = true;
|
|
128
|
+
newTokens.push(token);
|
|
148
129
|
for (let i = 0; i < skipCount; i++) {
|
|
149
130
|
tokens.shift();
|
|
150
131
|
}
|
|
132
|
+
newTokens = newTokens.concat(childTokens);
|
|
133
|
+
} else {
|
|
134
|
+
if (result !== value) {
|
|
135
|
+
throw new Error(
|
|
136
|
+
"Changing value for at-rule is not supported"
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
newTokens.push(token);
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
changed2 = true;
|
|
143
|
+
for (let i = 0; i < skipCount; i++) {
|
|
144
|
+
tokens.shift();
|
|
151
145
|
}
|
|
152
|
-
nextToken();
|
|
153
146
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
callback(
|
|
161
|
-
{
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
case "rule": {
|
|
150
|
+
const value = token.value;
|
|
151
|
+
const selectorTokens = selectorStart.map((index) => newTokens[index]).filter((item2) => item2 !== null);
|
|
152
|
+
const result = callback({
|
|
162
153
|
type: "global",
|
|
163
154
|
prop: token.prop,
|
|
164
155
|
value,
|
|
@@ -179,122 +170,74 @@ function parseItem(item, callback, done) {
|
|
|
179
170
|
),
|
|
180
171
|
prevTokens: newTokens,
|
|
181
172
|
nextTokens: tokens.slice(0)
|
|
182
|
-
}
|
|
183
|
-
(result)
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
changed2 = true;
|
|
187
|
-
token.value = result;
|
|
188
|
-
}
|
|
189
|
-
newTokens.push(token);
|
|
190
|
-
} else {
|
|
173
|
+
});
|
|
174
|
+
if (result !== void 0) {
|
|
175
|
+
assertNotOldCode(result);
|
|
176
|
+
if (result !== value) {
|
|
191
177
|
changed2 = true;
|
|
178
|
+
token.value = result;
|
|
192
179
|
}
|
|
193
|
-
|
|
180
|
+
newTokens.push(token);
|
|
181
|
+
} else {
|
|
182
|
+
changed2 = true;
|
|
194
183
|
}
|
|
195
|
-
|
|
196
|
-
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
197
186
|
}
|
|
198
187
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
const parsedStyle = css_parse.parseInlineStyle(attribs.style);
|
|
210
|
-
if (parsedStyle === null) {
|
|
211
|
-
$element.removeAttr("style");
|
|
212
|
-
return done();
|
|
213
|
-
}
|
|
214
|
-
const propsQueue = Object.keys(parsedStyle);
|
|
215
|
-
let changed = false;
|
|
216
|
-
const parsedProps = () => {
|
|
217
|
-
if (changed) {
|
|
218
|
-
const newStyle = Object.keys(parsedStyle).map((key) => key + ":" + parsedStyle[key] + ";").join("");
|
|
219
|
-
if (!newStyle.length) {
|
|
220
|
-
$element.removeAttr("style");
|
|
221
|
-
} else {
|
|
222
|
-
$element.attr("style", newStyle);
|
|
188
|
+
if (changed2) {
|
|
189
|
+
const tree = css_parser_tree.tokensTree(
|
|
190
|
+
newTokens.filter((token) => token !== null)
|
|
191
|
+
);
|
|
192
|
+
if (!tree.length) {
|
|
193
|
+
$element.remove();
|
|
194
|
+
} else {
|
|
195
|
+
const newContent = css_parser_export.tokensToString(tree);
|
|
196
|
+
item.$element.text("\n" + newContent);
|
|
197
|
+
}
|
|
223
198
|
}
|
|
224
199
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
200
|
+
if (tagName === "style") {
|
|
201
|
+
parseStyleItem();
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const attribs = item.element.attribs;
|
|
205
|
+
if (attribs.style === void 0) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const parsedStyle = css_parse.parseInlineStyle(attribs.style);
|
|
209
|
+
if (parsedStyle === null) {
|
|
210
|
+
$element.removeAttr("style");
|
|
211
|
+
return;
|
|
231
212
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
213
|
+
let changed = false;
|
|
214
|
+
for (const prop in parsedStyle) {
|
|
215
|
+
const value = parsedStyle[prop];
|
|
216
|
+
const result = callback({
|
|
235
217
|
type: "inline",
|
|
236
218
|
prop,
|
|
237
219
|
value,
|
|
238
220
|
item
|
|
239
|
-
}
|
|
240
|
-
(result)
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
}
|
|
221
|
+
});
|
|
222
|
+
assertNotOldCode(result);
|
|
223
|
+
if (result !== value) {
|
|
224
|
+
changed = true;
|
|
225
|
+
if (result === void 0) {
|
|
226
|
+
delete parsedStyle[prop];
|
|
227
|
+
} else {
|
|
228
|
+
parsedStyle[prop] = result;
|
|
248
229
|
}
|
|
249
|
-
nextProp();
|
|
250
|
-
}
|
|
251
|
-
);
|
|
252
|
-
};
|
|
253
|
-
nextProp();
|
|
254
|
-
}
|
|
255
|
-
async function parseSVGStyle(svg, callback) {
|
|
256
|
-
return svg_parse.parseSVG(svg, (item) => {
|
|
257
|
-
return new Promise((fulfill, reject) => {
|
|
258
|
-
try {
|
|
259
|
-
parseItem(
|
|
260
|
-
item,
|
|
261
|
-
(styleItem, done) => {
|
|
262
|
-
try {
|
|
263
|
-
const result = callback(styleItem);
|
|
264
|
-
if (result instanceof Promise) {
|
|
265
|
-
result.then(done).catch(reject);
|
|
266
|
-
} else {
|
|
267
|
-
done(result);
|
|
268
|
-
}
|
|
269
|
-
} catch (err) {
|
|
270
|
-
reject(err);
|
|
271
|
-
}
|
|
272
|
-
},
|
|
273
|
-
fulfill
|
|
274
|
-
);
|
|
275
|
-
} catch (err) {
|
|
276
|
-
reject(err);
|
|
277
230
|
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
item,
|
|
286
|
-
(styleItem, done) => {
|
|
287
|
-
done(callback(styleItem));
|
|
288
|
-
},
|
|
289
|
-
() => {
|
|
290
|
-
if (!isSync) {
|
|
291
|
-
throw new Error("parseSVGStyleSync callback was async");
|
|
292
|
-
}
|
|
231
|
+
}
|
|
232
|
+
if (changed) {
|
|
233
|
+
const newStyle = Object.keys(parsedStyle).map((key) => key + ":" + parsedStyle[key] + ";").join("");
|
|
234
|
+
if (!newStyle.length) {
|
|
235
|
+
$element.removeAttr("style");
|
|
236
|
+
} else {
|
|
237
|
+
$element.attr("style", newStyle);
|
|
293
238
|
}
|
|
294
|
-
|
|
239
|
+
}
|
|
295
240
|
});
|
|
296
|
-
isSync = false;
|
|
297
241
|
}
|
|
298
242
|
|
|
299
243
|
exports.parseSVGStyle = parseSVGStyle;
|
|
300
|
-
exports.parseSVGStyleSync = parseSVGStyleSync;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { SVG } from './index.cjs';
|
|
2
|
+
import { CSSRuleToken, CSSToken, CSSAtRuleToken } from '../css/parser/types.cjs';
|
|
3
|
+
import { ParseSVGCallbackItem } from './parse.cjs';
|
|
4
|
+
import 'cheerio';
|
|
5
|
+
import '@iconify/types';
|
|
6
|
+
import '@iconify/utils/lib/customisations/defaults';
|
|
7
|
+
import '../misc/cheerio.cjs';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Item in callback
|
|
11
|
+
*/
|
|
12
|
+
interface ParseSVGStyleCallbackItemCommon {
|
|
13
|
+
prop: string;
|
|
14
|
+
value: string;
|
|
15
|
+
}
|
|
16
|
+
interface ParseSVGStyleCallbackItemInline extends ParseSVGStyleCallbackItemCommon {
|
|
17
|
+
type: 'inline';
|
|
18
|
+
item: ParseSVGCallbackItem;
|
|
19
|
+
}
|
|
20
|
+
interface ParseSVGStyleCallbackItemGlobal extends ParseSVGStyleCallbackItemCommon {
|
|
21
|
+
type: 'global';
|
|
22
|
+
token: CSSRuleToken;
|
|
23
|
+
selectors: string[];
|
|
24
|
+
selectorTokens: CSSToken[];
|
|
25
|
+
prevTokens: (CSSToken | null)[];
|
|
26
|
+
nextTokens: CSSToken[];
|
|
27
|
+
}
|
|
28
|
+
interface ParseSVGStyleCallbackItemGlobalAtRule extends ParseSVGStyleCallbackItemCommon {
|
|
29
|
+
token: CSSAtRuleToken;
|
|
30
|
+
childTokens: CSSToken[];
|
|
31
|
+
prevTokens: (CSSToken | null)[];
|
|
32
|
+
nextTokens: CSSToken[];
|
|
33
|
+
}
|
|
34
|
+
interface ParseSVGStyleCallbackItemGlobalGenericAtRule extends ParseSVGStyleCallbackItemGlobalAtRule {
|
|
35
|
+
type: 'at-rule';
|
|
36
|
+
}
|
|
37
|
+
interface ParseSVGStyleCallbackItemGlobalKeyframesAtRule extends ParseSVGStyleCallbackItemGlobalAtRule {
|
|
38
|
+
type: 'keyframes';
|
|
39
|
+
from: Record<string, string>;
|
|
40
|
+
}
|
|
41
|
+
type ParseSVGStyleCallbackItem = ParseSVGStyleCallbackItemInline | ParseSVGStyleCallbackItemGlobal | ParseSVGStyleCallbackItemGlobalGenericAtRule | ParseSVGStyleCallbackItemGlobalKeyframesAtRule;
|
|
42
|
+
/**
|
|
43
|
+
* Result: undefined to remove item, string to change/keep item
|
|
44
|
+
*/
|
|
45
|
+
type ParseSVGStyleCallbackResult = string | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Callback function
|
|
48
|
+
*/
|
|
49
|
+
type ParseSVGStyleCallback = (item: ParseSVGStyleCallbackItem) => ParseSVGStyleCallbackResult;
|
|
50
|
+
/**
|
|
51
|
+
* Parse styles in SVG
|
|
52
|
+
*
|
|
53
|
+
* This function finds CSS in SVG, parses it, calls callback for each rule.
|
|
54
|
+
* Callback should return new value (string) or undefined to remove rule.
|
|
55
|
+
*/
|
|
56
|
+
declare function parseSVGStyle(svg: SVG, callback: ParseSVGStyleCallback): void;
|
|
57
|
+
|
|
58
|
+
export { type ParseSVGStyleCallback, type ParseSVGStyleCallbackItem, type ParseSVGStyleCallbackResult, parseSVGStyle };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { SVG } from './index.mjs';
|
|
2
|
+
import { CSSRuleToken, CSSToken, CSSAtRuleToken } from '../css/parser/types.mjs';
|
|
3
|
+
import { ParseSVGCallbackItem } from './parse.mjs';
|
|
4
|
+
import 'cheerio';
|
|
5
|
+
import '@iconify/types';
|
|
6
|
+
import '@iconify/utils/lib/customisations/defaults';
|
|
7
|
+
import '../misc/cheerio.mjs';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Item in callback
|
|
11
|
+
*/
|
|
12
|
+
interface ParseSVGStyleCallbackItemCommon {
|
|
13
|
+
prop: string;
|
|
14
|
+
value: string;
|
|
15
|
+
}
|
|
16
|
+
interface ParseSVGStyleCallbackItemInline extends ParseSVGStyleCallbackItemCommon {
|
|
17
|
+
type: 'inline';
|
|
18
|
+
item: ParseSVGCallbackItem;
|
|
19
|
+
}
|
|
20
|
+
interface ParseSVGStyleCallbackItemGlobal extends ParseSVGStyleCallbackItemCommon {
|
|
21
|
+
type: 'global';
|
|
22
|
+
token: CSSRuleToken;
|
|
23
|
+
selectors: string[];
|
|
24
|
+
selectorTokens: CSSToken[];
|
|
25
|
+
prevTokens: (CSSToken | null)[];
|
|
26
|
+
nextTokens: CSSToken[];
|
|
27
|
+
}
|
|
28
|
+
interface ParseSVGStyleCallbackItemGlobalAtRule extends ParseSVGStyleCallbackItemCommon {
|
|
29
|
+
token: CSSAtRuleToken;
|
|
30
|
+
childTokens: CSSToken[];
|
|
31
|
+
prevTokens: (CSSToken | null)[];
|
|
32
|
+
nextTokens: CSSToken[];
|
|
33
|
+
}
|
|
34
|
+
interface ParseSVGStyleCallbackItemGlobalGenericAtRule extends ParseSVGStyleCallbackItemGlobalAtRule {
|
|
35
|
+
type: 'at-rule';
|
|
36
|
+
}
|
|
37
|
+
interface ParseSVGStyleCallbackItemGlobalKeyframesAtRule extends ParseSVGStyleCallbackItemGlobalAtRule {
|
|
38
|
+
type: 'keyframes';
|
|
39
|
+
from: Record<string, string>;
|
|
40
|
+
}
|
|
41
|
+
type ParseSVGStyleCallbackItem = ParseSVGStyleCallbackItemInline | ParseSVGStyleCallbackItemGlobal | ParseSVGStyleCallbackItemGlobalGenericAtRule | ParseSVGStyleCallbackItemGlobalKeyframesAtRule;
|
|
42
|
+
/**
|
|
43
|
+
* Result: undefined to remove item, string to change/keep item
|
|
44
|
+
*/
|
|
45
|
+
type ParseSVGStyleCallbackResult = string | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Callback function
|
|
48
|
+
*/
|
|
49
|
+
type ParseSVGStyleCallback = (item: ParseSVGStyleCallbackItem) => ParseSVGStyleCallbackResult;
|
|
50
|
+
/**
|
|
51
|
+
* Parse styles in SVG
|
|
52
|
+
*
|
|
53
|
+
* This function finds CSS in SVG, parses it, calls callback for each rule.
|
|
54
|
+
* Callback should return new value (string) or undefined to remove rule.
|
|
55
|
+
*/
|
|
56
|
+
declare function parseSVGStyle(svg: SVG, callback: ParseSVGStyleCallback): void;
|
|
57
|
+
|
|
58
|
+
export { type ParseSVGStyleCallback, type ParseSVGStyleCallbackItem, type ParseSVGStyleCallbackResult, parseSVGStyle };
|
package/lib/svg/parse-style.d.ts
CHANGED
|
@@ -46,19 +46,13 @@ type ParseSVGStyleCallbackResult = string | undefined;
|
|
|
46
46
|
/**
|
|
47
47
|
* Callback function
|
|
48
48
|
*/
|
|
49
|
-
type ParseSVGStyleCallback = (item: ParseSVGStyleCallbackItem) => ParseSVGStyleCallbackResult
|
|
50
|
-
type ParseSVGStyleCallbackSync = (item: ParseSVGStyleCallbackItem) => ParseSVGStyleCallbackResult;
|
|
49
|
+
type ParseSVGStyleCallback = (item: ParseSVGStyleCallbackItem) => ParseSVGStyleCallbackResult;
|
|
51
50
|
/**
|
|
52
51
|
* Parse styles in SVG
|
|
53
52
|
*
|
|
54
53
|
* This function finds CSS in SVG, parses it, calls callback for each rule.
|
|
55
54
|
* Callback should return new value (string) or undefined to remove rule.
|
|
56
|
-
* Callback can be asynchronous.
|
|
57
55
|
*/
|
|
58
|
-
declare function parseSVGStyle(svg: SVG, callback: ParseSVGStyleCallback):
|
|
59
|
-
/**
|
|
60
|
-
* Synchronous version
|
|
61
|
-
*/
|
|
62
|
-
declare function parseSVGStyleSync(svg: SVG, callback: ParseSVGStyleCallbackSync): void;
|
|
56
|
+
declare function parseSVGStyle(svg: SVG, callback: ParseSVGStyleCallback): void;
|
|
63
57
|
|
|
64
|
-
export { ParseSVGStyleCallback, ParseSVGStyleCallbackItem, ParseSVGStyleCallbackResult,
|
|
58
|
+
export { type ParseSVGStyleCallback, type ParseSVGStyleCallbackItem, type ParseSVGStyleCallbackResult, parseSVGStyle };
|