@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
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const commonColorAttributes = ["color"];
|
|
6
|
+
const shapeColorAttributes = ["fill", "stroke"];
|
|
7
|
+
const specialColorAttributes = [
|
|
8
|
+
"stop-color",
|
|
9
|
+
"flood-color"
|
|
10
|
+
];
|
|
11
|
+
const defaultBlackColor = {
|
|
12
|
+
type: "rgb",
|
|
13
|
+
r: 0,
|
|
14
|
+
g: 0,
|
|
15
|
+
b: 0,
|
|
16
|
+
alpha: 1
|
|
17
|
+
};
|
|
18
|
+
const defaultColorValues = {
|
|
19
|
+
"color": { type: "current" },
|
|
20
|
+
"fill": defaultBlackColor,
|
|
21
|
+
"stroke": { type: "none" },
|
|
22
|
+
"stop-color": defaultBlackColor,
|
|
23
|
+
"flood-color": defaultBlackColor
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
exports.commonColorAttributes = commonColorAttributes;
|
|
27
|
+
exports.defaultBlackColor = defaultBlackColor;
|
|
28
|
+
exports.defaultColorValues = defaultColorValues;
|
|
29
|
+
exports.shapeColorAttributes = shapeColorAttributes;
|
|
30
|
+
exports.specialColorAttributes = specialColorAttributes;
|
package/lib/colors/attribs.d.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Color } from '@iconify/utils/lib/colors/types';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Color attributes
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
declare type CommonColorAttributes = 'color';
|
|
7
|
+
declare const commonColorAttributes: CommonColorAttributes[];
|
|
8
|
+
declare type ShapeColorAttributes = 'fill' | 'stroke';
|
|
9
|
+
declare const shapeColorAttributes: ShapeColorAttributes[];
|
|
10
|
+
declare type SpecialColorAttributes = 'stop-color' | 'flood-color';
|
|
11
|
+
declare const specialColorAttributes: SpecialColorAttributes[];
|
|
12
|
+
declare type ColorAttributes = CommonColorAttributes | ShapeColorAttributes | SpecialColorAttributes;
|
|
12
13
|
/**
|
|
13
14
|
* Default values
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
declare const defaultBlackColor: Color;
|
|
17
|
+
declare const defaultColorValues: Record<ColorAttributes, Color>;
|
|
18
|
+
|
|
19
|
+
export { ColorAttributes, CommonColorAttributes, ShapeColorAttributes, SpecialColorAttributes, commonColorAttributes, defaultBlackColor, defaultColorValues, shapeColorAttributes, specialColorAttributes };
|
package/lib/colors/attribs.mjs
CHANGED
|
@@ -1,28 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var specialColorAttributes = [
|
|
1
|
+
const commonColorAttributes = ["color"];
|
|
2
|
+
const shapeColorAttributes = ["fill", "stroke"];
|
|
3
|
+
const specialColorAttributes = [
|
|
5
4
|
"stop-color",
|
|
6
5
|
"flood-color"
|
|
7
6
|
];
|
|
8
|
-
|
|
7
|
+
const defaultBlackColor = {
|
|
9
8
|
type: "rgb",
|
|
10
9
|
r: 0,
|
|
11
10
|
g: 0,
|
|
12
11
|
b: 0,
|
|
13
12
|
alpha: 1
|
|
14
13
|
};
|
|
15
|
-
|
|
14
|
+
const defaultColorValues = {
|
|
16
15
|
"color": { type: "current" },
|
|
17
16
|
"fill": defaultBlackColor,
|
|
18
17
|
"stroke": { type: "none" },
|
|
19
18
|
"stop-color": defaultBlackColor,
|
|
20
19
|
"flood-color": defaultBlackColor
|
|
21
20
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
defaultBlackColor,
|
|
25
|
-
defaultColorValues,
|
|
26
|
-
shapeColorAttributes,
|
|
27
|
-
specialColorAttributes
|
|
28
|
-
};
|
|
21
|
+
|
|
22
|
+
export { commonColorAttributes, defaultBlackColor, defaultColorValues, shapeColorAttributes, specialColorAttributes };
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const colors = require('@iconify/utils/lib/colors');
|
|
6
|
+
const svg_data_tags = require('../svg/data/tags.cjs');
|
|
7
|
+
const svg_parseStyle = require('../svg/parse-style.cjs');
|
|
8
|
+
const colors_attribs = require('./attribs.cjs');
|
|
9
|
+
const svg_data_attributes = require('../svg/data/attributes.cjs');
|
|
10
|
+
const svg_analyse = require('../svg/analyse.cjs');
|
|
11
|
+
require('../css/parse.cjs');
|
|
12
|
+
require('../css/parser/tokens.cjs');
|
|
13
|
+
require('../css/parser/error.cjs');
|
|
14
|
+
require('../css/parser/strings.cjs');
|
|
15
|
+
require('../css/parser/text.cjs');
|
|
16
|
+
require('../css/parser/export.cjs');
|
|
17
|
+
require('../css/parser/tree.cjs');
|
|
18
|
+
require('../svg/parse.cjs');
|
|
19
|
+
require('../svg/analyse/error.cjs');
|
|
20
|
+
|
|
21
|
+
const propsToCheck = Object.keys(colors_attribs.defaultColorValues);
|
|
22
|
+
const animatePropsToCheck = ["from", "to", "values"];
|
|
23
|
+
async function parseColors(svg, options = {}) {
|
|
24
|
+
const result = {
|
|
25
|
+
colors: [],
|
|
26
|
+
hasUnsetColor: false,
|
|
27
|
+
hasGlobalStyle: false
|
|
28
|
+
};
|
|
29
|
+
const defaultColor = typeof options.defaultColor === "string" ? colors.stringToColor(options.defaultColor) : options.defaultColor;
|
|
30
|
+
function findColor(color, add = false) {
|
|
31
|
+
const isString = typeof color === "string";
|
|
32
|
+
for (let i = 0; i < result.colors.length; i++) {
|
|
33
|
+
const item = result.colors[i];
|
|
34
|
+
if (item === color) {
|
|
35
|
+
return item;
|
|
36
|
+
}
|
|
37
|
+
if (!isString && typeof item !== "string" && colors.compareColors(item, color)) {
|
|
38
|
+
return item;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (add) {
|
|
42
|
+
result.colors.push(color);
|
|
43
|
+
return color;
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
function addColorToItem(prop, color, item, add = true) {
|
|
48
|
+
const addedColor = findColor(color, add !== false);
|
|
49
|
+
if (item) {
|
|
50
|
+
const itemColors = item._colors || (item._colors = {});
|
|
51
|
+
itemColors[prop] = addedColor === null ? color : addedColor;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function getElementColor(prop, item, elements2) {
|
|
55
|
+
function find(prop2) {
|
|
56
|
+
let currentItem = item;
|
|
57
|
+
while (currentItem) {
|
|
58
|
+
const element = elements2.get(currentItem.index);
|
|
59
|
+
const color = element._colors?.[prop2];
|
|
60
|
+
if (color !== void 0) {
|
|
61
|
+
return color;
|
|
62
|
+
}
|
|
63
|
+
currentItem = currentItem.parent;
|
|
64
|
+
if (currentItem?.usedAsMask) {
|
|
65
|
+
return colors_attribs.defaultColorValues[prop2];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return colors_attribs.defaultColorValues[prop2];
|
|
69
|
+
}
|
|
70
|
+
let propColor = find(prop);
|
|
71
|
+
if (typeof propColor === "object" && propColor.type === "current" && prop !== "color") {
|
|
72
|
+
propColor = find("color");
|
|
73
|
+
}
|
|
74
|
+
return propColor;
|
|
75
|
+
}
|
|
76
|
+
async function checkColor(prop, value, item) {
|
|
77
|
+
switch (value.trim().toLowerCase()) {
|
|
78
|
+
case "":
|
|
79
|
+
case "inherit":
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const parsedColor = colors.stringToColor(value);
|
|
83
|
+
const defaultValue = parsedColor || value;
|
|
84
|
+
if (parsedColor?.type === "function" && parsedColor.func === "url") {
|
|
85
|
+
addColorToItem(prop, defaultValue, item, false);
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
if (!options.callback) {
|
|
89
|
+
addColorToItem(prop, defaultValue, item);
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
let callbackResult = options.callback(prop, value, parsedColor, item?.tagName, item);
|
|
93
|
+
callbackResult = callbackResult instanceof Promise ? await callbackResult : callbackResult;
|
|
94
|
+
switch (callbackResult) {
|
|
95
|
+
case "remove": {
|
|
96
|
+
return item ? callbackResult : void 0;
|
|
97
|
+
}
|
|
98
|
+
case "unset":
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (callbackResult === value || parsedColor && callbackResult === parsedColor) {
|
|
102
|
+
addColorToItem(prop, defaultValue, item);
|
|
103
|
+
return value;
|
|
104
|
+
}
|
|
105
|
+
if (typeof callbackResult === "string") {
|
|
106
|
+
const newColor = colors.stringToColor(callbackResult);
|
|
107
|
+
addColorToItem(prop, newColor || callbackResult, item);
|
|
108
|
+
return callbackResult;
|
|
109
|
+
}
|
|
110
|
+
const newValue = colors.colorToString(callbackResult);
|
|
111
|
+
addColorToItem(prop, callbackResult, item);
|
|
112
|
+
return newValue;
|
|
113
|
+
}
|
|
114
|
+
await svg_parseStyle.parseSVGStyle(svg, async (item) => {
|
|
115
|
+
const prop = item.prop;
|
|
116
|
+
const value = item.value;
|
|
117
|
+
if (propsToCheck.indexOf(prop) === -1) {
|
|
118
|
+
return value;
|
|
119
|
+
}
|
|
120
|
+
const attr = prop;
|
|
121
|
+
const newValue = await checkColor(attr, value);
|
|
122
|
+
if (newValue === void 0) {
|
|
123
|
+
return newValue;
|
|
124
|
+
}
|
|
125
|
+
if (item.type === "global") {
|
|
126
|
+
result.hasGlobalStyle = true;
|
|
127
|
+
}
|
|
128
|
+
return newValue;
|
|
129
|
+
});
|
|
130
|
+
const iconData = await svg_analyse.analyseSVGStructure(svg, options);
|
|
131
|
+
const { elements, tree } = iconData;
|
|
132
|
+
const cheerio = svg.$svg;
|
|
133
|
+
const removedElements = /* @__PURE__ */ new Set();
|
|
134
|
+
const parsedElements = /* @__PURE__ */ new Set();
|
|
135
|
+
function removeElement(index, element) {
|
|
136
|
+
function removeChildren(element2) {
|
|
137
|
+
element2.children.forEach((item) => {
|
|
138
|
+
if (item.type !== "tag") {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const element3 = item;
|
|
142
|
+
const index2 = element3._index;
|
|
143
|
+
if (index2 && !removedElements.has(index2)) {
|
|
144
|
+
element3._removed = true;
|
|
145
|
+
removedElements.add(index2);
|
|
146
|
+
removeChildren(element3);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
element._removed = true;
|
|
151
|
+
removedElements.add(index);
|
|
152
|
+
removeChildren(element);
|
|
153
|
+
cheerio(element).remove();
|
|
154
|
+
}
|
|
155
|
+
async function parseTreeItem(item) {
|
|
156
|
+
const index = item.index;
|
|
157
|
+
if (removedElements.has(index) || parsedElements.has(index)) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
parsedElements.add(index);
|
|
161
|
+
const element = elements.get(index);
|
|
162
|
+
if (element._removed) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const { tagName, attribs } = element;
|
|
166
|
+
if (item.parent) {
|
|
167
|
+
const parentIndex = item.parent.index;
|
|
168
|
+
const parentElement = elements.get(parentIndex);
|
|
169
|
+
if (parentElement._colors) {
|
|
170
|
+
element._colors = {
|
|
171
|
+
...parentElement._colors
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
for (let i = 0; i < propsToCheck.length; i++) {
|
|
176
|
+
const prop = propsToCheck[i];
|
|
177
|
+
if (prop === "fill" && svg_data_tags.animateTags.has(tagName)) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
const value = attribs[prop];
|
|
181
|
+
if (value !== void 0) {
|
|
182
|
+
const newValue = await checkColor(prop, value, element);
|
|
183
|
+
if (newValue !== value) {
|
|
184
|
+
if (newValue === void 0) {
|
|
185
|
+
cheerio(element).removeAttr(prop);
|
|
186
|
+
if (element._colors) {
|
|
187
|
+
delete element._colors[prop];
|
|
188
|
+
}
|
|
189
|
+
} else if (newValue === "remove") {
|
|
190
|
+
removeElement(index, element);
|
|
191
|
+
return;
|
|
192
|
+
} else {
|
|
193
|
+
cheerio(element).attr(prop, newValue);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (svg_data_tags.animateTags.has(tagName)) {
|
|
199
|
+
const attr = attribs.attributeName;
|
|
200
|
+
if (propsToCheck.indexOf(attr) !== -1) {
|
|
201
|
+
for (let i = 0; i < animatePropsToCheck.length; i++) {
|
|
202
|
+
const elementProp = animatePropsToCheck[i];
|
|
203
|
+
const fullValue = attribs[elementProp];
|
|
204
|
+
if (typeof fullValue !== "string") {
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
const splitValues = fullValue.split(";");
|
|
208
|
+
let updatedValues = false;
|
|
209
|
+
for (let j = 0; j < splitValues.length; j++) {
|
|
210
|
+
const value = splitValues[j];
|
|
211
|
+
if (value !== void 0) {
|
|
212
|
+
const newValue = await checkColor(elementProp, value);
|
|
213
|
+
if (newValue !== value) {
|
|
214
|
+
updatedValues = true;
|
|
215
|
+
splitValues[j] = typeof newValue === "string" ? newValue : "";
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (updatedValues) {
|
|
220
|
+
cheerio(element).attr(elementProp, splitValues.join(";"));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (!result.hasGlobalStyle) {
|
|
226
|
+
let requiredProps;
|
|
227
|
+
if (svg_data_tags.shapeTags.has(tagName)) {
|
|
228
|
+
requiredProps = colors_attribs.shapeColorAttributes;
|
|
229
|
+
}
|
|
230
|
+
colors_attribs.specialColorAttributes.forEach((attr) => {
|
|
231
|
+
if (svg_data_attributes.tagSpecificPresentationalAttributes[tagName]?.has(attr)) {
|
|
232
|
+
requiredProps = [attr];
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
if (requiredProps) {
|
|
236
|
+
const itemColors = element._colors || (element._colors = {});
|
|
237
|
+
for (let i = 0; i < requiredProps.length; i++) {
|
|
238
|
+
const prop = requiredProps[i];
|
|
239
|
+
const color = getElementColor(prop, item, elements);
|
|
240
|
+
if (color === colors_attribs.defaultBlackColor) {
|
|
241
|
+
if (defaultColor) {
|
|
242
|
+
const defaultColorValue = typeof defaultColor === "function" ? defaultColor(prop, element, item, iconData) : defaultColor;
|
|
243
|
+
findColor(defaultColorValue, true);
|
|
244
|
+
cheerio(element).attr(prop, colors.colorToString(defaultColorValue));
|
|
245
|
+
itemColors[prop] = defaultColorValue;
|
|
246
|
+
} else {
|
|
247
|
+
result.hasUnsetColor = true;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
for (let i = 0; i < item.children.length; i++) {
|
|
254
|
+
const childItem = item.children[i];
|
|
255
|
+
if (!childItem.usedAsMask) {
|
|
256
|
+
await parseTreeItem(childItem);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
await parseTreeItem(tree);
|
|
261
|
+
return result;
|
|
262
|
+
}
|
|
263
|
+
function isEmptyColor(color) {
|
|
264
|
+
const type = color.type;
|
|
265
|
+
return type === "none" || type === "transparent";
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
exports.isEmptyColor = isEmptyColor;
|
|
269
|
+
exports.parseColors = parseColors;
|
package/lib/colors/parse.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { ColorAttributes } from './attribs';
|
|
4
|
-
import
|
|
1
|
+
import { Color } from '@iconify/utils/lib/colors/types';
|
|
2
|
+
import { SVG } from '../svg/index.js';
|
|
3
|
+
import { ColorAttributes } from './attribs.js';
|
|
4
|
+
import { ElementsTreeItem, AnalyseSVGStructureResult, AnalyseSVGStructureOptions, ExtendedTagElement } from '../svg/analyse/types.js';
|
|
5
|
+
import '@iconify/types';
|
|
6
|
+
import '@iconify/utils/lib/customisations';
|
|
7
|
+
|
|
5
8
|
/**
|
|
6
9
|
* Result
|
|
7
10
|
*/
|
|
8
|
-
|
|
11
|
+
interface FindColorsResult {
|
|
9
12
|
colors: (Color | string)[];
|
|
10
13
|
hasUnsetColor: boolean;
|
|
11
14
|
hasGlobalStyle: boolean;
|
|
@@ -24,11 +27,11 @@ declare type ParseColorsCallback = (attr: ColorAttributes, colorString: string,
|
|
|
24
27
|
/**
|
|
25
28
|
* Callback for default color
|
|
26
29
|
*/
|
|
27
|
-
|
|
30
|
+
declare type ParseColorOptionsDefaultColorCallback = (prop: string, item: ExtendedTagElementWithColors, treeItem: ElementsTreeItem, iconData: AnalyseSVGStructureResult) => Color;
|
|
28
31
|
/**
|
|
29
32
|
* Options
|
|
30
33
|
*/
|
|
31
|
-
|
|
34
|
+
interface ParseColorsOptions extends AnalyseSVGStructureOptions {
|
|
32
35
|
callback?: ParseColorsCallback;
|
|
33
36
|
defaultColor?: Color | string | ParseColorOptionsDefaultColorCallback;
|
|
34
37
|
}
|
|
@@ -36,7 +39,7 @@ export interface ParseColorsOptions extends AnalyseSVGStructureOptions {
|
|
|
36
39
|
* Extend properties for element
|
|
37
40
|
*/
|
|
38
41
|
declare type ItemColors = Partial<Record<ColorAttributes, Color | string>>;
|
|
39
|
-
|
|
42
|
+
interface ExtendedTagElementWithColors extends ExtendedTagElement {
|
|
40
43
|
_colors?: ItemColors;
|
|
41
44
|
_removed?: boolean;
|
|
42
45
|
}
|
|
@@ -46,9 +49,10 @@ export interface ExtendedTagElementWithColors extends ExtendedTagElement {
|
|
|
46
49
|
* Clean up icon before running this function to convert style to attributes using
|
|
47
50
|
* cleanupInlineStyle() or cleanupSVG(), otherwise results might be inaccurate
|
|
48
51
|
*/
|
|
49
|
-
|
|
52
|
+
declare function parseColors(svg: SVG, options?: ParseColorsOptions): Promise<FindColorsResult>;
|
|
50
53
|
/**
|
|
51
54
|
* Check if color is empty, such as 'none' or 'transparent'
|
|
52
55
|
*/
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
declare function isEmptyColor(color: Color): boolean;
|
|
57
|
+
|
|
58
|
+
export { ExtendedTagElementWithColors, FindColorsResult, ParseColorOptionsDefaultColorCallback, ParseColorsOptions, isEmptyColor, parseColors };
|
package/lib/colors/parse.mjs
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import { stringToColor, colorToString, compareColors } from '@iconify/utils/lib/colors';
|
|
2
|
+
import { animateTags, shapeTags } from '../svg/data/tags.mjs';
|
|
3
|
+
import { parseSVGStyle } from '../svg/parse-style.mjs';
|
|
4
|
+
import { specialColorAttributes, defaultBlackColor, defaultColorValues, shapeColorAttributes } from './attribs.mjs';
|
|
5
|
+
import { tagSpecificPresentationalAttributes } from '../svg/data/attributes.mjs';
|
|
6
|
+
import { analyseSVGStructure } from '../svg/analyse.mjs';
|
|
7
|
+
import '../css/parse.mjs';
|
|
8
|
+
import '../css/parser/tokens.mjs';
|
|
9
|
+
import '../css/parser/error.mjs';
|
|
10
|
+
import '../css/parser/strings.mjs';
|
|
11
|
+
import '../css/parser/text.mjs';
|
|
12
|
+
import '../css/parser/export.mjs';
|
|
13
|
+
import '../css/parser/tree.mjs';
|
|
14
|
+
import '../svg/parse.mjs';
|
|
15
|
+
import '../svg/analyse/error.mjs';
|
|
16
|
+
|
|
17
|
+
const propsToCheck = Object.keys(defaultColorValues);
|
|
18
|
+
const animatePropsToCheck = ["from", "to", "values"];
|
|
19
19
|
async function parseColors(svg, options = {}) {
|
|
20
20
|
const result = {
|
|
21
21
|
colors: [],
|
|
@@ -49,16 +49,15 @@ async function parseColors(svg, options = {}) {
|
|
|
49
49
|
}
|
|
50
50
|
function getElementColor(prop, item, elements2) {
|
|
51
51
|
function find(prop2) {
|
|
52
|
-
var _a;
|
|
53
52
|
let currentItem = item;
|
|
54
53
|
while (currentItem) {
|
|
55
54
|
const element = elements2.get(currentItem.index);
|
|
56
|
-
const color =
|
|
55
|
+
const color = element._colors?.[prop2];
|
|
57
56
|
if (color !== void 0) {
|
|
58
57
|
return color;
|
|
59
58
|
}
|
|
60
59
|
currentItem = currentItem.parent;
|
|
61
|
-
if (currentItem
|
|
60
|
+
if (currentItem?.usedAsMask) {
|
|
62
61
|
return defaultColorValues[prop2];
|
|
63
62
|
}
|
|
64
63
|
}
|
|
@@ -78,7 +77,7 @@ async function parseColors(svg, options = {}) {
|
|
|
78
77
|
}
|
|
79
78
|
const parsedColor = stringToColor(value);
|
|
80
79
|
const defaultValue = parsedColor || value;
|
|
81
|
-
if (
|
|
80
|
+
if (parsedColor?.type === "function" && parsedColor.func === "url") {
|
|
82
81
|
addColorToItem(prop, defaultValue, item, false);
|
|
83
82
|
return value;
|
|
84
83
|
}
|
|
@@ -86,7 +85,7 @@ async function parseColors(svg, options = {}) {
|
|
|
86
85
|
addColorToItem(prop, defaultValue, item);
|
|
87
86
|
return value;
|
|
88
87
|
}
|
|
89
|
-
let callbackResult = options.callback(prop, value, parsedColor, item
|
|
88
|
+
let callbackResult = options.callback(prop, value, parsedColor, item?.tagName, item);
|
|
90
89
|
callbackResult = callbackResult instanceof Promise ? await callbackResult : callbackResult;
|
|
91
90
|
switch (callbackResult) {
|
|
92
91
|
case "remove": {
|
|
@@ -127,8 +126,8 @@ async function parseColors(svg, options = {}) {
|
|
|
127
126
|
const iconData = await analyseSVGStructure(svg, options);
|
|
128
127
|
const { elements, tree } = iconData;
|
|
129
128
|
const cheerio = svg.$svg;
|
|
130
|
-
const removedElements = new Set();
|
|
131
|
-
const parsedElements = new Set();
|
|
129
|
+
const removedElements = /* @__PURE__ */ new Set();
|
|
130
|
+
const parsedElements = /* @__PURE__ */ new Set();
|
|
132
131
|
function removeElement(index, element) {
|
|
133
132
|
function removeChildren(element2) {
|
|
134
133
|
element2.children.forEach((item) => {
|
|
@@ -225,8 +224,7 @@ async function parseColors(svg, options = {}) {
|
|
|
225
224
|
requiredProps = shapeColorAttributes;
|
|
226
225
|
}
|
|
227
226
|
specialColorAttributes.forEach((attr) => {
|
|
228
|
-
|
|
229
|
-
if ((_a = tagSpecificPresentationalAttributes[tagName]) == null ? void 0 : _a.has(attr)) {
|
|
227
|
+
if (tagSpecificPresentationalAttributes[tagName]?.has(attr)) {
|
|
230
228
|
requiredProps = [attr];
|
|
231
229
|
}
|
|
232
230
|
});
|
|
@@ -262,7 +260,5 @@ function isEmptyColor(color) {
|
|
|
262
260
|
const type = color.type;
|
|
263
261
|
return type === "none" || type === "transparent";
|
|
264
262
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
parseColors
|
|
268
|
-
};
|
|
263
|
+
|
|
264
|
+
export { isEmptyColor, parseColors };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const colors = require('@iconify/utils/lib/colors');
|
|
6
|
+
const colors_parse = require('./parse.cjs');
|
|
7
|
+
require('../svg/data/tags.cjs');
|
|
8
|
+
require('../svg/parse-style.cjs');
|
|
9
|
+
require('../css/parse.cjs');
|
|
10
|
+
require('../css/parser/tokens.cjs');
|
|
11
|
+
require('../css/parser/error.cjs');
|
|
12
|
+
require('../css/parser/strings.cjs');
|
|
13
|
+
require('../css/parser/text.cjs');
|
|
14
|
+
require('../css/parser/export.cjs');
|
|
15
|
+
require('../css/parser/tree.cjs');
|
|
16
|
+
require('../svg/parse.cjs');
|
|
17
|
+
require('./attribs.cjs');
|
|
18
|
+
require('../svg/data/attributes.cjs');
|
|
19
|
+
require('../svg/analyse.cjs');
|
|
20
|
+
require('../svg/analyse/error.cjs');
|
|
21
|
+
|
|
22
|
+
async function validateColors(svg, expectMonotone, options) {
|
|
23
|
+
const palette = await colors_parse.parseColors(svg, options);
|
|
24
|
+
palette.colors.forEach((color) => {
|
|
25
|
+
if (typeof color === "string") {
|
|
26
|
+
throw new Error("Unexpected color: " + color);
|
|
27
|
+
}
|
|
28
|
+
switch (color.type) {
|
|
29
|
+
case "none":
|
|
30
|
+
case "transparent":
|
|
31
|
+
return;
|
|
32
|
+
case "current":
|
|
33
|
+
if (!expectMonotone) {
|
|
34
|
+
throw new Error("Unexpected color: " + colors.colorToString(color));
|
|
35
|
+
}
|
|
36
|
+
return;
|
|
37
|
+
case "rgb":
|
|
38
|
+
case "hsl":
|
|
39
|
+
if (expectMonotone) {
|
|
40
|
+
throw new Error("Unexpected color: " + colors.colorToString(color));
|
|
41
|
+
}
|
|
42
|
+
return;
|
|
43
|
+
default:
|
|
44
|
+
if (color.type !== "function" || color.func !== "url") {
|
|
45
|
+
throw new Error("Unexpected color: " + colors.colorToString(color));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return palette;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
exports.validateColors = validateColors;
|
package/lib/colors/validate.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ParseColorsOptions } from './parse';
|
|
3
|
-
import
|
|
1
|
+
import { SVG } from '../svg/index.js';
|
|
2
|
+
import { ParseColorsOptions, FindColorsResult } from './parse.js';
|
|
3
|
+
import '@iconify/types';
|
|
4
|
+
import '@iconify/utils/lib/customisations';
|
|
5
|
+
import '@iconify/utils/lib/colors/types';
|
|
6
|
+
import './attribs.js';
|
|
7
|
+
import '../svg/analyse/types.js';
|
|
8
|
+
|
|
4
9
|
/**
|
|
5
10
|
* Validate colors in icon
|
|
6
11
|
*
|
|
@@ -8,4 +13,6 @@ import type { FindColorsResult } from './parse';
|
|
|
8
13
|
*
|
|
9
14
|
* Throws exception on error
|
|
10
15
|
*/
|
|
11
|
-
|
|
16
|
+
declare function validateColors(svg: SVG, expectMonotone: boolean, options?: ParseColorsOptions): Promise<FindColorsResult>;
|
|
17
|
+
|
|
18
|
+
export { validateColors };
|
package/lib/colors/validate.mjs
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { colorToString } from '@iconify/utils/lib/colors';
|
|
2
|
+
import { parseColors } from './parse.mjs';
|
|
3
|
+
import '../svg/data/tags.mjs';
|
|
4
|
+
import '../svg/parse-style.mjs';
|
|
5
|
+
import '../css/parse.mjs';
|
|
6
|
+
import '../css/parser/tokens.mjs';
|
|
7
|
+
import '../css/parser/error.mjs';
|
|
8
|
+
import '../css/parser/strings.mjs';
|
|
9
|
+
import '../css/parser/text.mjs';
|
|
10
|
+
import '../css/parser/export.mjs';
|
|
11
|
+
import '../css/parser/tree.mjs';
|
|
12
|
+
import '../svg/parse.mjs';
|
|
13
|
+
import './attribs.mjs';
|
|
14
|
+
import '../svg/data/attributes.mjs';
|
|
15
|
+
import '../svg/analyse.mjs';
|
|
16
|
+
import '../svg/analyse/error.mjs';
|
|
17
|
+
|
|
4
18
|
async function validateColors(svg, expectMonotone, options) {
|
|
5
19
|
const palette = await parseColors(svg, options);
|
|
6
20
|
palette.colors.forEach((color) => {
|
|
@@ -30,6 +44,5 @@ async function validateColors(svg, expectMonotone, options) {
|
|
|
30
44
|
});
|
|
31
45
|
return palette;
|
|
32
46
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
47
|
+
|
|
48
|
+
export { validateColors };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const css_parser_tokens = require('./parser/tokens.cjs');
|
|
6
|
+
require('./parser/error.cjs');
|
|
7
|
+
require('./parser/strings.cjs');
|
|
8
|
+
require('./parser/text.cjs');
|
|
9
|
+
|
|
10
|
+
function parseInlineStyle(style) {
|
|
11
|
+
const tokens = css_parser_tokens.getTokens(style);
|
|
12
|
+
if (!(tokens instanceof Array)) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const results = /* @__PURE__ */ Object.create(null);
|
|
16
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
17
|
+
const token = tokens[i];
|
|
18
|
+
if (token.type !== "rule") {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
results[token.prop] = token.value;
|
|
22
|
+
}
|
|
23
|
+
return results;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
exports.parseInlineStyle = parseInlineStyle;
|
package/lib/css/parse.d.ts
CHANGED