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