@iconify/tools 2.2.6 → 3.0.0-beta.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 (80) hide show
  1. package/README.md +8 -2
  2. package/lib/colors/detect.cjs +4 -4
  3. package/lib/colors/detect.d.ts +1 -1
  4. package/lib/colors/detect.mjs +5 -5
  5. package/lib/colors/parse.cjs +275 -129
  6. package/lib/colors/parse.d.ts +14 -5
  7. package/lib/colors/parse.mjs +278 -133
  8. package/lib/colors/validate.cjs +11 -2
  9. package/lib/colors/validate.d.ts +10 -2
  10. package/lib/colors/validate.mjs +12 -4
  11. package/lib/download/api/download.cjs +4 -4
  12. package/lib/download/api/download.mjs +4 -4
  13. package/lib/download/api/index.cjs +0 -1
  14. package/lib/download/api/index.mjs +0 -1
  15. package/lib/download/git/index.cjs +1 -1
  16. package/lib/download/git/index.mjs +1 -1
  17. package/lib/download/git/reset.cjs +1 -1
  18. package/lib/download/git/reset.mjs +1 -1
  19. package/lib/download/github/hash.cjs +0 -1
  20. package/lib/download/github/hash.mjs +0 -1
  21. package/lib/download/github/index.cjs +1 -1
  22. package/lib/download/github/index.mjs +1 -1
  23. package/lib/download/gitlab/hash.cjs +0 -1
  24. package/lib/download/gitlab/hash.mjs +0 -1
  25. package/lib/download/gitlab/index.cjs +1 -1
  26. package/lib/download/gitlab/index.mjs +1 -1
  27. package/lib/download/helpers/unzip.cjs +5 -1
  28. package/lib/download/index.cjs +1 -1
  29. package/lib/download/index.mjs +1 -1
  30. package/lib/download/npm/index.cjs +1 -1
  31. package/lib/download/npm/index.mjs +1 -1
  32. package/lib/icon-set/index.cjs +18 -0
  33. package/lib/icon-set/index.d.ts +7 -1
  34. package/lib/icon-set/index.mjs +18 -0
  35. package/lib/icon-set/tags.cjs +2 -2
  36. package/lib/icon-set/tags.d.ts +1 -1
  37. package/lib/icon-set/tags.mjs +2 -2
  38. package/lib/icon-set/types.d.ts +5 -4
  39. package/lib/import/directory.cjs +101 -28
  40. package/lib/import/directory.d.ts +12 -5
  41. package/lib/import/directory.mjs +103 -31
  42. package/lib/import/figma/index.cjs +1 -2
  43. package/lib/import/figma/index.mjs +1 -2
  44. package/lib/import/figma/query.cjs +0 -1
  45. package/lib/import/figma/query.mjs +0 -1
  46. package/lib/index.cjs +7 -1
  47. package/lib/index.d.ts +6 -6
  48. package/lib/index.mjs +7 -7
  49. package/lib/misc/scan.cjs +61 -8
  50. package/lib/misc/scan.d.ts +12 -6
  51. package/lib/misc/scan.mjs +62 -10
  52. package/lib/svg/analyse.cjs +2 -2
  53. package/lib/svg/analyse.d.ts +1 -1
  54. package/lib/svg/analyse.mjs +4 -4
  55. package/lib/svg/cleanup/attribs.cjs +2 -2
  56. package/lib/svg/cleanup/attribs.d.ts +1 -1
  57. package/lib/svg/cleanup/attribs.mjs +3 -3
  58. package/lib/svg/cleanup/bad-tags.cjs +2 -2
  59. package/lib/svg/cleanup/bad-tags.d.ts +1 -1
  60. package/lib/svg/cleanup/bad-tags.mjs +3 -3
  61. package/lib/svg/cleanup/inline-style.cjs +2 -2
  62. package/lib/svg/cleanup/inline-style.d.ts +1 -1
  63. package/lib/svg/cleanup/inline-style.mjs +3 -3
  64. package/lib/svg/cleanup/root-style.cjs +1 -1
  65. package/lib/svg/cleanup/root-style.d.ts +1 -5
  66. package/lib/svg/cleanup/root-style.mjs +2 -2
  67. package/lib/svg/cleanup/svgo-style.cjs +2 -2
  68. package/lib/svg/cleanup/svgo-style.d.ts +1 -1
  69. package/lib/svg/cleanup/svgo-style.mjs +3 -3
  70. package/lib/svg/cleanup.cjs +6 -6
  71. package/lib/svg/cleanup.d.ts +1 -1
  72. package/lib/svg/cleanup.mjs +6 -6
  73. package/lib/svg/index.cjs +5 -1
  74. package/lib/svg/parse-style.cjs +149 -89
  75. package/lib/svg/parse-style.d.ts +6 -1
  76. package/lib/svg/parse-style.mjs +150 -91
  77. package/lib/svg/parse.cjs +56 -18
  78. package/lib/svg/parse.d.ts +8 -2
  79. package/lib/svg/parse.mjs +56 -19
  80. package/package.json +15 -17
@@ -1,7 +1,7 @@
1
- import { stringToColor, colorToString, compareColors } from '@iconify/utils/lib/colors';
1
+ import { stringToColor, compareColors, colorToString } from '@iconify/utils/lib/colors';
2
2
  import { animateTags, shapeTags } from '../svg/data/tags.mjs';
3
- import { parseSVGStyle } from '../svg/parse-style.mjs';
4
- import { specialColorAttributes, defaultBlackColor, defaultColorValues, shapeColorAttributes, allowDefaultColorValue } from './attribs.mjs';
3
+ import { parseSVGStyle, parseSVGStyleSync } from '../svg/parse-style.mjs';
4
+ import { defaultColorValues, allowDefaultColorValue, specialColorAttributes, defaultBlackColor, shapeColorAttributes } 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
- async function parseColors(svg, options = {}) {
19
+ function createContext(options, callback) {
20
20
  const result = {
21
21
  colors: [],
22
22
  hasUnsetColor: false,
@@ -47,12 +47,12 @@ async function parseColors(svg, options = {}) {
47
47
  itemColors[prop] = addedColor === null ? color : addedColor;
48
48
  }
49
49
  }
50
- function getElementColor(prop, item, elements2) {
50
+ function getElementColor(prop, item, elements) {
51
51
  function find(prop2) {
52
52
  let currentItem = item;
53
53
  const allowDefaultColor = allowDefaultColorValue[prop2];
54
54
  while (currentItem) {
55
- const element = elements2.get(
55
+ const element = elements.get(
56
56
  currentItem.index
57
57
  );
58
58
  const color = element._colors?.[prop2];
@@ -77,67 +77,81 @@ async function parseColors(svg, options = {}) {
77
77
  }
78
78
  return propColor;
79
79
  }
80
- async function checkColor(prop, value, item) {
80
+ function checkColor(done, prop, value, item) {
81
81
  switch (value.trim().toLowerCase()) {
82
82
  case "":
83
83
  case "inherit":
84
- return;
84
+ return done();
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 value;
90
+ return done(value);
91
91
  }
92
- if (!options.callback) {
92
+ if (!callback) {
93
93
  addColorToItem(prop, defaultValue, item);
94
- return value;
94
+ return done(value);
95
95
  }
96
- let callbackResult = options.callback(
97
- prop,
98
- value,
99
- parsedColor,
100
- item?.tagName,
101
- item
102
- );
103
- callbackResult = callbackResult instanceof Promise ? await callbackResult : callbackResult;
104
- switch (callbackResult) {
105
- case "remove": {
106
- return item ? callbackResult : void 0;
96
+ callback(
97
+ [prop, value, parsedColor, item?.tagName, item],
98
+ (callbackResult) => {
99
+ switch (callbackResult) {
100
+ case "remove": {
101
+ return done(item ? callbackResult : void 0);
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);
107
118
  }
108
- case "unset":
109
- return;
110
- }
111
- if (callbackResult === value || parsedColor && callbackResult === parsedColor) {
112
- addColorToItem(prop, defaultValue, item);
113
- return value;
114
- }
115
- if (typeof callbackResult === "string") {
116
- const newColor = stringToColor(callbackResult);
117
- addColorToItem(prop, newColor || callbackResult, item);
118
- return callbackResult;
119
- }
120
- const newValue = colorToString(callbackResult);
121
- addColorToItem(prop, callbackResult, item);
122
- return newValue;
119
+ );
123
120
  }
124
- await parseSVGStyle(svg, async (item) => {
121
+ function parseStyleItem(item, done) {
125
122
  const prop = item.prop;
126
123
  const value = item.value;
127
124
  if (propsToCheck.indexOf(prop) === -1) {
128
- return value;
125
+ return done(value);
129
126
  }
130
127
  const attr = prop;
131
- const newValue = await checkColor(attr, value);
132
- if (newValue === void 0) {
133
- return newValue;
134
- }
135
- if (item.type === "global") {
136
- result.hasGlobalStyle = true;
137
- }
138
- return newValue;
139
- });
140
- const iconData = await analyseSVGStructure(svg, options);
128
+ checkColor(
129
+ (newValue) => {
130
+ if (newValue === void 0) {
131
+ return done(newValue);
132
+ }
133
+ if (item.type === "global") {
134
+ result.hasGlobalStyle = true;
135
+ }
136
+ return done(newValue);
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);
141
155
  const { elements, tree } = iconData;
142
156
  const cheerio = svg.$svg;
143
157
  const removedElements = /* @__PURE__ */ new Set();
@@ -162,15 +176,15 @@ async function parseColors(svg, options = {}) {
162
176
  removeChildren(element);
163
177
  cheerio(element).remove();
164
178
  }
165
- async function parseTreeItem(item) {
179
+ function parseTreeItem(item, done2) {
166
180
  const index = item.index;
167
181
  if (removedElements.has(index) || parsedElements.has(index)) {
168
- return;
182
+ return done2();
169
183
  }
170
184
  parsedElements.add(index);
171
185
  const element = elements.get(index);
172
186
  if (element._removed) {
173
- return;
187
+ return done2();
174
188
  }
175
189
  const { tagName, attribs } = element;
176
190
  if (item.parent) {
@@ -184,112 +198,243 @@ async function parseColors(svg, options = {}) {
184
198
  };
185
199
  }
186
200
  }
187
- for (let i = 0; i < propsToCheck.length; i++) {
188
- const prop = propsToCheck[i];
189
- if (prop === "fill" && animateTags.has(tagName)) {
190
- continue;
191
- }
192
- const value = attribs[prop];
193
- if (value !== void 0) {
194
- const newValue = await checkColor(prop, value, element);
195
- if (newValue !== value) {
196
- if (newValue === void 0) {
197
- cheerio(element).removeAttr(prop);
198
- if (element._colors) {
199
- delete element._colors[prop];
200
- }
201
- } else if (newValue === "remove") {
202
- removeElement(index, element);
203
- return;
204
- } else {
205
- cheerio(element).attr(prop, newValue);
206
- }
201
+ function parseCommonProps(done3) {
202
+ const propsQueue = [];
203
+ for (let i = 0; i < propsToCheck.length; i++) {
204
+ const prop = propsToCheck[i];
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]);
207
211
  }
208
212
  }
209
- }
210
- if (animateTags.has(tagName)) {
211
- const attr = attribs.attributeName;
212
- if (propsToCheck.indexOf(attr) !== -1) {
213
- for (let i = 0; i < animatePropsToCheck.length; i++) {
214
- const elementProp = animatePropsToCheck[i];
215
- const fullValue = attribs[elementProp];
216
- if (typeof fullValue !== "string") {
217
- continue;
218
- }
219
- const splitValues = fullValue.split(";");
220
- let updatedValues = false;
221
- for (let j = 0; j < splitValues.length; j++) {
222
- const value = splitValues[j];
223
- if (value !== void 0) {
224
- const newValue = await checkColor(
225
- elementProp,
226
- value
227
- // Do not pass third parameter
228
- );
229
- if (newValue !== value) {
230
- updatedValues = true;
231
- splitValues[j] = typeof newValue === "string" ? newValue : "";
213
+ const parsePropsQueue = () => {
214
+ const queueItem = propsQueue.shift();
215
+ if (!queueItem) {
216
+ return done3();
217
+ }
218
+ const [prop, value] = queueItem;
219
+ context.checkColor(
220
+ (newValue) => {
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);
232
231
  }
233
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;
252
+ }
253
+ propsQueue.push([elementProp, fullValue]);
234
254
  }
255
+ }
256
+ }
257
+ const parsePropsQueue = () => {
258
+ const queueItem = propsQueue.shift();
259
+ if (!queueItem) {
260
+ return done3();
261
+ }
262
+ const [elementProp, fullValue] = queueItem;
263
+ const splitValues = fullValue.split(";");
264
+ let updatedValues = false;
265
+ const parsedAllItems = () => {
235
266
  if (updatedValues) {
236
267
  cheerio(element).attr(
237
268
  elementProp,
238
269
  splitValues.join(";")
239
270
  );
240
271
  }
241
- }
242
- }
272
+ return parsePropsQueue();
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
298
  }
244
- if (!result.hasGlobalStyle) {
245
- let requiredProps;
246
- if (shapeTags.has(tagName)) {
247
- requiredProps = shapeColorAttributes;
248
- }
249
- specialColorAttributes.forEach((attr) => {
250
- if (tagSpecificPresentationalAttributes[tagName]?.has(attr)) {
251
- requiredProps = [attr];
252
- }
253
- });
254
- if (requiredProps) {
255
- const itemColors = element._colors || (element._colors = {});
256
- for (let i = 0; i < requiredProps.length; i++) {
257
- const prop = requiredProps[i];
258
- const color = getElementColor(prop, item, elements);
259
- if (color === defaultBlackColor) {
260
- if (defaultColor) {
261
- const defaultColorValue = typeof defaultColor === "function" ? defaultColor(
299
+ parseCommonProps(() => {
300
+ checkAnimations(() => {
301
+ if (!context.result.hasGlobalStyle) {
302
+ let requiredProps;
303
+ if (shapeTags.has(tagName)) {
304
+ requiredProps = shapeColorAttributes;
305
+ }
306
+ specialColorAttributes.forEach((attr) => {
307
+ if (tagSpecificPresentationalAttributes[tagName]?.has(
308
+ attr
309
+ )) {
310
+ requiredProps = [attr];
311
+ }
312
+ });
313
+ if (requiredProps) {
314
+ const itemColors = element._colors || (element._colors = {});
315
+ for (let i = 0; i < requiredProps.length; i++) {
316
+ const prop = requiredProps[i];
317
+ const color = context.getElementColor(
262
318
  prop,
263
- element,
264
319
  item,
265
- iconData
266
- ) : defaultColor;
267
- findColor(defaultColorValue, true);
268
- cheerio(element).attr(
269
- prop,
270
- colorToString(defaultColorValue)
320
+ elements
271
321
  );
272
- itemColors[prop] = defaultColorValue;
322
+ if (color === defaultBlackColor) {
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);
273
375
  } else {
274
- result.hasUnsetColor = true;
376
+ done(result);
275
377
  }
378
+ } catch (err) {
379
+ reject(err);
276
380
  }
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);
277
393
  }
394
+ });
395
+ }).then(() => {
396
+ try {
397
+ analyseSVG(svg, context, () => {
398
+ fulfill(context.result);
399
+ });
400
+ } catch (err) {
401
+ reject(err);
278
402
  }
279
- }
280
- for (let i = 0; i < item.children.length; i++) {
281
- const childItem = item.children[i];
282
- if (!childItem.usedAsMask) {
283
- await parseTreeItem(childItem);
403
+ }).catch(reject);
404
+ });
405
+ }
406
+ function parseColorsSync(svg, options = {}) {
407
+ const callback = options.callback;
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");
284
420
  }
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");
285
430
  }
286
- }
287
- await parseTreeItem(tree);
288
- return result;
431
+ });
432
+ isSync = false;
433
+ return context.result;
289
434
  }
290
435
  function isEmptyColor(color) {
291
436
  const type = color.type;
292
437
  return type === "none" || type === "transparent";
293
438
  }
294
439
 
295
- export { isEmptyColor, parseColors };
440
+ export { isEmptyColor, parseColors, parseColorsSync };
@@ -17,8 +17,7 @@ require('../svg/data/attributes.cjs');
17
17
  require('../svg/analyse.cjs');
18
18
  require('../svg/analyse/error.cjs');
19
19
 
20
- async function validateColors(svg, expectMonotone, options) {
21
- const palette = await colors_parse.parseColors(svg, options);
20
+ function checkPalette(palette, expectMonotone) {
22
21
  palette.colors.forEach((color) => {
23
22
  if (typeof color === "string") {
24
23
  throw new Error("Unexpected color: " + color);
@@ -50,7 +49,17 @@ async function validateColors(svg, expectMonotone, options) {
50
49
  }
51
50
  }
52
51
  });
52
+ }
53
+ async function validateColors(svg, expectMonotone, options) {
54
+ const palette = await colors_parse.parseColors(svg, options);
55
+ checkPalette(palette, expectMonotone);
56
+ return palette;
57
+ }
58
+ function validateColorsSync(svg, expectMonotone, options) {
59
+ const palette = colors_parse.parseColorsSync(svg, options);
60
+ checkPalette(palette, expectMonotone);
53
61
  return palette;
54
62
  }
55
63
 
56
64
  exports.validateColors = validateColors;
65
+ exports.validateColorsSync = validateColorsSync;
@@ -1,5 +1,5 @@
1
1
  import { SVG } from '../svg/index.js';
2
- import { ParseColorsOptions, FindColorsResult } from './parse.js';
2
+ import { ParseColorsOptions, FindColorsResult, ParseColorsSyncOptions } from './parse.js';
3
3
  import '@iconify/types';
4
4
  import '@iconify/utils/lib/customisations/defaults';
5
5
  import '@iconify/utils/lib/colors/types';
@@ -14,5 +14,13 @@ import '../svg/analyse/types.js';
14
14
  * Throws exception on error
15
15
  */
16
16
  declare function validateColors(svg: SVG, expectMonotone: boolean, options?: ParseColorsOptions): Promise<FindColorsResult>;
17
+ /**
18
+ * Validate colors in icon, synchronous version
19
+ *
20
+ * If icon is monotone,
21
+ *
22
+ * Throws exception on error
23
+ */
24
+ declare function validateColorsSync(svg: SVG, expectMonotone: boolean, options?: ParseColorsSyncOptions): FindColorsResult;
17
25
 
18
- export { validateColors };
26
+ export { validateColors, validateColorsSync };
@@ -1,5 +1,5 @@
1
1
  import { colorToString } from '@iconify/utils/lib/colors';
2
- import { parseColors } from './parse.mjs';
2
+ import { parseColors, parseColorsSync } from './parse.mjs';
3
3
  import '../svg/data/tags.mjs';
4
4
  import '../svg/parse-style.mjs';
5
5
  import '../css/parse.mjs';
@@ -15,8 +15,7 @@ import '../svg/data/attributes.mjs';
15
15
  import '../svg/analyse.mjs';
16
16
  import '../svg/analyse/error.mjs';
17
17
 
18
- async function validateColors(svg, expectMonotone, options) {
19
- const palette = await parseColors(svg, options);
18
+ function checkPalette(palette, expectMonotone) {
20
19
  palette.colors.forEach((color) => {
21
20
  if (typeof color === "string") {
22
21
  throw new Error("Unexpected color: " + color);
@@ -48,7 +47,16 @@ async function validateColors(svg, expectMonotone, options) {
48
47
  }
49
48
  }
50
49
  });
50
+ }
51
+ async function validateColors(svg, expectMonotone, options) {
52
+ const palette = await parseColors(svg, options);
53
+ checkPalette(palette, expectMonotone);
54
+ return palette;
55
+ }
56
+ function validateColorsSync(svg, expectMonotone, options) {
57
+ const palette = parseColorsSync(svg, options);
58
+ checkPalette(palette, expectMonotone);
51
59
  return palette;
52
60
  }
53
61
 
54
- export { validateColors };
62
+ export { validateColors, validateColorsSync };
@@ -1,11 +1,10 @@
1
1
  'use strict';
2
2
 
3
- const fetch = require('node-fetch');
4
3
  const util = require('util');
5
4
  const stream = require('stream');
6
- const fs = require('fs');
5
+ const promises = require('fs/promises');
7
6
 
8
- const streamPipeline = util.promisify(stream.pipeline);
7
+ util.promisify(stream.pipeline);
9
8
  async function downloadFile(query, target) {
10
9
  const params = query.params ? query.params.toString() : "";
11
10
  const url = query.uri + (params ? "?" + params : "");
@@ -16,7 +15,8 @@ async function downloadFile(query, target) {
16
15
  if (!response.ok || !response.body) {
17
16
  throw new Error(`Error downloading ${url}: ${response.status}`);
18
17
  }
19
- await streamPipeline(response.body, fs.createWriteStream(target));
18
+ const data = await response.arrayBuffer();
19
+ await promises.writeFile(target, Buffer.from(data));
20
20
  }
21
21
 
22
22
  exports.downloadFile = downloadFile;
@@ -1,9 +1,8 @@
1
- import fetch from 'node-fetch';
2
1
  import { promisify } from 'util';
3
2
  import { pipeline } from 'stream';
4
- import { createWriteStream } from 'fs';
3
+ import { writeFile } from 'fs/promises';
5
4
 
6
- const streamPipeline = promisify(pipeline);
5
+ promisify(pipeline);
7
6
  async function downloadFile(query, target) {
8
7
  const params = query.params ? query.params.toString() : "";
9
8
  const url = query.uri + (params ? "?" + params : "");
@@ -14,7 +13,8 @@ async function downloadFile(query, target) {
14
13
  if (!response.ok || !response.body) {
15
14
  throw new Error(`Error downloading ${url}: ${response.status}`);
16
15
  }
17
- await streamPipeline(response.body, createWriteStream(target));
16
+ const data = await response.arrayBuffer();
17
+ await writeFile(target, Buffer.from(data));
18
18
  }
19
19
 
20
20
  export { downloadFile };
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const fetch = require('node-fetch');
4
3
  const download_api_cache = require('./cache.cjs');
5
4
  require('fs');
6
5
  require('crypto');
@@ -1,4 +1,3 @@
1
- import fetch from 'node-fetch';
2
1
  import { apiCacheKey, getAPICache, storeAPICache } from './cache.mjs';
3
2
  import 'fs';
4
3
  import 'crypto';
@@ -23,11 +23,11 @@ require('@iconify/utils/lib/icon-set/convert-info');
23
23
  require('../../icon-set/props.cjs');
24
24
  require('@iconify/utils/lib/misc/objects');
25
25
  require('@iconify/utils/lib/colors');
26
- require('node-fetch');
27
26
  require('crypto');
28
27
  require('../api/download.cjs');
29
28
  require('util');
30
29
  require('stream');
30
+ require('fs/promises');
31
31
  require('extract-zip');
32
32
  require('tar');
33
33
 
@@ -21,11 +21,11 @@ import '@iconify/utils/lib/icon-set/convert-info';
21
21
  import '../../icon-set/props.mjs';
22
22
  import '@iconify/utils/lib/misc/objects';
23
23
  import '@iconify/utils/lib/colors';
24
- import 'node-fetch';
25
24
  import 'crypto';
26
25
  import '../api/download.mjs';
27
26
  import 'util';
28
27
  import 'stream';
28
+ import 'fs/promises';
29
29
  import 'extract-zip';
30
30
  import 'tar';
31
31