@iconify/tools 2.1.0 → 2.1.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.
Files changed (114) hide show
  1. package/lib/colors/detect.cjs +68 -0
  2. package/lib/colors/detect.d.ts +15 -0
  3. package/lib/colors/detect.mjs +64 -0
  4. package/lib/colors/parse.cjs +31 -7
  5. package/lib/colors/parse.d.ts +1 -1
  6. package/lib/colors/parse.mjs +31 -7
  7. package/lib/colors/validate.cjs +9 -3
  8. package/lib/colors/validate.d.ts +1 -1
  9. package/lib/colors/validate.mjs +9 -3
  10. package/lib/css/parser/error.cjs +1 -1
  11. package/lib/css/parser/error.mjs +1 -1
  12. package/lib/css/parser/strings.cjs +10 -2
  13. package/lib/css/parser/strings.mjs +10 -2
  14. package/lib/css/parser/tokens.cjs +133 -109
  15. package/lib/css/parser/tokens.mjs +133 -109
  16. package/lib/download/api/cache.cjs +28 -21
  17. package/lib/download/api/cache.mjs +28 -21
  18. package/lib/download/git/branch.cjs +1 -1
  19. package/lib/download/git/branch.mjs +1 -1
  20. package/lib/download/git/hash.cjs +1 -1
  21. package/lib/download/git/hash.mjs +1 -1
  22. package/lib/download/git/index.cjs +7 -4
  23. package/lib/download/git/index.mjs +7 -4
  24. package/lib/download/git/reset.cjs +1 -2
  25. package/lib/download/git/reset.mjs +1 -2
  26. package/lib/download/github/index.cjs +10 -7
  27. package/lib/download/github/index.mjs +10 -7
  28. package/lib/download/gitlab/hash.cjs +3 -1
  29. package/lib/download/gitlab/hash.mjs +3 -1
  30. package/lib/download/gitlab/index.cjs +9 -6
  31. package/lib/download/gitlab/index.mjs +9 -6
  32. package/lib/download/index.cjs +4 -3
  33. package/lib/download/index.mjs +4 -3
  34. package/lib/download/npm/index.cjs +12 -8
  35. package/lib/download/npm/index.mjs +12 -8
  36. package/lib/download/npm/version.cjs +4 -2
  37. package/lib/download/npm/version.mjs +4 -2
  38. package/lib/export/directory.d.ts +1 -1
  39. package/lib/export/helpers/types-version.cjs +3 -1
  40. package/lib/export/helpers/types-version.mjs +3 -1
  41. package/lib/export/icon-package.d.ts +1 -1
  42. package/lib/export/json-package.cjs +13 -3
  43. package/lib/export/json-package.d.ts +1 -1
  44. package/lib/export/json-package.mjs +13 -3
  45. package/lib/icon-set/index.cjs +20 -8
  46. package/lib/icon-set/index.d.ts +1 -1
  47. package/lib/icon-set/index.mjs +20 -8
  48. package/lib/icon-set/match.d.ts +1 -1
  49. package/lib/icon-set/merge.d.ts +1 -1
  50. package/lib/icon-set/modified.d.ts +1 -1
  51. package/lib/icon-set/props.d.ts +1 -1
  52. package/lib/icon-set/tags.cjs +97 -0
  53. package/lib/icon-set/tags.d.ts +22 -0
  54. package/lib/icon-set/tags.mjs +91 -0
  55. package/lib/icon-set/types.d.ts +1 -1
  56. package/lib/import/directory.cjs +4 -1
  57. package/lib/import/directory.d.ts +1 -1
  58. package/lib/import/directory.mjs +4 -1
  59. package/lib/import/figma/index.cjs +5 -2
  60. package/lib/import/figma/index.d.ts +1 -1
  61. package/lib/import/figma/index.mjs +5 -2
  62. package/lib/import/figma/nodes.cjs +6 -2
  63. package/lib/import/figma/nodes.d.ts +2 -2
  64. package/lib/import/figma/nodes.mjs +6 -2
  65. package/lib/import/figma/query.cjs +29 -15
  66. package/lib/import/figma/query.d.ts +1 -1
  67. package/lib/import/figma/query.mjs +29 -15
  68. package/lib/import/figma/types/nodes.d.ts +1 -1
  69. package/lib/import/figma/types/options.d.ts +1 -1
  70. package/lib/import/figma/types/result.d.ts +1 -1
  71. package/lib/index.cjs +6 -3
  72. package/lib/index.d.ts +3 -1
  73. package/lib/index.mjs +4 -3
  74. package/lib/misc/compare-dirs.cjs +3 -1
  75. package/lib/misc/compare-dirs.mjs +3 -1
  76. package/lib/misc/exec.cjs +7 -8
  77. package/lib/misc/exec.mjs +7 -8
  78. package/lib/misc/keyword.cjs +4 -1
  79. package/lib/misc/keyword.mjs +4 -1
  80. package/lib/misc/scan.cjs +3 -1
  81. package/lib/misc/scan.mjs +3 -1
  82. package/lib/optimise/flags.cjs +9 -3
  83. package/lib/optimise/flags.d.ts +1 -1
  84. package/lib/optimise/flags.mjs +9 -3
  85. package/lib/optimise/global-style.cjs +10 -3
  86. package/lib/optimise/global-style.d.ts +1 -1
  87. package/lib/optimise/global-style.mjs +10 -3
  88. package/lib/optimise/scale.d.ts +1 -1
  89. package/lib/optimise/svgo.d.ts +1 -1
  90. package/lib/svg/analyse.cjs +20 -6
  91. package/lib/svg/analyse.d.ts +1 -1
  92. package/lib/svg/analyse.mjs +20 -6
  93. package/lib/svg/cleanup/attribs.d.ts +1 -1
  94. package/lib/svg/cleanup/bad-tags.cjs +7 -2
  95. package/lib/svg/cleanup/bad-tags.d.ts +1 -1
  96. package/lib/svg/cleanup/bad-tags.mjs +7 -2
  97. package/lib/svg/cleanup/inline-style.cjs +12 -4
  98. package/lib/svg/cleanup/inline-style.d.ts +1 -1
  99. package/lib/svg/cleanup/inline-style.mjs +12 -4
  100. package/lib/svg/cleanup/root-style.d.ts +1 -1
  101. package/lib/svg/cleanup/root-svg.d.ts +1 -1
  102. package/lib/svg/cleanup/svgo-style.d.ts +1 -1
  103. package/lib/svg/cleanup.d.ts +1 -1
  104. package/lib/svg/data/attributes.cjs +0 -1
  105. package/lib/svg/data/attributes.mjs +0 -1
  106. package/lib/svg/index.cjs +12 -3
  107. package/lib/svg/index.d.ts +2 -2
  108. package/lib/svg/index.mjs +12 -3
  109. package/lib/svg/parse-style.cjs +13 -8
  110. package/lib/svg/parse-style.d.ts +1 -1
  111. package/lib/svg/parse-style.mjs +13 -8
  112. package/lib/svg/parse.d.ts +1 -1
  113. package/package.json +23 -8
  114. package/lib/types-6360d61e.d.ts +0 -261
@@ -0,0 +1,68 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const colors_parse = require('./parse.cjs');
6
+ require('@iconify/utils/lib/colors');
7
+ require('../svg/data/tags.cjs');
8
+ require('../svg/parse-style.cjs');
9
+ require('../css/parse.cjs');
10
+ require('../css/parser/tokens.cjs');
11
+ require('../css/parser/error.cjs');
12
+ require('../css/parser/strings.cjs');
13
+ require('../css/parser/text.cjs');
14
+ require('../css/parser/export.cjs');
15
+ require('../css/parser/tree.cjs');
16
+ require('../svg/parse.cjs');
17
+ require('./attribs.cjs');
18
+ require('../svg/data/attributes.cjs');
19
+ require('../svg/analyse.cjs');
20
+ require('../svg/analyse/error.cjs');
21
+
22
+ async function detectIconSetPalette(iconSet) {
23
+ let palette;
24
+ await iconSet.forEach(
25
+ async (name) => {
26
+ if (palette === null) {
27
+ return;
28
+ }
29
+ const svg = iconSet.toSVG(name);
30
+ if (!svg) {
31
+ return;
32
+ }
33
+ let iconPalette;
34
+ await colors_parse.parseColors(svg, {
35
+ callback: (attr, colorStr, color) => {
36
+ if (!color) {
37
+ iconPalette = null;
38
+ return colorStr;
39
+ }
40
+ if (iconPalette === null || colors_parse.isEmptyColor(color)) {
41
+ return color;
42
+ }
43
+ const isColor = color.type !== "current";
44
+ if (iconPalette === void 0) {
45
+ iconPalette = isColor;
46
+ return color;
47
+ }
48
+ if (iconPalette !== isColor) {
49
+ iconPalette = null;
50
+ }
51
+ return color;
52
+ }
53
+ });
54
+ if (iconPalette === void 0) {
55
+ iconPalette = null;
56
+ }
57
+ if (palette === void 0) {
58
+ palette = iconPalette;
59
+ } else if (palette !== iconPalette) {
60
+ palette = null;
61
+ }
62
+ },
63
+ ["icon"]
64
+ );
65
+ return palette === void 0 ? null : palette;
66
+ }
67
+
68
+ exports.detectIconSetPalette = detectIconSetPalette;
@@ -0,0 +1,15 @@
1
+ import { IconSet } from '../icon-set/index.js';
2
+ import '@iconify/types';
3
+ import '@iconify/utils/lib/customisations/defaults';
4
+ import '../icon-set/types.js';
5
+ import '../svg/index.js';
6
+ import '@iconify/utils/lib/icon-set/tree';
7
+
8
+ /**
9
+ * Detect palette
10
+ *
11
+ * Returns null if icon set has mixed colors
12
+ */
13
+ declare function detectIconSetPalette(iconSet: IconSet): Promise<boolean | null>;
14
+
15
+ export { detectIconSetPalette };
@@ -0,0 +1,64 @@
1
+ import { parseColors, isEmptyColor } from './parse.mjs';
2
+ import '@iconify/utils/lib/colors';
3
+ import '../svg/data/tags.mjs';
4
+ import '../svg/parse-style.mjs';
5
+ import '../css/parse.mjs';
6
+ import '../css/parser/tokens.mjs';
7
+ import '../css/parser/error.mjs';
8
+ import '../css/parser/strings.mjs';
9
+ import '../css/parser/text.mjs';
10
+ import '../css/parser/export.mjs';
11
+ import '../css/parser/tree.mjs';
12
+ import '../svg/parse.mjs';
13
+ import './attribs.mjs';
14
+ import '../svg/data/attributes.mjs';
15
+ import '../svg/analyse.mjs';
16
+ import '../svg/analyse/error.mjs';
17
+
18
+ async function detectIconSetPalette(iconSet) {
19
+ let palette;
20
+ await iconSet.forEach(
21
+ async (name) => {
22
+ if (palette === null) {
23
+ return;
24
+ }
25
+ const svg = iconSet.toSVG(name);
26
+ if (!svg) {
27
+ return;
28
+ }
29
+ let iconPalette;
30
+ await parseColors(svg, {
31
+ callback: (attr, colorStr, color) => {
32
+ if (!color) {
33
+ iconPalette = null;
34
+ return colorStr;
35
+ }
36
+ if (iconPalette === null || isEmptyColor(color)) {
37
+ return color;
38
+ }
39
+ const isColor = color.type !== "current";
40
+ if (iconPalette === void 0) {
41
+ iconPalette = isColor;
42
+ return color;
43
+ }
44
+ if (iconPalette !== isColor) {
45
+ iconPalette = null;
46
+ }
47
+ return color;
48
+ }
49
+ });
50
+ if (iconPalette === void 0) {
51
+ iconPalette = null;
52
+ }
53
+ if (palette === void 0) {
54
+ palette = iconPalette;
55
+ } else if (palette !== iconPalette) {
56
+ palette = null;
57
+ }
58
+ },
59
+ ["icon"]
60
+ );
61
+ return palette === void 0 ? null : palette;
62
+ }
63
+
64
+ export { detectIconSetPalette };
@@ -56,7 +56,9 @@ async function parseColors(svg, options = {}) {
56
56
  let currentItem = item;
57
57
  const allowDefaultColor = colors_attribs.allowDefaultColorValue[prop2];
58
58
  while (currentItem) {
59
- const element = elements2.get(currentItem.index);
59
+ const element = elements2.get(
60
+ currentItem.index
61
+ );
60
62
  const color = element._colors?.[prop2];
61
63
  if (color !== void 0) {
62
64
  return color;
@@ -95,7 +97,13 @@ async function parseColors(svg, options = {}) {
95
97
  addColorToItem(prop, defaultValue, item);
96
98
  return value;
97
99
  }
98
- let callbackResult = options.callback(prop, value, parsedColor, item?.tagName, item);
100
+ let callbackResult = options.callback(
101
+ prop,
102
+ value,
103
+ parsedColor,
104
+ item?.tagName,
105
+ item
106
+ );
99
107
  callbackResult = callbackResult instanceof Promise ? await callbackResult : callbackResult;
100
108
  switch (callbackResult) {
101
109
  case "remove": {
@@ -171,7 +179,9 @@ async function parseColors(svg, options = {}) {
171
179
  const { tagName, attribs } = element;
172
180
  if (item.parent) {
173
181
  const parentIndex = item.parent.index;
174
- const parentElement = elements.get(parentIndex);
182
+ const parentElement = elements.get(
183
+ parentIndex
184
+ );
175
185
  if (parentElement._colors) {
176
186
  element._colors = {
177
187
  ...parentElement._colors
@@ -215,7 +225,10 @@ async function parseColors(svg, options = {}) {
215
225
  for (let j = 0; j < splitValues.length; j++) {
216
226
  const value = splitValues[j];
217
227
  if (value !== void 0) {
218
- const newValue = await checkColor(elementProp, value);
228
+ const newValue = await checkColor(
229
+ elementProp,
230
+ value
231
+ );
219
232
  if (newValue !== value) {
220
233
  updatedValues = true;
221
234
  splitValues[j] = typeof newValue === "string" ? newValue : "";
@@ -223,7 +236,10 @@ async function parseColors(svg, options = {}) {
223
236
  }
224
237
  }
225
238
  if (updatedValues) {
226
- cheerio(element).attr(elementProp, splitValues.join(";"));
239
+ cheerio(element).attr(
240
+ elementProp,
241
+ splitValues.join(";")
242
+ );
227
243
  }
228
244
  }
229
245
  }
@@ -245,9 +261,17 @@ async function parseColors(svg, options = {}) {
245
261
  const color = getElementColor(prop, item, elements);
246
262
  if (color === colors_attribs.defaultBlackColor) {
247
263
  if (defaultColor) {
248
- const defaultColorValue = typeof defaultColor === "function" ? defaultColor(prop, element, item, iconData) : defaultColor;
264
+ const defaultColorValue = typeof defaultColor === "function" ? defaultColor(
265
+ prop,
266
+ element,
267
+ item,
268
+ iconData
269
+ ) : defaultColor;
249
270
  findColor(defaultColorValue, true);
250
- cheerio(element).attr(prop, colors.colorToString(defaultColorValue));
271
+ cheerio(element).attr(
272
+ prop,
273
+ colors.colorToString(defaultColorValue)
274
+ );
251
275
  itemColors[prop] = defaultColorValue;
252
276
  } else {
253
277
  result.hasUnsetColor = true;
@@ -2,7 +2,7 @@ import { Color } from '@iconify/utils/lib/colors/types';
2
2
  import { SVG } from '../svg/index.js';
3
3
  import { ColorAttributes } from './attribs.js';
4
4
  import { ElementsTreeItem, AnalyseSVGStructureResult, AnalyseSVGStructureOptions, ExtendedTagElement } from '../svg/analyse/types.js';
5
- import '../types-6360d61e.js';
5
+ import '@iconify/types';
6
6
  import '@iconify/utils/lib/customisations/defaults';
7
7
 
8
8
  /**
@@ -52,7 +52,9 @@ async function parseColors(svg, options = {}) {
52
52
  let currentItem = item;
53
53
  const allowDefaultColor = allowDefaultColorValue[prop2];
54
54
  while (currentItem) {
55
- const element = elements2.get(currentItem.index);
55
+ const element = elements2.get(
56
+ currentItem.index
57
+ );
56
58
  const color = element._colors?.[prop2];
57
59
  if (color !== void 0) {
58
60
  return color;
@@ -91,7 +93,13 @@ async function parseColors(svg, options = {}) {
91
93
  addColorToItem(prop, defaultValue, item);
92
94
  return value;
93
95
  }
94
- let callbackResult = options.callback(prop, value, parsedColor, item?.tagName, item);
96
+ let callbackResult = options.callback(
97
+ prop,
98
+ value,
99
+ parsedColor,
100
+ item?.tagName,
101
+ item
102
+ );
95
103
  callbackResult = callbackResult instanceof Promise ? await callbackResult : callbackResult;
96
104
  switch (callbackResult) {
97
105
  case "remove": {
@@ -167,7 +175,9 @@ async function parseColors(svg, options = {}) {
167
175
  const { tagName, attribs } = element;
168
176
  if (item.parent) {
169
177
  const parentIndex = item.parent.index;
170
- const parentElement = elements.get(parentIndex);
178
+ const parentElement = elements.get(
179
+ parentIndex
180
+ );
171
181
  if (parentElement._colors) {
172
182
  element._colors = {
173
183
  ...parentElement._colors
@@ -211,7 +221,10 @@ async function parseColors(svg, options = {}) {
211
221
  for (let j = 0; j < splitValues.length; j++) {
212
222
  const value = splitValues[j];
213
223
  if (value !== void 0) {
214
- const newValue = await checkColor(elementProp, value);
224
+ const newValue = await checkColor(
225
+ elementProp,
226
+ value
227
+ );
215
228
  if (newValue !== value) {
216
229
  updatedValues = true;
217
230
  splitValues[j] = typeof newValue === "string" ? newValue : "";
@@ -219,7 +232,10 @@ async function parseColors(svg, options = {}) {
219
232
  }
220
233
  }
221
234
  if (updatedValues) {
222
- cheerio(element).attr(elementProp, splitValues.join(";"));
235
+ cheerio(element).attr(
236
+ elementProp,
237
+ splitValues.join(";")
238
+ );
223
239
  }
224
240
  }
225
241
  }
@@ -241,9 +257,17 @@ async function parseColors(svg, options = {}) {
241
257
  const color = getElementColor(prop, item, elements);
242
258
  if (color === defaultBlackColor) {
243
259
  if (defaultColor) {
244
- const defaultColorValue = typeof defaultColor === "function" ? defaultColor(prop, element, item, iconData) : defaultColor;
260
+ const defaultColorValue = typeof defaultColor === "function" ? defaultColor(
261
+ prop,
262
+ element,
263
+ item,
264
+ iconData
265
+ ) : defaultColor;
245
266
  findColor(defaultColorValue, true);
246
- cheerio(element).attr(prop, colorToString(defaultColorValue));
267
+ cheerio(element).attr(
268
+ prop,
269
+ colorToString(defaultColorValue)
270
+ );
247
271
  itemColors[prop] = defaultColorValue;
248
272
  } else {
249
273
  result.hasUnsetColor = true;
@@ -31,18 +31,24 @@ async function validateColors(svg, expectMonotone, options) {
31
31
  return;
32
32
  case "current":
33
33
  if (!expectMonotone) {
34
- throw new Error("Unexpected color: " + colors.colorToString(color));
34
+ throw new Error(
35
+ "Unexpected color: " + colors.colorToString(color)
36
+ );
35
37
  }
36
38
  return;
37
39
  case "rgb":
38
40
  case "hsl":
39
41
  if (expectMonotone) {
40
- throw new Error("Unexpected color: " + colors.colorToString(color));
42
+ throw new Error(
43
+ "Unexpected color: " + colors.colorToString(color)
44
+ );
41
45
  }
42
46
  return;
43
47
  default:
44
48
  if (color.type !== "function" || color.func !== "url") {
45
- throw new Error("Unexpected color: " + colors.colorToString(color));
49
+ throw new Error(
50
+ "Unexpected color: " + colors.colorToString(color)
51
+ );
46
52
  }
47
53
  }
48
54
  });
@@ -1,6 +1,6 @@
1
1
  import { SVG } from '../svg/index.js';
2
2
  import { ParseColorsOptions, FindColorsResult } from './parse.js';
3
- import '../types-6360d61e.js';
3
+ import '@iconify/types';
4
4
  import '@iconify/utils/lib/customisations/defaults';
5
5
  import '@iconify/utils/lib/colors/types';
6
6
  import './attribs.js';
@@ -27,18 +27,24 @@ async function validateColors(svg, expectMonotone, options) {
27
27
  return;
28
28
  case "current":
29
29
  if (!expectMonotone) {
30
- throw new Error("Unexpected color: " + colorToString(color));
30
+ throw new Error(
31
+ "Unexpected color: " + colorToString(color)
32
+ );
31
33
  }
32
34
  return;
33
35
  case "rgb":
34
36
  case "hsl":
35
37
  if (expectMonotone) {
36
- throw new Error("Unexpected color: " + colorToString(color));
38
+ throw new Error(
39
+ "Unexpected color: " + colorToString(color)
40
+ );
37
41
  }
38
42
  return;
39
43
  default:
40
44
  if (color.type !== "function" || color.func !== "url") {
41
- throw new Error("Unexpected color: " + colorToString(color));
45
+ throw new Error(
46
+ "Unexpected color: " + colorToString(color)
47
+ );
42
48
  }
43
49
  }
44
50
  });
@@ -11,7 +11,7 @@ function styleParseError(message, code, index) {
11
11
  const end = start + remaining.length - trimmed.length;
12
12
  const code2 = code.slice(0, end);
13
13
  const line = code2.length - code2.replace(/\n/g, "").length + 1;
14
- fullMessage = message + " on line " + line;
14
+ fullMessage = message + " on line " + line.toString();
15
15
  }
16
16
  return {
17
17
  type: "style-parse-error",
@@ -7,7 +7,7 @@ function styleParseError(message, code, index) {
7
7
  const end = start + remaining.length - trimmed.length;
8
8
  const code2 = code.slice(0, end);
9
9
  const line = code2.length - code2.replace(/\n/g, "").length + 1;
10
- fullMessage = message + " on line " + line;
10
+ fullMessage = message + " on line " + line.toString();
11
11
  }
12
12
  return {
13
13
  type: "style-parse-error",
@@ -60,12 +60,20 @@ function findEndOfURL(code, start) {
60
60
  return css_parser_error.styleParseError("Invalid URL", code, start);
61
61
  default:
62
62
  if (code.charCodeAt(index) < 32) {
63
- return css_parser_error.styleParseError("Invalid URL", code, start);
63
+ return css_parser_error.styleParseError(
64
+ "Invalid URL",
65
+ code,
66
+ start
67
+ );
64
68
  }
65
69
  }
66
70
  index++;
67
71
  if (index >= length) {
68
- return css_parser_error.styleParseError("Cannot find end of URL", code, start);
72
+ return css_parser_error.styleParseError(
73
+ "Cannot find end of URL",
74
+ code,
75
+ start
76
+ );
69
77
  }
70
78
  next = code.charAt(index);
71
79
  }
@@ -56,12 +56,20 @@ function findEndOfURL(code, start) {
56
56
  return styleParseError("Invalid URL", code, start);
57
57
  default:
58
58
  if (code.charCodeAt(index) < 32) {
59
- return styleParseError("Invalid URL", code, start);
59
+ return styleParseError(
60
+ "Invalid URL",
61
+ code,
62
+ start
63
+ );
60
64
  }
61
65
  }
62
66
  index++;
63
67
  if (index >= length) {
64
- return styleParseError("Cannot find end of URL", code, start);
68
+ return styleParseError(
69
+ "Cannot find end of URL",
70
+ code,
71
+ start
72
+ );
65
73
  }
66
74
  next = code.charAt(index);
67
75
  }