@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
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Color } from '@iconify/utils/lib/colors/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Color attributes
|
|
5
|
+
*/
|
|
6
|
+
type CommonColorAttributes = 'color';
|
|
7
|
+
declare const commonColorAttributes: CommonColorAttributes[];
|
|
8
|
+
type ShapeColorAttributes = 'fill' | 'stroke';
|
|
9
|
+
declare const shapeColorAttributes: ShapeColorAttributes[];
|
|
10
|
+
type SpecialColorAttributes = 'stop-color' | 'flood-color';
|
|
11
|
+
declare const specialColorAttributes: SpecialColorAttributes[];
|
|
12
|
+
type ColorAttributes = CommonColorAttributes | ShapeColorAttributes | SpecialColorAttributes;
|
|
13
|
+
/**
|
|
14
|
+
* Default values
|
|
15
|
+
*/
|
|
16
|
+
declare const defaultBlackColor: Color;
|
|
17
|
+
declare const defaultColorValues: Record<ColorAttributes, Color>;
|
|
18
|
+
/**
|
|
19
|
+
* Ignore default color for some tags:
|
|
20
|
+
* - If value is true, allow default color
|
|
21
|
+
* - If value is attribute name, allow default color if attribute is set
|
|
22
|
+
*
|
|
23
|
+
* Parent elements are not checked for these tags!
|
|
24
|
+
*/
|
|
25
|
+
declare const allowDefaultColorValue: Partial<Record<ColorAttributes, string | true>>;
|
|
26
|
+
|
|
27
|
+
export { type ColorAttributes, type CommonColorAttributes, type ShapeColorAttributes, type SpecialColorAttributes, allowDefaultColorValue, commonColorAttributes, defaultBlackColor, defaultColorValues, shapeColorAttributes, specialColorAttributes };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Color } from '@iconify/utils/lib/colors/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Color attributes
|
|
5
|
+
*/
|
|
6
|
+
type CommonColorAttributes = 'color';
|
|
7
|
+
declare const commonColorAttributes: CommonColorAttributes[];
|
|
8
|
+
type ShapeColorAttributes = 'fill' | 'stroke';
|
|
9
|
+
declare const shapeColorAttributes: ShapeColorAttributes[];
|
|
10
|
+
type SpecialColorAttributes = 'stop-color' | 'flood-color';
|
|
11
|
+
declare const specialColorAttributes: SpecialColorAttributes[];
|
|
12
|
+
type ColorAttributes = CommonColorAttributes | ShapeColorAttributes | SpecialColorAttributes;
|
|
13
|
+
/**
|
|
14
|
+
* Default values
|
|
15
|
+
*/
|
|
16
|
+
declare const defaultBlackColor: Color;
|
|
17
|
+
declare const defaultColorValues: Record<ColorAttributes, Color>;
|
|
18
|
+
/**
|
|
19
|
+
* Ignore default color for some tags:
|
|
20
|
+
* - If value is true, allow default color
|
|
21
|
+
* - If value is attribute name, allow default color if attribute is set
|
|
22
|
+
*
|
|
23
|
+
* Parent elements are not checked for these tags!
|
|
24
|
+
*/
|
|
25
|
+
declare const allowDefaultColorValue: Partial<Record<ColorAttributes, string | true>>;
|
|
26
|
+
|
|
27
|
+
export { type ColorAttributes, type CommonColorAttributes, type ShapeColorAttributes, type SpecialColorAttributes, allowDefaultColorValue, commonColorAttributes, defaultBlackColor, defaultColorValues, shapeColorAttributes, specialColorAttributes };
|
package/lib/colors/attribs.d.ts
CHANGED
|
@@ -24,4 +24,4 @@ declare const defaultColorValues: Record<ColorAttributes, Color>;
|
|
|
24
24
|
*/
|
|
25
25
|
declare const allowDefaultColorValue: Partial<Record<ColorAttributes, string | true>>;
|
|
26
26
|
|
|
27
|
-
export { ColorAttributes, CommonColorAttributes, ShapeColorAttributes, SpecialColorAttributes, allowDefaultColorValue, commonColorAttributes, defaultBlackColor, defaultColorValues, shapeColorAttributes, specialColorAttributes };
|
|
27
|
+
export { type ColorAttributes, type CommonColorAttributes, type ShapeColorAttributes, type SpecialColorAttributes, allowDefaultColorValue, commonColorAttributes, defaultBlackColor, defaultColorValues, shapeColorAttributes, specialColorAttributes };
|
package/lib/colors/detect.cjs
CHANGED
|
@@ -29,7 +29,7 @@ function detectIconSetPalette(iconSet) {
|
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
31
|
let iconPalette;
|
|
32
|
-
colors_parse.
|
|
32
|
+
colors_parse.parseColors(svg, {
|
|
33
33
|
callback: (attr, colorStr, color) => {
|
|
34
34
|
if (!color) {
|
|
35
35
|
iconPalette = null;
|
|
@@ -60,7 +60,7 @@ function detectIconSetPalette(iconSet) {
|
|
|
60
60
|
},
|
|
61
61
|
["icon"]
|
|
62
62
|
);
|
|
63
|
-
return palette
|
|
63
|
+
return palette ?? null;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
exports.detectIconSetPalette = detectIconSetPalette;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IconSet } from '../icon-set/index.cjs';
|
|
2
|
+
import '@iconify/types';
|
|
3
|
+
import '@iconify/utils/lib/customisations/defaults';
|
|
4
|
+
import '../icon-set/types.cjs';
|
|
5
|
+
import '../svg/index.cjs';
|
|
6
|
+
import 'cheerio';
|
|
7
|
+
import '@iconify/utils/lib/icon-set/tree';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Detect palette
|
|
11
|
+
*
|
|
12
|
+
* Returns null if icon set has mixed colors
|
|
13
|
+
*/
|
|
14
|
+
declare function detectIconSetPalette(iconSet: IconSet): boolean | null;
|
|
15
|
+
|
|
16
|
+
export { detectIconSetPalette };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IconSet } from '../icon-set/index.mjs';
|
|
2
|
+
import '@iconify/types';
|
|
3
|
+
import '@iconify/utils/lib/customisations/defaults';
|
|
4
|
+
import '../icon-set/types.mjs';
|
|
5
|
+
import '../svg/index.mjs';
|
|
6
|
+
import 'cheerio';
|
|
7
|
+
import '@iconify/utils/lib/icon-set/tree';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Detect palette
|
|
11
|
+
*
|
|
12
|
+
* Returns null if icon set has mixed colors
|
|
13
|
+
*/
|
|
14
|
+
declare function detectIconSetPalette(iconSet: IconSet): boolean | null;
|
|
15
|
+
|
|
16
|
+
export { detectIconSetPalette };
|
package/lib/colors/detect.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parseColors, isEmptyColor } from './parse.mjs';
|
|
2
2
|
import '@iconify/utils/lib/colors';
|
|
3
3
|
import '../svg/data/tags.mjs';
|
|
4
4
|
import '../svg/parse-style.mjs';
|
|
@@ -27,7 +27,7 @@ function detectIconSetPalette(iconSet) {
|
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
29
|
let iconPalette;
|
|
30
|
-
|
|
30
|
+
parseColors(svg, {
|
|
31
31
|
callback: (attr, colorStr, color) => {
|
|
32
32
|
if (!color) {
|
|
33
33
|
iconPalette = null;
|
|
@@ -58,7 +58,7 @@ function detectIconSetPalette(iconSet) {
|
|
|
58
58
|
},
|
|
59
59
|
["icon"]
|
|
60
60
|
);
|
|
61
|
-
return palette
|
|
61
|
+
return palette ?? null;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export { detectIconSetPalette };
|
package/lib/colors/parse.cjs
CHANGED
|
@@ -18,7 +18,7 @@ require('../svg/analyse/error.cjs');
|
|
|
18
18
|
|
|
19
19
|
const propsToCheck = Object.keys(colors_attribs.defaultColorValues);
|
|
20
20
|
const animatePropsToCheck = ["from", "to", "values"];
|
|
21
|
-
function
|
|
21
|
+
function parseColors(svg, options = {}) {
|
|
22
22
|
const result = {
|
|
23
23
|
colors: [],
|
|
24
24
|
hasUnsetColor: false,
|
|
@@ -49,12 +49,12 @@ function createContext(options, callback) {
|
|
|
49
49
|
itemColors[prop] = addedColor === null ? color : addedColor;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
function getElementColor(prop, item,
|
|
52
|
+
function getElementColor(prop, item, elements2) {
|
|
53
53
|
function find(prop2) {
|
|
54
54
|
let currentItem = item;
|
|
55
55
|
const allowDefaultColor = colors_attribs.allowDefaultColorValue[prop2];
|
|
56
56
|
while (currentItem) {
|
|
57
|
-
const element =
|
|
57
|
+
const element = elements2.get(
|
|
58
58
|
currentItem.index
|
|
59
59
|
);
|
|
60
60
|
const color = element._colors?.[prop2];
|
|
@@ -79,81 +79,69 @@ function createContext(options, callback) {
|
|
|
79
79
|
}
|
|
80
80
|
return propColor;
|
|
81
81
|
}
|
|
82
|
-
function checkColor(
|
|
82
|
+
function checkColor(prop, value, item) {
|
|
83
83
|
switch (value.trim().toLowerCase()) {
|
|
84
84
|
case "":
|
|
85
85
|
case "inherit":
|
|
86
|
-
return
|
|
86
|
+
return;
|
|
87
87
|
}
|
|
88
88
|
const parsedColor = colors.stringToColor(value);
|
|
89
89
|
const defaultValue = parsedColor || value;
|
|
90
90
|
if (parsedColor?.type === "function" && parsedColor.func === "url") {
|
|
91
91
|
addColorToItem(prop, defaultValue, item, false);
|
|
92
|
-
return
|
|
92
|
+
return value;
|
|
93
93
|
}
|
|
94
|
-
if (!callback) {
|
|
94
|
+
if (!options.callback) {
|
|
95
95
|
addColorToItem(prop, defaultValue, item);
|
|
96
|
-
return
|
|
96
|
+
return value;
|
|
97
97
|
}
|
|
98
|
-
callback(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
case "unset":
|
|
106
|
-
return done();
|
|
107
|
-
}
|
|
108
|
-
if (callbackResult === value || parsedColor && callbackResult === parsedColor) {
|
|
109
|
-
addColorToItem(prop, defaultValue, item);
|
|
110
|
-
return done(value);
|
|
111
|
-
}
|
|
112
|
-
if (typeof callbackResult === "string") {
|
|
113
|
-
const newColor = colors.stringToColor(callbackResult);
|
|
114
|
-
addColorToItem(prop, newColor || callbackResult, item);
|
|
115
|
-
return done(callbackResult);
|
|
116
|
-
}
|
|
117
|
-
const newValue = colors.colorToString(callbackResult);
|
|
118
|
-
addColorToItem(prop, callbackResult, item);
|
|
119
|
-
return done(newValue);
|
|
120
|
-
}
|
|
98
|
+
const callbackResult = options.callback(
|
|
99
|
+
prop,
|
|
100
|
+
value,
|
|
101
|
+
parsedColor,
|
|
102
|
+
item?.tagName,
|
|
103
|
+
item
|
|
121
104
|
);
|
|
105
|
+
if (callbackResult instanceof Promise) {
|
|
106
|
+
throw new Error("parseColors does not support async callbacks");
|
|
107
|
+
}
|
|
108
|
+
switch (callbackResult) {
|
|
109
|
+
case "remove": {
|
|
110
|
+
return item ? callbackResult : void 0;
|
|
111
|
+
}
|
|
112
|
+
case "unset":
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (callbackResult === value || parsedColor && callbackResult === parsedColor) {
|
|
116
|
+
addColorToItem(prop, defaultValue, item);
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
119
|
+
if (typeof callbackResult === "string") {
|
|
120
|
+
const newColor = colors.stringToColor(callbackResult);
|
|
121
|
+
addColorToItem(prop, newColor || callbackResult, item);
|
|
122
|
+
return callbackResult;
|
|
123
|
+
}
|
|
124
|
+
const newValue = colors.colorToString(callbackResult);
|
|
125
|
+
addColorToItem(prop, callbackResult, item);
|
|
126
|
+
return newValue;
|
|
122
127
|
}
|
|
123
|
-
|
|
128
|
+
svg_parseStyle.parseSVGStyle(svg, (item) => {
|
|
124
129
|
const prop = item.prop;
|
|
125
130
|
const value = item.value;
|
|
126
|
-
if (propsToCheck.
|
|
127
|
-
return
|
|
131
|
+
if (!propsToCheck.includes(prop)) {
|
|
132
|
+
return value;
|
|
128
133
|
}
|
|
129
134
|
const attr = prop;
|
|
130
|
-
checkColor(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
attr,
|
|
141
|
-
value
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
return {
|
|
145
|
-
result,
|
|
146
|
-
defaultColor,
|
|
147
|
-
rawOptions: options,
|
|
148
|
-
findColor,
|
|
149
|
-
addColorToItem,
|
|
150
|
-
getElementColor,
|
|
151
|
-
checkColor,
|
|
152
|
-
parseStyleItem
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
function analyseSVG(svg, context, done) {
|
|
156
|
-
const iconData = svg_analyse.analyseSVGStructure(svg, context.rawOptions);
|
|
135
|
+
const newValue = checkColor(attr, value);
|
|
136
|
+
if (newValue === void 0) {
|
|
137
|
+
return newValue;
|
|
138
|
+
}
|
|
139
|
+
if (item.type === "global") {
|
|
140
|
+
result.hasGlobalStyle = true;
|
|
141
|
+
}
|
|
142
|
+
return newValue;
|
|
143
|
+
});
|
|
144
|
+
const iconData = svg_analyse.analyseSVGStructure(svg, options);
|
|
157
145
|
const { elements, tree } = iconData;
|
|
158
146
|
const cheerio = svg.$svg;
|
|
159
147
|
const removedElements = /* @__PURE__ */ new Set();
|
|
@@ -178,15 +166,15 @@ function analyseSVG(svg, context, done) {
|
|
|
178
166
|
removeChildren(element);
|
|
179
167
|
cheerio(element).remove();
|
|
180
168
|
}
|
|
181
|
-
function parseTreeItem(item
|
|
169
|
+
function parseTreeItem(item) {
|
|
182
170
|
const index = item.index;
|
|
183
171
|
if (removedElements.has(index) || parsedElements.has(index)) {
|
|
184
|
-
return
|
|
172
|
+
return;
|
|
185
173
|
}
|
|
186
174
|
parsedElements.add(index);
|
|
187
175
|
const element = elements.get(index);
|
|
188
176
|
if (element._removed) {
|
|
189
|
-
return
|
|
177
|
+
return;
|
|
190
178
|
}
|
|
191
179
|
const { tagName, attribs } = element;
|
|
192
180
|
if (item.parent) {
|
|
@@ -200,239 +188,108 @@ function analyseSVG(svg, context, done) {
|
|
|
200
188
|
};
|
|
201
189
|
}
|
|
202
190
|
}
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if (prop === "fill" && svg_data_tags.animateTags.has(tagName)) {
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
const value = attribs[prop];
|
|
211
|
-
if (value !== void 0) {
|
|
212
|
-
propsQueue.push([prop, value]);
|
|
213
|
-
}
|
|
191
|
+
for (let i = 0; i < propsToCheck.length; i++) {
|
|
192
|
+
const prop = propsToCheck[i];
|
|
193
|
+
if (prop === "fill" && svg_data_tags.animateTags.has(tagName)) {
|
|
194
|
+
continue;
|
|
214
195
|
}
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
if (newValue !== value) {
|
|
224
|
-
if (newValue === void 0) {
|
|
225
|
-
cheerio(element).removeAttr(prop);
|
|
226
|
-
if (element._colors) {
|
|
227
|
-
delete element._colors[prop];
|
|
228
|
-
}
|
|
229
|
-
} else if (newValue === "remove") {
|
|
230
|
-
removeElement(index, element);
|
|
231
|
-
} else {
|
|
232
|
-
cheerio(element).attr(prop, newValue);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return parsePropsQueue();
|
|
236
|
-
},
|
|
237
|
-
prop,
|
|
238
|
-
value,
|
|
239
|
-
element
|
|
240
|
-
);
|
|
241
|
-
};
|
|
242
|
-
parsePropsQueue();
|
|
243
|
-
}
|
|
244
|
-
function checkAnimations(done3) {
|
|
245
|
-
const propsQueue = [];
|
|
246
|
-
if (svg_data_tags.animateTags.has(tagName)) {
|
|
247
|
-
const attr = attribs.attributeName;
|
|
248
|
-
if (propsToCheck.indexOf(attr) !== -1) {
|
|
249
|
-
for (let i = 0; i < animatePropsToCheck.length; i++) {
|
|
250
|
-
const elementProp = animatePropsToCheck[i];
|
|
251
|
-
const fullValue = attribs[elementProp];
|
|
252
|
-
if (typeof fullValue !== "string") {
|
|
253
|
-
continue;
|
|
196
|
+
const value = attribs[prop];
|
|
197
|
+
if (value !== void 0) {
|
|
198
|
+
const newValue = checkColor(prop, value, element);
|
|
199
|
+
if (newValue !== value) {
|
|
200
|
+
if (newValue === void 0) {
|
|
201
|
+
cheerio(element).removeAttr(prop);
|
|
202
|
+
if (element._colors) {
|
|
203
|
+
delete element._colors[prop];
|
|
254
204
|
}
|
|
255
|
-
|
|
205
|
+
} else if (newValue === "remove") {
|
|
206
|
+
removeElement(index, element);
|
|
207
|
+
return;
|
|
208
|
+
} else {
|
|
209
|
+
cheerio(element).attr(prop, newValue);
|
|
256
210
|
}
|
|
257
211
|
}
|
|
258
212
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
213
|
+
}
|
|
214
|
+
if (svg_data_tags.animateTags.has(tagName)) {
|
|
215
|
+
const attr = attribs.attributeName;
|
|
216
|
+
if (propsToCheck.includes(attr)) {
|
|
217
|
+
for (let i = 0; i < animatePropsToCheck.length; i++) {
|
|
218
|
+
const elementProp = animatePropsToCheck[i];
|
|
219
|
+
const fullValue = attribs[elementProp];
|
|
220
|
+
if (typeof fullValue !== "string") {
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
const splitValues = fullValue.split(";");
|
|
224
|
+
let updatedValues = false;
|
|
225
|
+
for (let j = 0; j < splitValues.length; j++) {
|
|
226
|
+
const value = splitValues[j];
|
|
227
|
+
if (value !== void 0) {
|
|
228
|
+
const newValue = checkColor(
|
|
229
|
+
elementProp,
|
|
230
|
+
value
|
|
231
|
+
// Do not pass third parameter
|
|
232
|
+
);
|
|
233
|
+
if (newValue !== value) {
|
|
234
|
+
updatedValues = true;
|
|
235
|
+
splitValues[j] = typeof newValue === "string" ? newValue : "";
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
268
239
|
if (updatedValues) {
|
|
269
240
|
cheerio(element).attr(
|
|
270
241
|
elementProp,
|
|
271
242
|
splitValues.join(";")
|
|
272
243
|
);
|
|
273
244
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const parseItem = (index2) => {
|
|
277
|
-
if (index2 >= splitValues.length) {
|
|
278
|
-
return parsedAllItems();
|
|
279
|
-
}
|
|
280
|
-
const value = splitValues[index2];
|
|
281
|
-
if (value === void 0) {
|
|
282
|
-
return parseItem(index2 + 1);
|
|
283
|
-
}
|
|
284
|
-
context.checkColor(
|
|
285
|
-
(newValue) => {
|
|
286
|
-
if (newValue !== value) {
|
|
287
|
-
updatedValues = true;
|
|
288
|
-
splitValues[index2] = typeof newValue === "string" ? newValue : "";
|
|
289
|
-
}
|
|
290
|
-
parseItem(index2 + 1);
|
|
291
|
-
},
|
|
292
|
-
elementProp,
|
|
293
|
-
value
|
|
294
|
-
// Do not pass third parameter
|
|
295
|
-
);
|
|
296
|
-
};
|
|
297
|
-
parseItem(0);
|
|
298
|
-
};
|
|
299
|
-
parsePropsQueue();
|
|
245
|
+
}
|
|
246
|
+
}
|
|
300
247
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const
|
|
319
|
-
const color = context.getElementColor(
|
|
248
|
+
if (!result.hasGlobalStyle) {
|
|
249
|
+
let requiredProps;
|
|
250
|
+
if (svg_data_tags.shapeTags.has(tagName)) {
|
|
251
|
+
requiredProps = colors_attribs.shapeColorAttributes;
|
|
252
|
+
}
|
|
253
|
+
colors_attribs.specialColorAttributes.forEach((attr) => {
|
|
254
|
+
if (svg_data_attributes.tagSpecificPresentationalAttributes[tagName]?.has(attr)) {
|
|
255
|
+
requiredProps = [attr];
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
if (requiredProps) {
|
|
259
|
+
const itemColors = element._colors || (element._colors = {});
|
|
260
|
+
for (let i = 0; i < requiredProps.length; i++) {
|
|
261
|
+
const prop = requiredProps[i];
|
|
262
|
+
const color = getElementColor(prop, item, elements);
|
|
263
|
+
if (color === colors_attribs.defaultBlackColor) {
|
|
264
|
+
if (defaultColor) {
|
|
265
|
+
const defaultColorValue = typeof defaultColor === "function" ? defaultColor(
|
|
320
266
|
prop,
|
|
267
|
+
element,
|
|
321
268
|
item,
|
|
322
|
-
|
|
269
|
+
iconData
|
|
270
|
+
) : defaultColor;
|
|
271
|
+
findColor(defaultColorValue, true);
|
|
272
|
+
cheerio(element).attr(
|
|
273
|
+
prop,
|
|
274
|
+
colors.colorToString(defaultColorValue)
|
|
323
275
|
);
|
|
324
|
-
|
|
325
|
-
const defaultColor = context.defaultColor;
|
|
326
|
-
if (defaultColor) {
|
|
327
|
-
const defaultColorValue = typeof defaultColor === "function" ? defaultColor(
|
|
328
|
-
prop,
|
|
329
|
-
element,
|
|
330
|
-
item,
|
|
331
|
-
iconData
|
|
332
|
-
) : defaultColor;
|
|
333
|
-
context.findColor(defaultColorValue, true);
|
|
334
|
-
cheerio(element).attr(
|
|
335
|
-
prop,
|
|
336
|
-
colors.colorToString(defaultColorValue)
|
|
337
|
-
);
|
|
338
|
-
itemColors[prop] = defaultColorValue;
|
|
339
|
-
} else {
|
|
340
|
-
context.result.hasUnsetColor = true;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
let index2 = 0;
|
|
347
|
-
const parseChildItem = () => {
|
|
348
|
-
if (index2 >= item.children.length) {
|
|
349
|
-
return done2();
|
|
350
|
-
}
|
|
351
|
-
const childItem = item.children[index2];
|
|
352
|
-
index2++;
|
|
353
|
-
if (!childItem.usedAsMask) {
|
|
354
|
-
parseTreeItem(childItem, parseChildItem);
|
|
355
|
-
} else {
|
|
356
|
-
parseChildItem();
|
|
357
|
-
}
|
|
358
|
-
};
|
|
359
|
-
parseChildItem();
|
|
360
|
-
});
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
parseTreeItem(tree, done);
|
|
364
|
-
}
|
|
365
|
-
function parseColors(svg, options = {}) {
|
|
366
|
-
const callback = options.callback;
|
|
367
|
-
return new Promise((fulfill, reject) => {
|
|
368
|
-
let context;
|
|
369
|
-
try {
|
|
370
|
-
context = createContext(
|
|
371
|
-
options,
|
|
372
|
-
callback ? (params, done) => {
|
|
373
|
-
try {
|
|
374
|
-
const result = callback(...params);
|
|
375
|
-
if (result instanceof Promise) {
|
|
376
|
-
result.then(done).catch(reject);
|
|
276
|
+
itemColors[prop] = defaultColorValue;
|
|
377
277
|
} else {
|
|
378
|
-
|
|
278
|
+
result.hasUnsetColor = true;
|
|
379
279
|
}
|
|
380
|
-
} catch (err) {
|
|
381
|
-
reject(err);
|
|
382
280
|
}
|
|
383
|
-
} : void 0
|
|
384
|
-
);
|
|
385
|
-
} catch (err) {
|
|
386
|
-
reject(err);
|
|
387
|
-
return;
|
|
388
|
-
}
|
|
389
|
-
svg_parseStyle.parseSVGStyle(svg, (item) => {
|
|
390
|
-
return new Promise((fulfill2, reject2) => {
|
|
391
|
-
try {
|
|
392
|
-
context.parseStyleItem(item, fulfill2);
|
|
393
|
-
} catch (err) {
|
|
394
|
-
reject2(err);
|
|
395
281
|
}
|
|
396
|
-
});
|
|
397
|
-
}).then(() => {
|
|
398
|
-
try {
|
|
399
|
-
analyseSVG(svg, context, () => {
|
|
400
|
-
fulfill(context.result);
|
|
401
|
-
});
|
|
402
|
-
} catch (err) {
|
|
403
|
-
reject(err);
|
|
404
282
|
}
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
const context = createContext(
|
|
411
|
-
options,
|
|
412
|
-
callback ? (params, done) => {
|
|
413
|
-
done(callback(...params));
|
|
414
|
-
} : void 0
|
|
415
|
-
);
|
|
416
|
-
svg_parseStyle.parseSVGStyleSync(svg, (item) => {
|
|
417
|
-
let isSync2 = true;
|
|
418
|
-
let result;
|
|
419
|
-
context.parseStyleItem(item, (value) => {
|
|
420
|
-
if (!isSync2) {
|
|
421
|
-
throw new Error("parseStyleItem callback supposed to be sync");
|
|
283
|
+
}
|
|
284
|
+
for (let i = 0; i < item.children.length; i++) {
|
|
285
|
+
const childItem = item.children[i];
|
|
286
|
+
if (!childItem.usedAsMask) {
|
|
287
|
+
parseTreeItem(childItem);
|
|
422
288
|
}
|
|
423
|
-
result = value;
|
|
424
|
-
});
|
|
425
|
-
isSync2 = false;
|
|
426
|
-
return result;
|
|
427
|
-
});
|
|
428
|
-
let isSync = true;
|
|
429
|
-
analyseSVG(svg, context, () => {
|
|
430
|
-
if (!isSync) {
|
|
431
|
-
throw new Error("analyseSVG callback supposed to be sync");
|
|
432
289
|
}
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
return
|
|
290
|
+
}
|
|
291
|
+
parseTreeItem(tree);
|
|
292
|
+
return result;
|
|
436
293
|
}
|
|
437
294
|
function isEmptyColor(color) {
|
|
438
295
|
const type = color.type;
|
|
@@ -441,4 +298,3 @@ function isEmptyColor(color) {
|
|
|
441
298
|
|
|
442
299
|
exports.isEmptyColor = isEmptyColor;
|
|
443
300
|
exports.parseColors = parseColors;
|
|
444
|
-
exports.parseColorsSync = parseColorsSync;
|