@iconify/tools 1.3.17 → 2.0.0-dev.2

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.
Files changed (147) hide show
  1. package/.editorconfig +13 -0
  2. package/.eslintignore +2 -0
  3. package/lib/colors/attribs.d.ts +16 -0
  4. package/lib/colors/attribs.js +26 -0
  5. package/lib/colors/attribs.mjs +28 -0
  6. package/lib/colors/parse.d.ts +37 -0
  7. package/lib/colors/parse.js +261 -0
  8. package/lib/colors/parse.mjs +212 -0
  9. package/lib/css/parse.d.ts +4 -0
  10. package/lib/css/parse.js +23 -0
  11. package/lib/css/parse.mjs +20 -0
  12. package/lib/css/parser/error.d.ts +11 -0
  13. package/lib/css/parser/error.js +27 -0
  14. package/lib/css/parser/error.mjs +23 -0
  15. package/lib/css/parser/export.d.ts +5 -0
  16. package/lib/css/parser/export.js +69 -0
  17. package/lib/css/parser/export.mjs +46 -0
  18. package/lib/css/parser/strings.d.ts +13 -0
  19. package/lib/css/parser/strings.js +93 -0
  20. package/lib/css/parser/strings.mjs +74 -0
  21. package/lib/css/parser/text.d.ts +17 -0
  22. package/lib/css/parser/text.js +174 -0
  23. package/lib/css/parser/text.mjs +133 -0
  24. package/lib/css/parser/tokens.d.ts +6 -0
  25. package/lib/css/parser/tokens.js +200 -0
  26. package/lib/css/parser/tokens.mjs +186 -0
  27. package/lib/css/parser/tree.d.ts +5 -0
  28. package/lib/css/parser/tree.js +44 -0
  29. package/lib/css/parser/tree.mjs +40 -0
  30. package/lib/css/parser/types.d.ts +51 -0
  31. package/lib/css/parser/types.js +2 -0
  32. package/lib/css/parser/types.mjs +0 -0
  33. package/lib/icon-set/index.d.ts +134 -0
  34. package/lib/icon-set/index.js +776 -0
  35. package/lib/icon-set/index.mjs +617 -0
  36. package/lib/icon-set/match.d.ts +6 -0
  37. package/lib/icon-set/match.js +66 -0
  38. package/lib/icon-set/match.mjs +55 -0
  39. package/lib/icon-set/merge.d.ts +5 -0
  40. package/lib/icon-set/merge.js +91 -0
  41. package/lib/icon-set/merge.mjs +75 -0
  42. package/lib/icon-set/props.d.ts +10 -0
  43. package/lib/icon-set/props.js +33 -0
  44. package/lib/icon-set/props.mjs +25 -0
  45. package/lib/icon-set/types.d.ts +68 -0
  46. package/lib/icon-set/types.js +2 -0
  47. package/lib/icon-set/types.mjs +0 -0
  48. package/lib/import/directory.d.ts +35 -0
  49. package/lib/import/directory.js +59 -0
  50. package/lib/import/directory.mjs +47 -0
  51. package/lib/misc/keyword.d.ts +4 -0
  52. package/lib/misc/keyword.js +31 -0
  53. package/lib/misc/keyword.mjs +17 -0
  54. package/lib/misc/scan.d.ts +24 -0
  55. package/lib/misc/scan.js +48 -0
  56. package/lib/misc/scan.mjs +43 -0
  57. package/lib/optimise/flags.d.ts +5 -0
  58. package/lib/optimise/flags.js +303 -0
  59. package/lib/optimise/flags.mjs +241 -0
  60. package/lib/optimise/scale.d.ts +5 -0
  61. package/lib/optimise/scale.js +42 -0
  62. package/lib/optimise/scale.mjs +22 -0
  63. package/lib/optimise/svgo.d.ts +27 -0
  64. package/lib/optimise/svgo.js +88 -0
  65. package/lib/optimise/svgo.mjs +75 -0
  66. package/lib/svg/cleanup/attribs.d.ts +5 -0
  67. package/lib/svg/cleanup/attribs.js +43 -0
  68. package/lib/svg/cleanup/attribs.mjs +36 -0
  69. package/lib/svg/cleanup/bad-tags.d.ts +5 -0
  70. package/lib/svg/cleanup/bad-tags.js +69 -0
  71. package/lib/svg/cleanup/bad-tags.mjs +68 -0
  72. package/lib/svg/cleanup/inline-style.d.ts +5 -0
  73. package/lib/svg/cleanup/inline-style.js +77 -0
  74. package/lib/svg/cleanup/inline-style.mjs +65 -0
  75. package/lib/svg/cleanup/root-svg.d.ts +5 -0
  76. package/lib/svg/cleanup/root-svg.js +106 -0
  77. package/lib/svg/cleanup/root-svg.mjs +88 -0
  78. package/lib/svg/cleanup/svgo-style.d.ts +5 -0
  79. package/lib/svg/cleanup/svgo-style.js +35 -0
  80. package/lib/svg/cleanup/svgo-style.mjs +29 -0
  81. package/lib/svg/cleanup.d.ts +5 -0
  82. package/lib/svg/cleanup.js +24 -0
  83. package/lib/svg/cleanup.mjs +16 -0
  84. package/lib/svg/data/attributes.d.ts +71 -0
  85. package/lib/svg/data/attributes.js +403 -0
  86. package/lib/svg/data/attributes.mjs +352 -0
  87. package/lib/svg/data/tags.d.ts +89 -0
  88. package/lib/svg/data/tags.js +185 -0
  89. package/lib/svg/data/tags.mjs +136 -0
  90. package/lib/svg/index.d.ts +33 -0
  91. package/lib/svg/index.js +122 -0
  92. package/lib/svg/index.mjs +85 -0
  93. package/lib/svg/parse-style.d.ts +40 -0
  94. package/lib/svg/parse-style.js +131 -0
  95. package/lib/svg/parse-style.mjs +109 -0
  96. package/lib/svg/parse.d.ts +30 -0
  97. package/lib/svg/parse.js +49 -0
  98. package/lib/svg/parse.mjs +40 -0
  99. package/package.json +167 -13
  100. package/README.md +0 -576
  101. package/license.txt +0 -21
  102. package/sample/parse.js +0 -74
  103. package/sample/source/icon-close.svg +0 -15
  104. package/sample/source/icon-confirm.svg +0 -14
  105. package/sample/source/icon-search.svg +0 -16
  106. package/src/collection.js +0 -641
  107. package/src/colors/change_palette.js +0 -227
  108. package/src/colors/get_palette.js +0 -143
  109. package/src/colors/opacify.js +0 -195
  110. package/src/export/component.js +0 -482
  111. package/src/export/dir.js +0 -109
  112. package/src/export/json.js +0 -329
  113. package/src/export/phantomjs.js +0 -76
  114. package/src/export/phantomjs_script.js +0 -125
  115. package/src/export/png.js +0 -193
  116. package/src/export/svg.js +0 -55
  117. package/src/export/templates/component.md +0 -79
  118. package/src/export/templates/info.md +0 -3
  119. package/src/export/templates/sample-react-1.md +0 -21
  120. package/src/export/templates/sample-react-2.md +0 -15
  121. package/src/export/templates/sample-react.md +0 -11
  122. package/src/export/templates/sample-svelte.md +0 -11
  123. package/src/export/templates/sample-svelte1.md +0 -22
  124. package/src/export/templates/sample-svelte2.md +0 -13
  125. package/src/export/templates/sample-vue-0.md +0 -30
  126. package/src/export/templates/sample-vue-1.md +0 -25
  127. package/src/export/templates/sample-vue-2.md +0 -27
  128. package/src/export/templates/sample-vue.md +0 -28
  129. package/src/helpers.js +0 -43
  130. package/src/import/dir.js +0 -234
  131. package/src/import/font.js +0 -402
  132. package/src/import/json.js +0 -200
  133. package/src/import/svg.js +0 -60
  134. package/src/import/web_icons.js +0 -248
  135. package/src/modules.js +0 -50
  136. package/src/optimize/crop.js +0 -554
  137. package/src/optimize/crop_script.js +0 -525
  138. package/src/optimize/flags.js +0 -430
  139. package/src/optimize/scale.js +0 -72
  140. package/src/optimize/svgo.js +0 -161
  141. package/src/optimize/tags.js +0 -522
  142. package/src/shapes/convert.js +0 -264
  143. package/src/shapes/index.js +0 -135
  144. package/src/shapes/length.js +0 -707
  145. package/src/shapes/length_script.js +0 -105
  146. package/src/shapes/options.js +0 -60
  147. package/src/svg.js +0 -162
package/.editorconfig ADDED
@@ -0,0 +1,13 @@
1
+ root = true
2
+
3
+ [*]
4
+ end_of_line = lf
5
+ insert_final_newline = true
6
+ indent_style = tab
7
+ indent_size = 4
8
+ charset = utf-8
9
+ trim_trailing_whitespace = true
10
+
11
+ [{*.json,*.yml}]
12
+ indent_style = space
13
+ indent_size = 2
package/.eslintignore ADDED
@@ -0,0 +1,2 @@
1
+ lib
2
+ tests-compiled
@@ -0,0 +1,16 @@
1
+ import type { Color } from '@iconify/utils/lib/colors/types';
2
+ /**
3
+ * Color attributes
4
+ */
5
+ export declare type CommonColorAttributes = 'color';
6
+ export declare const commonColorAttributes: CommonColorAttributes[];
7
+ export declare type ShapeColorAttributes = 'fill' | 'stroke';
8
+ export declare const shapeColorAttributes: ShapeColorAttributes[];
9
+ export declare type SpecialColorAttributes = 'stop-color' | 'flood-color';
10
+ export declare const specialColorAttributes: SpecialColorAttributes[];
11
+ export declare type ColorAttributes = CommonColorAttributes | ShapeColorAttributes | SpecialColorAttributes;
12
+ /**
13
+ * Default values
14
+ */
15
+ export declare const defaultBlackColor: Color;
16
+ export declare const defaultColorValues: Record<ColorAttributes, Color>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultColorValues = exports.defaultBlackColor = exports.specialColorAttributes = exports.shapeColorAttributes = exports.commonColorAttributes = void 0;
4
+ exports.commonColorAttributes = ['color'];
5
+ exports.shapeColorAttributes = ['fill', 'stroke'];
6
+ exports.specialColorAttributes = [
7
+ 'stop-color',
8
+ 'flood-color',
9
+ ];
10
+ /**
11
+ * Default values
12
+ */
13
+ exports.defaultBlackColor = {
14
+ type: 'rgb',
15
+ r: 0,
16
+ g: 0,
17
+ b: 0,
18
+ alpha: 1,
19
+ };
20
+ exports.defaultColorValues = {
21
+ 'color': { type: 'current' },
22
+ 'fill': exports.defaultBlackColor,
23
+ 'stroke': { type: 'none' },
24
+ 'stop-color': exports.defaultBlackColor,
25
+ 'flood-color': exports.defaultBlackColor,
26
+ };
@@ -0,0 +1,28 @@
1
+ // src/colors/attribs.ts
2
+ var commonColorAttributes = ["color"];
3
+ var shapeColorAttributes = ["fill", "stroke"];
4
+ var specialColorAttributes = [
5
+ "stop-color",
6
+ "flood-color"
7
+ ];
8
+ var defaultBlackColor = {
9
+ type: "rgb",
10
+ r: 0,
11
+ g: 0,
12
+ b: 0,
13
+ alpha: 1
14
+ };
15
+ var defaultColorValues = {
16
+ "color": { type: "current" },
17
+ "fill": defaultBlackColor,
18
+ "stroke": { type: "none" },
19
+ "stop-color": defaultBlackColor,
20
+ "flood-color": defaultBlackColor
21
+ };
22
+ export {
23
+ commonColorAttributes,
24
+ defaultBlackColor,
25
+ defaultColorValues,
26
+ shapeColorAttributes,
27
+ specialColorAttributes
28
+ };
@@ -0,0 +1,37 @@
1
+ import type { Color } from '@iconify/utils/lib/colors/types';
2
+ import type { SVG } from '../svg';
3
+ import { ColorAttributes } from './attribs';
4
+ /**
5
+ * Result
6
+ */
7
+ interface FindColorsResult {
8
+ colors: (Color | string)[];
9
+ hasUnsetColor: boolean;
10
+ hasGlobalStyle: boolean;
11
+ }
12
+ /**
13
+ * Callback to call for each found color
14
+ *
15
+ * Callback should return:
16
+ * - new color value to change color
17
+ * - first parameter to keep old value
18
+ * - undefined to delete old value
19
+ */
20
+ declare type ParseColorsCallbackResult = Color | string | undefined;
21
+ declare type ParseColorsCallback = (attr: ColorAttributes, color: Color | string, tagName?: string) => ParseColorsCallbackResult | Promise<ParseColorsCallbackResult>;
22
+ /**
23
+ * Options
24
+ */
25
+ export interface ParseColorsOptions {
26
+ callback?: ParseColorsCallback;
27
+ defaultColor?: Color | string;
28
+ }
29
+ /**
30
+ * Find colors in icon
31
+ */
32
+ export declare function parseColors(svg: SVG, options?: ParseColorsOptions): Promise<FindColorsResult>;
33
+ /**
34
+ * Check if color is empty, such as 'none' or 'transparent'
35
+ */
36
+ export declare function isEmptyColor(color: Color): boolean;
37
+ export {};
@@ -0,0 +1,261 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isEmptyColor = exports.parseColors = void 0;
4
+ const colors_1 = require("@iconify/utils/lib/colors");
5
+ const parse_1 = require("../svg/parse");
6
+ const tags_1 = require("../svg/data/tags");
7
+ const parse_style_1 = require("../svg/parse-style");
8
+ const attribs_1 = require("./attribs");
9
+ const attributes_1 = require("../svg/data/attributes");
10
+ /**
11
+ * Properties to check
12
+ */
13
+ const propsToCheck = Object.keys(attribs_1.defaultColorValues);
14
+ const animatePropsToCheck = ['from', 'to', 'values'];
15
+ /**
16
+ * Find colors in icon
17
+ */
18
+ async function parseColors(svg, options = {}) {
19
+ const result = {
20
+ colors: [],
21
+ hasUnsetColor: false,
22
+ hasGlobalStyle: false,
23
+ };
24
+ // Default color
25
+ const defaultColor = typeof options.defaultColor === 'string'
26
+ ? (0, colors_1.stringToColor)(options.defaultColor)
27
+ : options.defaultColor;
28
+ function findColor(color, add = false) {
29
+ const isString = typeof color === 'string';
30
+ for (let i = 0; i < result.colors.length; i++) {
31
+ const item = result.colors[i];
32
+ if (item === color) {
33
+ return item;
34
+ }
35
+ if (!isString &&
36
+ typeof item !== 'string' &&
37
+ (0, colors_1.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
+ /**
48
+ * Add color to item and to results
49
+ */
50
+ function addColorToItem(prop, color, item) {
51
+ const addedColor = findColor(color, true);
52
+ if (item) {
53
+ const itemColors = item.colors || {};
54
+ if (!item.colors) {
55
+ item.colors = itemColors;
56
+ }
57
+ itemColors[prop] = addedColor;
58
+ }
59
+ }
60
+ /**
61
+ * Get element color
62
+ */
63
+ function getElementColor(prop, item) {
64
+ function find(prop) {
65
+ var _a;
66
+ let currentItem = item;
67
+ while (currentItem) {
68
+ const color = (_a = currentItem.colors) === null || _a === void 0 ? void 0 : _a[prop];
69
+ if (color !== void 0) {
70
+ return color;
71
+ }
72
+ currentItem = currentItem.parents[0];
73
+ }
74
+ return attribs_1.defaultColorValues[prop];
75
+ }
76
+ let propColor = find(prop);
77
+ if (typeof propColor === 'object' &&
78
+ propColor.type === 'current' &&
79
+ prop !== 'color') {
80
+ // currentColor: get color
81
+ propColor = find('color');
82
+ }
83
+ return propColor;
84
+ }
85
+ /**
86
+ * Change color
87
+ */
88
+ async function checkColor(prop, value, item) {
89
+ // Ignore empty values
90
+ switch (value.trim().toLowerCase()) {
91
+ case '':
92
+ case 'inherit':
93
+ return;
94
+ }
95
+ // Resolve color
96
+ const color = (0, colors_1.stringToColor)(value);
97
+ const defaultValue = color || value;
98
+ // Check if callback exists
99
+ if (!options.callback) {
100
+ addColorToItem(prop, defaultValue, item);
101
+ return value;
102
+ }
103
+ // Call callback
104
+ let callbackResult = options.callback(prop, defaultValue, item === null || item === void 0 ? void 0 : item.tagName);
105
+ callbackResult =
106
+ callbackResult instanceof Promise
107
+ ? await callbackResult
108
+ : callbackResult;
109
+ // Remove entry
110
+ if (callbackResult === void 0) {
111
+ return callbackResult;
112
+ }
113
+ if (callbackResult === defaultValue) {
114
+ // Not changed
115
+ addColorToItem(prop, defaultValue, item);
116
+ return value;
117
+ }
118
+ if (typeof callbackResult === 'string') {
119
+ const newColor = (0, colors_1.stringToColor)(callbackResult);
120
+ addColorToItem(prop, newColor || callbackResult, item);
121
+ return callbackResult;
122
+ }
123
+ // Color
124
+ const newValue = (0, colors_1.colorToString)(callbackResult);
125
+ addColorToItem(prop, callbackResult, item);
126
+ return newValue;
127
+ }
128
+ // Parse colors in style
129
+ await (0, parse_style_1.parseSVGStyle)(svg, async (item) => {
130
+ const prop = item.prop;
131
+ const value = item.value;
132
+ if (propsToCheck.indexOf(prop) === -1) {
133
+ return value;
134
+ }
135
+ // Color
136
+ const attr = prop;
137
+ const newValue = checkColor(attr, value);
138
+ if (newValue === void 0) {
139
+ return newValue;
140
+ }
141
+ // Got color
142
+ if (item.type === 'global') {
143
+ result.hasGlobalStyle = true;
144
+ }
145
+ return newValue;
146
+ }, {
147
+ skipMasks: true,
148
+ });
149
+ // Parse colors in SVG
150
+ await (0, parse_1.parseSVG)(svg, async (item) => {
151
+ const tagName = item.tagName;
152
+ if (tags_1.maskAndSymbolTags.has(tagName)) {
153
+ // Ignore masks
154
+ item.testChildren = false;
155
+ return;
156
+ }
157
+ const $element = item.$element;
158
+ const attribs = item.element.attribs;
159
+ // Check common properties
160
+ for (let i = 0; i < propsToCheck.length; i++) {
161
+ const prop = propsToCheck[i];
162
+ if (prop === 'fill' && tags_1.animateTags.has(tagName)) {
163
+ // 'fill' has different meaning in animations
164
+ continue;
165
+ }
166
+ const value = attribs[prop];
167
+ if (value !== void 0) {
168
+ const newValue = await checkColor(prop, value, item);
169
+ if (newValue !== value) {
170
+ if (newValue === void 0) {
171
+ $element.removeAttr(prop);
172
+ }
173
+ else {
174
+ $element.attr(prop, newValue);
175
+ }
176
+ }
177
+ }
178
+ }
179
+ // Check animations
180
+ if (tags_1.animateTags.has(tagName)) {
181
+ const attr = attribs.attributeName;
182
+ if (propsToCheck.indexOf(attr) !== -1) {
183
+ // Valid property
184
+ for (let i = 0; i < animatePropsToCheck.length; i++) {
185
+ const elementProp = animatePropsToCheck[i];
186
+ const fullValue = attribs[elementProp];
187
+ if (typeof fullValue !== 'string') {
188
+ continue;
189
+ }
190
+ // Split values
191
+ const splitValues = fullValue.split(';');
192
+ let updatedValues = false;
193
+ for (let j = 0; j < splitValues.length; j++) {
194
+ const value = splitValues[j];
195
+ if (value !== void 0) {
196
+ const newValue = await checkColor(elementProp, value
197
+ // Do not pass third parameter
198
+ );
199
+ if (newValue !== value) {
200
+ updatedValues = true;
201
+ splitValues[j] =
202
+ typeof newValue === 'string'
203
+ ? newValue
204
+ : '';
205
+ }
206
+ }
207
+ }
208
+ // Merge values back
209
+ if (updatedValues) {
210
+ $element.attr(elementProp, splitValues.join(';'));
211
+ }
212
+ }
213
+ }
214
+ }
215
+ // Check shape for default colors
216
+ if (!result.hasGlobalStyle) {
217
+ // Get list of properties required to render element
218
+ let requiredProps;
219
+ if (tags_1.shapeTags.has(tagName)) {
220
+ requiredProps = attribs_1.shapeColorAttributes;
221
+ }
222
+ attribs_1.specialColorAttributes.forEach((attr) => {
223
+ var _a;
224
+ if ((_a = attributes_1.tagSpecificPresentationalAttributes[tagName]) === null || _a === void 0 ? void 0 : _a.has(attr)) {
225
+ requiredProps = [attr];
226
+ }
227
+ });
228
+ // Check colors
229
+ if (requiredProps) {
230
+ const itemColors = item.colors || {};
231
+ if (!item.colors) {
232
+ item.colors = itemColors;
233
+ }
234
+ for (let i = 0; i < requiredProps.length; i++) {
235
+ const prop = requiredProps[i];
236
+ const color = getElementColor(prop, item);
237
+ if (color === attribs_1.defaultBlackColor) {
238
+ // Default black color: change it
239
+ result.hasUnsetColor = true;
240
+ if (defaultColor) {
241
+ // Add color to results and change attribute
242
+ findColor(defaultColor, true);
243
+ $element.attr(prop, (0, colors_1.colorToString)(defaultColor));
244
+ itemColors[prop] = defaultColor;
245
+ }
246
+ }
247
+ }
248
+ }
249
+ }
250
+ });
251
+ return result;
252
+ }
253
+ exports.parseColors = parseColors;
254
+ /**
255
+ * Check if color is empty, such as 'none' or 'transparent'
256
+ */
257
+ function isEmptyColor(color) {
258
+ const type = color.type;
259
+ return type === 'none' || type === 'transparent';
260
+ }
261
+ exports.isEmptyColor = isEmptyColor;
@@ -0,0 +1,212 @@
1
+ // src/colors/parse.ts
2
+ import {
3
+ compareColors,
4
+ stringToColor,
5
+ colorToString
6
+ } from "@iconify/utils/lib/colors";
7
+ import { parseSVG } from "../svg/parse.mjs";
8
+ import { animateTags, maskAndSymbolTags, shapeTags } from "../svg/data/tags.mjs";
9
+ import { parseSVGStyle } from "../svg/parse-style.mjs";
10
+ import {
11
+ defaultBlackColor,
12
+ defaultColorValues,
13
+ shapeColorAttributes,
14
+ specialColorAttributes
15
+ } from "./attribs.mjs";
16
+ import { tagSpecificPresentationalAttributes } from "../svg/data/attributes.mjs";
17
+ var propsToCheck = Object.keys(defaultColorValues);
18
+ var animatePropsToCheck = ["from", "to", "values"];
19
+ async function parseColors(svg, options = {}) {
20
+ const result = {
21
+ colors: [],
22
+ hasUnsetColor: false,
23
+ hasGlobalStyle: false
24
+ };
25
+ const defaultColor = typeof options.defaultColor === "string" ? stringToColor(options.defaultColor) : options.defaultColor;
26
+ function findColor(color, add = false) {
27
+ const isString = typeof color === "string";
28
+ for (let i = 0; i < result.colors.length; i++) {
29
+ const item = result.colors[i];
30
+ if (item === color) {
31
+ return item;
32
+ }
33
+ if (!isString && typeof item !== "string" && compareColors(item, color)) {
34
+ return item;
35
+ }
36
+ }
37
+ if (add) {
38
+ result.colors.push(color);
39
+ return color;
40
+ }
41
+ return null;
42
+ }
43
+ function addColorToItem(prop, color, item) {
44
+ const addedColor = findColor(color, true);
45
+ if (item) {
46
+ const itemColors = item.colors || {};
47
+ if (!item.colors) {
48
+ item.colors = itemColors;
49
+ }
50
+ itemColors[prop] = addedColor;
51
+ }
52
+ }
53
+ function getElementColor(prop, item) {
54
+ function find(prop2) {
55
+ var _a;
56
+ let currentItem = item;
57
+ while (currentItem) {
58
+ const color = (_a = currentItem.colors) == null ? void 0 : _a[prop2];
59
+ if (color !== void 0) {
60
+ return color;
61
+ }
62
+ currentItem = currentItem.parents[0];
63
+ }
64
+ return defaultColorValues[prop2];
65
+ }
66
+ let propColor = find(prop);
67
+ if (typeof propColor === "object" && propColor.type === "current" && prop !== "color") {
68
+ propColor = find("color");
69
+ }
70
+ return propColor;
71
+ }
72
+ async function checkColor(prop, value, item) {
73
+ switch (value.trim().toLowerCase()) {
74
+ case "":
75
+ case "inherit":
76
+ return;
77
+ }
78
+ const color = stringToColor(value);
79
+ const defaultValue = color || value;
80
+ if (!options.callback) {
81
+ addColorToItem(prop, defaultValue, item);
82
+ return value;
83
+ }
84
+ let callbackResult = options.callback(prop, defaultValue, item == null ? void 0 : item.tagName);
85
+ callbackResult = callbackResult instanceof Promise ? await callbackResult : callbackResult;
86
+ if (callbackResult === void 0) {
87
+ return callbackResult;
88
+ }
89
+ if (callbackResult === defaultValue) {
90
+ addColorToItem(prop, defaultValue, item);
91
+ return value;
92
+ }
93
+ if (typeof callbackResult === "string") {
94
+ const newColor = stringToColor(callbackResult);
95
+ addColorToItem(prop, newColor || callbackResult, item);
96
+ return callbackResult;
97
+ }
98
+ const newValue = colorToString(callbackResult);
99
+ addColorToItem(prop, callbackResult, item);
100
+ return newValue;
101
+ }
102
+ await parseSVGStyle(svg, async (item) => {
103
+ const prop = item.prop;
104
+ const value = item.value;
105
+ if (propsToCheck.indexOf(prop) === -1) {
106
+ return value;
107
+ }
108
+ const attr = prop;
109
+ const newValue = checkColor(attr, value);
110
+ if (newValue === void 0) {
111
+ return newValue;
112
+ }
113
+ if (item.type === "global") {
114
+ result.hasGlobalStyle = true;
115
+ }
116
+ return newValue;
117
+ }, {
118
+ skipMasks: true
119
+ });
120
+ await parseSVG(svg, async (item) => {
121
+ const tagName = item.tagName;
122
+ if (maskAndSymbolTags.has(tagName)) {
123
+ item.testChildren = false;
124
+ return;
125
+ }
126
+ const $element = item.$element;
127
+ const attribs = item.element.attribs;
128
+ for (let i = 0; i < propsToCheck.length; i++) {
129
+ const prop = propsToCheck[i];
130
+ if (prop === "fill" && animateTags.has(tagName)) {
131
+ continue;
132
+ }
133
+ const value = attribs[prop];
134
+ if (value !== void 0) {
135
+ const newValue = await checkColor(prop, value, item);
136
+ if (newValue !== value) {
137
+ if (newValue === void 0) {
138
+ $element.removeAttr(prop);
139
+ } else {
140
+ $element.attr(prop, newValue);
141
+ }
142
+ }
143
+ }
144
+ }
145
+ if (animateTags.has(tagName)) {
146
+ const attr = attribs.attributeName;
147
+ if (propsToCheck.indexOf(attr) !== -1) {
148
+ for (let i = 0; i < animatePropsToCheck.length; i++) {
149
+ const elementProp = animatePropsToCheck[i];
150
+ const fullValue = attribs[elementProp];
151
+ if (typeof fullValue !== "string") {
152
+ continue;
153
+ }
154
+ const splitValues = fullValue.split(";");
155
+ let updatedValues = false;
156
+ for (let j = 0; j < splitValues.length; j++) {
157
+ const value = splitValues[j];
158
+ if (value !== void 0) {
159
+ const newValue = await checkColor(elementProp, value);
160
+ if (newValue !== value) {
161
+ updatedValues = true;
162
+ splitValues[j] = typeof newValue === "string" ? newValue : "";
163
+ }
164
+ }
165
+ }
166
+ if (updatedValues) {
167
+ $element.attr(elementProp, splitValues.join(";"));
168
+ }
169
+ }
170
+ }
171
+ }
172
+ if (!result.hasGlobalStyle) {
173
+ let requiredProps;
174
+ if (shapeTags.has(tagName)) {
175
+ requiredProps = shapeColorAttributes;
176
+ }
177
+ specialColorAttributes.forEach((attr) => {
178
+ var _a;
179
+ if ((_a = tagSpecificPresentationalAttributes[tagName]) == null ? void 0 : _a.has(attr)) {
180
+ requiredProps = [attr];
181
+ }
182
+ });
183
+ if (requiredProps) {
184
+ const itemColors = item.colors || {};
185
+ if (!item.colors) {
186
+ item.colors = itemColors;
187
+ }
188
+ for (let i = 0; i < requiredProps.length; i++) {
189
+ const prop = requiredProps[i];
190
+ const color = getElementColor(prop, item);
191
+ if (color === defaultBlackColor) {
192
+ result.hasUnsetColor = true;
193
+ if (defaultColor) {
194
+ findColor(defaultColor, true);
195
+ $element.attr(prop, colorToString(defaultColor));
196
+ itemColors[prop] = defaultColor;
197
+ }
198
+ }
199
+ }
200
+ }
201
+ }
202
+ });
203
+ return result;
204
+ }
205
+ function isEmptyColor(color) {
206
+ const type = color.type;
207
+ return type === "none" || type === "transparent";
208
+ }
209
+ export {
210
+ isEmptyColor,
211
+ parseColors
212
+ };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Parse inline style
3
+ */
4
+ export declare function parseInlineStyle(style: string): Record<string, string> | null;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseInlineStyle = void 0;
4
+ const tokens_1 = require("./parser/tokens");
5
+ /**
6
+ * Parse inline style
7
+ */
8
+ function parseInlineStyle(style) {
9
+ const tokens = (0, tokens_1.getTokens)(style);
10
+ if (!(tokens instanceof Array)) {
11
+ return null;
12
+ }
13
+ const results = Object.create(null);
14
+ for (let i = 0; i < tokens.length; i++) {
15
+ const token = tokens[i];
16
+ if (token.type !== 'rule') {
17
+ return null;
18
+ }
19
+ results[token.prop] = token.value;
20
+ }
21
+ return results;
22
+ }
23
+ exports.parseInlineStyle = parseInlineStyle;
@@ -0,0 +1,20 @@
1
+ // src/css/parse.ts
2
+ import { getTokens } from "./parser/tokens.mjs";
3
+ function parseInlineStyle(style) {
4
+ const tokens = getTokens(style);
5
+ if (!(tokens instanceof Array)) {
6
+ return null;
7
+ }
8
+ const results = Object.create(null);
9
+ for (let i = 0; i < tokens.length; i++) {
10
+ const token = tokens[i];
11
+ if (token.type !== "rule") {
12
+ return null;
13
+ }
14
+ results[token.prop] = token.value;
15
+ }
16
+ return results;
17
+ }
18
+ export {
19
+ parseInlineStyle
20
+ };
@@ -0,0 +1,11 @@
1
+ export interface StyleParseError {
2
+ type: 'style-parse-error';
3
+ message: string;
4
+ code: string;
5
+ index?: number;
6
+ fullMessage: string;
7
+ }
8
+ /**
9
+ * Create error message
10
+ */
11
+ export declare function styleParseError(message: string, code: string, index?: number): StyleParseError;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.styleParseError = void 0;
4
+ /**
5
+ * Create error message
6
+ */
7
+ function styleParseError(message, code, index) {
8
+ let fullMessage = message;
9
+ if (typeof index === 'number' && index !== -1) {
10
+ const start = index;
11
+ // Check for space on left side of remaining code to calculate line start correctly
12
+ const remaining = code.slice(index) + '!';
13
+ const trimmed = remaining.trim();
14
+ const end = start + remaining.length - trimmed.length;
15
+ const code2 = code.slice(0, end);
16
+ const line = code2.length - code2.replace(/\n/g, '').length + 1;
17
+ fullMessage = message + ' on line ' + line;
18
+ }
19
+ return {
20
+ type: 'style-parse-error',
21
+ message,
22
+ code,
23
+ index,
24
+ fullMessage,
25
+ };
26
+ }
27
+ exports.styleParseError = styleParseError;